/** * 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 ); }
/** * Returns the namespace URI of an element node. * * @param node * the element node * @return the namespace if the argument is an element, or null otherwise */ @Override public String getElementNamespaceUri( Object node ) { String ns = null; if ( isElement( node ) ) { ElementNode<?> el = (ElementNode<?>) node; ns = el.getNamespaceUri(); } return ns; }
/** * Returns the namespace URI of an attribute node. * * @param node * attribute node, must not be null * @return namespace if the argument is an attribute, or <code>null</code> otherwise */ @Override public String getAttributeNamespaceUri( Object node ) { String ns = null; if ( isAttribute( node ) ) { AttributeNode<?> attr = (AttributeNode<?>) node; ns = attr.getNamespaceUri(); } return ns; }
private List<Property> getTargetProperties( final Feature feature, final ValueReference propName ) throws FeatureStoreException { if (propName == null) { return emptyList(); } try { final TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator(); final TypedObjectNode[] nodes = evaluator.eval( feature, propName ); final List<Property> props = new ArrayList<Property>(); if ( nodes != null ) { for ( final TypedObjectNode node : nodes ) { if ( !( node instanceof Property ) ) { final String msg = propName + " does not refer to a property."; throw new FeatureStoreException( msg ); } props.add( (Property) node ); } } return props; } catch ( FilterEvaluationException e ) { throw new FeatureStoreException( e.getMessage(), e ); } }
TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator();
@Override public TypedObjectNode[] eval( TypedObjectNode particle, ValueReference path ) throws FilterEvaluationException { if ( particle instanceof GMLObject ) { return eval( (GMLObject) particle, path ); } if ( particle instanceof ElementNode ) { return eval( (ElementNode) particle, path ); } throw new FilterEvaluationException( "Evaluation of XPath expressions on '" + particle.getClass() + "' is not supported." ); }
/** * 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 ); } }
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; }
/** * Returns the local name of an element node. * * @param node * the element node * @return a string representing the unqualified local name if the node is an element, or null otherwise */ @Override public String getElementName( Object node ) { String name = null; if ( isElement( node ) ) { ElementNode<?> el = (ElementNode<?>) node; name = el.getLocalName(); } return name; }
/** * Returns the local name of an attribute node. * * @param node * attribute node, must not be null * @return a string representing the unqualified local name if the node is an attribute, or <code>null</code> * otherwise */ @Override public String getAttributeName( Object node ) { String name = null; if ( isAttribute( node ) ) { AttributeNode<?> attr = (AttributeNode<?>) node; name = attr.getLocalName(); } return name; }
/** * Returns the qualified (=prefixed) name of an element node. * * @param node * the element node * @return a string representing the qualified (i.e. possibly prefixed) name if the argument is an element, or null * otherwise */ @Override public String getElementQName( Object node ) { String name = null; if ( isElement( node ) ) { ElementNode<?> el = (ElementNode<?>) node; name = el.getPrefixedName(); } return name; }
/** * Returns the qualified (=prefixed) name of an attribute node. * * @param node * attribute node, must not be null * @return a string representing the qualified (i.e. possibly prefixed) name if the argument is an attribute, or * <code>null</code> otherwise */ @Override public String getAttributeQName( Object node ) { String name = null; if ( isAttribute( node ) ) { AttributeNode<?> attr = (AttributeNode<?>) node; name = attr.getPrefixedName(); } return name; }
@Override public PropertyNode next() { if ( !hasNext() ) { throw new NoSuchElementException(); } Property prop = null; if ( propertyIter != null && propertyIter.hasNext() ) { prop = propertyIter.next(); } return new PropertyNode( parent, prop ); }
/** * Returns the string value of an attribute node. * * @param node * attribute node, must not be null * @return the text of the attribute value if the node is an attribute, <code>null</code> otherwise */ @Override public String getAttributeStringValue( Object node ) { String value = null; if ( isAttribute( node ) ) { value = ( (AttributeNode<?>) node ).getValue().getAsText(); } return value; }
private String getExternalRef( Feature building ) { String result = null; NamespaceBindings nsContext = new NamespaceBindings(); nsContext.addNamespace( "cgml", NS ); ValueReference propName = new ValueReference( "cgml:externalReference/cgml:informationSystem/text()", nsContext ); TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator( ); TypedObjectNode[] tons; try { tons = evaluator.eval( building, propName ); if ( tons.length > 0 ) { result = ( (PrimitiveValue) tons[0] ).getAsText().trim(); } } catch ( FilterEvaluationException e ) { LOG.error( "Retrieving of information system property failed: " + e.getMessage() ); } return result; }
public FeatureLayerData( List<Query> queries, FeatureStore featureStore, int maxFeatures, Style style, QName ftName ) { this.queries = queries; this.featureStore = featureStore; this.maxFeatures = maxFeatures; this.style = style; Map<String, QName> bindings = new HashMap<String, QName>(); Set<QName> validNames = AppSchemas.collectProperyNames( featureStore.getSchema(), ftName ); for ( QName name : validNames ) { bindings.put( name.getLocalPart(), name ); } evaluator = new TypedObjectNodeXPathEvaluator( bindings ); }
@SuppressWarnings({ "unchecked", "synthetic-access" }) @Override public int compare( Feature f1, Feature f2 ) { int order = 0; for ( SortProperty sortCrit : sortCrits ) { ValueReference propName = sortCrit.getSortProperty(); try { // TODO handle multi properties correctly TypedObjectNode[] values1 = evaluator.eval( f1, propName ); TypedObjectNode[] values2 = evaluator.eval( f2, propName ); for ( TypedObjectNode value1 : values1 ) { if ( value1 != null ) { for ( TypedObjectNode value2 : values2 ) { if ( value2 != null ) { Pair<Object, Object> comparablePair = getPrimitives( value1, value2 ); order = ( (Comparable<Object>) comparablePair.first ).compareTo( comparablePair.second ); if ( !sortCrit.getSortOrder() ) { order *= -1; } } } } } } catch ( Exception e ) { LOG.debug( "Cannot compare values: " + e.getMessage() ); } } return order; } } );
private boolean excludeByTimeSliceFilter( Property property ) { final TimeSlice timeSlice = (TimeSlice) property.getValue(); for ( final Filter timeSliceFilter : timeSliceFilters ) { TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator(); try { if ( !timeSliceFilter.evaluate( timeSlice, evaluator ) ) { return true; } } catch ( FilterEvaluationException e ) { LOG.warn( "Unable to evaluate time slice projection filter: " + e.getMessage() ); } } return false; }
break; TypedObjectNode[] values = evaluator.eval( member, request.getValueReference() ); for ( TypedObjectNode value : values ) { if ( valuesSkipped < startIndex ) {
final TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator();