|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.camel.support.ServiceSupport org.apache.camel.builder.xml.XPathBuilder
public class XPathBuilder
Creates an XPath expression builder which creates a nodeset result by default.
If you want to evaluate a String expression then call stringResult()
XPathBuilder
its adviced to invoke ServiceSupport.start()
to prepare the builder before using; though the builder will auto-start on first use.
XPathConstants.NODESET
Field Summary |
---|
Fields inherited from class org.apache.camel.support.ServiceSupport |
---|
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending |
Constructor Summary | |
---|---|
XPathBuilder(String text)
|
Method Summary | ||
---|---|---|
XPathBuilder |
booleanResult()
Sets the expression result type to boolean |
|
protected XPathFunctionResolver |
createDefaultFunctionResolver(XPathFunctionResolver parent)
|
|
protected DefaultNamespaceContext |
createNamespaceContext(XPathFactory factory)
|
|
protected XPathExpression |
createTraceNamespaceExpression()
|
|
protected XPathExpression |
createXPathExpression()
Creates a new xpath expression as there we no available in the pool. |
|
protected XPathFactory |
createXPathFactory()
|
|
XPathBuilder |
documentType(Class<?> documentType)
Configures the document type to use. |
|
protected Object |
doGetDocument(Exchange exchange,
Object body)
|
|
protected Object |
doInEvaluateAs(XPathExpression xpathExpression,
Exchange exchange,
QName resultQName)
|
|
void |
doStart()
Implementations override this method to support customized start/stop. |
|
void |
doStop()
Implementations override this method to support customized start/stop. |
|
void |
enableSaxon()
Enables Saxon on this particular XPath expression, as saxon() sets the default static XPathFactory which may have already been initialised
by previous XPath expressions |
|
String |
evaluate(CamelContext context,
Object body)
Evaluates the given xpath using the provided body as a String return type. |
|
|
evaluate(CamelContext context,
Object body,
Class<T> type)
Evaluates the given xpath using the provided body. |
|
protected Object |
evaluate(Exchange exchange)
|
|
|
evaluate(Exchange exchange,
Class<T> type)
Returns the value of the expression on the given exchange |
|
protected Object |
evaluateAs(Exchange exchange,
QName resultQName)
Evaluates the expression as the given result type |
|
XPathBuilder |
factory(XPathFactory xpathFactory)
Configures to use the provided XPath factory. |
|
XPathBuilder |
functionResolver(XPathFunctionResolver functionResolver)
Sets the XPathFunctionResolver instance to use on these XPath
expressions |
|
XPathFunction |
getBodyFunction()
Gets the XPathFunction for getting the input message body. |
|
protected Object |
getDocument(Exchange exchange,
Object body)
Strategy method to extract the document from the exchange. |
|
Class<?> |
getDocumentType()
|
|
XPathFunctionResolver |
getFunctionResolver()
|
|
XPathFunction |
getHeaderFunction()
Gets the XPathFunction for getting the input message header. |
|
DefaultNamespaceContext |
getNamespaceContext()
Gets the namespace context, can be null if no custom context has been assigned. |
|
String |
getObjectModelUri()
|
|
XPathFunction |
getOutBodyFunction()
Gets the XPathFunction for getting the output message body. |
|
XPathFunction |
getOutHeaderFunction()
Gets the XPathFunction for getting the output message header. |
|
XPathFunction |
getPropertiesFunction()
Gets the XPathFunction for getting the exchange properties. |
|
QName |
getResultQName()
|
|
Class<?> |
getResultType()
|
|
XPathFunction |
getSimpleFunction()
Gets the XPathFunction for executing simple
language as xpath function. |
|
String |
getText()
|
|
XPathFactory |
getXPathFactory()
Gets the xpath factory, can be null if no custom factory has been assigned. |
|
protected void |
initDefaultXPathFactory()
|
|
protected boolean |
isInputStreamNeeded(Exchange exchange)
Checks whether we need an InputStream to access the message body. |
|
boolean |
isLogNamespaces()
|
|
XPathBuilder |
logNamespaces()
Activates trace logging of all discovered namespaces in the message - to simplify debugging namespace-related issues Namespaces are printed in Hashmap style {xmlns:prefix=[namespaceURI], xmlns:prefix=[namespaceURI]} . |
|
boolean |
matches(CamelContext context,
Object body)
Matches the given xpath using the provided body. |
|
boolean |
matches(Exchange exchange)
Evaluates the predicate on the message exchange and returns true if this exchange matches the predicate |
|
XPathBuilder |
namespace(String prefix,
String uri)
Registers the namespace prefix and URI with the builder so that the prefix can be used in XPath expressions |
|
XPathBuilder |
namespaces(Namespaces namespaces)
Registers namespaces with the builder so that the registered prefixes can be used in XPath expressions |
|
XPathBuilder |
nodeResult()
Sets the expression result type to boolean |
|
XPathBuilder |
nodeSetResult()
Sets the expression result type to boolean |
|
XPathBuilder |
numberResult()
Sets the expression result type to boolean |
|
XPathBuilder |
objectModel(String uri)
Sets the object model URI to use |
|
protected void |
populateDefaultNamespaces(DefaultNamespaceContext context)
Populate a number of standard prefixes if they are not already there |
|
XPathBuilder |
resultType(Class<?> resultType)
Sets the expression result type to boolean |
|
XPathBuilder |
saxon()
Configures to use Saxon as the XPathFactory which allows you to use XPath 2.0 functions which may not be part of the build in JDK XPath parser. |
|
void |
setBodyFunction(XPathFunction bodyFunction)
|
|
void |
setDocumentType(Class<?> documentType)
|
|
void |
setFunctionResolver(XPathFunctionResolver functionResolver)
|
|
void |
setHeaderFunction(XPathFunction headerFunction)
|
|
void |
setLogNamespaces(boolean logNamespaces)
|
|
void |
setNamespaceContext(DefaultNamespaceContext namespaceContext)
|
|
protected void |
setNamespaceIfNotPresent(DefaultNamespaceContext context,
String prefix,
String uri)
|
|
void |
setNamespaces(Map<String,String> namespaces)
Injects the XML Namespaces of prefix -> uri mappings |
|
void |
setObjectModelUri(String objectModelUri)
|
|
void |
setOutBodyFunction(XPathFunction outBodyFunction)
|
|
void |
setOutHeaderFunction(XPathFunction outHeaderFunction)
|
|
void |
setPropertiesFunction(XPathFunction propertiesFunction)
|
|
void |
setResultQName(QName resultQName)
|
|
void |
setResultType(Class<?> resultType)
|
|
void |
setSimpleFunction(XPathFunction simpleFunction)
|
|
void |
setXPathFactory(XPathFactory xpathFactory)
|
|
XPathBuilder |
stringResult()
Sets the expression result type to boolean |
|
String |
toString()
|
|
XPathBuilder |
variable(String name,
Object value)
Registers a variable (in the global namespace) which can be referred to from XPath expressions |
|
static XPathBuilder |
xpath(String text)
|
|
static XPathBuilder |
xpath(String text,
Class<?> resultType)
|
Methods inherited from class org.apache.camel.support.ServiceSupport |
---|
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, start, stop, suspend |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XPathBuilder(String text)
text
- The XPath expressionMethod Detail |
---|
public static XPathBuilder xpath(String text)
public static XPathBuilder xpath(String text, Class<?> resultType)
public String toString()
toString
in class Object
public boolean matches(Exchange exchange)
Predicate
matches
in interface Predicate
exchange
- the message exchange
public <T> T evaluate(Exchange exchange, Class<T> type)
Expression
evaluate
in interface Expression
exchange
- the message exchange on which to evaluate the expressiontype
- the expected type of the evaluation result
public boolean matches(CamelContext context, Object body)
context
- the camel contextbody
- the body
public <T> T evaluate(CamelContext context, Object body, Class<T> type)
context
- the camel contextbody
- the bodytype
- the type to return
public String evaluate(CamelContext context, Object body)
context
- the camel contextbody
- the body
public XPathBuilder booleanResult()
public XPathBuilder nodeResult()
public XPathBuilder nodeSetResult()
public XPathBuilder numberResult()
public XPathBuilder stringResult()
public XPathBuilder resultType(Class<?> resultType)
public XPathBuilder objectModel(String uri)
public XPathBuilder saxon()
public XPathBuilder functionResolver(XPathFunctionResolver functionResolver)
XPathFunctionResolver
instance to use on these XPath
expressions
public XPathBuilder namespace(String prefix, String uri)
prefix
- is the namespace prefix that can be used in the XPath
expressionsuri
- is the namespace URI to which the prefix refers
public XPathBuilder namespaces(Namespaces namespaces)
namespaces
- is namespaces object that should be used in the
XPath expression
public XPathBuilder variable(String name, Object value)
name
- name of variablevalue
- value of variable
public XPathBuilder documentType(Class<?> documentType)
InputSource
to use SAX streams.
By default Camel uses Document
as the type.
documentType
- the document type
public XPathBuilder factory(XPathFactory xpathFactory)
xpathFactory
- the xpath factory to use
public XPathBuilder logNamespaces()
{xmlns:prefix=[namespaceURI], xmlns:prefix=[namespaceURI]}
.
The implicit XML namespace is omitted (http://www.w3.org/XML/1998/namespace).
XML allows for namespace prefixes to be redefined/overridden due to hierarchical scoping, i.e. prefix abc can be mapped to http://abc.com,
and deeper in the document it can be mapped to http://def.com. When two prefixes are detected which are equal but are mapped to different
namespace URIs, Camel will show all namespaces URIs it is mapped to in an array-style.
This feature is disabled by default.
public XPathFactory getXPathFactory()
public void setXPathFactory(XPathFactory xpathFactory)
public Class<?> getDocumentType()
public void setDocumentType(Class<?> documentType)
public String getText()
public QName getResultQName()
public void setResultQName(QName resultQName)
public DefaultNamespaceContext getNamespaceContext()
public void setNamespaceContext(DefaultNamespaceContext namespaceContext)
public XPathFunctionResolver getFunctionResolver()
public void setFunctionResolver(XPathFunctionResolver functionResolver)
public void setNamespaces(Map<String,String> namespaces)
NamespaceAware
setNamespaces
in interface NamespaceAware
namespaces
- the XML namespaces with the key of prefixes and the value the URIspublic XPathFunction getBodyFunction()
XPathFunction
for getting the input message body.
A default function will be assigned (if no custom assigned) when either starting this builder
or on first evaluation.
public void setBodyFunction(XPathFunction bodyFunction)
public XPathFunction getHeaderFunction()
XPathFunction
for getting the input message header.
A default function will be assigned (if no custom assigned) when either starting this builder
or on first evaluation.
public void setHeaderFunction(XPathFunction headerFunction)
public XPathFunction getOutBodyFunction()
XPathFunction
for getting the output message body.
A default function will be assigned (if no custom assigned) when either starting this builder
or on first evaluation.
public void setOutBodyFunction(XPathFunction outBodyFunction)
public XPathFunction getOutHeaderFunction()
XPathFunction
for getting the output message header.
A default function will be assigned (if no custom assigned) when either starting this builder
or on first evaluation.
public void setOutHeaderFunction(XPathFunction outHeaderFunction)
public XPathFunction getPropertiesFunction()
XPathFunction
for getting the exchange properties.
A default function will be assigned (if no custom assigned) when either starting this builder
or on first evaluation.
public void setPropertiesFunction(XPathFunction propertiesFunction)
public XPathFunction getSimpleFunction()
XPathFunction
for executing simple
language as xpath function.
A default function will be assigned (if no custom assigned) when either starting this builder
or on first evaluation.
public void setSimpleFunction(XPathFunction simpleFunction)
public Class<?> getResultType()
public void setResultType(Class<?> resultType)
public void setLogNamespaces(boolean logNamespaces)
public boolean isLogNamespaces()
public String getObjectModelUri()
public void enableSaxon()
saxon()
sets the default static XPathFactory which may have already been initialised
by previous XPath expressions
public void setObjectModelUri(String objectModelUri)
protected Object evaluate(Exchange exchange)
protected Object evaluateAs(Exchange exchange, QName resultQName)
protected Object doInEvaluateAs(XPathExpression xpathExpression, Exchange exchange, QName resultQName)
protected XPathExpression createXPathExpression() throws XPathExpressionException, XPathFactoryConfigurationException
XPathExpressionException
XPathFactoryConfigurationException
protected XPathExpression createTraceNamespaceExpression() throws XPathFactoryConfigurationException, XPathExpressionException
XPathFactoryConfigurationException
XPathExpressionException
protected DefaultNamespaceContext createNamespaceContext(XPathFactory factory)
protected void populateDefaultNamespaces(DefaultNamespaceContext context)
protected void setNamespaceIfNotPresent(DefaultNamespaceContext context, String prefix, String uri)
protected XPathFunctionResolver createDefaultFunctionResolver(XPathFunctionResolver parent)
protected boolean isInputStreamNeeded(Exchange exchange)
InputStream
to access the message body.
Depending on the content in the message body, we may not need to convert
to InputStream
.
exchange
- the current exchange
InputStream
beforehand converting afterwards.protected Object getDocument(Exchange exchange, Object body)
protected Object doGetDocument(Exchange exchange, Object body) throws Exception
Exception
public void doStart() throws Exception
ServiceSupport
ServiceSupport.doStop()
for more details.
doStart
in class ServiceSupport
Exception
ServiceSupport.doStop()
public void doStop() throws Exception
ServiceSupport
ServiceSupport.doStop()
method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext
is shutting down.
doStop
in class ServiceSupport
Exception
ServiceSupport.doStart()
protected XPathFactory createXPathFactory() throws XPathFactoryConfigurationException
XPathFactoryConfigurationException
protected void initDefaultXPathFactory() throws XPathFactoryConfigurationException
XPathFactoryConfigurationException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |