|
|||||||||
| Home >> All >> org >> jdom >> [ output overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jdom.output
Class XMLOutputter

java.lang.Objectorg.jdom.output.XMLOutputter
- All Implemented Interfaces:
- java.lang.Cloneable
- public class XMLOutputter
- extends java.lang.Object
- implements java.lang.Cloneable
- extends java.lang.Object
Outputs a JDOM document as a stream of bytes. The outputter can manage many
styles of document formatting, from untouched to pretty printed. The default
is to output the document content exactly as created, but this can be changed
by setting a new Format object. For pretty-print output, use
. For whitespace-normalized
output, use Format.getPrettyFormat() 55 .
Format.getCompactFormat() 55
There are output(...) 55 methods to print any of
the standard JDOM classes, including Document and Element, to either a Writer
or an OutputStream. Warning: When outputting to a Writer, make sure
the writer's encoding matches the encoding setting in the Format object. This
ensures the encoding in which the content is written (controlled by the
Writer configuration) matches the encoding placed in the document's XML
declaration (controlled by the XMLOutputter). Because a Writer cannot be
queried for its encoding, the information must be passed to the Format
manually in its constructor or via the
method. The default encoding is
UTF-8.
Format.setEncoding(java.lang.String) 55
The methods outputString(...) 55 are for
convenience only; for top performance you should call one of the output(...) 55 methods and pass in your own Writer or
OutputStream if possible.
XML declarations are always printed on their own line followed by a line
seperator (this doesn't change the semantics of the document). To omit
printing of the declaration use
. To omit printing of the
encoding in the declaration use Format.setOmitDeclaration(boolean) 55 .
Unfortunatly there is currently no way to know the original encoding of the
document.
Format.setOmitEncoding(boolean) 55
Empty elements are by default printed as <empty/>, but this can be
configured with to cause
them to be expanded to <empty></empty>.
Format.setExpandEmptyElements(boolean) 55
- Version:
- $Revision: 1.112 $, $Date: 2004/09/01 06:08:18 $
| Nested Class Summary | |
protected class |
XMLOutputter.NamespaceStack
Our own null subclass of NamespaceStack. |
| Field Summary | |
protected Format |
currentFormat
|
private static java.lang.String |
CVS_ID
|
private boolean |
escapeOutput
Whether output escaping is enabled for the being processed Element - default is true |
protected static Format |
preserveFormat
|
private Format |
userFormat
|
| Constructor Summary | |
XMLOutputter()
This will create an XMLOutputter with the default
Format matching Format.getRawFormat() 55 . |
|
XMLOutputter(Format format)
This will create an XMLOutputter with the specified
format characteristics. |
|
XMLOutputter(XMLOutputter that)
This will create an XMLOutputter with all the
options as set in the given XMLOutputter. |
|
| Method Summary | |
java.lang.Object |
clone()
Returns a copy of this XMLOutputter. |
private XMLOutputter.NamespaceStack |
createNamespaceStack()
Factory for making new NamespaceStack objects. |
private boolean |
endsWithWhite(java.lang.String str)
|
java.lang.String |
escapeAttributeEntities(java.lang.String str)
This will take the pre-defined entities in XML 1.0 and convert their character representation to the appropriate entity reference, suitable for XML attributes. |
java.lang.String |
escapeElementEntities(java.lang.String str)
This will take the three pre-defined entities in XML 1.0 (used specifically in XML elements) and convert their character representation to the appropriate entity reference, suitable for XML element content. |
Format |
getFormat()
Returns the current format in use by the outputter. |
private void |
indent(java.io.Writer out,
int level)
This will print indents (only if the newlines flag was set to true, and indent is non-null). |
private boolean |
isAllWhitespace(java.lang.Object obj)
|
private static boolean |
isWhitespace(char c)
|
private java.io.Writer |
makeWriter(java.io.OutputStream out)
Get an OutputStreamWriter, using prefered encoding (see Format.setEncoding(java.lang.String) 55 ). |
private static java.io.Writer |
makeWriter(java.io.OutputStream out,
java.lang.String enc)
Get an OutputStreamWriter, use specified encoding. |
private void |
newline(java.io.Writer out)
This will print a new line only if the newlines flag was set to true. |
private static int |
nextNonText(java.util.List content,
int start)
|
void |
output(org.jdom.CDATA cdata,
java.io.OutputStream out)
Print out a org.jdom.CDATA node. |
void |
output(org.jdom.CDATA cdata,
java.io.Writer out)
Print out a org.jdom.CDATA node. |
void |
output(org.jdom.Comment comment,
java.io.OutputStream out)
Print out a org.jdom.Comment. |
void |
output(org.jdom.Comment comment,
java.io.Writer out)
Print out a org.jdom.Comment. |
void |
output(org.jdom.DocType doctype,
java.io.OutputStream out)
Print out the org.jdom.DocType. |
void |
output(org.jdom.DocType doctype,
java.io.Writer out)
Print out the org.jdom.DocType. |
void |
output(org.jdom.Document doc,
java.io.OutputStream out)
This will print the Document to the given output stream. |
void |
output(org.jdom.Document doc,
java.io.Writer out)
This will print the Document to the given Writer. |
void |
output(org.jdom.Element element,
java.io.OutputStream out)
Print out an org.jdom.Element, including
its org.jdom.Attributes, and all
contained (child) elements, etc. |
void |
output(org.jdom.Element element,
java.io.Writer out)
Print out an org.jdom.Element, including
its org.jdom.Attributes, and all
contained (child) elements, etc. |
void |
output(org.jdom.EntityRef entity,
java.io.OutputStream out)
Print out a org.jdom.EntityRef. |
void |
output(org.jdom.EntityRef entity,
java.io.Writer out)
Print out a org.jdom.EntityRef. |
void |
output(java.util.List list,
java.io.OutputStream out)
This will handle printing out a list of nodes. |
void |
output(java.util.List list,
java.io.Writer out)
This will handle printing out a list of nodes. |
void |
output(org.jdom.ProcessingInstruction pi,
java.io.OutputStream out)
Print out a org.jdom.ProcessingInstruction. |
void |
output(org.jdom.ProcessingInstruction pi,
java.io.Writer out)
Print out a org.jdom.ProcessingInstruction. |
void |
output(org.jdom.Text text,
java.io.OutputStream out)
Print out a org.jdom.Text node. |
void |
output(org.jdom.Text text,
java.io.Writer out)
Print out a org.jdom.Text node. |
void |
outputElementContent(org.jdom.Element element,
java.io.OutputStream out)
This will handle printing out an org.jdom.Element's content only, not including its tag, and
attributes. |
void |
outputElementContent(org.jdom.Element element,
java.io.Writer out)
This will handle printing out an org.jdom.Element's content only, not including its tag, and
attributes. |
java.lang.String |
outputString(org.jdom.CDATA cdata)
Return a string representing a CDATA node. |
java.lang.String |
outputString(org.jdom.Comment comment)
Return a string representing a comment. |
java.lang.String |
outputString(org.jdom.DocType doctype)
Return a string representing a DocType. |
java.lang.String |
outputString(org.jdom.Document doc)
Return a string representing a document. |
java.lang.String |
outputString(org.jdom.Element element)
Return a string representing an element. |
java.lang.String |
outputString(org.jdom.EntityRef entity)
Return a string representing an entity. |
java.lang.String |
outputString(java.util.List list)
Return a string representing a list of nodes. |
java.lang.String |
outputString(org.jdom.ProcessingInstruction pi)
Return a string representing a PI. |
java.lang.String |
outputString(org.jdom.Text text)
Return a string representing a Text node. |
private void |
printAdditionalNamespaces(java.io.Writer out,
org.jdom.Element element,
XMLOutputter.NamespaceStack namespaces)
|
protected void |
printAttributes(java.io.Writer out,
java.util.List attributes,
org.jdom.Element parent,
XMLOutputter.NamespaceStack namespaces)
This will handle printing of a org.jdom.Attribute list. |
protected void |
printCDATA(java.io.Writer out,
org.jdom.CDATA cdata)
This will handle printing of org.jdom.CDATA text. |
protected void |
printComment(java.io.Writer out,
org.jdom.Comment comment)
This will handle printing of comments. |
private void |
printContentRange(java.io.Writer out,
java.util.List content,
int start,
int end,
int level,
XMLOutputter.NamespaceStack namespaces)
This will handle printing of content within a given range. |
protected void |
printDeclaration(java.io.Writer out,
org.jdom.Document doc,
java.lang.String encoding)
This will handle printing of the declaration. |
protected void |
printDocType(java.io.Writer out,
org.jdom.DocType docType)
This handle printing the DOCTYPE declaration if one exists. |
protected void |
printElement(java.io.Writer out,
org.jdom.Element element,
int level,
XMLOutputter.NamespaceStack namespaces)
This will handle printing of a org.jdom.Element,
its org.jdom.Attributes, and all contained (child)
elements, etc. |
private void |
printElementNamespace(java.io.Writer out,
org.jdom.Element element,
XMLOutputter.NamespaceStack namespaces)
|
protected void |
printEntityRef(java.io.Writer out,
org.jdom.EntityRef entity)
This will handle printing a org.jdom.EntityRef. |
private void |
printNamespace(java.io.Writer out,
org.jdom.Namespace ns,
XMLOutputter.NamespaceStack namespaces)
This will handle printing of any needed org.jdom.Namespace
declarations. |
protected void |
printProcessingInstruction(java.io.Writer out,
org.jdom.ProcessingInstruction pi)
This will handle printing of processing instructions. |
private void |
printQualifiedName(java.io.Writer out,
org.jdom.Attribute a)
|
private void |
printQualifiedName(java.io.Writer out,
org.jdom.Element e)
|
private void |
printString(java.io.Writer out,
java.lang.String str)
This will handle printing a string. |
protected void |
printText(java.io.Writer out,
org.jdom.Text text)
This will handle printing of org.jdom.Text strings. |
private void |
printTextRange(java.io.Writer out,
java.util.List content,
int start,
int end)
This will handle printing of a sequence of org.jdom.CDATA
or org.jdom.Text nodes. |
void |
setFormat(Format newFormat)
Sets the new format logic for the outputter. |
private int |
skipLeadingWhite(java.util.List content,
int start)
|
private int |
skipTrailingWhite(java.util.List content,
int start)
|
private boolean |
startsWithWhite(java.lang.String str)
|
java.lang.String |
toString()
Return a string listing of the settings for this XMLOutputter instance. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
CVS_ID
private static final java.lang.String CVS_ID
- See Also:
- Constant Field Values
userFormat
private Format userFormat
preserveFormat
protected static final Format preserveFormat
currentFormat
protected Format currentFormat
escapeOutput
private boolean escapeOutput
- Whether output escaping is enabled for the being processed
Element - default is
true
| Constructor Detail |
XMLOutputter
public XMLOutputter()
- This will create an
XMLOutputterwith the default Format matchingFormat.getRawFormat()55 .
XMLOutputter
public XMLOutputter(Format format)
- This will create an
XMLOutputterwith the specified format characteristics. Note the format object is cloned internally before use.
XMLOutputter
public XMLOutputter(XMLOutputter that)
- This will create an
XMLOutputterwith all the options as set in the givenXMLOutputter. Note thatXMLOutputter two = (XMLOutputter)one.clone();would work equally well.
| Method Detail |
setFormat
public void setFormat(Format newFormat)
- Sets the new format logic for the outputter. Note the Format
object is cloned internally before use.
getFormat
public Format getFormat()
- Returns the current format in use by the outputter. Note the
Format object returned is a clone of the one used internally.
output
public void output(org.jdom.Document doc, java.io.OutputStream out) throws java.io.IOException
- This will print the
Documentto the given output stream. The characters are printed using the encoding specified in the constructor, or a default of UTF-8.
output
public void output(org.jdom.DocType doctype, java.io.OutputStream out) throws java.io.IOException
- Print out the
org.jdom.DocType.
output
public void output(org.jdom.Element element, java.io.OutputStream out) throws java.io.IOException
- Print out an
org.jdom.Element, including itsorg.jdom.Attributes, and all contained (child) elements, etc.
outputElementContent
public void outputElementContent(org.jdom.Element element, java.io.OutputStream out) throws java.io.IOException
- This will handle printing out an
org.jdom.Element's content only, not including its tag, and attributes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".
output
public void output(java.util.List list, java.io.OutputStream out) throws java.io.IOException
- 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>".
output
public void output(org.jdom.CDATA cdata, java.io.OutputStream out) throws java.io.IOException
- Print out a
org.jdom.CDATAnode.
output
public void output(org.jdom.Text text, java.io.OutputStream out) throws java.io.IOException
- Print out a
org.jdom.Textnode. Perfoms the necessary entity escaping and whitespace stripping.
output
public void output(org.jdom.Comment comment, java.io.OutputStream out) throws java.io.IOException
- Print out a
org.jdom.Comment.
output
public void output(org.jdom.ProcessingInstruction pi, java.io.OutputStream out) throws java.io.IOException
- Print out a
org.jdom.ProcessingInstruction.
output
public void output(org.jdom.EntityRef entity, java.io.OutputStream out) throws java.io.IOException
- Print out a
org.jdom.EntityRef.
makeWriter
private java.io.Writer makeWriter(java.io.OutputStream out) throws java.io.UnsupportedEncodingException
- Get an OutputStreamWriter, using prefered encoding
(see
Format.setEncoding(java.lang.String)55 ).
makeWriter
private static java.io.Writer makeWriter(java.io.OutputStream out, java.lang.String enc) throws java.io.UnsupportedEncodingException
- Get an OutputStreamWriter, use specified encoding.
output
public void output(org.jdom.Document doc, java.io.Writer out) throws java.io.IOException
- This will print the
Documentto 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.
output
public void output(org.jdom.DocType doctype, java.io.Writer out) throws java.io.IOException
- Print out the
org.jdom.DocType.
output
public void output(org.jdom.Element element, java.io.Writer out) throws java.io.IOException
- Print out an
org.jdom.Element, including itsorg.jdom.Attributes, and all contained (child) elements, etc.
outputElementContent
public void outputElementContent(org.jdom.Element element, java.io.Writer out) throws java.io.IOException
- This will handle printing out an
org.jdom.Element's content only, not including its tag, and attributes. This can be useful for printing the content of an element that contains HTML, like "<description>JDOM is <b>fun>!</description>".
output
public void output(java.util.List list, java.io.Writer out) throws java.io.IOException
- 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>".
output
public void output(org.jdom.CDATA cdata, java.io.Writer out) throws java.io.IOException
- Print out a
org.jdom.CDATAnode.
output
public void output(org.jdom.Text text, java.io.Writer out) throws java.io.IOException
- Print out a
org.jdom.Textnode. Perfoms the necessary entity escaping and whitespace stripping.
output
public void output(org.jdom.Comment comment, java.io.Writer out) throws java.io.IOException
- Print out a
org.jdom.Comment.
output
public void output(org.jdom.ProcessingInstruction pi, java.io.Writer out) throws java.io.IOException
- Print out a
org.jdom.ProcessingInstruction.
output
public void output(org.jdom.EntityRef entity, java.io.Writer out) throws java.io.IOException
- Print out a
org.jdom.EntityRef.
outputString
public java.lang.String outputString(org.jdom.Document doc)
- Return a string representing a document. Uses an internal
StringWriter. Warning: a String is Unicode, which may not match
the outputter's specified encoding.
outputString
public java.lang.String outputString(org.jdom.DocType doctype)
- Return a string representing a DocType. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
outputString
public java.lang.String outputString(org.jdom.Element element)
- Return a string representing an element. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
outputString
public java.lang.String outputString(java.util.List list)
- Return a string representing a list of nodes. The list is
assumed to contain legal JDOM nodes.
outputString
public java.lang.String outputString(org.jdom.CDATA cdata)
- Return a string representing a CDATA node. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
outputString
public java.lang.String outputString(org.jdom.Text text)
- Return a string representing a Text node. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
outputString
public java.lang.String outputString(org.jdom.Comment comment)
- Return a string representing a comment. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
outputString
public java.lang.String outputString(org.jdom.ProcessingInstruction pi)
- Return a string representing a PI. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
outputString
public java.lang.String outputString(org.jdom.EntityRef entity)
- Return a string representing an entity. Warning: a String is
Unicode, which may not match the outputter's specified
encoding.
printDeclaration
protected void printDeclaration(java.io.Writer out, org.jdom.Document doc, java.lang.String encoding) throws java.io.IOException
- This will handle printing of the declaration.
Assumes XML version 1.0 since we don't directly know.
printDocType
protected void printDocType(java.io.Writer out, org.jdom.DocType docType) throws java.io.IOException
- This handle printing the DOCTYPE declaration if one exists.
printComment
protected void printComment(java.io.Writer out, org.jdom.Comment comment) throws java.io.IOException
- This will handle printing of comments.
printProcessingInstruction
protected void printProcessingInstruction(java.io.Writer out, org.jdom.ProcessingInstruction pi) throws java.io.IOException
- This will handle printing of processing instructions.
printEntityRef
protected void printEntityRef(java.io.Writer out, org.jdom.EntityRef entity) throws java.io.IOException
- This will handle printing a
org.jdom.EntityRef. Only the entity reference such as&entity;will be printed. However, subclasses are free to override this method to print the contents of the entity instead.
printCDATA
protected void printCDATA(java.io.Writer out, org.jdom.CDATA cdata) throws java.io.IOException
- This will handle printing of
org.jdom.CDATAtext.
printText
protected void printText(java.io.Writer out, org.jdom.Text text) throws java.io.IOException
- This will handle printing of
org.jdom.Textstrings.
printString
private void printString(java.io.Writer out, java.lang.String str) throws java.io.IOException
- This will handle printing a string. Escapes the element entities,
trims interior whitespace, etc. if necessary.
printElement
protected void printElement(java.io.Writer out, org.jdom.Element element, int level, XMLOutputter.NamespaceStack namespaces) throws java.io.IOException
- This will handle printing of a
org.jdom.Element, itsorg.jdom.Attributes, and all contained (child) elements, etc.
printContentRange
private void printContentRange(java.io.Writer out, java.util.List content, int start, int end, int level, XMLOutputter.NamespaceStack namespaces) throws java.io.IOException
- This will handle printing of content within a given range.
The range to print is specified in typical Java fashion; the
starting index is inclusive, while the ending index is
exclusive.
printTextRange
private void printTextRange(java.io.Writer out, java.util.List content, int start, int end) throws java.io.IOException
- This will handle printing of a sequence of
org.jdom.CDATAororg.jdom.Textnodes. It is an error to have any other pass this method any other type of node.
printNamespace
private void printNamespace(java.io.Writer out, org.jdom.Namespace ns, XMLOutputter.NamespaceStack namespaces) throws java.io.IOException
- This will handle printing of any needed
org.jdom.Namespacedeclarations.
printAttributes
protected void printAttributes(java.io.Writer out, java.util.List attributes, org.jdom.Element parent, XMLOutputter.NamespaceStack namespaces) throws java.io.IOException
- This will handle printing of a
org.jdom.Attributelist.
printElementNamespace
private void printElementNamespace(java.io.Writer out, org.jdom.Element element, XMLOutputter.NamespaceStack namespaces) throws java.io.IOException
printAdditionalNamespaces
private void printAdditionalNamespaces(java.io.Writer out, org.jdom.Element element, XMLOutputter.NamespaceStack namespaces) throws java.io.IOException
newline
private void newline(java.io.Writer out) throws java.io.IOException
- This will print a new line only if the newlines flag was set to
true.
indent
private void indent(java.io.Writer out, int level) throws java.io.IOException
- This will print indents (only if the newlines flag was
set to
true, and indent is non-null).
skipLeadingWhite
private int skipLeadingWhite(java.util.List content, int start)
skipTrailingWhite
private int skipTrailingWhite(java.util.List content, int start)
nextNonText
private static int nextNonText(java.util.List content, int start)
isAllWhitespace
private boolean isAllWhitespace(java.lang.Object obj)
startsWithWhite
private boolean startsWithWhite(java.lang.String str)
endsWithWhite
private boolean endsWithWhite(java.lang.String str)
isWhitespace
private static boolean isWhitespace(char c)
escapeAttributeEntities
public java.lang.String escapeAttributeEntities(java.lang.String str)
- This will take the pre-defined entities in XML 1.0 and
convert their character representation to the appropriate
entity reference, suitable for XML attributes. It does not convert
the single quote (') because it's not necessary as the outputter
writes attributes surrounded by double-quotes.
escapeElementEntities
public java.lang.String escapeElementEntities(java.lang.String str)
- This will take the three pre-defined entities in XML 1.0
(used specifically in XML elements) and convert their character
representation to the appropriate entity reference, suitable for
XML element content.
clone
public java.lang.Object clone()
- Returns a copy of this XMLOutputter.
toString
public java.lang.String toString()
- Return a string listing of the settings for this
XMLOutputter instance.
createNamespaceStack
private XMLOutputter.NamespaceStack createNamespaceStack()
- Factory for making new NamespaceStack objects. The NamespaceStack
created is actually an inner class extending the package protected
NamespaceStack, as a way to make NamespaceStack "friendly" toward
subclassers.
printQualifiedName
private void printQualifiedName(java.io.Writer out, org.jdom.Element e) throws java.io.IOException
printQualifiedName
private void printQualifiedName(java.io.Writer out, org.jdom.Attribute a) throws java.io.IOException
|
|||||||||
| Home >> All >> org >> jdom >> [ output overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.jdom.output.XMLOutputter