Class XmlPrintStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- org.symphonyoss.symphony.messageml.util.IndentedPrintStream
-
- org.symphonyoss.symphony.messageml.util.XmlPrintStream
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class XmlPrintStream extends IndentedPrintStream
A PrintStream based on IndentedPrintStream which adds functions to format XML.- Author:
- Bruce Skingle
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description XmlPrintStream(OutputStream outputStream)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseElement()Close an element previously created with openElement().Stringescape(String in)Translate reserved XML characters to XML entities.Stringescape(String in, XMLAttribute.Format format)Translate reserved XML characters to XML entities.voidopenElement(String name)Open an XML element with the given name.voidopenElement(String name, Object... attributes)Open an XML element with the given name, and attributes.voidopenElement(String name, Map<?,?> attributes)Open an XML element with the given name, and attributes.voidprintComment(String comment)Output a comment.voidprintElement(String name)Output a complete empty element.voidprintElement(String elementName, Object value)Output a complete element with the given content.voidprintElement(String name, String value, Object... attributes)Output an element with the given content (value).voidprintElement(String elementName, String value, Map<?,?> attributes)Output a complete element with the given content and attributes.voidprintElement(String elementName, Map<?,?> attributes)Output a complete element with the given attributes.static StringremoveNewLines(String textContent)Replace multiple newline characters with a single space.-
Methods inherited from class org.symphonyoss.symphony.messageml.util.IndentedPrintStream
align, closeBlock, closeBlock, continueBlock, forceNewLine, getLinePrefix, getOffset, getPrintOffsets, indent, isNoIndent, isNoNl, isoNlCr, isRemoveNl, openBlock, openBlock, outdent, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, printAlignedBlock, printlines, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, setLinePrefix, setNoIndent, setNoNl, setoNlCr, setPrintOffsets, setRemoveNl
-
Methods inherited from class java.io.PrintStream
append, append, append, checkError, clearError, close, flush, format, format, printf, printf, setError, write, write
-
Methods inherited from class java.io.FilterOutputStream
write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
XmlPrintStream
public XmlPrintStream(OutputStream outputStream)
Constructor.- Parameters:
outputStream- An OutputStream to which the formatted output will be sent.
-
-
Method Detail
-
openElement
public void openElement(String name)
Open an XML element with the given name. A call to closeElement() will output the appropriate XML closing tag. This class remembers the tag names.- Parameters:
name- Name of the XML element to open.
-
openElement
public void openElement(String name, Map<?,?> attributes)
Open an XML element with the given name, and attributes. A call to closeElement() will output the appropriate XML closing tag. This class remembers the tag names.- Parameters:
name- Name of the XML element to open.attributes- A map of name value pairs which will be used to add attributes to the element. Normally you can useMap<String,String>but if you want specify the attribute format useMap<String, XMLAttribute>. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
-
openElement
public void openElement(String name, Object... attributes)
Open an XML element with the given name, and attributes. A call to closeElement() will output the appropriate XML closing tag. This class remembers the tag names. The String parameters are taken to be alternatively names and values. Any odd value at the end of the list is added as a valueless attribute.- Parameters:
name- Name of the element.attributes- Attributes in name value pairs. Normally you can use pair of String,String but if you want specify the attribute format use pair of String, XMLAttribute. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
-
closeElement
public void closeElement()
Close an element previously created with openElement().
-
printElement
public void printElement(String elementName, Object value)
Output a complete element with the given content.- Parameters:
elementName- Name of element.value- Content of element.
-
printElement
public void printElement(String name, String value, Object... attributes)
Output an element with the given content (value). The opening and closing tags are output in a single operation.- Parameters:
name- Name of the element.value- Contents of the element.attributes- Alternate names and values of attributes for the element. Normally you can use pair of String,String but if you want specify the attribute format use pair of String, XMLAttribute. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
-
printElement
public void printElement(String elementName, Map<?,?> attributes)
Output a complete element with the given attributes.- Parameters:
elementName- Name of element.attributes- A map of name value pairs which will be used to add attributes to the element. Normally you can useMap<String,String>but if you want specify the attribute format useMap<String, XMLAttribute>. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
-
printElement
public void printElement(String elementName, String value, Map<?,?> attributes)
Output a complete element with the given content and attributes.- Parameters:
elementName- Name of element.value- Content of element.attributes- A map of name value pairs which will be used to add attributes to the element. Normally you can useMap<String,String>but if you want specify the attribute format useMap<String, XMLAttribute>. In particular, attributes containing json can be processed to avoid escaping of double quote, but wrapping the attribute in a single quote
-
printElement
public void printElement(String name)
Output a complete empty element.- Parameters:
name- Name of element.
-
printComment
public void printComment(String comment)
Output a comment.- Parameters:
comment- Comment text.
-
escape
public String escape(String in)
Translate reserved XML characters to XML entities.- Parameters:
in- Input string.
-
escape
public String escape(String in, XMLAttribute.Format format)
Translate reserved XML characters to XML entities.- Parameters:
in- Input string.format- Input format. The Json format does not escape ", but it escapes ' !
-
-