| Method from org.dom4j.io.OutputFormat Detail: |
public static OutputFormat createCompactFormat() {
OutputFormat format = new OutputFormat();
format.setIndent(false);
format.setNewlines(false);
format.setTrimText(true);
return format;
}
A static helper method to create the default compact format. This format
does not have any indentation or newlines after an alement and all other
whitespace trimmed |
public static OutputFormat createPrettyPrint() {
OutputFormat format = new OutputFormat();
format.setIndentSize(2);
format.setNewlines(true);
format.setTrimText(true);
format.setPadText(true);
return format;
}
A static helper method to create the default pretty printing format. This
format consists of an indent of 2 spaces, newlines after each element and
all other whitespace trimmed, and XMTML is false. |
public char getAttributeQuoteCharacter() {
return attributeQuoteChar;
}
|
public String getEncoding() {
return encoding;
}
|
public String getIndent() {
return indent;
}
|
public String getLineSeparator() {
return lineSeparator;
}
|
public int getNewLineAfterNTags() {
return newLineAfterNTags;
}
|
public boolean isExpandEmptyElements() {
return expandEmptyElements;
}
|
public boolean isNewLineAfterDeclaration() {
return newLineAfterDeclaration;
}
|
public boolean isNewlines() {
return newlines;
}
|
public boolean isOmitEncoding() {
return omitEncoding;
}
|
public boolean isPadText() {
return padText;
}
|
public boolean isSuppressDeclaration() {
return suppressDeclaration;
}
|
public boolean isTrimText() {
return trimText;
}
|
public boolean isXHTML() {
return doXHTML;
}
Whether or not to use the XHTML standard: like HTML but passes an XML
parser with real, closed tags. Also, XHTML CDATA sections will be output
with the CDATA delimiters: ( " <![CDATA[ " and "
]]> " ) otherwise, the class HTMLWriter will output the
CDATA text, but not the delimiters.
Default is false
|
public int parseOptions(String[] args,
int i) {
for (int size = args.length; i < size; i++) {
if (args[i].equals("-suppressDeclaration")) {
setSuppressDeclaration(true);
} else if (args[i].equals("-omitEncoding")) {
setOmitEncoding(true);
} else if (args[i].equals("-indent")) {
setIndent(args[++i]);
} else if (args[i].equals("-indentSize")) {
setIndentSize(Integer.parseInt(args[++i]));
} else if (args[i].startsWith("-expandEmpty")) {
setExpandEmptyElements(true);
} else if (args[i].equals("-encoding")) {
setEncoding(args[++i]);
} else if (args[i].equals("-newlines")) {
setNewlines(true);
} else if (args[i].equals("-lineSeparator")) {
setLineSeparator(args[++i]);
} else if (args[i].equals("-trimText")) {
setTrimText(true);
} else if (args[i].equals("-padText")) {
setPadText(true);
} else if (args[i].startsWith("-xhtml")) {
setXHTML(true);
} else {
return i;
}
}
return i;
}
Parses command line arguments of the form -omitEncoding
-indentSize 3 -newlines -trimText |
public void setAttributeQuoteCharacter(char quoteChar) {
if ((quoteChar == '\'") || (quoteChar == '"")) {
attributeQuoteChar = quoteChar;
} else {
throw new IllegalArgumentException("Invalid attribute quote "
+ "character (" + quoteChar + ")");
}
}
Sets the character used to quote attribute values. The specified
character must be a valid XML attribute quote character, otherwise an
IllegalArgumentException will be thrown. |
public void setEncoding(String encoding) {
if (encoding != null) {
this.encoding = encoding;
}
}
|
public void setExpandEmptyElements(boolean expandEmptyElements) {
this.expandEmptyElements = expandEmptyElements;
}
|
public void setIndent(String indent) {
// nullify empty string to void unnecessary indentation code
if ((indent != null) && (indent.length() < = 0)) {
indent = null;
}
this.indent = indent;
}
This will set the 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)
|
public void setIndent(boolean doIndent) {
if (doIndent) {
this.indent = STANDARD_INDENT;
} else {
this.indent = null;
}
}
Set the indent on or off. If setting on, will use the value of
STANDARD_INDENT, which is usually two spaces. |
public void setIndentSize(int indentSize) {
StringBuffer indentBuffer = new StringBuffer();
for (int i = 0; i < indentSize; i++) {
indentBuffer.append(" ");
}
this.indent = indentBuffer.toString();
}
This will set the indent String's size; an indentSize of
4 would result in the indention being equivalent to the
String " " (four space characters).
|
public void setLineSeparator(String separator) {
lineSeparator = separator;
}
This will set the new-line separator. The default is \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"))
|
public void setNewLineAfterDeclaration(boolean newLineAfterDeclaration) {
this.newLineAfterDeclaration = newLineAfterDeclaration;
}
This will set whether a new line is printed after the XML declaration
(assuming it is not supressed.)
|
public void setNewLineAfterNTags(int tagCount) {
newLineAfterNTags = tagCount;
}
Controls output of a line.separator every tagCount tags when isNewlines
is false. If tagCount equals zero, it means don't do anything special. If
greater than zero, then a line.separator will be output after tagCount
tags have been output. Used when you would like to squeeze the html as
much as possible, but some browsers don't like really long lines. A tag
count of 10 would produce a line.separator in the output after 10 close
tags (including single tags). |
public void setNewlines(boolean newlines) {
this.newlines = newlines;
}
|
public void setOmitEncoding(boolean omitEncoding) {
this.omitEncoding = omitEncoding;
}
This will set whether the XML declaration (<?xml version="1.0"
encoding="UTF-8"?>)
includes the encoding of the document. It is common to suppress this in
protocols such as WML and SOAP.
|
public void setPadText(boolean padText) {
this.padText = padText;
}
Ensure that text immediately preceded by or followed by an element will
be "padded" with a single space. This is used to allow make
browser-friendly HTML, avoiding trimText's transformation of, e.g.,
The quick <b>brown</b> fox into The
quick<b>brown</b>fox
(the latter will run the three separate words together into a single
word). This setting is not too useful if you haven't also called
#setTrimText .
The padding string will only be added if the text itself starts or ends
with some whitespace characters.
Default: false
|
public void setSuppressDeclaration(boolean suppressDeclaration) {
this.suppressDeclaration = suppressDeclaration;
}
This will set whether the XML declaration (<?xml version="1.0"
encoding="UTF-8"?>)
is included or not. It is common to suppress this in protocols such as
WML and SOAP.
|
public void setTrimText(boolean trimText) {
this.trimText = trimText;
}
|
public void setXHTML(boolean xhtml) {
doXHTML = xhtml;
}
This will set whether or not to use the XHTML standard: like HTML but
passes an XML parser with real, closed tags. Also, XHTML CDATA sections
will be output with the CDATA delimiters: ( " <[CDATA[
" and " ]]< ) otherwise, the class HTMLWriter
will output the CDATA text, but not the delimiters.
Default: false
|