Package com.adaptris.core.util
Class XmlHelper
java.lang.Object
com.adaptris.core.util.XmlHelper
Helper class for handling XML within an AdaptrisMessage
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Document
Deprecated.static Document
createDocument
(AdaptrisMessage msg, boolean namespaceAware) Deprecated.since 3.1.0 use {createDocument(AdaptrisMessage, DocumentBuilderFactoryBuilder)
instead.static Document
createDocument
(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder) Create a document from an AdaptrisMessage.static Document
createDocument
(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure) Create a document from an AdaptrisMessage.static Document
createDocument
(AdaptrisMessage msg, NamespaceContext namespaceContext) Deprecated.since 3.1.0 use {createDocument(AdaptrisMessage, DocumentBuilderFactoryBuilder)
instead.static Document
createDocument
(InputStream in, DocumentBuilderFactoryBuilder builder) Create a document from anInputStream
.static Document
createDocument
(InputStream in, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure) Create a document from anInputStream
.static Document
Deprecated.since 3.1.0 use {createDocument(String, DocumentBuilderFactoryBuilder)
instead.static Document
createDocument
(String s, boolean namespaceAware) Deprecated.since 3.1.0 use {createDocument(String, DocumentBuilderFactoryBuilder)
instead.static Document
createDocument
(String s, DocumentBuilderFactoryBuilder builder) Create a document from an AdaptrisMessage.static Document
createDocument
(String s, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure) Create a document from an AdaptrisMessage.static Document
createDocument
(String s, NamespaceContext namespaceContext) Deprecated.since 3.1.0 use {createDocument(String, DocumentBuilderFactoryBuilder)
instead.static XmlUtils
Deprecated.Consider usingcreateXmlUtils(AdaptrisMessage, NamespaceContext)
instead.static XmlUtils
createXmlUtils
(AdaptrisMessage msg, NamespaceContext ctx) Deprecated.since 3.1.0 use {createDocument(AdaptrisMessage, DocumentBuilderFactoryBuilder)
instead.static XmlUtils
createXmlUtils
(AdaptrisMessage msg, NamespaceContext ctx, DocumentBuilderFactoryBuilder builder) Create an XMLUtils class from an AdaptrisMessage.static String
getXmlEncoding
(AdaptrisMessage msg, String enc) Figure out what encoding to use when writing a document.static String
nodeToString
(Node node) Convert an XML Node into a String snippet.static String
safeElementName
(String input, String defaultIfBlank) Make a safe element name by stripping out illegal XML characters and illegal element characters.static String
stripIllegalXmlCharacters
(String input) Strip illegal XML characters from data.static void
writeXmlDocument
(Document doc, AdaptrisMessage msg, String encoding) Write an XML document to the message with specified encoding.static void
writeXmlDocument
(Document doc, AdaptrisMessage msg, String encoding, Transformer serializer) Write an XML document to the message with specified encoding.
-
Field Details
-
FALLBACK_TRANSFORMER_FACTORY_IMPL
- See Also:
-
-
Constructor Details
-
XmlHelper
public XmlHelper()
-
-
Method Details
-
createXmlUtils
Deprecated.Consider usingcreateXmlUtils(AdaptrisMessage, NamespaceContext)
instead.Create an XMLUtils class from an AdaptrisMessage.- Parameters:
msg
- the Adaptris message- Returns:
- an XxmlUtils instance
- Throws:
CoreException
- if the msg does not contain valid XML.
-
createXmlUtils
@Deprecated public static XmlUtils createXmlUtils(AdaptrisMessage msg, NamespaceContext ctx) throws CoreException Deprecated.since 3.1.0 use {createDocument(AdaptrisMessage, DocumentBuilderFactoryBuilder)
instead.Create an XMLUtils class from an AdaptrisMessage.- Parameters:
msg
- the Adaptris messagectx
- the NamespaceContext.- Returns:
- an XxmlUtils instance
- Throws:
CoreException
- if the msg does not contain valid XML.
-
createXmlUtils
public static XmlUtils createXmlUtils(AdaptrisMessage msg, NamespaceContext ctx, DocumentBuilderFactoryBuilder builder) throws CoreException Create an XMLUtils class from an AdaptrisMessage.- Parameters:
msg
- the Adaptris messagectx
- the NamespaceContext.builder
- configuration for the underlyingDocumentBuilderFactory
instance..- Returns:
- an XmlUtils instance
- Throws:
CoreException
- if the msg does not contain valid XML.
-
createDocument
@Deprecated public static Document createDocument(AdaptrisMessage msg) throws ParserConfigurationException, IOException, SAXException Deprecated.Consider usingcreateDocument(AdaptrisMessage, NamespaceContext)
instead.Create a document from an AdaptrisMessage. -
createDocument
@Deprecated public static Document createDocument(AdaptrisMessage msg, boolean namespaceAware) throws ParserConfigurationException, IOException, SAXException Deprecated.since 3.1.0 use {createDocument(AdaptrisMessage, DocumentBuilderFactoryBuilder)
instead.Create a document from an AdaptrisMessage.- Parameters:
msg
- the AdaptrisMessagenamespaceAware
- whether or not the document builder factory used will be namespace aware.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
public static Document createDocument(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder) throws ParserConfigurationException, IOException, SAXException Create a document from an AdaptrisMessage.- Parameters:
msg
- the AdaptrisMessagebuilder
- configuration for the underlyingDocumentBuilderFactory
instance..- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
public static Document createDocument(AdaptrisMessage msg, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure) throws ParserConfigurationException, IOException, SAXException Create a document from an AdaptrisMessage.- Parameters:
msg
- the AdaptrisMessagebuilder
- configuration for the underlyingDocumentBuilderFactory
instance.newDocOnFailure
- create a new Document if the msg failed to parse.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
@Deprecated public static Document createDocument(AdaptrisMessage msg, NamespaceContext namespaceContext) throws ParserConfigurationException, IOException, SAXException Deprecated.since 3.1.0 use {createDocument(AdaptrisMessage, DocumentBuilderFactoryBuilder)
instead.Convenience method to create a document from an AdaptrisMessage.- Parameters:
msg
- the AdaptrisMessagenamespaceContext
- the name space context, if null, then we will not be namespace aware.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
@Deprecated public static Document createDocument(String s) throws ParserConfigurationException, IOException, SAXException Deprecated.since 3.1.0 use {createDocument(String, DocumentBuilderFactoryBuilder)
instead.Create a document from a String.- Parameters:
s
- the string containing XML- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
@Deprecated public static Document createDocument(String s, NamespaceContext namespaceContext) throws ParserConfigurationException, IOException, SAXException Deprecated.since 3.1.0 use {createDocument(String, DocumentBuilderFactoryBuilder)
instead.Convenience method to create a document from an AdaptrisMessage.- Parameters:
s
- the string containing XMLnamespaceContext
- the namespace context, if null, then we will not be namespace aware.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
@Deprecated public static Document createDocument(String s, boolean namespaceAware) throws ParserConfigurationException, IOException, SAXException Deprecated.since 3.1.0 use {createDocument(String, DocumentBuilderFactoryBuilder)
instead.Create a document from a String.- Parameters:
s
- the string containing XMLnamespaceAware
- whether or not the document builder factory used will be namespace aware.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
public static Document createDocument(String s, DocumentBuilderFactoryBuilder builder) throws ParserConfigurationException, IOException, SAXException Create a document from an AdaptrisMessage.- Parameters:
s
- the string containing XMLbuilder
- configuration for the underlyingDocumentBuilderFactory
instance..- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
public static Document createDocument(String s, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure) throws ParserConfigurationException, IOException, SAXException Create a document from an AdaptrisMessage.- Parameters:
s
- the string containing XMLbuilder
- configuration for the underlyingDocumentBuilderFactory
instance..newDocOnFailure
- return a new document if the String is not XML.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
public static Document createDocument(InputStream in, DocumentBuilderFactoryBuilder builder) throws ParserConfigurationException, IOException, SAXException Create a document from anInputStream
.- Parameters:
in
- the inputstreambuilder
- configuration for the underlyingDocumentBuilderFactory
instance..- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
createDocument
public static Document createDocument(InputStream in, DocumentBuilderFactoryBuilder builder, boolean newDocOnFailure) throws ParserConfigurationException, IOException, SAXException Create a document from anInputStream
.- Parameters:
in
- the inputstreambuilder
- configuration for the underlyingDocumentBuilderFactory
instance.newDocOnFailure
- return a new document if the input stream failed to parse.- Returns:
- the Document element
- Throws:
ParserConfigurationException
IOException
SAXException
-
safeElementName
Make a safe element name by stripping out illegal XML characters and illegal element characters.- Parameters:
input
- the input string.defaultIfBlank
- the default element name if the input resolves to the blank string (whitespace is trimmed).- Returns:
- a safe element name that conforms to the specification.
-
stripIllegalXmlCharacters
Strip illegal XML characters from data.The following regular expression is used to strip out all invalid XML 1.0 characters :
"[^ \r\n --�𐀀-]"
.- Parameters:
input
- the input string- Returns:
- a string where all the invalid characters have been removed.
-
writeXmlDocument
public static void writeXmlDocument(Document doc, AdaptrisMessage msg, String encoding) throws Exception Write an XML document to the message with specified encoding.- Parameters:
doc
- the documentmsg
- the messageencoding
- will default to "UTF-8" if not specified, and the msg does not have a declared content encoding.- Throws:
Exception
-
writeXmlDocument
public static void writeXmlDocument(Document doc, AdaptrisMessage msg, String encoding, Transformer serializer) throws Exception Write an XML document to the message with specified encoding.- Parameters:
doc
- the documentmsg
- the messageencoding
- will default to "UTF-8" if not specified, and the msg does not have a declared content encoding.serializer
- theTransformer
to use.- Throws:
Exception
-
getXmlEncoding
Figure out what encoding to use when writing a document.- Parameters:
msg
- the messageenc
- the configured encoding, if any.- Returns:
- either the value of
encoding
,AdaptrisMessage#getContentEncoding()
or 'UTF-8' in that order or preference.
-
nodeToString
Convert an XML Node into a String snippet.- Parameters:
node
- The node to get as an XML String.- Returns:
- The XML String representation of the Node.
-
createDocument(AdaptrisMessage, NamespaceContext)
instead.