Package org.apache.xpath

Examples of org.apache.xpath.CachedXPathAPI


       

        Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(in.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


        NormalizedMessage msg = (NormalizedMessage) receiver.getMessageList().flushMessages().get(0);

        Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(msg.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

            }
        }
    }

    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

      out.setContent(in.getContent());
     
      String propertySetName = "";
      if (xpathForPropertySet != null) {
        try {
          CachedXPathAPI xpathApi = new org.apache.xpath.CachedXPathAPI();
          Document doc = new SourceTransformer().toDOMDocument(in);
          XObject propSetXO = xpathApi.eval(doc.getDocumentElement(),xpathForPropertySet);
          propertySetName = propSetXO.str();
        } catch (Exception e) {
          throw new MessagingException("Problem getting the propertySet using XPath", e);
        }
      } else if (this.propertySet != null) {
View Full Code Here

   * @throws JBIException
   * @throws PropertySetNotFoundException
   */
  private PropertySet createPropertySet(String propertySetName) throws JBIException , PropertySetNotFoundException{
    PropertySet ps; 
    CachedXPathAPI xpath = new CachedXPathAPI();
    StringBuffer xpathSB = new StringBuffer("//")
                  .append(XML_ELEMENT_NAME)
                  .append("[@name='")
                  .append(propertySetName)
                  .append("']");
    try {
      Node propertySetNode = xpath.selectSingleNode(xmlMPSdom,xpathSB.toString());
      if (propertySetNode == null) {
        throw new PropertySetNotFoundException("Could not find a property-set for [" + propertySetName + "] in " + xmlConfiguration.getFilename());
      }
      ps = new PropertySet(propertySetName,(Element) propertySetNode);
      this.propertSets.put(propertySetName, ps);
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

     * Sets the doc for the xpath transformation. Resets the cache if needed
     * @param doc
     */
    public static void setDoc(Document doc) {                   
        if (localDoc.get()!=doc) {
            CachedXPathAPI cx=(CachedXPathAPI)local.get();
            if (cx==null) {
                cx=new CachedXPathAPI();
                local.set(cx);
                localDoc.set(doc);
                return;
            }
            //Different docs reset.
            cx.getXPathContext().reset();
            localDoc.set(doc);                    
        }   
    }
View Full Code Here

    /**
     * @return the cachexpathapi for this thread
     */
    public static CachedXPathAPI getCachedXPathAPI() {       
        CachedXPathAPI cx=(CachedXPathAPI)local.get();       
        if (cx==null) {
            cx=new CachedXPathAPI();
            local.set(cx);
            localDoc.set(null);           
        }
      return cx;
    }
View Full Code Here

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder dbuilder = factory.newDocumentBuilder();
            Document doc = dbuilder.parse(inputSource);

            CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
            NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc,xpath);
            return iterator.nextNode()!=null;

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

            DocumentBuilder dbuilder = factory.newDocumentBuilder();
            Document doc = dbuilder.parse(inputSource);

            // We should associated the cachedXPathAPI object with the message being evaluated
            // since that should speedup subsequent xpath expressions.
            CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
            NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc,xpath);
            return iterator.nextNode()!=null;
        } catch (Throwable e) {
            return false;
        }
    }
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.