public class XpathMessageSplitter extends MessageSplitterImp
Implementation of MessageSplitter
which splits an XML document based on an XPath.
TheMessage must be an XML document and split is specified by an XPath which returns a repeating subset of the document.
Given the following input document:
<envelope>
<document>one</document>
<document>two</document>
<document>three</document>
</envelope>
then the following XPath: /envelope/document
will create 3 documents each of which will only contain the
element.
If the DocumentBuilderFactoryBuilder
has been explicitly set to be not namespace aware and the document does in fact
contain namespaces, then Saxon can cause merry havoc in the sense that //NonNamespaceXpath
doesn't work if the document
has namespaces in it. We have included a shim so that behaviour can be toggled based on what you have configured.
XPath.newXPathInstance(DocumentBuilderFactoryBuilder, NamespaceContext)
In the adapter configuration file this class is aliased as xpath-message-splitter which is the preferred alternative to the fully qualified classname when building your configuration.
MessageSplitterImp.SplitMessageIterator
logR
Constructor and Description |
---|
XpathMessageSplitter() |
XpathMessageSplitter(java.lang.String xpath) |
XpathMessageSplitter(java.lang.String xpath,
java.lang.String encoding) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getEncoding()
Gets the encoding used by this splitter
|
KeyValuePairSet |
getNamespaceContext() |
DocumentBuilderFactoryBuilder |
getXmlDocumentFactoryConfig() |
java.lang.String |
getXpath()
Get the XPath to use to extract the individual messages.
|
void |
setEncoding(java.lang.String charSet)
Sets the encoding to use on the output XML docs.
|
void |
setNamespaceContext(KeyValuePairSet kvps)
Set the namespace context for resolving namespaces.
|
void |
setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder xml) |
void |
setXpath(java.lang.String xp)
Set the XPath to use to extract the individual messages
|
CloseableIterable<AdaptrisMessage> |
splitMessage(AdaptrisMessage msg)
Splits an
AdaptrisMessage into some number of AdaptrisMessage objects. |
copyMetadata, getCopyMetadata, getCopyObjectMetadata, getMessageFactory, selectFactory, setCopyMetadata, setCopyObjectMetadata, setMessageFactory
public XpathMessageSplitter()
public XpathMessageSplitter(java.lang.String xpath)
public XpathMessageSplitter(java.lang.String xpath, java.lang.String encoding)
public CloseableIterable<AdaptrisMessage> splitMessage(AdaptrisMessage msg) throws CoreException
MessageSplitter
Splits an AdaptrisMessage
into some number of AdaptrisMessage objects. Preservation of metadata is down to the
implementation.
If this method returns a CloseableIterable
, it must be closed by the caller! This contract cannot be clearly
expressed in Java code without breaking the API in uncomfortable ways for things just returning a List, which is why
this method is only declared to return Iterable.
msg
- the msg to splitIterable
of AdaptrisMessage
CoreException
- wrapping any other exceptionpublic void setXpath(java.lang.String xp)
xp
- the XPathpublic java.lang.String getXpath()
public void setEncoding(java.lang.String charSet)
charSet
- the encoding, defaults to ISO-8859-1public java.lang.String getEncoding()
public KeyValuePairSet getNamespaceContext()
public void setNamespaceContext(KeyValuePairSet kvps)
kvps
- the namespace contextSimpleNamespaceContext.create(KeyValuePairSet)
public DocumentBuilderFactoryBuilder getXmlDocumentFactoryConfig()
public void setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder xml)