Package javax.xml.xpath

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


   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

      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

                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

                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

        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

        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

    @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

        XMLStreamReader reader = staxHelper.createXMLStreamReader(XPATH);
        reader.nextTag();
        String xpathExp = reader.getAttributeValue(null, "attachTo");
        XPath xpath = xpathHelper.newXPath();
        // Compile the expression without taking a snapshot of the namespace context
        XPathExpression expression = xpathHelper.compile(xpath, reader.getNamespaceContext(), xpathExp);
        // 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

               XPath path = xpathHelper.newXPath();
               NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext());
               path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext));               
                                         
               attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext));
               XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo);
               attachment.setAttachTo(attachTo);
               attachment.setAttachToXPathExpression(expression);
           } catch (XPathExpressionException e) {
               ContributionReadException ce = new ContributionReadException(e);
               error(monitor, "ContributionReadException", attachment, ce);             
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPathExpression

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.