public class Format
extends java.lang.Object
implements java.lang.Cloneable
getRawFormat()
(no whitespace changes),
getPrettyFormat()
(whitespace beautification), and
getCompactFormat()
(whitespace normalization).
Several modes are available to effect the way textual content is printed.
See the documentation for Format.TextMode
for details.Modifier and Type | Class and Description |
---|---|
(package private) class |
Format.DefaultEscapeStrategy
Handle common charsets quickly and easily.
|
static class |
Format.TextMode
Class to signify how text should be handled on output.
|
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.String |
encoding
The encoding format
|
(package private) org.jdom.output.EscapeStrategy |
escapeStrategy
entity escape logic
|
(package private) boolean |
expandEmptyElements
Whether or not to expand empty elements to
<tagName></tagName> - default is
false |
(package private) boolean |
ignoreTrAXEscapingPIs
Whether TrAX output escaping disabling/enabling PIs are ignored
or processed - default is
false |
(package private) java.lang.String |
indent
The default indent is no spaces (as original document)
|
(package private) java.lang.String |
lineSeparator
New line separator
|
(package private) Format.TextMode |
mode
text handling mode
|
(package private) boolean |
omitDeclaration
Whether or not to output the XML declaration
- default is
false |
(package private) boolean |
omitEncoding
Whether or not to output the encoding in the XML declaration
- default is
false |
private static java.lang.String |
STANDARD_ENCODING
standard encoding
|
private static java.lang.String |
STANDARD_INDENT
standard value to indent by, if we are indenting
|
private static java.lang.String |
STANDARD_LINE_SEPARATOR
standard string with which to end a line
|
Modifier | Constructor and Description |
---|---|
private |
Format()
Creates a new Format instance with default (raw) behavior.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
clone() |
static Format |
getCompactFormat()
Returns a new Format object that performs whitespace normalization, uses
the UTF-8 encoding, doesn't expand empty elements, includes the
declaration and encoding, and uses the default entity escape strategy.
|
java.lang.String |
getEncoding()
Returns the configured output encoding.
|
org.jdom.output.EscapeStrategy |
getEscapeStrategy()
Returns the current escape strategy
|
boolean |
getExpandEmptyElements()
Returns whether empty elements are expanded.
|
boolean |
getIgnoreTrAXEscapingPIs()
Returns whether JAXP TrAX processing instructions for
disabling/enabling output escaping are ignored.
|
java.lang.String |
getIndent()
Returns the indent string in use.
|
java.lang.String |
getLineSeparator()
Returns the current line separator.
|
boolean |
getOmitDeclaration()
Returns whether the XML declaration will be omitted.
|
boolean |
getOmitEncoding()
Returns whether the XML declaration encoding will be omitted.
|
static Format |
getPrettyFormat()
Returns a new Format object that performs whitespace beautification with
2-space indents, uses the UTF-8 encoding, doesn't expand empty elements,
includes the declaration and encoding, and uses the default entity
escape strategy.
|
static Format |
getRawFormat()
Returns a new Format object that performs no whitespace changes, uses
the UTF-8 encoding, doesn't expand empty elements, includes the
declaration and encoding, and uses the default entity escape strategy.
|
Format.TextMode |
getTextMode()
Returns the current text output style.
|
Format |
setEncoding(java.lang.String encoding)
Sets the output encoding.
|
Format |
setEscapeStrategy(org.jdom.output.EscapeStrategy strategy)
Sets the
EscapeStrategy to use for character escaping. |
Format |
setExpandEmptyElements(boolean expandEmptyElements)
This will set whether empty elements are expanded from
<tagName/> to
<tagName></tagName> . |
void |
setIgnoreTrAXEscapingPIs(boolean ignoreTrAXEscapingPIs)
This will set whether JAXP TrAX processing instructions for
disabling/enabling output escaping are ignored.
|
Format |
setIndent(java.lang.String indent)
This will set the indent
String to use; this
is usually a String of empty spaces. |
Format |
setLineSeparator(java.lang.String separator)
This will set the newline separator (
lineSeparator ). |
Format |
setOmitDeclaration(boolean omitDeclaration)
This will set whether the XML declaration
(
<?xml version="1.0"?gt; )
will be omitted or not. |
Format |
setOmitEncoding(boolean omitEncoding)
This will set whether the XML declaration
(
<?xml version="1.0"
encoding="UTF-8"?> )
includes the encoding of the document. |
Format |
setTextMode(Format.TextMode mode)
This sets the text output style.
|
private static final java.lang.String STANDARD_INDENT
private static final java.lang.String STANDARD_LINE_SEPARATOR
private static final java.lang.String STANDARD_ENCODING
java.lang.String indent
java.lang.String lineSeparator
java.lang.String encoding
boolean omitDeclaration
false
boolean omitEncoding
false
boolean expandEmptyElements
false
boolean ignoreTrAXEscapingPIs
false
Format.TextMode mode
org.jdom.output.EscapeStrategy escapeStrategy
private Format()
public static Format getRawFormat()
public static Format getPrettyFormat()
public static Format getCompactFormat()
public Format setEscapeStrategy(org.jdom.output.EscapeStrategy strategy)
EscapeStrategy
to use for character escaping.strategy
- the EscapeStrategy to usepublic org.jdom.output.EscapeStrategy getEscapeStrategy()
public Format setLineSeparator(java.lang.String separator)
lineSeparator
).
The default is \r\n
. Note that if the "newlines"
property is false, this value is irrelevant. To make it output
the system default line ending string, call
setLineSeparator(System.getProperty("line.separator"))
To output "UNIX-style" documents, call
setLineSeparator("\n")
. To output "Mac-style"
documents, call setLineSeparator("\r")
. DOS-style
documents use CR-LF ("\r\n"), which is the default.
Note that this only applies to newlines generated by the
outputter. If you parse an XML document that contains newlines
embedded inside a text node, and you do not set TextMode.NORMALIZE,
then the newlines will be output
verbatim, as "\n" which is how parsers normalize them.
separator
- String
line separator to use.setTextMode(org.apache.maven.archetype.common.util.Format.TextMode)
public java.lang.String getLineSeparator()
public Format setOmitEncoding(boolean omitEncoding)
<?xml version="1.0"
encoding="UTF-8"?>
)
includes the encoding of the document. It is common to omit
this in uses such as WML and other wireless device protocols.omitEncoding
- boolean
indicating whether or not
the XML declaration should indicate the document encoding.public boolean getOmitEncoding()
public Format setOmitDeclaration(boolean omitDeclaration)
<?xml version="1.0"?gt;
)
will be omitted or not. It is common to omit this in uses such
as SOAP and XML-RPC calls.omitDeclaration
- boolean
indicating whether or not
the XML declaration should be omitted.public boolean getOmitDeclaration()
public Format setExpandEmptyElements(boolean expandEmptyElements)
<tagName/>
to
<tagName></tagName>
.expandEmptyElements
- boolean
indicating whether or not
empty elements should be expanded.public boolean getExpandEmptyElements()
public void setIgnoreTrAXEscapingPIs(boolean ignoreTrAXEscapingPIs)
<?javax.xml.transform.disable-output-escaping ?>
and <?javax.xml.transform.enable-output-escaping ?>
PIs.
When ignored, the processing instructions are present in the
generated XML text and the pre-defined entities in XML 1.0 are
escaped.
Default: false
.ignoreTrAXEscapingPIs
- boolean
indicating
whether or not TrAX ouput escaping PIs are ignored.Result.PI_ENABLE_OUTPUT_ESCAPING
,
Result.PI_DISABLE_OUTPUT_ESCAPING
public boolean getIgnoreTrAXEscapingPIs()
public Format setTextMode(Format.TextMode mode)
Format.TextMode
instances. The default is Format.TextMode.PRESERVE
.public Format.TextMode getTextMode()
public Format setIndent(java.lang.String indent)
String
to use; this
is usually a String
of empty spaces. If you pass
null, or the empty string (""), then no indentation will
happen. Default: none (null)indent
- String
to use for indentation.public java.lang.String getIndent()
public Format setEncoding(java.lang.String encoding)
encoding
- the encoding format. Use XML-style names like
"UTF-8" or "ISO-8859-1" or "US-ASCII"public java.lang.String getEncoding()
protected java.lang.Object clone()
clone
in class java.lang.Object