Examples of XPathExpression


Examples of javax.xml.xpath.XPathExpression

      {
         // System.setProperty("javax.xml.xpath.XPathFactory",
         // "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl") ;
         // XPathFactory xpfactory = XPathFactory.newInstance() ;
         XPath xpath = XPathFactory.newInstance().newXPath();
         XPathExpression clientTypeExp = xpath.compile("/clients-type/client-type");
         XPathExpression nameExp = xpath.compile("name/text()");
         XPathExpression userAgentPatternExp = xpath.compile("userAgentPattern/text()");
         XPathExpression preferredMimeTypeExp = xpath.compile("preferredMimeType/text()");
         XPathExpression rendererExp = xpath.compile("renderer/text()");
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         java.net.URL url = cl.getResource("conf/portal/clients-type.xml");
         // S ystem.setProperty("javax.xml.parsers.DocumentBuilderFactory",
         // "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl") ;
         // S ystem.out.println("==================> " +
         // System.getProperty("javax.xml.parsers.DocumentBuilderFactory")) ;
         // S ystem.out.println("==================>" +
         // DocumentBuilderFactory.newInstance());
         Iterator itr = System.getProperties().entrySet().iterator();
         while (itr.hasNext())
         {
            Map.Entry entry = (Map.Entry)itr.next();
            String key = (String)entry.getKey();
            if (key.startsWith("javax"))
            {
               // System .out.println(key + " = " + entry.getValue());
            }
         }

         DocumentBuilderFactory finstance = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = finstance.newDocumentBuilder();
         Document document = builder.parse(url.openStream());
         NodeList nodes = (NodeList)clientTypeExp.evaluate(document, XPathConstants.NODESET);
         for (int i = 0; i < nodes.getLength(); i++)
         {
            Node node = nodes.item(i);
            String name = (String)nameExp.evaluate(node, XPathConstants.STRING);
            String userAgentPattern = (String)userAgentPatternExp.evaluate(node, XPathConstants.STRING);
            String preferredMimeType = (String)preferredMimeTypeExp.evaluate(node, XPathConstants.STRING);
            String renderer = (String)rendererExp.evaluate(node, XPathConstants.STRING);
            HttpClientType clientInfo;
            if (renderer != null && renderer.length() > 0)
            {
               clientInfo = new HttpClientType(name, userAgentPattern, preferredMimeType, renderer);
            }
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

      ServletContext servletContext = getServletContext();

      // XPath expression for selecting the url pattern for this servlet instance
      String exprValue = "//servlet-mapping[servlet-name='" + servletName + "']/url-pattern";
      XPath xpath = XPathFactory.newInstance().newXPath();
      XPathExpression expr;
      try
      {
         expr = xpath.compile(exprValue);
      }
      catch (XPathExpressionException e)
      {
         throw new ServletException(e);
      }

      //
      log.debug("Going to look for the configuration of the end point servlet " + servletName);

      // Obtain url pattern values in order to find out how this servlet instance is mapped
      InputStream in = servletContext.getResourceAsStream("/WEB-INF/web.xml");
      byte[] bytes;
      try
      {
         bytes = IOTools.getBytes(in);

         // That's the descriptor but we won't parse it as the encoding may not be correct, it's just here for debugging purpose
         String descriptor = new String(bytes);
         log.debug("The a priori descriptor is " + descriptor);
      }
      catch (IOException e)
      {
         throw new ServletException("The end point servlet " + servletName + " is not able to load the web descriptor");
      }
      finally
      {
         IOTools.safeClose(in);
      }

      //
      try
      {
         Document doc = XMLTools.getDocumentBuilderFactory().newDocumentBuilder().parse(new ByteArrayInputStream(bytes));
        
         //
         NodeList nodes = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);

         //
         for (int i = 0;i < nodes.getLength();i++)
         {
            Element urlPatternElt = (Element)nodes.item(i);
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

   private static List<String> extractServletNames(String descriptor) throws Exception
   {
      Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(new ByteArrayInputStream(descriptor.getBytes()));

      XPathExpression xPathExpression = XPathFactory.newInstance().newXPath().compile("/web-app/servlet/servlet-name");

      NodeList nodes = (NodeList) xPathExpression.evaluate(doc, XPathConstants.NODESET);

      List<String> servletNames = new ArrayList<String>();
      for (int i = 0; i < nodes.getLength(); i++)
      {
         Node node = nodes.item(i);
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

      ServletContext servletContext = getServletContext();

      // XPath expression for selecting the url pattern for this servlet instance
      String exprValue = "//servlet-mapping[servlet-name='" + servletName + "']/url-pattern";
      XPath xpath = XPathFactory.newInstance().newXPath();
      XPathExpression expr;
      try
      {
         expr = xpath.compile(exprValue);
      }
      catch (XPathExpressionException e)
      {
         throw new ServletException(e);
      }

      //
      log.debug("Going to look for the configuration of the end point servlet " + servletName);

      // Obtain url pattern values in order to find out how this servlet instance is mapped
      InputStream in = servletContext.getResourceAsStream("/WEB-INF/web.xml");
      byte[] bytes;
      try
      {
         bytes = IOTools.getBytes(in);

         // That's the descriptor but we won't parse it as the encoding may not be correct, it's just here for debugging purpose
         String descriptor = new String(bytes);
         log.debug("The a priori descriptor is " + descriptor);
      }
      catch (IOException e)
      {
         throw new ServletException("The end point servlet " + servletName + " is not able to load the web descriptor");
      }
      finally
      {
         IOTools.safeClose(in);
      }

      //
      try
      {
         Document doc = XMLTools.getDocumentBuilderFactory().newDocumentBuilder().parse(new ByteArrayInputStream(bytes));
        
         //
         NodeList nodes = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);

         //
         for (int i = 0;i < nodes.getLength();i++)
         {
            Element urlPatternElt = (Element)nodes.item(i);
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

                String s = r.getAttributeValue(null, "schemaLocation");
                if (StringUtils.isEmpty(s)) {
                    Document d = StaxUtils.read(r);
                    XPath p = XPathFactory.newInstance().newXPath();
                    p.setNamespaceContext(new W3CNamespaceContext(d.getDocumentElement()));
                    XPathExpression xpe = p.compile(d.getDocumentElement().getAttribute("node"));
                    for (XmlSchema schema : schemas.getXmlSchemas()) {
                        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
                            continue;
                        }
                        Object src = getSchemaNode(schema, schemas);
                        NodeList nodes = (NodeList)xpe.evaluate(src, XPathConstants.NODESET);
                        if (nodes.getLength() > 0) {
                            String key = schema.getSourceURI();
                            binding = convertToTmpInputSource(d.getDocumentElement(), key);
                            opts.addBindFile(binding);
                            binding = null;
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

                throw new IllegalStateException("Unsupported dialect: " + contentFilter.getDialect());
            }
            try {
                XPathFactory xpfactory = XPathFactory.newInstance();
                XPath xpath = xpfactory.newXPath();
                XPathExpression exp = xpath.compile(contentFilter.getContent().get(0).toString());
                Boolean ret = (Boolean) exp.evaluate(content, XPathConstants.BOOLEAN);
                return ret.booleanValue();
            } catch (XPathExpressionException e) {
                log.warn("Could not filter notification", e);
            }
            return false;
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

        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

Examples of javax.xml.xpath.XPathExpression

        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);
       
        boolean foundStrReference = false;
        for (int i = 0; i < sigReferenceNodes.getLength(); i++) {
            Node sigRefNode = (Node) sigReferenceNodes.item(i);
            String sigRefURI = sigRefNode.getAttributes().getNamedItem("URI").getNodeValue();
View Full Code Here

Examples of javax.xml.xpath.XPathExpression

    @Test
    public void testCompile() throws Exception {
        XMLStreamReader reader = staxHelper.createXMLStreamReader(XPATH);
        reader.nextTag();
        String xpath = reader.getAttributeValue(null, "attachTo");
        XPathExpression expression = xpathHelper.compile(reader.getNamespaceContext(), xpath);
        // Advance the reader so that the namespace context changes its prefix/namespace mapping
        reader.nextTag();
        reader.close();

        Document doc = domHelper.load(XML);
        NodeList nodes = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);
        Assert.assertEquals(1, nodes.getLength());
        Node node = nodes.item(0);
        Assert.assertTrue(node instanceof Element);
        Assert.assertEquals(node.getNodeName(), "c:child1");
    }
View Full Code Here

Examples of net.sf.saxon.sxpath.XPathExpression

      Source s = null;
        try {
          s = convertToSource(doc);
            XPathEvaluator eval = new XPathEvaluator();
            // Wrap the string() function to force a string return            
            XPathExpression expr = eval.createExpression(xpath);
            Object o = expr.evaluateSingle(s);
           
            if(o == null) {
                return null;
            }
           
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.