Refine search
public static List evaluate (Context context, Object arg) throws FunctionCallException { List contextNodes = context.getNodeSet(); if (contextNodes.size() == 0) return Collections.EMPTY_LIST; Navigator nav = context.getNavigator(); String xpathString; if ( arg instanceof String ) xpathString = (String)arg; else xpathString = StringFunction.evaluate(arg, nav); try { XPath xpath = nav.parseXPath(xpathString); ContextSupport support = context.getContextSupport(); xpath.setVariableContext( support.getVariableContext() ); xpath.setFunctionContext( support.getFunctionContext() ); xpath.setNamespaceContext( support.getNamespaceContext() ); return xpath.selectNodes( context.duplicate() ); } catch ( org.jaxen.saxpath.SAXPathException e ) { throw new FunctionCallException(e.toString()); } } }
@Override protected Object evaluateRawFirst(Object context) { try { return unWrapNS(xPath.selectSingleNode(context)); } catch (JaxenException e) { throw new IllegalStateException( "Unable to evaluate expression. See cause", e); } }
public String valueOf(Object context) { try { setNSContext(context); return xpath.stringValueOf(context); } catch (JaxenException e) { handleJaxenException(e); return ""; } }
/** * @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); }
@Override public List<Node> evaluate(final Node node, final RuleContext data) { final List<Node> results = new ArrayList<>(); try { initializeExpressionIfStatusIsNoneOrPartial(data.getLanguageVersion().getLanguageVersionHandler().getXPathHandler().getNavigator()); List<XPath> xPaths = getXPathsForNodeOrDefault(node.getXPathNodeName()); for (XPath xpath : xPaths) { @SuppressWarnings("unchecked") final List<Node> matchedNodes = xpath.selectNodes(node); results.addAll(matchedNodes); } } catch (final JaxenException e) { throw new RuntimeException(e); } return results; }
@Override @SuppressWarnings("unchecked") public List<Node> evaluateAsNodeList(Node node) { try { return xpath.selectNodes(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override public Node evaluateAsNode(Node node) { try { return (Node) xpath.selectSingleNode(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
public String evaluateAsString(Node node) { try { return xpath.stringValueOf(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
/** * Get a element for SOAP * @param envelope SOAP Envelope of which we should check required elements * @param decNamespaces Declared namespaces in RequiredElements assertion * @param expression XPATH expression of required elements * @return */ public static boolean checkRequiredElements(SOAPEnvelope envelope, HashMap decNamespaces, String expression) { // The XPath expression must be evaluated against the SOAP header // http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/ws-securitypolicy-1.2-spec-os.html#_Toc161826519 SOAPHeader header = envelope.getHeader(); Set namespaces = findAllPrefixNamespaces(header, decNamespaces); try { XPath xp = new AXIOMXPath(expression); for (Object namespace : namespaces) { OMNamespace tmpNs = (OMNamespace) namespace; xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI()); } List selectedNodes = xp.selectNodes(header); if (selectedNodes.size() == 0) { return false; } } catch (JaxenException e) { // This has to be changed to propagate an instance of a RampartException up throw new RuntimeException(e); } return true; }
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:"); je.printStackTrace(System.err); throw je;
public void setNamespaceContext(NamespaceContext namespaceContext) { this.namespaceContext = namespaceContext; xpath.setNamespaceContext(namespaceContext); }
@Override public double evaluateAsNumber(Node node) { try { return xpath.numberValueOf(node).doubleValue(); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override public boolean evaluateAsBoolean(Node node) { try { return xpath.booleanValueOf(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
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; }
/** * Evaluates the wrapped XPath expression and returns the list of selected * items. * * @param context * the node to use as context for evaluating the XPath expression. * @return the list of selected items, which may be of types: {@link Element} * , {@link Attribute}, {@link Text}, {@link CDATA}, {@link Comment} * , {@link ProcessingInstruction}, Boolean, Double, or String. * @throws JDOMException * if the evaluation of the XPath expression on the specified * context failed. */ @Override public List<?> selectNodes(Object context) throws JDOMException { try { navigator.setContext(context); return unWrap(xPath.selectNodes(context)); } catch (JaxenException ex1) { throw new JDOMException( "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1); } finally { navigator.reset(); } }
/** * Retrieves the MS CRM 2011 policy * * @return the policy string * @throws JaxenException issue with the response format * @throws IOException generic IO issue * @throws SOAPException issue with SOAP invocation */ public String retrievePolicy() throws IOException, SOAPException, JaxenException { String msg = FileUtil.readStringFromClasspath("/com/gooddata/msdynamics/RetrievePolicy.xml", MsDynamicsWrapper.class); SOAPMessage response = soap.execute(HTTPS + host + CRM_DISCOVERY_ENDPOINT, msg); XPath xp = soap.createXPath("//crm:Policy/text()", response); xp.addNamespace("crm", CRM_DISCOVERY_XMLNS); Text result = (Text) xp.selectSingleNode(response.getSOAPBody()); return result.getValue(); }
/** * Evaluates the wrapped XPath expression and returns the first entry in the * list of selected nodes (or atomics). * * @param context * the node to use as context for evaluating the XPath expression. * @return the first selected item, which may be of types: {@link Element}, * {@link Attribute}, {@link Text}, {@link CDATA}, {@link Comment}, * {@link ProcessingInstruction}, Boolean, Double, String, or * <code>null</code> if no item was selected. * @throws JDOMException * if the evaluation of the XPath expression on the specified * context failed. */ @Override public Object selectSingleNode(Object context) throws JDOMException { try { navigator.setContext(context); return unWrapNS(xPath.selectSingleNode(context)); } catch (JaxenException ex1) { throw new JDOMException( "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1); } finally { navigator.reset(); } }
/** * Returns the string value of the first node selected by applying the * wrapped XPath expression to the given context. * * @param context * the element to use as context for evaluating the XPath expression. * @return the string value of the first node selected by applying the * wrapped XPath expression to the given context. * @throws JDOMException * if the XPath expression is invalid or its evaluation on the * specified context failed. */ @Override public String valueOf(Object context) throws JDOMException { try { navigator.setContext(context); return xPath.stringValueOf(context); } catch (JaxenException ex1) { throw new JDOMException( "XPath error while evaluating \"" + xPath.toString() + "\": " + ex1.getMessage(), ex1); } finally { navigator.reset(); } }
public Node evaluateAsNode(String expression, Source context) throws XPathException { try { XPath xpath = createXPath(expression); Element element = getRootElement(context); return (Node) xpath.selectSingleNode(element); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex); } catch (TransformerException ex) { throw new XPathException("Could not transform context to DOM Node", ex); } }
public void setVariableContext(VariableContext variableContext) { xpath.setVariableContext(variableContext); }