Package org.apache.juneau.xml
Class XmlUtils
java.lang.Object
org.apache.juneau.xml.XmlUtils
XML utility methods.
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic LinkedList<Object>
collapseTextNodes
(LinkedList<Object> value) Given a list of Strings and other Objects, combines Strings that are next to each other in the list.static String
decode
(String value, StringBuilder sb) Translates any _x####_ sequences (introduced by the various encode methods) back into their original characters.static Writer
encodeAttrName
(Writer w, Object value) Serializes and encodes the specified object as valid XML attribute name.static Writer
encodeAttrValue
(Writer w, Object value, boolean trim) Encodes the specified attribute value and sends the results to the specified writer.static Writer
encodeElementName
(Writer w, Object value) Encodes any invalid XML element name characters to_x####_ sequences.static String
encodeElementName
(Object value) Encodes any invalid XML element name characters to_x####_ sequences.static Writer
encodeText
(Writer w, Object value, boolean trim, boolean preserveWhitespace) Encodes the specified element text and sends the results to the specified writer.static String
escapeText
(Object value) Escapes invalid XML text characters to_x####_ sequences.static Namespace
findNamespace
(List<Xml> xmls, List<XmlSchema> schemas) Find the namespace given a list of@Xml and@XmlSchema annotations.static String
Utility method that converts the current event on the XML stream to something human-readable for debug purposes.
-
Constructor Details
-
XmlUtils
public XmlUtils()
-
-
Method Details
-
encodeElementName
Encodes any invalid XML element name characters to_x####_ sequences.- Parameters:
w
- The writer to send the output to.value
- The object being encoded.- Returns:
- The same writer passed in.
-
encodeElementName
Encodes any invalid XML element name characters to_x####_ sequences.- Parameters:
value
- The object being encoded.- Returns:
- The encoded element name string.
-
escapeText
Escapes invalid XML text characters to_x####_ sequences.- Parameters:
value
- The object being encoded.- Returns:
- The encoded string.
-
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.value
- The object being encoded.trim
- Trim the text before serializing it.preserveWhitespace
- Specifies whether we're in preserve-whitespace mode. (e.g.XmlFormat.MIXED_PWS
orXmlFormat.TEXT_PWS
. Iftrue , leading and trailing whitespace characters will be encoded.- Returns:
- The same writer passed in.
-
encodeAttrName
Serializes and encodes the specified object as valid XML attribute name.- Parameters:
w
- The writer to send the output to.value
- The object being serialized.- 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.value
- The object being encoded.trim
- Trim the text before serializing it. Iftrue , leading and trailing whitespace characters will be encoded.- Returns:
- The same writer passed in.
-
decode
Translates any _x####_ sequences (introduced by the various encode methods) back into their original characters.- Parameters:
value
- The string being decoded.sb
- The string builder to use as a scratch pad.- Returns:
- The decoded string.
-
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.- Returns:
- The same list.
-
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.schemas
- The list of@XmlSchema annotations.- 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.- Returns:
- The event in human-readable form.
-