Example usage for org.apache.commons.jxpath JXPathContextFactory newInstance

List of usage examples for org.apache.commons.jxpath JXPathContextFactory newInstance

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContextFactory newInstance.

Prototype

public static JXPathContextFactory newInstance() 

Source Link

Document

Obtain a new instance of a JXPathContextFactory.

Usage

From source file:org.geotools.xml.impl.jxpath.JXPathStreamingParserHandler.java

protected boolean stream(ElementHandler handler) {
    //create an xpath context from the root element
    // TODO: cache the context, should work just the same
    //        JXPathIntrospector.registerDynamicClass(ElementHandlerImpl.class,
    //            ElementHandlerPropertyHandler.class);
    JXPathIntrospector.registerDynamicClass(NodeImpl.class, NodePropertyHandler.class);

    //        ElementHandler rootHandler = 
    //           ((DocumentHandler) handlers.firstElement()).getDocumentElementHandler();
    Node root = ((DocumentHandler) handlers.firstElement()).getParseNode();
    JXPathContext jxpContext = JXPathContextFactory.newInstance().newContext(null, root);

    jxpContext.setLenient(true);//  ww w.  j a  v a 2 s. c o m

    Iterator itr = jxpContext.iterate(xpath);

    for (; itr.hasNext();) {
        Object obj = itr.next();

        if (handler.getParseNode().equals(obj)) {
            return true;
        }
    }

    return false;
}

From source file:org.geotools.xml.impl.jxpath.JXPathTest.java

protected void setUp() throws Exception {
    ElementImpl e = new ElementImpl(null);
    e.setName("root");
    root = new NodeImpl(e);

    e = new ElementImpl(null);
    e.setName("child");
    child1 = new NodeImpl(e);
    //root.addChild( child1 );
    e = new ElementImpl(null);
    e.setName("child");
    child2 = new NodeImpl(e);
    //root.addChild( child2 );
    JXPathIntrospector.registerDynamicClass(NodeImpl.class, NodePropertyHandler.class);

    context = JXPathContextFactory.newInstance().newContext(null, root);
}