/** * Returns a parsed form of the given XPath string, which will be suitable for queries on <code>Feature</code> * objects. * * @param xpath * the XPath expression * @return a parsed form of the given XPath string * @throws SAXPathException * if the string is syntactically incorrect */ @Override public XPath parseXPath( String xpath ) throws SAXPathException { return new GMLObjectXPath( xpath, null ); }
/** * Create a new <code>GMLObjectXPath</code> from an XPath expression string. * * @param xpathExpr * the XPath expression, must not be <code>null</code> * @param root * root of the navigation hierarchy (document node), must not be <code>null</code> * @throws JaxenException * if there is a syntax error in the expression */ public GMLObjectXPath( String xpathExpr, GMLObject root ) throws JaxenException { super( xpathExpr, new GMLObjectNavigator( root ) ); SimpleFunctionContext fc = new XPathFunctionContext(); fc.registerFunction( WFS_200_NS, "valueOf", new ValueOf() ); fc.registerFunction( null, "valueOf", new ValueOf() ); SimpleNamespaceContext nc = new SimpleNamespaceContext(); nc.addNamespace( "wfs", WFS_200_NS ); setFunctionContext( fc ); setNamespaceContext( nc ); } }
try { synchronized ( context ) { XPath xpath = new GMLObjectXPath( propName.getAsText(), context ); xpath.setNamespaceContext( propName.getNsContext() ); List<?> selectedNodes;
public TypedObjectNode[] eval( Property element, ValueReference propName ) throws FilterEvaluationException { TypedObjectNode[] resultValues = null; try { XPath xpath = new GMLObjectXPath( propName.getAsText(), null ); xpath.setNamespaceContext( propName.getNsContext() ); List<?> selectedNodes; selectedNodes = xpath.selectNodes( new PropertyNode( null, element ) ); resultValues = new TypedObjectNode[selectedNodes.size()]; int i = 0; for ( Object node : selectedNodes ) { if ( node instanceof XPathNode<?> ) { resultValues[i++] = ( (XPathNode<?>) node ).getValue(); } else if ( node instanceof String || node instanceof Double || node instanceof Boolean ) { resultValues[i++] = new PrimitiveValue( node ); } else { throw new RuntimeException( "Internal error. Encountered unexpected value of type '" + node.getClass().getName() + "' (=" + node + ") during XPath-evaluation." ); } } } catch ( JaxenException e ) { throw new FilterEvaluationException( e.getMessage() ); } return resultValues; }
public TypedObjectNode[] eval( ElementNode element, ValueReference propName ) throws FilterEvaluationException { TypedObjectNode[] resultValues = null; try { XPath xpath = new GMLObjectXPath( propName.getAsText(), null ); xpath.setNamespaceContext( propName.getNsContext() ); List<?> selectedNodes; selectedNodes = xpath.selectNodes( new XMLElementNode( null, element ) ); resultValues = new TypedObjectNode[selectedNodes.size()]; int i = 0; for ( Object node : selectedNodes ) { if ( node instanceof XPathNode<?> ) { resultValues[i++] = ( (XPathNode<?>) node ).getValue(); } else if ( node instanceof String || node instanceof Double || node instanceof Boolean ) { resultValues[i++] = new PrimitiveValue( node ); } else { throw new RuntimeException( "Internal error. Encountered unexpected value of type '" + node.getClass().getName() + "' (=" + node + ") during XPath-evaluation." ); } } } catch ( JaxenException e ) { throw new FilterEvaluationException( e.getMessage() ); } return resultValues; }