Package javax.xml.xpath

Examples of javax.xml.xpath.XPath


    return null;
  }
 
  public String[] getMQs() {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    Object result;
    try {
      XPathExpression expr =
        xpath.compile("/stratcon/iep/mq/@type");
      result = expr.evaluate(doc, XPathConstants.NODESET);
    }
    catch(XPathExpressionException e) {
      System.err.println("Bad expression: " + e.getMessage());
      return null;
View Full Code Here


    return getIepParameter("mq[@type=\"" + type + "\"]", param);
  }
 
  public String getIepParameter(String which, String param) {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    Object result;
    try {
      XPathExpression expr =
        xpath.compile("/stratcon/iep/" + which + "/" + param + "/text()");
      result = expr.evaluate(doc, XPathConstants.NODESET);
    }
    catch(XPathExpressionException e) {
      System.err.println("Bad expression: " + e.getMessage());
      return null;
View Full Code Here

        DocumentBuilder builder = factory.newDocumentBuilder();
        String validXml = ParserUtil.checkUnicodeString(page.getContent());
        fel.getContext().set("$page_content", validXml);
        Document doc = builder.parse(new ByteArrayInputStream(validXml.getBytes()));
        XPathFactory xfactory = XPathFactoryImpl.newInstance();
        XPath xpathParser = xfactory.newXPath();
        //设置命名空间
        xpathParser.setNamespaceContext(new NamespaceContext() {
            public String getPrefix(String uri) {
                throw new UnsupportedOperationException();
            }
            public Iterator<?> getPrefixes(String uri) {
                throw new UnsupportedOperationException();
            }
      public String getNamespaceURI(String prefix) {
        if (prefix == null)
          throw new NullPointerException("Null prefix");
        else {
              Namespaces nss = target.getModel().getNamespaces();
              if (nss != null) {
                List<NSMap> nsList = nss.getNamespace();
                if (nsList != null) {
                  for (NSMap ns : nsList){
                    if (prefix.equals(ns.getPrefix()))
                      return ns.getUri();
                  }
                }
              }
            }
       
        try {
          return "http://www." + new URI(task.site.getUrl()).getHost();
        } catch (URISyntaxException e) {
          return task.site.getUrl();
        }
//            return XMLConstants.NULL_NS_URI;
      }
    });
       
        final List<Field> fields = target.getModel().getField();
    String isModelArray = target.getModel().getIsArray();
    String modelXpath = target.getModel().getXpath();
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    if ("1".equals(isModelArray) || "tre".equals(isModelArray)){
      XPathExpression expr = xpathParser.compile(modelXpath);
          Object result = expr.evaluate(doc, XPathConstants.NODESET);
//        listener.onInfo(Thread.currentThread(), "modelXpath -> " + modelXpath + " parse result -> " + result);
          if (result != null){
            NodeList nodes = (NodeList) result;
            if (nodes.getLength() > 0){
View Full Code Here

    final String analyzerName = DOMUtil.getAttr(attrs, "class");

    // check for all of these up front, so we can error if used in
    // conjunction with an explicit analyzer class.
    final XPath xpath = XPathFactory.newInstance().newXPath();
    final NodeList charFilterNodes = (NodeList) xpath.evaluate
      ("./charFilter",  node, XPathConstants.NODESET);
    final NodeList tokenizerNodes = (NodeList) xpath.evaluate
      ("./tokenizer", node, XPathConstants.NODESET);
    final NodeList tokenFilterNodes = (NodeList) xpath.evaluate
      ("./filter", node, XPathConstants.NODESET);

    if (analyzerName != null) {

      // explicitly check for child analysis factories instead of
View Full Code Here

    try {
      // pass the config resource loader to avoid building an empty one for no reason:
      // in the current case though, the stream is valid so we wont load the resource by name
      final Config schemaConf = new Config(loader, "datatypeConfig", is, "/datatypeConfig/");
      final Document document = schemaConf.getDocument();
      final XPath xpath = schemaConf.getXPath();
      final Node nd = (Node) xpath.evaluate("/datatypeConfig/@name", document, XPathConstants.NODE);
      if (nd == null) {
        log.warn("datatypeConfig has no name!");
      }
      else {
        name = nd.getNodeValue();
        log.info("datatypeConfig name=" + name);
      }

      version = schemaConf.get("/datatypeConfig/@version");

      final AbstractPluginLoader<Datatype> datatypeLoader =
        new AbstractPluginLoader<Datatype>("[datatypeConfig] datatype",
                                           Datatype.class, true, true) {

        @Override
        protected Datatype create(final SolrResourceLoader loader,
                                  final String name, final String className,
                                  final Node node)
        throws Exception {
          final Datatype dt = loader.newInstance(className, Datatype.class);
          dt.setDatatypeName(name);

          // An analyzer with type="index"
          String expression = "./analyzer[@type='index']";
          Node anode = (Node) xpath.evaluate(expression, node, XPathConstants.NODE);
          final Analyzer analyzer = AnalyzerConfigReader.readAnalyzer(anode,
            loader, luceneMatchVersion);
          if (analyzer != null) dt.setAnalyzer(analyzer);

          expression = "./analyzer[@type='query']";
          anode = (Node) xpath.evaluate(expression, node, XPathConstants.NODE);
          final Analyzer queryAnalyzer = AnalyzerConfigReader.readAnalyzer(anode,
            loader, luceneMatchVersion);
          if (queryAnalyzer != null) dt.setQueryAnalyzer(queryAnalyzer);

          return dt;
        }

        @Override
        protected void init(final Datatype plugin, final Node node)
        throws Exception {
          final Map<String,String> params = DOMUtil.toMapExcept(node.getAttributes(), "name", "class");
          plugin.setArgs(params);
        }

        @Override
        protected Datatype register(final String name, final Datatype plugin)
        throws Exception {
          log.trace("datatype defined: " + plugin);
          return datatypes.put(name, plugin);
        }
      };

      final String expression = "/datatypeConfig/datatype";
      final NodeList nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
      datatypeLoader.load(loader, nodes);
    }
    catch (final SolrException e) {
      throw e;
    }
View Full Code Here

      e.printStackTrace();
    } finally {
      reader.close();
    }
    XPathFactory xpFactory = XPathFactory.newInstance();
    XPath xpath = xpFactory.newXPath();
    XPathExpression expr =null;
    try {
      expr = xpath.compile(xpathString);
    } catch (XPathExpressionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Element result = null;
View Full Code Here

        final String expectedSignatureMethod = binding.getAlgorithmSuite().getAsymmetricSignature();
        final String expectedDigestAlgorithm = binding.getAlgorithmSuite().getDigest();
        final String expectedCanonAlgorithm  = binding.getAlgorithmSuite().getInclusiveC14n();
           
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        final NamespaceContext nsContext = this.getNamespaceContext();
        xpath.setNamespaceContext(nsContext);
       
        // Signature Algorithm
        final XPathExpression sigAlgoExpr =
            xpath.compile("/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo"
                              + "/ds:SignatureMethod/@Algorithm");
       
        final String sigMethod =  (String) sigAlgoExpr.evaluate(signedDoc, XPathConstants.STRING);
        assertEquals(expectedSignatureMethod, sigMethod);
       
        // Digest Method Algorithm
        final XPathExpression digestAlgoExpr = xpath.compile(
            "/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestMethod");
       
        final NodeList digestMethodNodes =
            (NodeList) digestAlgoExpr.evaluate(signedDoc, XPathConstants.NODESET);
       
        for (int i = 0; i < digestMethodNodes.getLength(); i++) {
            Node node = (Node)digestMethodNodes.item(i);
            String digestAlgorithm = node.getAttributes().getNamedItem("Algorithm").getNodeValue();
            assertEquals(expectedDigestAlgorithm, digestAlgorithm);
        }
       
        // Canonicalization Algorithm
        final XPathExpression canonAlgoExpr =
            xpath.compile("/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo"
                              + "/ds:CanonicalizationMethod/@Algorithm");
        final String canonMethod =  (String) canonAlgoExpr.evaluate(signedDoc, XPathConstants.STRING);
        assertEquals(expectedCanonAlgorithm, canonMethod);
    }
View Full Code Here

   
    // TODO: This method can be removed when runOutInterceptorAndValidateSamlTokenAttached
    // is cleaned up.
    private void verifySignatureCoversAssertion(Document signedDoc, String assertionId) throws Exception {
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        final NamespaceContext nsContext = this.getNamespaceContext();
        xpath.setNamespaceContext(nsContext);
       
        // Find the SecurityTokenReference for the assertion
        final XPathExpression strExpr = xpath.compile(
            "/s:Envelope/s:Header/wsse:Security/wsse:SecurityTokenReference/wsse:KeyIdentifier");
       
        final NodeList strKeyIdNodes =
            (NodeList) strExpr.evaluate(signedDoc, XPathConstants.NODESET);
       
        String strId = null;
        for (int i = 0; i < strKeyIdNodes.getLength(); i++) {
            Node keyIdNode = (Node) strKeyIdNodes.item(i);
            String strKey = keyIdNode.getTextContent();
            if (strKey.equals(assertionId)) {
                Node strNode = (Node) keyIdNode.getParentNode();
                strId = strNode.getAttributes().
                    getNamedItemNS(nsContext.getNamespaceURI("wsu"), "Id").getNodeValue();
                break;
            }
        }
        assertNotNull("SecurityTokenReference for " + assertionId + " not found in security header.", strId);
       
        // Verify STR is included in the signature references
        final XPathExpression sigRefExpr = xpath.compile(
            "/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo/ds:Reference");
       
        final NodeList sigReferenceNodes =
            (NodeList) sigRefExpr.evaluate(signedDoc, XPathConstants.NODESET);
       
View Full Code Here

        Vector<WSEncryptionPart> result = new Vector<WSEncryptionPart>();
       
        if (xpaths != null && !xpaths.isEmpty()) {
            XPathFactory factory = XPathFactory.newInstance();
            for (String expression : xpaths) {
                XPath xpath = factory.newXPath();
                if (namespaces != null) {
                    xpath.setNamespaceContext(new MapNamespaceContext(namespaces));
                }
              
                NodeList list = (NodeList)xpath.evaluate(expression, saaj.getSOAPPart().getEnvelope(),
                                               XPathConstants.NODESET);
                for (int x = 0; x < list.getLength(); x++) {
                    Element el = (Element)list.item(x);
                   
                    if (!found.contains(el)) {
View Full Code Here

                RequiredElements rp = (RequiredElements)ai.getAssertion();
                ai.setAsserted(true);
                Map<String, String> namespaces = rp.getDeclaredNamespaces();
                XPathFactory factory = XPathFactory.newInstance();
                for (String expression : rp.getXPathExpressions()) {
                    XPath xpath = factory.newXPath();
                    if (namespaces != null) {
                        xpath.setNamespaceContext(new MapNamespaceContext(namespaces));
                    }
                    NodeList list;
                    try {
                        list = (NodeList)xpath.evaluate(expression,
                                                                 header,
                                                                 XPathConstants.NODESET);
                        if (list.getLength() == 0) {
                            ai.setNotAsserted("No header element matching XPath " + expression + " found.");
                        }
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.