Package org.apache.xpath

Examples of org.apache.xpath.CachedXPathAPI


      Document doc = uri.getOwnerDocument();

      // this must be done so that Xalan can catch ALL namespaces
      XMLUtils.circumventBug2650(doc);

      CachedXPathAPI cXPathAPI = new CachedXPathAPI();

      try {
         if (isXPointerSlash(uri, BaseURI)) {
            resultNodes =
               cXPathAPI.selectNodeList(doc,
                                        Canonicalizer.XPATH_C14N_WITH_COMMENTS);
         } else if (isXPointerId(uri, BaseURI)) {
            String id = getXPointerId(uri, BaseURI);
            Element selectedElem = IdResolver.getElementById(doc, id);

            // cat.debug("Use #xpointer(id('" + id + "')) on element " + selectedElem);

            if (selectedElem == null) {
               Object exArgs[] = { id };

               throw new ResourceResolverException(
                  "signature.Verification.MissingID", exArgs, uri, BaseURI);
            }

            resultNodes =
               cXPathAPI
                  .selectNodeList(selectedElem, Canonicalizer
                     .XPATH_C14N_WITH_COMMENTS_SINGLE_NODE);
         }
      } catch (javax.xml.transform.TransformerException ex) {
         throw new ResourceResolverException("generic.EmptyMessage", ex, uri,
View Full Code Here


      Document doc = uri.getOwnerDocument();

      // this must be done so that Xalan can catch ALL namespaces
      XMLUtils.circumventBug2650(doc);

      CachedXPathAPI cXPathAPI = new CachedXPathAPI();

      if (uriNodeValue.equals("")) {

         /*
          * Identifies the node-set (minus any comment nodes) of the XML
          * resource containing the signature
          */

         // cat.debug("ResolverFragment with empty URI (means complete document)");
         try {
            resultNodes =
               cXPathAPI.selectNodeList(doc,
                                        Canonicalizer.XPATH_C14N_OMIT_COMMENTS);
         } catch (javax.xml.transform.TransformerException ex) {
            throw new ResourceResolverException("generic.EmptyMessage", ex,
                                                uri, BaseURI);
         }
      } else {

         /*
          * URI="#chapter1"
          * Identifies a node-set containing the element with ID attribute
          * value 'chapter1' of the XML resource containing the signature.
          * XML Signature (and its applications) modify this node-set to
          * include the element plus all descendents including namespaces and
          * attributes -- but not comments.
          */
         String id = uriNodeValue.substring(1);

         // Element selectedElem = doc.getElementById(id);
         Element selectedElem = IdResolver.getElementById(doc, id);

         // cat.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem);
         if (selectedElem == null) {
            resultNodes = new HelperNodeList();
         } else {
            try {
               resultNodes =
                  cXPathAPI
                     .selectNodeList(selectedElem, Canonicalizer
                        .XPATH_C14N_OMIT_COMMENTS_SINGLE_NODE);
            } catch (javax.xml.transform.TransformerException ex) {
               throw new ResourceResolverException("generic.EmptyMessage", ex,
                                                   uri, BaseURI);
View Full Code Here

            // verify signed message

            Document doc = inMsg.getSOAPEnvelope().getAsDocument();
            String BaseURI = "http://xml-security";
            CachedXPathAPI xpathAPI = new CachedXPathAPI();

            Element nsctx = doc.createElement("nsctx");
            nsctx.setAttribute("xmlns:ds", Constants.SignatureSpecNS);

            Element signatureElem = (Element) xpathAPI.selectSingleNode(doc,
                    "//ds:Signature", nsctx);

            // check to make sure that the document claims to have been signed
            if (signatureElem == null) {
                System.out.println("The document is not signed");
View Full Code Here

     * @param xpath
     * @return
     * @throws TransformerException
     */
    protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
        Node root = iterator.nextNode();
        if (root instanceof Element) {
            Element element = (Element) root;
            if (element == null) {
                return "";
View Full Code Here

     * @param xpath
     * @return
     * @throws TransformerException
     */
    protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
        Node root = iterator.nextNode();
        if (root instanceof Element) {
            Element element = (Element) root;
            if (element == null) {
                return "";
View Full Code Here

            }
        }
    }

    public String getQuery(Node node) throws Exception {
        CachedXPathAPI xpath = new CachedXPathAPI();

        node = xpath.selectSingleNode(node, "sql/child::text()");

        // First child should be <sql></sql> element
        if (node == null) {
            throw new IllegalStateException("Expecting <sql></sql> node. Found: " + node);
        }
View Full Code Here

     * @param xpath
     * @return
     * @throws TransformerException
     */
    protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
        Node root = iterator.nextNode();
        if (root instanceof Element) {
            Element element = (Element) root;
            if (element == null) {
                return "";
View Full Code Here

            //An XPath expression could return a true or false value instead of a node.
            //eval() is a better way to determine the boolean value of the exp.
            //For compliance with legacy behavior where selecting an empty node returns true,
            //selectNodeIterator is attempted in case of a failure.

            CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
            XObject result = cachedXPathAPI.eval(doc, xpath);
            if (result.bool())
              return true;
            else {
              NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
              return (iterator.nextNode() != null);
            }

        } catch (Throwable e) {
            return false;
View Full Code Here

        writer.write(baos);
        log.info(baos.toString());
    }

    private void checkHeadersForServiceName(Iterator headers) throws Exception {
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        boolean foundServiceNameNode = false;
        int headerCount = 0;
        while (headers.hasNext()) {
            headerCount++;
            DocumentFragment df = (DocumentFragment)headers.next();
            Element root = (Element)(cachedXPathAPI.selectNodeIterator(df, "//*[local-name() = 'ServiceName']").nextNode());
            if (root != null) {
                foundServiceNameNode = true;
                checkServiceNameNamespace(df);
            }
        }
View Full Code Here

        assertTrue(foundServiceNameNode);
        assertEquals(headerCount, 2);
    }

    protected void checkUserIdNamespace(Node node) throws Exception {
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
        Element root = (Element) iterator.nextNode();
        QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
        assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
        assertEquals("string", qname.getLocalPart());
  }
View Full Code Here

TOP

Related Classes of org.apache.xpath.CachedXPathAPI

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.