private void buildExtentTemplate(Document document, Map<String, String> hashMap, XMLPathCtx xmlPathCtx) { hashMap.put("west", xmlPathCtx.findIn(document).text("//gmd:westBoundLongitude/*/text()").get()); hashMap.put("east", xmlPathCtx.findIn(document).text("//gmd:eastBoundLongitude/*/text()").get()); hashMap.put("north", xmlPathCtx.findIn(document).text("//gmd:northBoundLatitude/*/text()").get()); hashMap.put("south", xmlPathCtx.findIn(document).text("//gmd:southBoundLatitude/*/text()").get()); }
private void buildPartyTemplate(Document document, Map<String, String> hashMap, XMLPathCtx xmlPathCtx) { hashMap.put("IndividualName", xmlPathCtx.findIn(document).text("//gmd:individualName/*/text()").get()); hashMap.put("PositionName", xmlPathCtx.findIn(document).text("//gmd:positionName/*/text()").get()); hashMap.put("OrganisationName", xmlPathCtx.findIn(document).text("//gmd:organisationName/*/text()").get()); hashMap.put("Voice", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:phone/*/gmd:voice/*/text()").get()); hashMap.put("Fax", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:phone/*/gmd:facsimile/*/text()").get()); hashMap.put("DeliveryPoint", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:address/*/gmd:deliveryPoint/*/text()").get()); hashMap.put("City", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:address/*/gmd:city/*/text()").get()); hashMap.put("AdministrativeArea", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:address/*/gmd:administrativeArea/*/text()").get()); hashMap.put("PostalCode", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:address/*/gmd:postalCode/*/text()").get()); hashMap.put("Country", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:address/*/gmd:country/*/text()").get()); hashMap.put("MailAddress", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:address/*/gmd:electronicMailAddress/*/text()").get()); hashMap.put("Role", xmlPathCtx.findIn(document).text("//gmd:role/*/@codeListValue").get()); hashMap.put("Url", xmlPathCtx.findIn(document).text("//gmd:contactInfo/*/gmd:onlineResource/*/gmd:linkage/gmd:URL").get()); }
/** * Load a builder class defined in '/catalog_api_factory.xml' * * @param pType xml or kvp is standard, any other type might be given also * @param pName Name of the REquest (GetRecords, GetCapabilities, ect) * @return Class or null, if not loaded */ protected Class loadClass(String pType, String pName) { String lExpression = "//api:BuilderFactory/api:Group[@type='" + pType + "']/api:Builder[@name='" + pName + "']/api:class"; LOG.debug("Evaluating expression: {} ", lExpression); String className = xmlPathCtx.findIn(mRoot).text(lExpression).get(); if (className == null) { LOG.warn(lExpression + " could not be evaluated. Result is null."); return null; } try { return Class.forName(className); } catch (ClassNotFoundException e) { LOG.error(e.getMessage()); return null; } }
private void debugPDPResponse(Element response) { StringBuilder text = new StringBuilder(); String resourceId = XMLPathCtx.createNew().findIn(response).text("//*[local-name() = 'Result']/@ResourceId").get(); String decision = XMLPathCtx.createNew().findIn(response).text("//*[local-name() = 'Result']/*[local-name() = 'Decision']/text()").get(); text.append("Resource: \t").append(resourceId ).append("\n"); text.append("Decision: \t").append(decision).append("\n"); NodeList obligationNodes = XMLPathCtx.createNew().findIn(response).all("//*[local-name() = 'Obligation']").get(); for (int i = 0; i < obligationNodes.getLength(); i++) { Element obligationElem = (Element) obligationNodes.item(i); String oblId = obligationElem.getAttribute("ObligationId"); String fulfillOn = obligationElem.getAttribute("FulfillOn"); text.append("Obligation: \t").append(oblId ).append("(fulfillOn:").append(fulfillOn).append(")\n"); appendAttributeAssignments(text, XMLPathCtx.createNew().findIn(obligationElem).all(".//*[local-name()='AttributeAssignment']").get()); } LOG.debug("PDP response\n" + text); }
String fileIdentifier = xmlPathContextFactory.createContext().findIn(document).text("//gmd:fileIdentifier/gco:CharacterString/text()").get();
public String getTemplateFor(Document document) { Node rootNode = context.findIn(document).node("/*[1]").get(); String serviceType = getServiceTypeFrom(rootNode); String version = context.findIn(rootNode).text("@version").get(); return version.equals("") ? templateMap.get(serviceType) : templateMap.get(serviceType + "_" + version); }
for (Document record : records) { Map<String, Object> innerMap = new HashMap<>(); String fileIdentifier = context.findIn(record).text("//gmd:fileIdentifier[1]/*/text()").get(); String title = context.findIn(record).text("//gmd:identificationInfo[1]/*/gmd:citation/*/gmd:title/*/text()").get(); String lResourceType = context.findIn(record).text("//gmd:hierarchyLevel[1]/*/@codeListValue").get(); innerMap.put("title", title); innerMap.put("resourceType", lResourceType); for (int i = 0; i < identifiers.getLength(); i++) { Node node = identifiers.item(i); String code = context.findIn(node).text("gmd:code/*/text()").get(); String codeSpace = context.findIn(node).text("gmd:codeSpace/*/text()").get(); StringBuilder stringBuilder = new StringBuilder(); if (!StringUtils.isEmpty(codeSpace)) {
public String getAssertionConsumerUrl() { return getXpathCtx().findIn( m_paosResponse).text("//samlp:AuthnRequest/@AssertionConsumerServiceURL").get(); }
/** * Creates an instance of this class from an XML file. * * @param in * a service excpetion XML document * * @return * @throws org.xml.sax.SAXException * @throws IOException */ public static ServiceException createFromXML(InputSource in) { Document excDoc = DOMParser.createNew().parse(in); XMLPathCtx pathCtx = XMLPathCtx.createNew(); String cd = pathCtx.findIn(excDoc).text("//ServiceException/@code").get().trim(); if (cd.equals("")) cd = "No code available"; String msg = pathCtx.findIn(excDoc).text("//ServiceException/text()").get().trim(); if (msg.equals("")) msg = "No exception information available"; return new ServiceException(msg, cd); }
private List<AuthenticationMethod> getSupportedAuthenticationMethods() { List<AuthenticationMethod> supportedAuthNMethods = new ArrayList<AuthenticationMethod>(); NodeList authenticationMethodList = m_xPathCtx.findIn(m_capsDoc).all("//authn:AuthenticationMethod").get(); for (int i = 0; i < authenticationMethodList.getLength(); i++) { org.w3c.dom.Node currentAuthMethod = authenticationMethodList.item(i); String type = m_xPathCtx.findIn(currentAuthMethod).text("@xsi:type").get(); type = type.substring(type.lastIndexOf(":") + 1); String method = m_xPathCtx.findIn(currentAuthMethod).text("@method").get(); AuthenticationMethod supportedAuthMethod; if (type.equals("WASType")) { org.w3c.dom.Node accAuthNServiceNode = m_xPathCtx.findIn(currentAuthMethod).node("//authn:AuthenticationService").get(); String wasName = m_xPathCtx.findIn(accAuthNServiceNode).text("authn:Name/text()").get(); String wasUrl = m_xPathCtx.findIn(accAuthNServiceNode).text("authn:OnlineResource/@xlink:href").get(); supportedAuthMethod = new org.n52.security.authentication.WASAuthenticationMethod(wasName, wasUrl, ""); } else { supportedAuthMethod = AuthenticationMethodFactory.getDefault().create(method); } supportedAuthNMethods.add(supportedAuthMethod); } return supportedAuthNMethods; } }
@RequestMapping(value = "/saveTemplate", method = RequestMethod.POST) public void saveTemplate(HttpServletResponse response) throws Exception { // get backend document Document mergeBackend = backendManagerService.mergeBackend(); String title = xmlPathContextFactory.createContext().findIn(mergeBackend).text("//gmd:title/*/text()").get(); try { templateManager.saveTemplate(title, "MD_Metadata", userInfoBean.getUserId() != null ? userInfoBean.getUserId() : "", userInfoBean.getGroupId() != null ? userInfoBean.getGroupId() : "", "public", DOMUtil.convertToString(mergeBackend, false)); } catch (Exception e) { LOG.error(e.getMessage()); response.sendError(500, e.getMessage()); } LOG.info("Template saved..."); } }
/** * @return */ public LicensePrecondition getLicensePrecondition() { org.w3c.dom.Node licBroClientElement = m_xPathCtx.findIn(m_capsDoc).node("/wss:WSS_Capabilities/wss:Capability/licb:LicensePrecondition/licb:LicenseBrokerClient").get(); if (licBroClientElement == null) { return null; } String licenseRedirectURL = m_xPathCtx.findIn(licBroClientElement).text("licb:RedirectURL/text()").get(); String ssoGetURL = m_xPathCtx.findIn(licBroClientElement).text("licb:SSOGetURL").get(); if (licenseRedirectURL == null && ssoGetURL == null) { String baseUrl = m_xPathCtx.findIn(licBroClientElement).text("ows:DCP/ows:HTTP/ows:Post/text()").get(); if (baseUrl == null) { return null; } baseUrl = ensureSingleEndingSlash(baseUrl); licenseRedirectURL = baseUrl + "getOrCreateLicenseToken.faces"; ssoGetURL = baseUrl + "getLicenseToken.faces"; } LicensePrecondition licensePrecondition = new LicensePrecondition(ssoGetURL.trim(), licenseRedirectURL.trim(), null); return licensePrecondition; }
private ResponseDocument convertToXACML1XmlBeanResponse(String xmlChunk) { Document responseChunk = DOMParser.createNew().parse(new InputSource(new StringReader(xmlChunk))); ResponseDocument responseDoc = ResponseDocument.Factory.newInstance(); ResponseType response = responseDoc.addNewResponse(); ResultType result = response.addNewResult(); result.setDecision(DecisionType.Enum.forString(xmlPathCtx.findIn(responseChunk).text("/c:Response/c:Result[1]/c:Decision/text()").get())); result.setResourceId(xmlPathCtx.findIn(responseChunk).text("/c:Response/c:Result[1]/@ResourceId").get()); NodeList obligationNodes = xmlPathCtx.findIn(responseChunk).all("/c:Response/c:Result[1]/p:Obligations/*").get(); ObligationsType obligations; if (obligationNodes.getLength() > 0) { obligations = result.addNewObligations(); for (int i = 0; i < obligationNodes.getLength(); i++) { Element oblElem = (Element) obligationNodes.item(i); fillObligationFromElem(obligations.addNewObligation(), oblElem); } } return responseDoc; }
/** * Simply determines the resource type from the current backend * * @return */ public String getResourceType() { if (getMergeDocument() != null) { return xmlPathContextFactory.createContext().findIn(getMergeDocument()).text("//gmd:hierarchyLevel/*/@codeListValue").get(); } return null; }
String offeringID = xPath.findIn(offering).text("@gml:id").get(); String lcContent = xPath.findIn(actual).text("gml:Envelope/gml:lowerCorner/text()").get(); String ucContent = xPath.findIn(actual).text("gml:Envelope/gml:upperCorner/text()").get(); String bpContent = xPath.findIn(timePeriod).text("gml:beginPosition/text()").get(); String epContent = xPath.findIn(timePeriod).text("gml:endPosition/text()").get();
public static SAML2IdPMetadata createFrom(Element idpSsoDescrElement) throws MalformedURLException { XMLPathCtx xpathCtx = XMLPathCtx.createNew().addNamespace("md", "urn:oasis:names:tc:SAML:2.0:metadata"); NodeList nodeList = xpathCtx.findIn(idpSsoDescrElement).all("md:SingleSignOnService").get(); SAML2IdPMetadata metadata = new SAML2IdPMetadata(); for (int i = 0; i < nodeList.getLength(); i++) { Element ssoService = (Element) nodeList.item(i); String binding = ssoService.getAttribute("Binding"); String location = ssoService.getAttribute("Location"); metadata.addSSOBinding(binding, new URL(location)); } Element organizationElem = (Element) xpathCtx.findIn(idpSsoDescrElement).node("./../md:Organization").get(); if (organizationElem == null) { String entityID = xpathCtx.findIn(idpSsoDescrElement).text("./../@entityID").get(); metadata.setOrganisationDisplayName(entityID); } else { String idpDisplayName = xpathCtx.findIn(organizationElem).text("md:OrganizationDisplayName/text()").get(); metadata.setOrganisationDisplayName(idpDisplayName); } return metadata; }
/** * validates the backend bean properties against a given schematron (or else) validator * * @param target * @param errors */ public void validate(Object target, Errors errors) { BackendBean lBean = (BackendBean) target; // chekc if we need to validate if (lBean.getValidatorId() != null && !lBean.getValidatorId().equals("")) { // apply schematron transformation Document lReport = mService.validate(lBean.getValidatorId()); // add assertions to errors. XMLPathCtx context = xmlPathContextFactory.createContext(); NodeList nodeList = context.findIn(lReport).all("//svrl:failed-assert").get(); for (int i = 0; i < nodeList.getLength(); i++) { Node lNode = nodeList.item(i); String id = context.findIn(lNode).text("@id").get(); String text = context.findIn(lNode).text("svrl:text").get(); errors.rejectValue(id,text); } } } }
private void addNodes(Node pNode, ITreeNode pTreeNode) { ITreeNode lCurrentNode = new TreeNode(); String lValue = xmlPathContextFactory.createContext().findIn(pNode).text("value").get(); String lName = xmlPathContextFactory.createContext().findIn(pNode).text("name").get(); LOG.debug("Node name is: {}", lName); LOG.debug("Node value is: {}", lValue); // add to pTreeNode if (pTreeNode.getName().equals("")) { pTreeNode.setId(lValue); pTreeNode.setName(lName); pTreeNode.setType(lValue); lCurrentNode = pTreeNode; } else { lCurrentNode.setId(lValue); lCurrentNode.setName(lName); lCurrentNode.setType(lValue); pTreeNode.addChild(lCurrentNode); } lCurrentNode.setObject(new HashMap<>(getDefaultOptions())); LOG.debug("added node with id {}", lCurrentNode.getId()); // has lChildrenList? NodeList lChildrenList = xmlPathContextFactory.createContext().findIn(pNode).all("./node").get(); if (lChildrenList != null) { LOG.debug("Node has ChildrenList"); for (int i = 0; i < lChildrenList.getLength(); i++) { addNodes(lChildrenList.item(i), lCurrentNode); } } LOG.debug("node has no ChildrenList"); }