Package org.apache.juneau.marshall.xml
Class XmlUtils
java.lang.Object
org.apache.juneau.marshall.xml.XmlUtils
XML utility methods.
See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncollapseTextNodes(List<Object> value) Given a list of Strings and other Objects, combines Strings that are next to each other in the list.static Stringdecode(String value, StringBuilder sb) Translates any _x####_ sequences (introduced by the various encode methods) back into their original characters.static WriterencodeAttrName(Writer w, Object value) Serializes and encodes the specified object as valid XML attribute name.static WriterencodeAttrValue(Writer w, Object value, boolean trim) Encodes the specified attribute value and sends the results to the specified writer.static WriterencodeElementName(Writer w, Object value) Encodes any invalid XML element name characters to_x####_ sequences.static StringencodeElementName(Object value) Encodes any invalid XML element name characters to_x####_ sequences.static WriterencodeText(Writer w, Object value, boolean trim, boolean preserveWhitespace) Encodes the specified element text and sends the results to the specified writer.static StringescapeText(Object value) Escapes invalid XML text characters to_x####_ sequences.static NamespacefindNamespace(List<Xml> xmls, List<XmlSchema> schemas) Find the namespace given a list of@Xml and@XmlSchema annotations.static StringUtility method that converts the current event on the XML stream to something human-readable for debug purposes.
-
Method Details
-
collapseTextNodes
Given a list of Strings and other Objects, combines Strings that are next to each other in the list.- Parameters:
value- The list of text nodes to collapse.
Must not benull .- Returns:
- The same list.
-
decode
Translates any _x####_ sequences (introduced by the various encode methods) back into their original characters.- Parameters:
value- The string being decoded.
Can benull (returnsnull ).sb- The string builder to use as a scratch pad.
Can benull (a new one is created).- Returns:
- The decoded string, or
null if the input wasnull or represented anull value.
-
encodeAttrName
Serializes and encodes the specified object as valid XML attribute name.- Parameters:
w- The writer to send the output to.
Must not benull .value- The object being serialized.
Can benull (written as the_x0000_ null marker).- Returns:
- This object.
- Throws:
IOException- If a problem occurred.
-
encodeAttrValue
Encodes the specified attribute value and sends the results to the specified writer.Encodes any invalid XML text characters to
_x####_ sequences and sends the response to the specified writer.
Encodes'&' ,'<' ,'>' ,'"' , and'\'' as XML entities.
Encodes invalid XML text characters to_x####_ sequences.- Parameters:
w- The writer to send the output to.
Must not benull .value- The object being encoded.
Can benull (written as the_x0000_ null marker).trim- Trim the text before serializing it. Iftrue , leading and trailing whitespace characters will be encoded.- Returns:
- The same writer passed in.
-
encodeElementName
Encodes any invalid XML element name characters to_x####_ sequences.- Parameters:
value- The object being encoded.
Can benull (returns the_x0000_ null marker).- Returns:
- The encoded element name string.
-
encodeElementName
Encodes any invalid XML element name characters to_x####_ sequences.- Parameters:
w- The writer to send the output to.
Must not benull .value- The object being encoded.
Can benull (written as the_x0000_ null marker).- Returns:
- The same writer passed in.
-
encodeText
Encodes the specified element text and sends the results to the specified writer.Encodes any invalid XML text characters to
_x####_ sequences and sends the response to the specified writer.
Encodes'&' ,'<' , and'>' as XML entities.
Encodes invalid XML text characters to_x####_ sequences.- Parameters:
w- The writer to send the output to.
Must not benull .value- The object being encoded.
Can benull (written as the_x0000_ null marker).trim- Trim the text before serializing it.preserveWhitespace- Specifies whether we're in preserve-whitespace mode. (e.g.XmlFormat.MIXED_PWSorXmlFormat.TEXT_PWS. Iftrue , leading and trailing whitespace characters will be encoded.- Returns:
- The same writer passed in.
-
escapeText
Escapes invalid XML text characters to_x####_ sequences.- Parameters:
value- The object being encoded.
Can benull (returns the_x0000_ null marker).- Returns:
- The encoded string.
-
findNamespace
Find the namespace given a list of@Xml and@XmlSchema annotations.The annotations should be a parent-to-child ordering of annotations found on a class or method.
- Parameters:
xmls- The list of@Xml annotations.
Must not benull .schemas- The list of@XmlSchema annotations.
Must not benull .- Returns:
- The namespace, or
null if it couldn't be found.
-
toReadableEvent
Utility method that converts the current event on the XML stream to something human-readable for debug purposes.- Parameters:
r- The XML stream reader whose current event is to be converted to a readable string.
Must not benull .- Returns:
- The event in human-readable form.
-