public class OutputFormat
extends java.lang.Object
The two interesting constructors are:
OutputFormat(String,String,boolean)
creates a format for the specified method (XML, HTML, Text, etc), encoding and indentation
OutputFormat(Document,String,boolean)
creates a format compatible with the document type (XML, HTML, Text, etc), encoding and indentation
Serializer
,
Method
,
LineSeparator
Modifier and Type | Class and Description |
---|---|
static class |
OutputFormat.Defaults |
static class |
OutputFormat.DTD |
Constructor and Description |
---|
OutputFormat()
Constructs a new output format with the default values.
|
OutputFormat(org.w3c.dom.Document doc)
Constructs a new output format with the proper method,
document type identifiers and media type for the specified
document.
|
OutputFormat(org.w3c.dom.Document doc,
java.lang.String encoding,
boolean indenting)
Constructs a new output format with the proper method,
document type identifiers and media type for the specified
document, and with the specified encoding.
|
OutputFormat(java.lang.String method,
java.lang.String encoding,
boolean indenting)
Constructs a new output format with the default values for
the specified method and encoding.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getBreakEachAttribute() |
java.lang.String[] |
getCDataElements()
Returns a list of all the elements whose text node children
should be output as CDATA, or null if no such elements were
specified.
|
java.lang.String |
getDoctypePublic()
Returns the specified document type public identifier,
or null.
|
java.lang.String |
getDoctypeSystem()
Returns the specified document type system identifier,
or null.
|
java.lang.String |
getEncoding()
Returns the specified encoding.
|
EncodingInfo |
getEncodingInfo()
Returns an {@code EncodingInfo{@code instance for the encoding.
|
int |
getIndent()
Returns the indentation specified.
|
boolean |
getIndenting()
Returns true if indentation was specified.
|
char |
getLastPrintable()
Returns the last printable character based on the selected
encoding.
|
java.lang.String |
getLineSeparator()
Returns a specific line separator to use.
|
int |
getLineWidth()
Return the selected line width for breaking up long lines.
|
java.lang.String |
getMediaType()
Returns the specified media type, or null.
|
java.lang.String |
getMethod()
Returns the method specified for this output format.
|
java.lang.String[] |
getNonEscapingElements()
Returns a list of all the elements whose text node children
should be output unescaped (no character references), or null
if no such elements were specified.
|
boolean |
getOmitComments()
Returns true if comments should be ommited.
|
boolean |
getOmitDocumentType()
Returns true if the DOCTYPE declaration should
be ommited.
|
boolean |
getOmitXMLDeclaration()
Returns true if the XML document declaration should
be ommited.
|
boolean |
getPreserveEmptyAttributes()
Returns the preserveEmptyAttribute flag.
|
boolean |
getPreserveSpace()
Returns true if the default behavior for this format is to
preserve spaces.
|
java.util.Comparator<java.lang.String> |
getSortAttributeNamesBy()
Returns the
Comparator used to apply an order to attribute names. |
boolean |
getStandalone()
Returns true if the document type is standalone.
|
java.lang.String |
getVersion()
Returns the version for this output method.
|
boolean |
isCDataElement(java.lang.String tagName)
Returns true if the text node children of the given elements
should be output as CDATA.
|
boolean |
isNonEscapingElement(java.lang.String tagName)
Returns true if the text node children of the given elements
should be output unescaped.
|
boolean |
setAllowJavaNames()
Returns whether java encoding names are permitted
|
void |
setAllowJavaNames(boolean allow)
Sets whether java encoding names are permitted
|
void |
setBreakEachAttribute(boolean on) |
void |
setCDataElements(java.lang.String[] cdataElements)
Sets the list of elements for which text node children
should be output as CDATA.
|
void |
setDoctype(java.lang.String publicId,
java.lang.String systemId)
Sets the document type public and system identifiers.
|
void |
setEncoding(EncodingInfo encInfo)
Sets the encoding for this output method with an
EncodingInfo
instance. |
void |
setEncoding(java.lang.String encoding)
Sets the encoding for this output method.
|
void |
setIndent(int indent)
Sets the indentation.
|
void |
setIndenting(boolean on)
Sets the indentation on and off.
|
void |
setLineSeparator(java.lang.String lineSeparator)
Sets the line separator.
|
void |
setLineWidth(int lineWidth)
Sets the line width.
|
void |
setMediaType(java.lang.String mediaType)
Sets the media type.
|
void |
setMethod(java.lang.String method)
Sets the method for this output format.
|
void |
setNonEscapingElements(java.lang.String[] nonEscapingElements)
Sets the list of elements for which text node children
should be output unescaped (no character references).
|
void |
setOmitComments(boolean omit)
Sets comment omitting on and off.
|
void |
setOmitDocumentType(boolean omit)
Sets DOCTYPE declaration omitting on and off.
|
void |
setOmitXMLDeclaration(boolean omit)
Sets XML declaration omitting on and off.
|
void |
setPreserveEmptyAttributes(boolean preserve)
Sets the preserveEmptyAttribute flag.
|
void |
setPreserveSpace(boolean preserve)
Sets space preserving as the default behavior.
|
void |
setSortAttributeNamesBy(java.util.Comparator<java.lang.String> sortAttributeNamesBy)
Sets the comparator to use for applying an order to attribute names.
|
void |
setStandalone(boolean standalone)
Sets document DTD standalone.
|
void |
setVersion(java.lang.String version)
Sets the version for this output method.
|
static java.lang.String |
whichDoctypePublic(org.w3c.dom.Document doc)
Returns the document type public identifier
specified for this document, or null.
|
static java.lang.String |
whichDoctypeSystem(org.w3c.dom.Document doc)
Returns the document type system identifier
specified for this document, or null.
|
static java.lang.String |
whichMediaType(java.lang.String method)
Returns the suitable media format for a document
output with the specified method.
|
static java.lang.String |
whichMethod(org.w3c.dom.Document doc)
Determine the output method for the specified document.
|
public OutputFormat()
public OutputFormat(java.lang.String method, java.lang.String encoding, boolean indenting)
method
- The specified output methodencoding
- The specified encodingindenting
- True for pretty printingsetEncoding(java.lang.String)
,
setIndenting(boolean)
,
setMethod(java.lang.String)
public OutputFormat(org.w3c.dom.Document doc)
doc
- The document to outputwhichMethod(org.w3c.dom.Document)
public OutputFormat(org.w3c.dom.Document doc, java.lang.String encoding, boolean indenting)
doc
- The document to outputencoding
- The specified encodingindenting
- True for pretty printingsetEncoding(java.lang.String)
,
setIndenting(boolean)
,
whichMethod(org.w3c.dom.Document)
public java.lang.String getMethod()
whichMethod(org.w3c.dom.Document)
.public void setMethod(java.lang.String method)
method
- The output method, or nullgetMethod()
public java.lang.String getVersion()
public void setVersion(java.lang.String version)
version
- The output method version, or nullgetVersion()
public int getIndent()
setIndenting(boolean)
public boolean getIndenting()
public void setIndent(int indent)
setIndenting(boolean)
will reset this
value to zero (off) or the default (on).indent
- The indentation, or zeropublic void setIndenting(boolean on)
OutputFormat.Defaults.Indent
and OutputFormat.Defaults.LineWidth
).
To specify a different indentation level or line wrapping,
use setIndent(int)
and setLineWidth(int)
.on
- True if indentation should be onpublic java.lang.String getEncoding()
public void setEncoding(java.lang.String encoding)
Writer
.encoding
- The encoding, or nullgetEncoding()
public void setEncoding(EncodingInfo encInfo)
EncodingInfo
instance.public EncodingInfo getEncodingInfo() throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
setEncoding(java.lang.String)
public void setAllowJavaNames(boolean allow)
public boolean setAllowJavaNames()
public java.lang.String getMediaType()
whichMediaType(java.lang.String)
.public void setMediaType(java.lang.String mediaType)
mediaType
- The specified media typegetMediaType()
public void setDoctype(java.lang.String publicId, java.lang.String systemId)
publicId
- The public identifier, or nullsystemId
- The system identifier, or nullpublic java.lang.String getDoctypePublic()
public java.lang.String getDoctypeSystem()
public boolean getOmitComments()
public void setOmitComments(boolean omit)
omit
- True if comments should be ommitedpublic boolean getOmitDocumentType()
public void setOmitDocumentType(boolean omit)
omit
- True if DOCTYPE declaration should be ommitedpublic boolean getOmitXMLDeclaration()
public void setOmitXMLDeclaration(boolean omit)
omit
- True if XML declaration should be ommitedpublic boolean getStandalone()
public void setStandalone(boolean standalone)
standalone
- True if document DTD is standalonepublic java.lang.String[] getCDataElements()
public boolean isCDataElement(java.lang.String tagName)
tagName
- The element's tag namepublic void setCDataElements(java.lang.String[] cdataElements)
cdataElements
- List of CDATA element tag namespublic java.lang.String[] getNonEscapingElements()
public boolean isNonEscapingElement(java.lang.String tagName)
tagName
- The element's tag namepublic void setNonEscapingElements(java.lang.String[] nonEscapingElements)
nonEscapingElements
- List of unescaped element tag namespublic java.lang.String getLineSeparator()
public void setLineSeparator(java.lang.String lineSeparator)
lineSeparator
- The specified line separatorpublic boolean getPreserveSpace()
public void setPreserveSpace(boolean preserve)
preserve
- True if spaces should be preservedpublic int getLineWidth()
public void setLineWidth(int lineWidth)
setIndenting(boolean)
will reset this
value to zero (off) or the default (on).lineWidth
- The line width to use, zero for defaultgetLineWidth()
,
setIndenting(boolean)
public boolean getBreakEachAttribute()
public void setBreakEachAttribute(boolean on)
public boolean getPreserveEmptyAttributes()
public void setPreserveEmptyAttributes(boolean preserve)
preserve
- the preserve flagpublic java.util.Comparator<java.lang.String> getSortAttributeNamesBy()
Comparator
used to apply an order to attribute names.public void setSortAttributeNamesBy(java.util.Comparator<java.lang.String> sortAttributeNamesBy)
sortAttributeNamesBy
- public char getLastPrintable()
public static java.lang.String whichMethod(org.w3c.dom.Document doc)
HTMLDocument
then the method is said to be html. If the root
element is 'html' and all text nodes preceding the root
element are all whitespace, then the method is said to be
html. Otherwise the method is xml.doc
- The document to checkpublic static java.lang.String whichDoctypePublic(org.w3c.dom.Document doc)
public static java.lang.String whichDoctypeSystem(org.w3c.dom.Document doc)
public static java.lang.String whichMediaType(java.lang.String method)
Copyright © 2010 - 2020 Adobe. All Rights Reserved