/** * Construct an XPath expression from a given string and initialize its * namespace context based on a given element. * * @param element The element that determines the namespace context of the * XPath expression. See {@link #addNamespaces(OMElement)} * for more details. * @param xpathExpr the string representation of the XPath expression. * @throws JaxenException if there is a syntax error while parsing the expression * or if the namespace context could not be set up */ public AXIOMXPath(OMElement element, String xpathExpr) throws JaxenException { this(xpathExpr); addNamespaces(element); }
/** * Helper method to create an AXIOMXPath * * @param source OMElement to be used to find NameSpaces * @param xpath XPath expression string * @return an <code>AXIOMXPath </code> instance */ private AXIOMXPath createAxiomXPath(OMElement source, String xpath) { try { AXIOMXPath axiomxPath = new AXIOMXPath(xpath); axiomxPath.addNamespaces(source); return axiomxPath; } catch (JaxenException e) { throw new LoggedRuntimeException("Error creating XPath " + xpath, log); } }
/** * Execute xPath expression and return value as object. * * @param element OMElement which requires to evaluate * @param xPathExp String xPath expression * @param nameSpaceMap name value pair containing namespace and prefixes * @return the Object which evaluated from OMElement * @throws JaxenException when having an issue with xPath expression */ protected Object xPathEvaluate(OMElement element, String xPathExp, Map<String, String> nameSpaceMap) throws JaxenException { AXIOMXPath xpath = new AXIOMXPath(element, xPathExp); xpath.addNamespaces(element); if (nameSpaceMap != null) { for (String prefix : nameSpaceMap.keySet()) { xpath.addNamespace(prefix, nameSpaceMap.get(prefix)); } } return xpath.evaluate(element); }
/** * Execute xPath expression and return value as object. * * @param element OMElement which requires to evaluate * @param xPathExp String xPath expression * @param nameSpaceMap name value pair containing namespace and prefixes * @return the Object which evaluated from OMElement * @throws JaxenException when having an issue with xPath expression */ protected Object xPathEvaluate(OMElement element, String xPathExp, Map<String, String> nameSpaceMap) throws JaxenException { AXIOMXPath xpath = new AXIOMXPath(element, xPathExp); xpath.addNamespaces(element); if (nameSpaceMap != null) { for (String prefix : nameSpaceMap.keySet()) { xpath.addNamespace(prefix, nameSpaceMap.get(prefix)); } } return xpath.evaluate(element); }
/** * Evaluates the given xpath on the complete message envelope and returns the extracted value * * @param xpath xpath to be used to extract the value * @return the extracted value if there is one , otherwise null */ public Object selectOnMessage(String xpath) { if (message == null) { if (log.isDebugEnabled()) { log.debug("The message is null. Returning null"); } return null; } try { AXIOMXPath axiomxPath = new AXIOMXPath(xpath); OMElement xml = (OMElement) messageInterceptor.extractEnvelope(message).getValue(); axiomxPath.addNamespaces(xml); return XPathHelper.evaluate(xml, axiomxPath); } catch (JaxenException e) { throw new LoggedRuntimeException("Error creating XPath " + xpath, log); } }