Class XpathMessageSplitter

java.lang.Object
com.adaptris.core.services.splitter.MessageSplitterImp
com.adaptris.core.services.splitter.XpathMessageSplitter
All Implemented Interfaces:
MessageSplitter

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.

See Also:

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.

  • Constructor Details

    • XpathMessageSplitter

      public XpathMessageSplitter()
    • XpathMessageSplitter

      public XpathMessageSplitter(String xpath)
    • XpathMessageSplitter

      public XpathMessageSplitter(String xpath, String encoding)
  • Method Details

    • splitMessage

      Description copied from interface: 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.

      Parameters:
      msg - the msg to split
      Returns:
      an Iterable of AdaptrisMessage
      Throws:
      CoreException - wrapping any other exception
    • setXpath

      public void setXpath(String xp)
      Set the XPath to use to extract the individual messages
      Parameters:
      xp - the XPath
    • getXpath

      public String getXpath()
      Get the XPath to use to extract the individual messages.
      Returns:
      the XPath as a String
    • setEncoding

      public void setEncoding(String charSet)
      Sets the encoding to use on the output XML docs.
      Parameters:
      charSet - the encoding, defaults to ISO-8859-1
    • getEncoding

      public String getEncoding()
      Gets the encoding used by this splitter
      Returns:
      the encoding.
    • getNamespaceContext

      public KeyValuePairSet getNamespaceContext()
      Returns:
      the namespaceContext
    • setNamespaceContext

      public void setNamespaceContext(KeyValuePairSet kvps)
      Set the namespace context for resolving namespaces.
      • The key is the namespace prefix
      • The value is the namespace uri
      Parameters:
      kvps - the namespace context
      See Also:
    • getXmlDocumentFactoryConfig

      public DocumentBuilderFactoryBuilder getXmlDocumentFactoryConfig()
    • setXmlDocumentFactoryConfig

      public void setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder xml)