Package org.apache.xpath

Examples of org.apache.xpath.CachedXPathAPI


      byte c14nBytes[] = null;

      if (xpath == null) {
         c14nBytes = c14n.canonicalizeSubtree(doc);
      } else {
         CachedXPathAPI xpathAPI = new CachedXPathAPI();
         NodeList nl = null;

         if (xpath instanceof String) {
            nl = xpathAPI.selectNodeList(doc, (String) xpath);
         } else {
            Element xpathElement = (Element) xpath;
            String xpathStr = ((Text) xpathElement.getFirstChild()).getData();

            nl = xpathAPI.selectNodeList(doc, xpathStr, xpathElement);
         }

         c14nBytes = c14n.canonicalizeXPathNodeSet(nl);
      }
View Full Code Here


      dbf.setNamespaceAware(true);

      javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
      org.w3c.dom.Document doc = db.parse(new FileInputStream(signatureFile));
      String BaseURI = signatureFile.toURL().toString();
      CachedXPathAPI xpathAPI = new CachedXPathAPI();
      Element nsctx = doc.createElementNS(null, "nsctx");

      nsctx.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds",
                           Constants.SignatureSpecNS);

      Element signatureElem = (Element) xpathAPI.selectSingleNode(doc,
                                 "//ds:Signature", nsctx);
      XMLSignature sig = new XMLSignature(signatureElem, BaseURI);
      boolean verify = sig.checkSignatureValue(sig.getKeyInfo().getPublicKey());

      System.out.println("The signature is" + (verify
View Full Code Here

      String s1 =
         "<!--Small Comment Test--><RootElement><Element1/><Element2/><Element3>Text in Element3</Element3></RootElement>";

      //XMLUtils.circumventBug2650(doc);

      CachedXPathAPI cXPathAPI = new CachedXPathAPI();
      NodeList nl = cXPathAPI.selectNodeList(doc,
                                             "(//. | //@* | //namespace::*)");

      return XMLUtils.convertNodelistToSet(nl);
   }
View Full Code Here

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        XMLSerializer serializer = new XMLSerializer(output, format);
        serializer.serialize((Document) node);
        logger.info(output.toString());
       
        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

        assertEquals("string", qname.getLocalPart());
       
    }

    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

            assertEquals("undeploy", textValueOfXPath(node, "//jbi:frmwk-task-result//jbi:task-id"));
        }
    }
    
    protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        XObject list = cachedXPathAPI.eval(node, xpath, new PrefixResolver() {
            public String getNamespaceForPrefix(String prefix) {
                if ("jbi".equals(prefix)) {
                    return "http://java.sun.com/xml/ns/jbi/management-message";
                }
                return null;
View Full Code Here

   * Return null if the value was empty or not there
   */
  public String getPropertyValue(NormalizedMessage msg) throws JBIException {
    String resultValue = null;
    if (msg.getContent() != null) {
      CachedXPathAPI xpathApi = new CachedXPathAPI();
      try {
        Document doc = new SourceTransformer().toDOMDocument(msg);
        XObject result = xpathApi.eval(doc,xpath);

        resultValue = result.toString();
        if ("".equals(resultValue)) {
          resultValue = null;
        }
View Full Code Here

    public void toNMS(NormalizedMessage normalizedMessage, HttpMethod method)
            throws Exception {
        addNmsProperties(normalizedMessage, method);
        String response = method.getResponseBodyAsString();
        Node node = sourceTransformer.toDOMNode(new StringSource(response));
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "/*/*[local-name()='Body']/*");
        Node root = iterator.nextNode();
        if (root instanceof Element == false) {
          throw new IllegalStateException("Could not find body content");
        }
        Element element = (Element) root;
View Full Code Here

    new SaajMarshaler().toNMS(nm, sm);

        Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(nm.getContent()));
        logger.info(new SourceTransformer().toString(node));
   
        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

        msg.writeTo(baos);
        String soapEnv = new String(baos.toByteArray());
        logger.info("Prepared SOAP: {}", soapEnv);
        Node node2 = new SourceTransformer().toDOMNode(new StringSource(soapEnv));
         
        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node2, "//*[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.