Refine search
LOGGER.finest("evaluator=" + evaluator); XPath xpath = new BaseXPath(xPath, new DocumentNavigator()); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("xpath=" + xpath); evaluationResults = xpath.selectNodes(rootNode); } catch (Exception e) { LOGGER.finest("selectNodes problem:");
xpath = xpathCache.get(xpathQuery); if (xpath == null) { xpath = new BaseXPath(xpathQuery, FM_DOM_NAVIGATOR); xpath.setNamespaceContext(customNamespaceContext); xpath.setFunctionContext(FM_FUNCTION_CONTEXT); xpath.setVariableContext(FM_VARIABLE_CONTEXT); xpathCache.put(xpathQuery, xpath); List result = xpath.selectNodes(context != null ? context : EMPTY_ARRAYLIST); if (result.size() == 1) {
pending.push(originalXPath.getRootExpr()); while (!pending.isEmpty()) { final Expr node = pending.pop();
@Override @SuppressWarnings("unchecked") public List<Node> findChildNodesWithXPath(String xpathString) throws JaxenException { return new BaseXPath(xpathString, new DocumentNavigator()).selectNodes(this); }
private BaseXPath createXPath(final String xpathQueryString, final Navigator navigator) throws JaxenException { final BaseXPath xpath = new BaseXPath(xpathQueryString, navigator); if (properties.size() > 1) { final SimpleVariableContext vc = new SimpleVariableContext(); for (Entry<PropertyDescriptor<?>, Object> e : properties.entrySet()) { final String propName = e.getKey().name(); if (!"xpath".equals(propName)) { final Object value = e.getValue(); vc.setVariableValue(propName, value != null ? value.toString() : null); } } xpath.setVariableContext(vc); } return xpath; } }
/** * @param expression The XPath expression * @param filter The coercion filter * @param variables The XPath variable context * @param namespaces The XPath namespace context */ public JaxenCompiled(String expression, Filter<T> filter, Map<String, Object> variables, Namespace[] namespaces) { super(expression, filter, variables, namespaces); try { xPath = new BaseXPath(expression, navigator); } catch (JaxenException e) { throw new IllegalArgumentException("Unable to compile '" + expression + "'. See Cause.", e); } xPath.setNamespaceContext(this); xPath.setVariableContext(this); }
public static XPath getXPath(String path, Map<String, String> namespaces, Map<QName, Function> functions, Map<QName, Object> variables) throws JaxenException { DocumentNavigator nav = new DocumentNavigator(); XPath contextpath = new BaseXPath(path, nav); if (namespaces != null) { for (Map.Entry<String, String> entry : namespaces.entrySet()) { contextpath.addNamespace(entry.getKey(), entry.getValue()); } } if (functions != null) { contextpath.setFunctionContext(getFunctionContext(functions, (SimpleFunctionContext)contextpath .getFunctionContext())); } if (variables != null) contextpath.setVariableContext(getVariableContext(variables, (SimpleVariableContext)contextpath .getVariableContext())); return contextpath; }
/** * Compiles and sets the XPath expression wrapped by this object. * * @param expr * the XPath expression to wrap. * @throws JDOMException * if the XPath expression is invalid. */ private void setXPath(String expr) throws JDOMException { try { xPath = new BaseXPath(expr, navigator); xPath.setNamespaceContext(navigator); } catch (Exception ex1) { throw new JDOMException("Invalid XPath expression: \"" + expr + "\"", ex1); } }
/** * Returns the namespace prefixes that are used in the given XPath 1.0 expression. * <p> * If the expression is not a valid XPath expression, the empty set is returned. * </p> * * @param text * xpath expression, must not be <code>null</code> * @return namespace prefixes used in the expression, never <code>null</code>, but can be empty */ public static Set<String> extractPrefixes( String text ) { try { return extractPrefixes( new BaseXPath( text, null ).getRootExpr() ); } catch ( JaxenException e ) { // not an XPath expression return Collections.emptySet(); } }
public XPath parseXPath(String s) throws SAXPathException { return new BaseXPath(s, this); }
/** Select only the first node selected by this XPath * expression. If multiple nodes match, only one node will be * returned. The selected node will be the first * selected node in document-order, as defined by the XPath * specification. * </p> * * @param node the node, node-set or Context object for evaluation. * This value can be null. * * @return the node-set of all items selected * by this XPath expression * @throws JaxenException if an XPath error occurs during expression evaluation * * @see #selectNodes */ public Object selectSingleNode(Object node) throws JaxenException { List results = selectNodes( node ); if ( results.isEmpty() ) { return null; } return results.get( 0 ); }
@SuppressWarnings("unchecked") public String getElementNameWithPredicates() throws JaxenException { BaseXPath baseXPath = new BaseXPath(xPath, new DocumentNavigator()); Expr rootExpr = baseXPath.getRootExpr(); LocationPath locationPath = (LocationPath) rootExpr; List<Step> steps = locationPath.getSteps(); Step lastStep = steps.get(steps.size() - 1); return MCRNodeBuilder.simplify(lastStep.getText()); }
@Override @SuppressWarnings("unchecked") public List<Node> findChildNodesWithXPath(String xpathString) throws JaxenException { return new BaseXPath(xpathString, new DocumentNavigator()).selectNodes(this); }
@Override public final XPath parseXPath(String path) throws SAXPathException { return new BaseXPath(path, this); }
private BaseXPath createXPath(final String xpathQueryString, final Navigator navigator) throws JaxenException { final BaseXPath xpath = new BaseXPath(xpathQueryString, navigator); if (properties.size() > 1) { final SimpleVariableContext vc = new SimpleVariableContext(); for (Entry<PropertyDescriptor<?>, Object> e : properties.entrySet()) { final String propName = e.getKey().name(); if (!"xpath".equals(propName)) { final Object value = e.getValue(); vc.setVariableValue(propName, value != null ? value.toString() : null); } } xpath.setVariableContext(vc); } return xpath; } }
List answer = selectNodes(context);
LOGGER.finest("evaluator=" + evaluator); XPath xpath = new BaseXPath(xPath, new DocumentNavigator()); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("xpath=" + xpath); evaluationResults = xpath.selectNodes(rootNode); } catch (Exception e) { LOGGER.finest("selectNodes problem:");
xpath = (BaseXPath) xpathCache.get(xpathQuery); if (xpath == null) { xpath = new BaseXPath(xpathQuery, fmDomNavigator); xpath.setNamespaceContext(customNamespaceContext); xpath.setFunctionContext(fmFunctionContext); xpath.setVariableContext(fmVariableContext); xpathCache.put(xpathQuery, xpath); List result = xpath.selectNodes(context != null ? context : EMPTY_ARRAYLIST); if (result.size() == 1) { return ObjectWrapper.DEFAULT_WRAPPER.wrap(result.get(0));
public static List<QName> extractQNames( XPath xpath ) { List<QName> list = new ArrayList<QName>(); try { Expr expr = new BaseXPath( xpath.getXPath(), null ).getRootExpr(); if ( expr instanceof LocationPath ) { LocationPath lp = (LocationPath) expr; for ( Object o : lp.getSteps() ) { findQName( list, (Step) o, xpath.getNamespaceContext() ); } } } catch ( JaxenException e ) { // not a proper xpath } return list; }
/** * Returns a parsed form of the given xpath string, which will be suitable for queries on * documents that use the same navigator as this one. * * @param xpath the XPath expression * @return Returns a new XPath expression object. * @throws SAXPathException if the string is not a syntactically correct XPath expression * @see XPath */ public XPath parseXPath(String xpath) throws SAXPathException { return new BaseXPath(xpath, this); }