XMLOutputProcessor
for supporting the XMLOutputter.
This class is marked abstract even though all methods are fully implemented.
The process*(...) methods are public because they match the
XMLOutputProcessor interface but the remaining methods are all protected.
People who want to create a custom XMLOutputProcessor for XMLOutputter are
able to extend this class and modify any functionality they want. Before
sub-classing this you should first check to see if the Format class
can get you the results you want.
Subclasses of this should have reentrant methods. This is easiest to accomplish simply by not allowing any instance fields. If your sub-class has an instance field/variable, then it's probably broken.
One significant feature of this implementation is that it creates and
maintains both a NamespaceStack and FormatStack that are
managed in the
printElement(Writer, FormatStack, NamespaceStack, Element) method.
The stacks are pushed and popped in that method only. They significantly
improve the performance and readability of the code.
The NamespaceStack is only sent through to the
printElement(Writer, FormatStack, NamespaceStack, Element) and
printContent(Writer, FormatStack, NamespaceStack, Walker) methods,
but the FormatStack is pushed through to all print* Methods.
In XML the concept of 'Text' can be loosely defined as anything that can be
found between an Element's start and end tags, excluding Comments and
Processing Instructions. When considered from a JDOM perspective, this means
Text, CDATA and EntityRef content. This will be
referred to as 'Text-like content'
XMLOutputter delegates the management and formatting of Content to a
Walker instance. See Walker and its various implementations for
details on how the Element content is processed.
Because the Walker interface specifies that Text/CDATA content may be
returned as either Text/CDATA instances or as formatted String values
this class sometimes uses printCDATA(...) and printText(...), and sometimes
uses the more direct textCDATA(Writer, String) or
textRaw(Writer, String) as
appropriate. In other words, subclasses should probably override these second
methods instead of the print methods.
Non-text content is processed via the respective print* methods. The usage should be logical based on the method name.
The general observations are:
write(...) methods. Thus, all other methods do their
respective processing and delegate the actual destination output to the
write(Writer, char) or write(Writer, String) methods.
All Text-like content (printCDATA, printText, and printEntityRef) will ultimately be output through the the text* methods (and no other content).
XMLOutputter, XMLOutputProcessor
| Modifier and Type | Field and Description |
|---|---|
| protected static final String | CDATAPOST
Simple constant for a close-CDATA |
| protected static final String | CDATAPRE
Simple constant for an open-CDATA |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | attributeEscapedEntitiesFilter(final Writer
The destination Writer out, final FormatStack The fstack, final String FormatStackString Attribute value to escape.This will take the three pre-defined entities in XML 1.0 ('<', '>', and '&' - used specifically in XML elements) as well as CR/NL and Quote characters which require escaping inside Attribute values and convert their character representation to the appropriate entity reference suitable for XML attribute content. |
| protected void | printAttribute(final Writer
Writer to use.The current FormatStack fstack, final Attribute Attribute to outputThis will handle printing of an |
| protected void | printCDATA(final Writer
Writer to use.the FormatStack fstack, final CDATA CDATA to write.This will handle printing of a |
| protected void | printComment(final Writer
Writer to use.the FormatStack fstack, final Comment Comment to write.This will handle printing of a |
| protected void | printContent(final Writer
Writer to use.the FormatStack fstack, final NamespaceStack the NamespaceStack nstack, final Walker Walker of Content to write.This will handle printing of a List of |
| protected void | printDeclaration(final Writer
Writer to use.the FormatStack fstack)This will handle printing of the XML declaration. |
| protected void | printDocType(final Writer
Writer to use.the FormatStack fstack, final DocType DocType to write.This will handle printing of a |
| protected void | printDocument(final Writer
Writer to use.the FormatStack fstack, final NamespaceStack the NamespaceStack nstack, final Document Document to write.This will handle printing of a |
| protected void | printElement(final Writer
Writer to use.the FormatStack fstack, final NamespaceStack the NamespaceStack nstack, final Element Element to write.This will handle printing of an |
| protected void | printEntityRef(final Writer
Writer to use.the FormatStack fstack, final EntityRef EntotyRef to write.This will handle printing of an |
| protected void | printNamespace(final Writer
Writer to use.The current FormatStack fstack, final Namespace Namespace to print definition ofThis will handle printing of any needed |
| protected void | printProcessingInstruction(final Writer
Writer to use.the FormatStack fstack, final ProcessingInstruction ProcessingInstruction to write.This will handle printing of a |
| protected void | printText(final Writer
Writer to use.the FormatStack fstack, final Text Text to write.This will handle printing of a |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | process(final Writer
Writer to use.Format instance specifying output styleProcessingInstruction to output.Implements org. .
|
| public void | |
| protected void | |
| protected void | textEntityRef(final Writer
the destination Writer. out, final String the EntityRef's name. name)Write an |
| protected void | textRaw(final Writer
the destination writer. out, final String the String to write. str)Convenience method that simply passes the input str to
|
| protected void | textRaw(final Writer
the destination Writer. out, final char the char to write. ch)Convenience method that simply passes the input char to
|
| protected void | |
| protected void |
| CDATAPOST | back to summary |
|---|---|
| protected static final String CDATAPOST Simple constant for a close-CDATA | |
| CDATAPRE | back to summary |
|---|---|
| protected static final String CDATAPRE Simple constant for an open-CDATA | |
| AbstractXMLOutputProcessor | back to summary |
|---|---|
| public AbstractXMLOutputProcessor() | |
| attributeEscapedEntitiesFilter | back to summary |
|---|---|
| protected void attributeEscapedEntitiesFilter(final Writer out, final FormatStack fstack, final String value) throws IOException This will take the three pre-defined entities in XML 1.0 ('<', '>', and '&' - used specifically in XML elements) as well as CR/NL and Quote characters which require escaping inside Attribute values and convert their character representation to the appropriate entity reference suitable for XML attribute content. Further, some special characters (e.g. characters that are not valid in the current encoding) are converted to escaped representations. Note If
| |
| printAttribute | back to summary |
|---|---|
| protected void printAttribute(final Writer out, final FormatStack fstack, final Attribute attribute) throws IOException This will handle printing of an
| |
| printCDATA | back to summary |
|---|---|
| protected void printCDATA(final Writer out, final FormatStack fstack, final CDATA cdata) throws IOException This will handle printing of a
| |
| printComment | back to summary |
|---|---|
| protected void printComment(final Writer out, final FormatStack fstack, final Comment comment) throws IOException This will handle printing of a
| |
| printContent | back to summary |
|---|---|
| protected void printContent(final Writer out, final FormatStack fstack, final NamespaceStack nstack, final Walker walker) throws IOException This will handle printing of a List of The list of Content is basically processed as one of three types of content
| |
| printDeclaration | back to summary |
|---|---|
| protected void printDeclaration(final Writer out, final FormatStack fstack) throws IOException This will handle printing of the XML declaration. Assumes XML version 1.0 since we don't directly know.
| |
| printDocType | back to summary |
|---|---|
| protected void printDocType(final Writer out, final FormatStack fstack, final DocType docType) throws IOException This will handle printing of a
| |
| printDocument | back to summary |
|---|---|
| protected void printDocument(final Writer out, final FormatStack fstack, final NamespaceStack nstack, final Document doc) throws IOException This will handle printing of a
| |
| printElement | back to summary |
|---|---|
| protected void printElement(final Writer out, final FormatStack fstack, final NamespaceStack nstack, final Element element) throws IOException This will handle printing of an This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.
| |
| printEntityRef | back to summary |
|---|---|
| protected void printEntityRef(final Writer out, final FormatStack fstack, final EntityRef entity) throws IOException This will handle printing of an
| |
| printNamespace | back to summary |
|---|---|
| protected void printNamespace(final Writer out, final FormatStack fstack, final Namespace ns) throws IOException This will handle printing of any needed
| |
| printProcessingInstruction | back to summary |
|---|---|
| protected void printProcessingInstruction(final Writer out, final FormatStack fstack, final ProcessingInstruction pi) throws IOException This will handle printing of a
| |
| printText | back to summary |
|---|---|
| protected void printText(final Writer out, final FormatStack fstack, final Text text) throws IOException This will handle printing of a
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final Document doc) throws IOException Implements org. Doc from org. This will print the Warning using your own Writer may cause the outputter's preferred character encoding to be ignored. If you use encodings other than UTF-8, we recommend using the method that takes an OutputStream instead.
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final DocType doctype) throws IOException Implements org. Doc from org. Print out the
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final Element element) throws IOException Implements org. Doc from org. Print out an
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final List<? extends Content> list) throws IOException Implements org. Doc from org. This will handle printing out a list of nodes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>". | |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final CDATA cdata) throws IOException Implements org. Doc from org. Print out a
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final Text text) throws IOException Implements org. Doc from org. Print out a
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final Comment comment) throws IOException Implements org. Doc from org. Print out a
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final ProcessingInstruction pi) throws IOException Implements org. Doc from org. Print out a
| |
| process | back to summary |
|---|---|
| public void process(final Writer out, final Format format, final EntityRef entity) throws IOException Implements org. Doc from org. Print out a
| |
| textCDATA | back to summary |
|---|---|
| protected void textCDATA(final Writer out, final String text) throws IOException Write a
| |
| textEntityRef | back to summary |
|---|---|
| protected void textEntityRef(final Writer out, final String name) throws IOException Write an
| |
| textRaw | back to summary |
|---|---|
| protected void textRaw(final Writer out, final String str) throws IOException Convenience method that simply passes the input str to
| |
| textRaw | back to summary |
|---|---|
| protected void textRaw(final Writer out, final char ch) throws IOException Convenience method that simply passes the input char to
| |
| write | back to summary |
|---|---|
| protected void write(final Writer out, final String str) throws IOException Print some string value to the output. Null values are ignored. This ignore-null property is used for a few tricks.
| |
| write | back to summary |
|---|---|
| protected void write(final Writer out, final char c) throws IOException Write a single character to the output Writer.
| |