|
JDOM 2.0.2 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jdom2.output.support.AbstractOutputProcessor
org.jdom2.output.support.AbstractXMLOutputProcessor
public abstract class AbstractXMLOutputProcessor
This class provides a concrete implementation of 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| Field Summary | |
|---|---|
protected static java.lang.String |
CDATAPOST
Simple constant for a close-CDATA |
protected static java.lang.String |
CDATAPRE
Simple constant for an open-CDATA |
| Constructor Summary | |
|---|---|
AbstractXMLOutputProcessor()
|
|
| Method Summary | |
|---|---|
protected void |
attributeEscapedEntitiesFilter(java.io.Writer out,
FormatStack fstack,
java.lang.String value)
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(java.io.Writer out,
FormatStack fstack,
Attribute attribute)
This will handle printing of an . |
protected void |
printCDATA(java.io.Writer out,
FormatStack fstack,
CDATA cdata)
This will handle printing of a CDATA. |
protected void |
printComment(java.io.Writer out,
FormatStack fstack,
Comment comment)
This will handle printing of a Comment. |
protected void |
printContent(java.io.Writer out,
FormatStack fstack,
NamespaceStack nstack,
Walker walker)
This will handle printing of a List of Content. |
protected void |
printDeclaration(java.io.Writer out,
FormatStack fstack)
This will handle printing of the XML declaration. |
protected void |
printDocType(java.io.Writer out,
FormatStack fstack,
DocType docType)
This will handle printing of a DocType. |
protected void |
printDocument(java.io.Writer out,
FormatStack fstack,
NamespaceStack nstack,
Document doc)
This will handle printing of a Document. |
protected void |
printElement(java.io.Writer out,
FormatStack fstack,
NamespaceStack nstack,
Element element)
This will handle printing of an Element. |
protected void |
printEntityRef(java.io.Writer out,
FormatStack fstack,
EntityRef entity)
This will handle printing of an EntityRef. |
protected void |
printNamespace(java.io.Writer out,
FormatStack fstack,
Namespace ns)
This will handle printing of any needed
declarations. |
protected void |
printProcessingInstruction(java.io.Writer out,
FormatStack fstack,
ProcessingInstruction pi)
This will handle printing of a ProcessingInstruction. |
protected void |
printText(java.io.Writer out,
FormatStack fstack,
Text text)
This will handle printing of a Text. |
void |
process(java.io.Writer out,
Format format,
CDATA cdata)
Print out a node. |
void |
process(java.io.Writer out,
Format format,
Comment comment)
Print out a . |
void |
process(java.io.Writer out,
Format format,
DocType doctype)
Print out the . |
void |
process(java.io.Writer out,
Format format,
Document doc)
This will print the to the given Writer. |
void |
process(java.io.Writer out,
Format format,
Element element)
Print out an , including its
s, and all contained (child) elements, etc. |
void |
process(java.io.Writer out,
Format format,
EntityRef entity)
Print out a . |
void |
process(java.io.Writer out,
Format format,
java.util.List<? extends Content> list)
This will handle printing out a list of nodes. |
void |
process(java.io.Writer out,
Format format,
ProcessingInstruction pi)
Print out a . |
void |
process(java.io.Writer out,
Format format,
Text text)
Print out a node. |
protected void |
textCDATA(java.io.Writer out,
java.lang.String text)
Write a CDATA to the destination |
protected void |
textEntityRef(java.io.Writer out,
java.lang.String name)
Write an EntityRef to the destination. |
protected void |
textRaw(java.io.Writer out,
char ch)
Convenience method that simply passes the input char to write(Writer, char). |
protected void |
textRaw(java.io.Writer out,
java.lang.String str)
Convenience method that simply passes the input str to write(Writer, String). |
protected void |
write(java.io.Writer out,
char c)
Write a single character to the output Writer. |
protected void |
write(java.io.Writer out,
java.lang.String str)
Print some string value to the output. |
| Methods inherited from class org.jdom2.output.support.AbstractOutputProcessor |
|---|
buildWalker |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.lang.String CDATAPRE
protected static final java.lang.String CDATAPOST
| Constructor Detail |
|---|
public AbstractXMLOutputProcessor()
| Method Detail |
|---|
public void process(java.io.Writer out,
Format format,
Document doc)
throws java.io.IOException
XMLOutputProcessorDocument to the given Writer.
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 in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output styledoc - Document to format.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
DocType doctype)
throws java.io.IOException
XMLOutputProcessorDocType.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output styledoctype - DocType to output.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
Element element)
throws java.io.IOException
XMLOutputProcessorElement, including its
Attributes, and all contained (child) elements, etc.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output styleelement - Element to output.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
java.util.List<? extends Content> list)
throws java.io.IOException
XMLOutputProcessor
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output stylelist - List of nodes.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
CDATA cdata)
throws java.io.IOException
XMLOutputProcessorCDATA node.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output stylecdata - CDATA to output.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
Text text)
throws java.io.IOException
XMLOutputProcessorText node. Perfoms the necessary entity
escaping and whitespace stripping.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output styletext - Text to output.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
Comment comment)
throws java.io.IOException
XMLOutputProcessorComment.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output stylecomment - Comment to output.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
ProcessingInstruction pi)
throws java.io.IOException
XMLOutputProcessorProcessingInstruction.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output stylepi - ProcessingInstruction to output.
java.io.IOException - if there's any problem writing.
public void process(java.io.Writer out,
Format format,
EntityRef entity)
throws java.io.IOException
XMLOutputProcessorEntityRef.
process in interface XMLOutputProcessorout - Writer to use.format - Format instance specifying output styleentity - EntityRef to output.
java.io.IOException - if there's any problem writing.
protected void write(java.io.Writer out,
java.lang.String str)
throws java.io.IOException
out - The Writer to write to.str - The String to write (can be null).
java.io.IOException - if the out Writer fails.
protected void write(java.io.Writer out,
char c)
throws java.io.IOException
out - The Writer to write to.c - The char to write.
java.io.IOException - if the Writer fails.
protected void attributeEscapedEntitiesFilter(java.io.Writer out,
FormatStack fstack,
java.lang.String value)
throws java.io.IOException
Note: If FormatStack.getEscapeOutput() is false then no
escaping will happen.
out - The destination Writerfstack - The FormatStackvalue - String Attribute value to escape.
java.io.IOException - if the destination Writer fails.
IllegalDataException - if an entity can not be escaped
protected void textRaw(java.io.Writer out,
java.lang.String str)
throws java.io.IOException
write(Writer, String). This could be useful for subclasses to
hook in to. All text-type output will come through this or the
textRaw(Writer, char) method.
out - the destination writer.str - the String to write.
java.io.IOException - if the Writer fails.
protected void textRaw(java.io.Writer out,
char ch)
throws java.io.IOException
write(Writer, char). This could be useful for subclasses to hook
in to. All text-type output will come through this or the
textRaw(Writer, String) method.
out - the destination Writer.ch - the char to write.
java.io.IOException - if the Writer fails.
protected void textEntityRef(java.io.Writer out,
java.lang.String name)
throws java.io.IOException
EntityRef to the destination.
out - the destination Writer.name - the EntityRef's name.
java.io.IOException - if the Writer fails.
protected void textCDATA(java.io.Writer out,
java.lang.String text)
throws java.io.IOException
CDATA to the destination
out - the destination Writertext - the CDATA text
java.io.IOException - if the Writer fails.
protected void printDocument(java.io.Writer out,
FormatStack fstack,
NamespaceStack nstack,
Document doc)
throws java.io.IOException
Document.
out - Writer to use.fstack - the FormatStacknstack - the NamespaceStackdoc - Document to write.
java.io.IOException - if the destination Writer fails
protected void printDeclaration(java.io.Writer out,
FormatStack fstack)
throws java.io.IOException
out - Writer to use.fstack - the FormatStack
java.io.IOException - if the destination Writer fails
protected void printDocType(java.io.Writer out,
FormatStack fstack,
DocType docType)
throws java.io.IOException
DocType.
out - Writer to use.fstack - the FormatStackdocType - DocType to write.
java.io.IOException - if the destination Writer fails
protected void printProcessingInstruction(java.io.Writer out,
FormatStack fstack,
ProcessingInstruction pi)
throws java.io.IOException
ProcessingInstruction.
out - Writer to use.fstack - the FormatStackpi - ProcessingInstruction to write.
java.io.IOException - if the destination Writer fails
protected void printComment(java.io.Writer out,
FormatStack fstack,
Comment comment)
throws java.io.IOException
Comment.
out - Writer to use.fstack - the FormatStackcomment - Comment to write.
java.io.IOException - if the destination Writer fails
protected void printEntityRef(java.io.Writer out,
FormatStack fstack,
EntityRef entity)
throws java.io.IOException
EntityRef.
out - Writer to use.fstack - the FormatStackentity - EntotyRef to write.
java.io.IOException - if the destination Writer fails
protected void printCDATA(java.io.Writer out,
FormatStack fstack,
CDATA cdata)
throws java.io.IOException
CDATA.
out - Writer to use.fstack - the FormatStackcdata - CDATA to write.
java.io.IOException - if the destination Writer fails
protected void printText(java.io.Writer out,
FormatStack fstack,
Text text)
throws java.io.IOException
Text.
out - Writer to use.fstack - the FormatStacktext - Text to write.
java.io.IOException - if the destination Writer fails
protected void printElement(java.io.Writer out,
FormatStack fstack,
NamespaceStack nstack,
Element element)
throws java.io.IOException
Element.
This method arranges for outputting the Element infrastructure including Namespace Declarations and Attributes.
out - Writer to use.fstack - the FormatStacknstack - the NamespaceStackelement - Element to write.
java.io.IOException - if the destination Writer fails
protected void printContent(java.io.Writer out,
FormatStack fstack,
NamespaceStack nstack,
Walker walker)
throws java.io.IOException
Content.
The list of Content is basically processed as one of three types of content
printCDATA(Writer, FormatStack, CDATA), or
printComment(Writer, FormatStack, Comment),
out - Writer to use.fstack - the FormatStacknstack - the NamespaceStackwalker - Walker of Content to write.
java.io.IOException - if the destination Writer fails
protected void printNamespace(java.io.Writer out,
FormatStack fstack,
Namespace ns)
throws java.io.IOException
Namespace
declarations.
out - Writer to use.fstack - The current FormatStackns - Namespace to print definition of
java.io.IOException - if the output fails
protected void printAttribute(java.io.Writer out,
FormatStack fstack,
Attribute attribute)
throws java.io.IOException
Attribute.
out - Writer to use.fstack - The current FormatStackattribute - Attribute to output
java.io.IOException - if the output fails
|
JDOM 2.0.2 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||