org.n52.security.common.xml.XMLPathCtx类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中org.n52.security.common.xml.XMLPathCtx类的一些代码示例,展示了XMLPathCtx类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLPathCtx类的具体详情如下:
包路径:org.n52.security.common.xml.XMLPathCtx
类名称:XMLPathCtx

XMLPathCtx介绍

[英]Encapsulates context informations for xpath expressions.

Use this class to create new XMLPath objectes and combinations of them.

This class wraps the javax.xml.xpath package with performance improvments and simpler useage.
[中]封装xpath表达式的上下文信息。
使用此类创建新的XMLPath对象及其组合。
这个类包装了javax。xml。xpath包,性能改进,使用更简单。

代码示例

代码示例来源:origin: org.n52.security/52n-security-facade

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;
}

代码示例来源:origin: org.n52.security/52n-security-core

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;
}

代码示例来源:origin: org.n52.security/52n-security-core

/**
 * Method creates a new XMLPathCtx instance. The instance uses the internaly
 * xpath instance pool.
 *
 * @return XMLPathCtx.
 */
public static XMLPathCtx createNew() {
  return new XMLPathCtx(getGlobalXPathPool());
}

代码示例来源:origin: org.n52.security/52n-security-decision-xacml

XACML2ResponseChunkHandler(List<ResponseDocument> responseSet) {
  m_responseSet = responseSet;
  xmlPathCtx = XMLPathCtx.createNew();
  xmlPathCtx.addNamespace("c", "urn:oasis:names:tc:xacml:2.0:context:schema:os").addNamespace("p",
      "urn:oasis:names:tc:xacml:2.0:policy:schema:os");
}

代码示例来源:origin: org.n52.metadata/smarteditor-api

public TemplateFactory(Map<String, String> namespaces) {
  context = XMLPathCtx.createNew();
  context.addNamespaces(namespaces);
}

代码示例来源:origin: org.n52.security/52n-security-core

/**
 * 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))));
}

代码示例来源:origin: org.n52.security/52n-security-decision-xacml

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);
}

代码示例来源:origin: org.n52.metadata/smarteditor-api

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());
}

代码示例来源:origin: org.n52.security/52n-security-decision-xacml

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);
}

代码示例来源:origin: org.n52.security/52n-security-wss

private WSSCapabilitiesDocument(Document capsDoc) {
  m_capsDoc = capsDoc;
  m_xPathCtx = XMLPathCtx.createNew();
  m_xPathCtx.addNamespace("authn", "http://www.gdi-nrw.org/authn");
  m_xPathCtx.addNamespace("xlink", "http://www.w3.org/1999/xlink");
  m_xPathCtx.addNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  m_xPathCtx.addNamespace("licb", "http://www.conterra.de/licb");
  m_xPathCtx.addNamespace("ows", "http://www.opengis.net/ows");
  m_xPathCtx.addNamespace("wss", "http://www.gdi-nrw.org/wss");
  m_editor = new Editor();
  m_parser = new Parser();
}

代码示例来源:origin: org.n52.metadata/smarteditor-api

public XPathContextFactory(Map<String, String> namespaces) {
  xmlPathCtx = XMLPathCtx.createNew();
  xmlPathCtx.addNamespaces(namespaces);
}

代码示例来源:origin: org.n52.security/52n-security-enforcement-impl

XMLPathCtx.createNew().addNamespace("ows", "http://www.opengis.net/ows/1.1")
    .addNamespace("sos", "http://www.opengis.net/sos/1.0");
  ctx.findIn(doc)
      .all("//*/ows:Operation[@name='" + entry.getKey() + "']/ows:DCP/ows:HTTP/ows:"
          + SOSInterceptorGlobals.GET).get();
  ctx.findIn(doc)
      .all("//*/ows:Operation[@name='" + entry.getKey() + "']/ows:DCP/ows:HTTP/ows:"
          + SOSInterceptorGlobals.POST).get();

代码示例来源:origin: org.n52.metadata/smarteditor-api

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);
}

代码示例来源:origin: org.n52.security/52n-security-core

/**
 * 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);
}

代码示例来源:origin: org.n52.security/52n-security-facade

public PAOSResponse(Element paosResponse) {
  m_paosResponse = paosResponse;
  setXpathCtx(XMLPathCtx.createNew().addNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol").addNamespace(
      "ecp", "urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp"));
}

代码示例来源:origin: org.n52.security/52n-security-facade

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;
}

代码示例来源:origin: org.n52.security/52n-security-enforcement-impl

/**
 * 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";
}

代码示例来源:origin: org.n52.security/52n-security-gatekeeper

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);
}

代码示例来源:origin: org.n52.metadata/smarteditor-api

/**
 * Class constructor.
 * <p/>
 * <p>
 * Within this initialization, the classloader searches the xml configuration file <br>
 * called 'catalog_api_factory.xml' that needs to be in the classpath. If not, the <br>
 * initialization of the factory fails.
 * </p>
 */
public BuilderFactory() {
  InputStream is = BuilderFactory.class.getResourceAsStream("/catalog_api_factory.xml");
  if (is != null) {
    mRoot = DOMUtil.createFromStream(is, null);
    xmlPathCtx = XMLPathCtx.createNew();
    xmlPathCtx.addNamespace("api", "http://www.conterra.de/catalog/config/catapi");
  } else {
    LOG.error("Could not find 'catalog_api_factory.xml' in CLASSPATH. BuilderFactory is not available");
    mRoot = null;
  }
}

代码示例来源:origin: org.n52.security/52n-security-enforcement-impl

XMLPathCtx.createNew().addNamespace("ows", "http://www.opengis.net/ows/1.1")
        .addNamespace("sos", "http://www.opengis.net/sos/1.0");
NodeList nl = ctx.findIn(doc).all("//*/ows:Operation[@name]").get();
Map<String, Node> nodesMap = new HashMap<String, Node>();

相关文章