org.apache.synapse.util.xpath
public class: SynapseXPath [javadoc |
source]
java.lang.Object
org.apache.axiom.om.xpath.AXIOMXPath
org.apache.synapse.util.xpath.SynapseXPath
XPath that has been used inside Synapse xpath processing. This has a extension function named
get-property
which is use to retrieve message context properties with the given
name from the function
For example the following function get-property('prop')
can be evaluatedd using
an XPath to retrieve the message context property value with the name prop
.
Apart from that this XPath has a certain set of XPath variables associated with it. They are
as follows;
- body
- The SOAP 1.1 or 1.2 body element.
- header
- The SOAP 1.1 or 1.2 header element.
Also there are some XPath prefixes defined in SynapseXPath
to access various
properties using XPath variables, where the variable name represents the particular prefix and
the property name as the local part of the variable. Those variables are;
- ctx
- Prefix for Synapse MessageContext properties
- axis2
- Prefix for Axis2 MessageContext properties
- trp
- Prefix for the transport headers
This XPath is Thread Safe, and provides a special set of evaluate functions for the
MessageContext
and SOAPEnvelope
as well as a method to retrieve
string values of the evaluated XPaths
Constructor: |
public SynapseXPath(String xpathString) throws JaxenException {
super(xpathString);
}
Parameters:
xpathString - xpath in its string format
Throws:
JaxenException - in case of an initialization failure
|
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.synapse.util.xpath.SynapseXPath Detail: |
public void addNamespace(OMNamespace ns) throws JaxenException {
addNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
|
protected Context getContext(Object obj) {
if (obj instanceof MessageContext) {
MessageContext synCtx = (MessageContext)obj;
ContextSupport baseContextSupport = getContextSupport();
ContextSupport contextSupport =
new ContextSupport(baseContextSupport.getNamespaceContext(),
new SynapseXPathFunctionContext(baseContextSupport.getFunctionContext(), synCtx),
new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), synCtx),
baseContextSupport.getNavigator());
Context context = new Context(contextSupport);
context.setNodeSet(new SingletonList(synCtx.getEnvelope()));
return context;
} else if (obj instanceof SOAPEnvelope) {
SOAPEnvelope env = (SOAPEnvelope)obj;
ContextSupport baseContextSupport = getContextSupport();
ContextSupport contextSupport =
new ContextSupport(baseContextSupport.getNamespaceContext(),
baseContextSupport.getFunctionContext(),
new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), env),
baseContextSupport.getNavigator());
Context context = new Context(contextSupport);
context.setNodeSet(new SingletonList(env));
return context;
} else {
return super.getContext(obj);
}
}
|
public String stringValueOf(MessageContext synCtx) {
try {
Object result = evaluate(synCtx);
if (result == null) {
return null;
}
StringBuffer textValue = new StringBuffer();
if (result instanceof List) {
List list = (List) result;
for (Object o : list) {
if (o == null && list.size() == 1) {
return null;
}
if (o instanceof OMTextImpl) {
textValue.append(((OMTextImpl) o).getText());
} else if (o instanceof OMElementImpl) {
String s = ((OMElementImpl) o).getText();
if (s.trim().length() == 0) {
s = o.toString();
}
textValue.append(s);
} else if (o instanceof OMDocumentImpl) {
textValue.append(
((OMDocumentImpl) o).getOMDocumentElement().toString());
}
}
} else {
textValue.append(result.toString());
}
return textValue.toString();
} catch (JaxenException je) {
handleException("Evaluation of the XPath expression " + this.toString() +
" resulted in an error", je);
}
return null;
}
Evaluates the XPath expression against the MessageContext of the current message and
returns a String representation of the result
|