Package javax.xml.xpath

Examples of javax.xml.xpath.XPathExpression


    }

    private void traceNamespaces(Exchange exchange) {
        InputStream is = null;
        NodeList answer = null;
        XPathExpression xpathExpression = null;

        try {
            xpathExpression = poolTraceNamespaces.poll();
            if (xpathExpression == null) {
                xpathExpression = createTraceNamespaceExpression();
            }

            // prepare the input
            Object document;
            if (isInputStreamNeeded(exchange)) {
                is = exchange.getIn().getBody(InputStream.class);
                document = getDocument(exchange, is);
            } else {
                Object body = exchange.getIn().getBody();
                document = getDocument(exchange, body);
            }
            // fetch all namespaces
            if (document instanceof InputSource) {
                InputSource inputSource = (InputSource) document;
                answer = (NodeList) xpathExpression.evaluate(inputSource, XPathConstants.NODESET);
            } else if (document instanceof DOMSource) {
                DOMSource source = (DOMSource) document;
                answer = (NodeList) xpathExpression.evaluate(source.getNode(), XPathConstants.NODESET);
            } else {
                answer = (NodeList) xpathExpression.evaluate(document, XPathConstants.NODESET);
            }
        } catch (Exception e) {
            LOG.trace("Unable to trace discovered namespaces in XPath expression", e);
        } finally {
            // IOHelper can handle if is is null
View Full Code Here


        if (appliesTo != null) {
            try {
                XPath path = xpathHelper.newXPath();
                NamespaceContext nsContext = xpathHelper.getNamespaceContext(appliesTo, reader.getNamespaceContext());
                // path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(context));
                XPathExpression expression = xpathHelper.compile(path, nsContext, appliesTo);
                policySet.setAppliesToXPathExpression(expression);
            } catch (XPathExpressionException e) {
                ContributionReadException ce = new ContributionReadException(e);
                error(monitor, "ContributionReadException", policySet, ce);
                //throw ce;
            }
        }

        String attachTo = reader.getAttributeValue(null, ATTACH_TO);
        if (attachTo != null) {
            try {
                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);
                policySet.setAttachTo(attachTo);
                policySet.setAttachToXPathExpression(expression);
            } catch (XPathExpressionException e) {
                ContributionReadException ce = new ContributionReadException(e);
                error(monitor, "ContributionReadException", policySet, ce);
View Full Code Here

    /**
     * Evaluates the expression as the given result type
     */
    protected Object evaluateAs(Exchange exchange, QName resultQName) {
        // pool a pre compiled expression from pool
        XPathExpression xpathExpression = pool.poll();
        if (xpathExpression == null) {
            LOG.trace("Creating new XPathExpression as none was available from pool");
            // no avail in pool then create one
            try {
                xpathExpression = createXPathExpression();
View Full Code Here

    }

    private void logNamespaces(Exchange exchange) {
        InputStream is = null;
        NodeList answer = null;
        XPathExpression xpathExpression = null;

        try {
            xpathExpression = poolLogNamespaces.poll();
            if (xpathExpression == null) {
                xpathExpression = createTraceNamespaceExpression();
            }

            // prepare the input
            Object document;
            if (isInputStreamNeeded(exchange)) {
                is = exchange.getIn().getBody(InputStream.class);
                document = getDocument(exchange, is);
            } else {
                Object body = exchange.getIn().getBody();
                document = getDocument(exchange, body);
            }
            // fetch all namespaces
            if (document instanceof InputSource) {
                InputSource inputSource = (InputSource) document;
                answer = (NodeList) xpathExpression.evaluate(inputSource, XPathConstants.NODESET);
            } else if (document instanceof DOMSource) {
                DOMSource source = (DOMSource) document;
                answer = (NodeList) xpathExpression.evaluate(source.getNode(), XPathConstants.NODESET);
            } else {
                answer = (NodeList) xpathExpression.evaluate(document, XPathConstants.NODESET);
            }
        } catch (Exception e) {
            LOG.warn("Unable to trace discovered namespaces in XPath expression", e);
        } finally {
            // IOHelper can handle if is is null
View Full Code Here

      Document doc = dBuilder.parse(new File(projectFolder, ".project"));
      doc.getDocumentElement().normalize();
     
      XPathFactory xFactory = XPathFactory.newInstance();
      XPath xpath = xFactory.newXPath();
      XPathExpression expr = xpath.compile("/projectDescription/name/text()");
     
      return (String) expr.evaluate(doc, XPathConstants.STRING);
     
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();

      xpath.setNamespaceContext(new OlefNamespaceContext());

      XPathExpression expr = xpath.compile(xpathExpression);
      Object obj = expr.evaluate(doc, returnType);
      result = obj;
    } catch (XPathExpressionException e) {
      e.printStackTrace();
    }
    return result;
View Full Code Here

      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();

      xpath.setNamespaceContext(new MyNamespaceContext());

      XPathExpression expr = xpath.compile(xpathExpression);
      Object obj = expr.evaluate(doc, returnType);
      result = obj;
    } catch (XPathExpressionException e) {
      e.printStackTrace();
    }
    return result;
View Full Code Here

            Document document = documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
            NodeList nodeList = document.getElementsByTagNameNS(WSSConstants.TAG_dsig_Signature.getNamespaceURI(), WSSConstants.TAG_dsig_Signature.getLocalPart());
            Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());

            XPathExpression xPathExpression = getXPath("/soap:Envelope/soap:Header/wsse:Security/dsig:Signature/dsig:KeyInfo/wsse:SecurityTokenReference/dsig:X509Data/dsig:X509IssuerSerial/dsig:X509SerialNumber");
            Node node = (Node) xPathExpression.evaluate(document, XPathConstants.NODE);
            Assert.assertNotNull(node);

            nodeList = document.getElementsByTagNameNS(WSSConstants.TAG_dsig_Reference.getNamespaceURI(), WSSConstants.TAG_dsig_Reference.getLocalPart());
            Assert.assertEquals(nodeList.getLength(), 1);
View Full Code Here

            Properties properties = new Properties();
            properties.setProperty(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
            Document securedDocument = doOutboundSecurityWithWSS4J(sourceDocument, action, properties);

            //some test that we can really sure we get what we want from WSS4J
            XPathExpression xPathExpression = getXPath("/soap:Envelope/soap:Header/wsse:Security/dsig:Signature/dsig:KeyInfo/wsse:SecurityTokenReference/dsig:X509Data/dsig:X509IssuerSerial/dsig:X509SerialNumber");
            Node node = (Node) xPathExpression.evaluate(securedDocument, XPathConstants.NODE);
            Assert.assertNotNull(node);

            javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
            transformer.transform(new DOMSource(securedDocument), new StreamResult(baos));
        }
View Full Code Here

            Document document = documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
            NodeList nodeList = document.getElementsByTagNameNS(WSSConstants.TAG_dsig_Signature.getNamespaceURI(), WSSConstants.TAG_dsig_Signature.getLocalPart());
            Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());

            XPathExpression xPathExpression = getXPath("/soap:Envelope/soap:Header/wsse:Security/dsig:Signature/dsig:KeyInfo/wsse:SecurityTokenReference/dsig:X509Data/dsig:X509IssuerSerial/dsig:X509SerialNumber");
            Node node = (Node) xPathExpression.evaluate(document, XPathConstants.NODE);
            Assert.assertNotNull(node);

            nodeList = document.getElementsByTagNameNS(WSSConstants.TAG_dsig_Reference.getNamespaceURI(), WSSConstants.TAG_dsig_Reference.getLocalPart());
            Assert.assertEquals(nodeList.getLength(), 1);
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.