Class OutputFormat
- All Implemented Interfaces:
Cloneable
OutputFormat represents the format configuration used by
XMLWriterand its base classes to format the XML output- Version:
- $Revision: 1.17 $
- Author:
- James Strachan
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringstandard value to indent by, if we are indenting -
Constructor Summary
ConstructorsConstructorDescriptionCreates anOutputFormatwith no additional whitespace (indent or new lines) added.OutputFormat(String indent) Creates anOutputFormatwith the given indent added but no new lines added.OutputFormat(String indent, boolean newlines) Creates anOutputFormatwith the given indent added with optional newlines between the Elements.OutputFormat(String indent, boolean newlines, String encoding) Creates anOutputFormatwith the given indent added with optional newlines between the Elements and the given encoding format. -
Method Summary
Modifier and TypeMethodDescriptionstatic OutputFormatA static helper method to create the default compact format.static OutputFormatA static helper method to create the default pretty printing format.charintbooleanbooleanDOCUMENT ME!booleanbooleanbooleanbooleanDOCUMENT ME!booleanbooleanisXHTML()Whether or not to use the XHTML standard: like HTML but passes an XML parser with real, closed tags.intparseOptions(String[] args, int i) Parses command line arguments of the form-omitEncoding -indentSize 3 -newlines -trimTextvoidsetAttributeQuoteCharacter(char quoteChar) Sets the character used to quote attribute values.voidsetEncoding(String encoding) DOCUMENT ME!voidsetExpandEmptyElements(boolean expandEmptyElements) This will set whether empty elements are expanded from<tagName>to<tagName></tagName>.voidsetIndent(boolean doIndent) Set the indent on or off.voidThis will set the indentStringto use; this is usually aStringof empty spaces.voidsetIndentSize(int indentSize) This will set the indentString's size; an indentSize of 4 would result in the indention being equivalent to theString" " (four space characters).voidsetLineSeparator(String separator) This will set the new-line separator.voidsetNewLineAfterDeclaration(boolean newLineAfterDeclaration) This will set whether a new line is printed after the XML declaration (assuming it is not supressed.)voidsetNewLineAfterNTags(int tagCount) Controls output of a line.separator every tagCount tags when isNewlines is false.voidsetNewlines(boolean newlines) DOCUMENT ME!voidsetOmitEncoding(boolean omitEncoding) This will set whether the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) includes the encoding of the document.voidsetPadText(boolean padText) Ensure that text immediately preceded by or followed by an element will be "padded" with a single space.voidsetSuppressDeclaration(boolean suppressDeclaration) This will set whether the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) is included or not.voidsetTrimText(boolean trimText) This will set whether the text is output verbatim (false) or with whitespace stripped as per.Element.getTextTrim()voidsetXHTML(boolean xhtml) This will set whether or not to use the XHTML standard: like HTML but passes an XML parser with real, closed tags.
-
Field Details
-
STANDARD_INDENT
standard value to indent by, if we are indenting- See Also:
-
-
Constructor Details
-
OutputFormat
public OutputFormat()Creates anOutputFormatwith no additional whitespace (indent or new lines) added. The whitespace from the element text content is fully preserved. -
OutputFormat
Creates anOutputFormatwith the given indent added but no new lines added. All whitespace from element text will be included.- Parameters:
indent- is the indent string to be used for indentation (usually a number of spaces).
-
OutputFormat
Creates anOutputFormatwith the given indent added with optional newlines between the Elements. All whitespace from element text will be included.- Parameters:
indent- is the indent string to be used for indentation (usually a number of spaces).newlines- whether new lines are added to layout the
-
OutputFormat
Creates anOutputFormatwith the given indent added with optional newlines between the Elements and the given encoding format.- Parameters:
indent- is the indent string to be used for indentation (usually a number of spaces).newlines- whether new lines are added to layout theencoding- is the text encoding to use for writing the XML
-
-
Method Details
-
getLineSeparator
-
setLineSeparator
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, callsetLineSeparator(System.getProperty("line.separator"))- Parameters:
separator-Stringline separator to use.- See Also:
-
isNewlines
public boolean isNewlines() -
setNewlines
public void setNewlines(boolean newlines) DOCUMENT ME!- Parameters:
newlines-trueindicates new lines should be printed, else new lines are ignored (compacted).- See Also:
-
getEncoding
-
setEncoding
-
isOmitEncoding
public boolean isOmitEncoding() -
setOmitEncoding
public void setOmitEncoding(boolean 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.- Parameters:
omitEncoding-booleanindicating whether or not the XML declaration should indicate the document encoding.
-
setSuppressDeclaration
public void setSuppressDeclaration(boolean 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.- Parameters:
suppressDeclaration-booleanindicating whether or not the XML declaration should be suppressed.
-
isSuppressDeclaration
public boolean isSuppressDeclaration()DOCUMENT ME!- Returns:
- true if the output of the XML declaration (
<?xml version="1.0"?>) should be suppressed else false.
-
setNewLineAfterDeclaration
public void setNewLineAfterDeclaration(boolean newLineAfterDeclaration) This will set whether a new line is printed after the XML declaration (assuming it is not supressed.)
- Parameters:
newLineAfterDeclaration-booleanindicating whether or not to print new line following the XML declaration. The default is true.
-
isNewLineAfterDeclaration
public boolean isNewLineAfterDeclaration()DOCUMENT ME!- Returns:
- true if a new line should be printed following XML declaration
-
isExpandEmptyElements
public boolean isExpandEmptyElements() -
setExpandEmptyElements
public void setExpandEmptyElements(boolean expandEmptyElements) This will set whether empty elements are expanded from
<tagName>to<tagName></tagName>.- Parameters:
expandEmptyElements-booleanindicating whether or not empty elements should be expanded.
-
isTrimText
public boolean isTrimText() -
setTrimText
public void setTrimText(boolean trimText) This will set whether the text is output verbatim (false) or with whitespace stripped as per. Default: falseElement.getTextTrim()- Parameters:
trimText-booleantrue ? trim the whitespace, false ? use text verbatim
-
isPadText
public boolean isPadText() -
setPadText
public void setPadText(boolean 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> foxintoThe 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 calledsetTrimText(boolean). The padding string will only be added if the text itself starts or ends with some whitespace characters. Default: false- Parameters:
padText-booleanif true, pad string-element boundaries
-
getIndent
-
setIndent
This will set the indentStringto use; this is usually aStringof empty spaces. If you pass null, or the empty string (""), then no indentation will happen. Default: none (null)- Parameters:
indent-Stringto use for indentation.
-
setIndent
public void setIndent(boolean doIndent) Set the indent on or off. If setting on, will use the value of STANDARD_INDENT, which is usually two spaces.- Parameters:
doIndent- if true, set indenting on; if false, set indenting off
-
setIndentSize
public void setIndentSize(int indentSize) This will set the indentString's size; an indentSize of 4 would result in the indention being equivalent to theString" " (four space characters).- Parameters:
indentSize-intnumber of spaces in indentation.
-
isXHTML
public boolean isXHTML()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 isfalse- Returns:
- DOCUMENT ME!
-
setXHTML
public void setXHTML(boolean 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- Parameters:
xhtml-booleantrue ? conform to XHTML, false ? conform to HTML, can have unclosed tags, etc.
-
getNewLineAfterNTags
public int getNewLineAfterNTags() -
setNewLineAfterNTags
public void setNewLineAfterNTags(int 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).- Parameters:
tagCount- DOCUMENT ME!
-
getAttributeQuoteCharacter
public char getAttributeQuoteCharacter() -
setAttributeQuoteCharacter
public void setAttributeQuoteCharacter(char quoteChar) Sets the character used to quote attribute values. The specified character must be a valid XML attribute quote character, otherwise anIllegalArgumentExceptionwill be thrown.- Parameters:
quoteChar- The character to use when quoting attribute values.- Throws:
IllegalArgumentException- If the specified character is not a valid XML attribute quote character.
-
parseOptions
Parses command line arguments of the form-omitEncoding -indentSize 3 -newlines -trimText- Parameters:
args- is the array of command line argumentsi- is the index in args to start parsing options- Returns:
- the index of first parameter that we didn't understand
-
createPrettyPrint
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.- Returns:
- DOCUMENT ME!
-
createCompactFormat
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- Returns:
- DOCUMENT ME!
-