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); }
/** * Get position from feature node. * * @param node * feature * @return position as text */ private String getPositionFromSamplingPoint(Node node) { NodeList nl = ctx.findIn(node) .all("./" + SOSInterceptorGlobals.ELEMENT_SA_POSITION + "/" + SOSInterceptorGlobals.ELEMENT_GML_POINT + "/" + SOSInterceptorGlobals.ELEMENT_GML_POS).get(); for (int i = 0; i < nl.getLength();) { return nl.item(i).getTextContent(); } return "0 0"; }
/** * Get position from feature node. * * @param node * feature * @return position as text */ private String getPositionFromSamplingPoint(Node node) { NodeList nl = ctxResponse .findIn(node) .all("./" + SOSInterceptorGlobals.ELEMENT_SA_POSITION + "/" + SOSInterceptorGlobals.ELEMENT_GML_POINT + "/" + SOSInterceptorGlobals.ELEMENT_GML_POS).get(); for (int i = 0; i < nl.getLength();) { return nl.item(i).getTextContent(); } return "0 0"; }
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); } }
/** * Get EPSG code from feature node. * * @param node * feature * @return EPSG code */ private String getEpsgCodeFromPosition(Node node) { NodeList nl = ctxResponse .findIn(node) .all("./" + SOSInterceptorGlobals.ELEMENT_SA_POSITION + "/" + SOSInterceptorGlobals.ELEMENT_GML_POINT + "/" + SOSInterceptorGlobals.ELEMENT_GML_POS).get(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).hasAttributes()) { NamedNodeMap attributes = nl.item(i).getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { if (attributes.item(i).getLocalName().equalsIgnoreCase(SOSInterceptorGlobals.ATTRIBUTE_SRS_NAME)) { return attributes.item(i).getTextContent(); } } } } return ""; }
/** * Get EPSG code from feature node. * * @param node * feature * @return EPSG code */ private String getEpsgCodeFromPosition(Node node) { NodeList nl = ctx.findIn(node) .all("./" + SOSInterceptorGlobals.ELEMENT_SA_POSITION + "/" + SOSInterceptorGlobals.ELEMENT_GML_POINT + "/" + SOSInterceptorGlobals.ELEMENT_GML_POS).get(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).hasAttributes()) { NamedNodeMap attributes = nl.item(i).getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { if (attributes.item(i).getLocalName().equalsIgnoreCase(SOSInterceptorGlobals.ATTRIBUTE_SRS_NAME)) { return attributes.item(i).getTextContent(); } } } } return ""; }
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; }
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); }
.all("//*/ows:Operation[@name='" + entry.getKey() + "']/ows:DCP/ows:HTTP/ows:" + SOSInterceptorGlobals.GET).get(); for (int i = 0; i < nl.getLength(); i++) { .all("//*/ows:Operation[@name='" + entry.getKey() + "']/ows:DCP/ows:HTTP/ows:" + SOSInterceptorGlobals.POST).get(); for (int i = 0; i < nl.getLength(); i++) {
public Payload replace(String pOldURL, Transferable res, String pEncoding, String pMimeType) { Document doc = DOMParser.createNew().parse(new InputSource(res.getPayload().getAsStream())); XMLPathCtx ctx = XMLPathCtx.createNew(); NodeList nodes = ctx.findIn(doc).all("//OnlineResource").get(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getParentNode().getParentNode().getLocalName().equals("HTTP")) { String name = node.getParentNode().getLocalName(); node.getParentNode().getParentNode().replaceChild(buildReplacement(name, doc), node.getParentNode()); } } // WMS 1.? // TODO extend XPath for POST nodes: //DCPType/HTTP/*[self::Get // or self::Post]/OnlineResource // WFS 1.1 // TODO extend XPath for POST nodes: // //ows:Operation/ows:DCP/ows:HTTP/*[self::ows:Get or // self::ows:Post] // WFS 1.0 // TODO add XPath for WFS 1.0.0: //DCPType/HTTP/*[self::Get or // self::Post]/@onlineResource DOMSerializer serializer = DOMSerializer.createNew(); String response = serializer.serializeToString(doc); Pattern lPattern = Pattern.compile(pOldURL.replaceAll("\\?", "\\\\?")); Matcher mMatcher = lPattern.matcher(response); response = mMatcher.replaceAll(m_gatekeeperURL); sLogger.debug("Modified ResponseDocument:\n" + response); return new TextualPayload(response, pEncoding); }
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"); } } }
NodeList nl = ctx.findIn(doc).all("//*/ows:Operation[@name]").get(); Map<String, Node> nodesMap = new HashMap<String, Node>();
innerMap.put("title", title); innerMap.put("resourceType", lResourceType); NodeList identifiers = context.findIn(record).all("//gmd:identificationInfo[1]/*/gmd:citation/*/gmd:identifier/*").get(); List<String> resourceIdList = new ArrayList<>(); for (int i = 0; i < identifiers.getLength(); i++) {
NodeList nodes = xmlPathContextFactory.createContext().findIn(lDoc).all("//" + mMultiElementName + "/*").get(); for (int i = 0; i < nodes.getLength(); i++) { String nodeStr = DOMUtil.nodeToString(nodes.item(i));
NodeList nl = ctx.findIn(doc).all("/wps:Capabilities/wps:ProcessOfferings/wps:Process/ows:Identifier/text()").get(); for (int i = 0; i < nl.getLength(); i++) { Node processIdTextNode = nl.item(i);
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; } }
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; }
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; }
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"); }
/** * 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); } } } }