/** * Method findIn constructs a new XMLPath starting in a string source. * * @param source the source. * @return XMLPath. */ public XMLPath findIn(final String source) { return findIn(DOMParser.createNew().parse(new InputSource(new StringReader(source)))); }
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()); }
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); }
public void debugPDPRequest(final Element request) { StringBuilder text = new StringBuilder(); NodeList requestChildNodes = XMLPathCtx.createNew().findIn(request).all("/*[local-name() = 'Request']/*").get(); for (int i = 0; i < requestChildNodes.getLength(); i++) { Element requestChild = (Element) requestChildNodes.item(i); text.append(requestChild.getLocalName()).append("\n"); appendAttributes(text, XMLPathCtx.createNew().findIn(requestChild).all(".//*[local-name()='AttributeValue']").get()); } LOG.debug("PDP request\n" + text); }
/** * Method findIn constructs a new XMLPath starting in a InputSource source. * * @param source the source. * @return XMLPath. */ public XMLPath findIn(final InputSource source) { return findIn(DOMParser.createNew().parse(source)); }
public void setOperationUrls(String opUrl) { NodeList hrefNodes = m_xPathCtx.findIn(m_capsDoc).all("//ows:Operation/ows:DCP/ows:HTTP/*/@xlink:href").get(); for (int i = 0; i < hrefNodes.getLength(); i++) { Node hrefNode = hrefNodes.item(i); hrefNode.setTextContent(opUrl); } }
public String getValue(Node rootNode, XMLPathCtx context) { String nameSpaceURI = getNamespaceURI(rootNode); if (startsWith ? nameSpaceURI.startsWith(namespace) : nameSpaceURI.equals(namespace)) { if (nodeExists != null && context.findIn(rootNode).node(nodeExists).get() != null) { return value; } else { return value; } } return null; } }
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()); }
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); }
private Node getSecuredServiceTypeNode() { Node securedServiceTypeNode = m_xPathCtx.findIn(m_capsDoc).node("//wss:SecuredServiceType").get(); return securedServiceTypeNode; }
public void setAuthenticationMethods(Collection<AuthenticationMethod> methods) { Node newSuppAuthMethodsElem = m_capsDoc.createElementNS("http://www.gdi-nrw.org/wss", "SupportedAuthenticationMethodList"); Node capabilityElement = m_xPathCtx.findIn(m_capsDoc).node("//wss:Capability").get(); Node lOldSuppAuthMethodsElem = m_xPathCtx.findIn(capabilityElement).node("//wss:Capability/wss:SupportedAuthenticationMethodList").get(); if (lOldSuppAuthMethodsElem != null) { capabilityElement.removeChild(lOldSuppAuthMethodsElem); } AuthenticationMethodDOMRenderer renderer = new AuthenticationMethodDOMRenderer(); for (AuthenticationMethod method : methods) { Element authMethodElem = renderer.render(method); Node importedNode = m_capsDoc.importNode(authMethodElem, true); newSuppAuthMethodsElem.appendChild(importedNode); } capabilityElement.appendChild(newSuppAuthMethodsElem); }
public List<SAML2IdPMetadata> getIdPMetadata() { XMLPathCtx xpathCtx = XMLPathCtx.createNew().addNamespace("md", "urn:oasis:names:tc:SAML:2.0:metadata"); NodeList idpList = xpathCtx.findIn(m_federationMetadata).all("//md:IDPSSODescriptor").get(); List<SAML2IdPMetadata> mdList = new ArrayList<SAML2IdPMetadata>(); for (int i = 0; i < idpList.getLength(); i++) { Element idpSsoDescriptor = (Element) idpList.item(i); try { SAML2IdPMetadata idPMetadata = SAML2IdPMetadata.createFrom(idpSsoDescriptor); mdList.add(idPMetadata); } catch (MalformedURLException e) { LOG.error("Skipping IDPSSODescriptor element", e); } } return mdList; }
public void setLicensePrecondition(LicensePrecondition licenseProcondition) { if (licenseProcondition == null) { return; } Node caproot = m_xPathCtx.findIn(m_capsDoc).node("//wss:Capability").get(); String baseUrl = licenseProcondition.getBaseUrl(); String redirectUrl = licenseProcondition.getRedirectUrl(); String ssoUrl = licenseProcondition.getSsoGetUrl(); String filledTemplate = String.format(licensePreconditionTemplate, baseUrl, ssoUrl, redirectUrl, baseUrl); StringReader reader = new StringReader(filledTemplate); Document templateDoc = DOMParser.createNew().parse(new InputSource(reader)); Node importedTemplateNode = m_capsDoc.importNode(templateDoc.getDocumentElement(), true); caproot.appendChild(importedTemplateNode); }
public Element getAuthnRequest() { return (Element) getXpathCtx().findIn( m_paosResponse).node("//samlp:AuthnRequest").get(); }
public String getAssertionConsumerUrl() { return getXpathCtx().findIn( m_paosResponse).text("//samlp:AuthnRequest/@AssertionConsumerServiceURL").get(); }
private Node find(final String xpath) { Node node = XMLPathCtx.createNew().addNamespaces(namespaces).findIn(sourceDocument).node(xpath).get(); if (node == null) { throw new IllegalArgumentException("XPath <" + xpath + "> must resolve to an node"); } return (Element) node; }
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; }
public Element getRelayState() { return (Element) getXpathCtx().findIn(m_paosResponse).node("//ecp:RelayState").get(); }
private void fillObligationFromElem(ObligationType obligation, Element oblElem) { String oblId = oblElem.getAttribute("ObligationId"); String oblFulfillOn = oblElem.getAttribute("FulfillOn"); obligation.setObligationId(oblId); obligation.setFulfillOn(EffectType.Enum.forString(oblFulfillOn)); NodeList attrAssignmentElems = xmlPathCtx.findIn(oblElem).all("./p:AttributeAssignment").get(); for (int i = 0; i < attrAssignmentElems.getLength(); i++) { Element attAssignmentElem = (Element) attrAssignmentElems.item(i); String attributeId = attAssignmentElem.getAttribute("AttributeId"); AttributeAssignmentType attributeAssignment = obligation.addNewAttributeAssignment(); attributeAssignment.setAttributeId(attributeId); attributeAssignment.setDataType(attAssignmentElem.getAttribute("DataType")); ((XmlObjectBase) attributeAssignment).setStringValue("Three"); } } }
/** * 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; }