Top Description Inners Fields Constructors Methods
org.apache.xml.serialize

public Class OutputFormat

extends Object
Class Inheritance
Imports
java.io.UnsupportedEncodingException, org.w3c.dom.Document, .DocumentType, .Node, org.w3c.dom.html.HTMLDocument

Deprecated

This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML and HTML. See the Xerces documentation for more information.

Specifies an output format to control the serializer. Based on the XSLT specification for output format, plus additional parameters. Used to select the suitable serializer and determine how the document should be formatted on output.

The two interesting constructors are:

Author
Assaf Arkin Keith Visco
Version
$Revision: 476048 $ $Date: 2006-11-17 10:02:47 +0530 (Fri, 17 Nov 2006) $
See Also
Serializer, Method, LineSeparator

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
OutputFormat.Defaults

Deprecated This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML and HTML. See the Xerces documentation for more information.
public static class
OutputFormat.DTD

Deprecated This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML and HTML. See the Xerces documentation for more information.

Field Summary

Modifier and TypeField and Description
private boolean
private String[]
_cdataElements

List of element tag names whose text node children must be output as CDATA.

private String
_doctypePublic

The specified document type public identifier, or null.

private String
_doctypeSystem

The specified document type system identifier, or null.

private String
_encoding

The encoding to use, if an input stream is used.

private EncodingInfo
_encodingInfo

The EncodingInfo instance for _encoding.

private int
_indent

The indentation level, or zero if no indentation was requested.

private String
_lineSeparator

The selected line separator.

private int
_lineWidth

The line width at which to wrap long lines when indenting.

private String
_mediaType

The specified media type or null.

private String
_method

Holds the output method specified for this document, or null if no method was specified.

private String[]
_nonEscapingElements

List of element tag names whose text node children must be output unescaped.

private boolean
_omitComments

True if comments should be ommited;

private boolean
_omitDoctype

True if the DOCTYPE declaration should be ommited;

private boolean
_omitXmlDeclaration

True if the XML declaration should be ommited;

private boolean
_preserve

True if spaces should be preserved in elements that do not specify otherwise, or specify the default behavior.

private boolean
_preserveEmptyAttributes

If true, an empty string valued attribute is output as "".

private boolean
_standalone

True if the document type should be marked as standalone.

private String
_version

Specifies the version of the output method.

Constructor Summary

AccessConstructor and Description
public
OutputFormat()

Constructs a new output format with the default values.

public
OutputFormat(String
The specified output method
method
,
String
The specified encoding
encoding
,
boolean
True for pretty printing
indenting
)

Constructs a new output format with the default values for the specified method and encoding.

public
OutputFormat(Document
The document to output
doc
)

Constructs a new output format with the proper method, document type identifiers and media type for the specified document.

public
OutputFormat(Document
The document to output
doc
,
String
The specified encoding
encoding
,
boolean
True for pretty printing
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.

Method Summary

Modifier and TypeMethod and Description
public 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.

public String
getDoctypePublic()

Returns the specified document type public identifier, or null.

public String
getDoctypeSystem()

Returns the specified document type system identifier, or null.

public String

Returns:

The encoding
getEncoding
()

Returns the specified encoding.

public EncodingInfo
getEncodingInfo()

Deprecated as a consequence of EncodingInfo being deprecated.
Returns an EncodingInfo instance for the encoding.
public int

Returns:

The indentation or zero
getIndent
()

Returns the indentation specified.

public boolean
getIndenting()

Returns true if indentation was specified.

public char
getLastPrintable()

Returns the last printable character based on the selected encoding.

public String

Returns:

The specified line separator
getLineSeparator
()

Returns a specific line separator to use.

public int
getLineWidth()

Return the selected line width for breaking up long lines.

public String

Returns:

The specified media type, or null
getMediaType
()

Returns the specified media type, or null.

public String

Returns:

The specified output method, or null
getMethod
()

Returns the method specified for this output format.

public 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.

public boolean
getOmitComments()

Returns true if comments should be ommited.

public boolean
getOmitDocumentType()

Returns true if the DOCTYPE declaration should be ommited.

public boolean
getOmitXMLDeclaration()

Returns true if the XML document declaration should be ommited.

public boolean

Returns:

preserve the preserve flag
getPreserveEmptyAttributes
()

Returns the preserveEmptyAttribute flag.

public boolean
getPreserveSpace()

Returns true if the default behavior for this format is to preserve spaces.

public boolean
getStandalone()

Returns true if the document type is standalone.

public String

Returns:

The specified method version, or null
getVersion
()

Returns the version for this output method.

public boolean

Returns:

True if should serialize as CDATA
isCDataElement
(String
The element's tag name
tagName
)

Returns true if the text node children of the given elements should be output as CDATA.

public boolean

Returns:

True if should serialize unescaped
isNonEscapingElement
(String
The element's tag name
tagName
)

Returns true if the text node children of the given elements should be output unescaped.

public void
setAllowJavaNames(boolean allow)

Sets whether java encoding names are permitted

public boolean
setAllowJavaNames()

Returns whether java encoding names are permitted

public void
setCDataElements(String[]
List of CDATA element tag names
cdataElements
)

Sets the list of elements for which text node children should be output as CDATA.

public void
setDoctype(String
The public identifier, or null
publicId
,
String
The system identifier, or null
systemId
)

Sets the document type public and system identifiers.

public void
setEncoding(String
The encoding, or null
encoding
)

Sets the encoding for this output method.

public void
setEncoding(EncodingInfo encInfo)

Deprecated as a consequence of EncodingInfo being deprecated.
Sets the encoding for this output method with an EncodingInfo instance.
public void
setIndent(int
The indentation, or zero
indent
)

Sets the indentation.

public void
setIndenting(boolean
True if indentation should be on
on
)

Sets the indentation on and off.

public void
setLineSeparator(String
The specified line separator
lineSeparator
)

Sets the line separator.

public void
setLineWidth(int
The line width to use, zero for default
lineWidth
)

Sets the line width.

public void
setMediaType(String
The specified media type
mediaType
)

Sets the media type.

public void
setMethod(String
The output method, or null
method
)

Sets the method for this output format.

public void
setNonEscapingElements(String[]
List of unescaped element tag names
nonEscapingElements
)

Sets the list of elements for which text node children should be output unescaped (no character references).

public void
setOmitComments(boolean
True if comments should be ommited
omit
)

Sets comment omitting on and off.

public void
setOmitDocumentType(boolean
True if DOCTYPE declaration should be ommited
omit
)

Sets DOCTYPE declaration omitting on and off.

public void
setOmitXMLDeclaration(boolean
True if XML declaration should be ommited
omit
)

Sets XML declaration omitting on and off.

public void
setPreserveEmptyAttributes(boolean
the preserve flag
preserve
)

Sets the preserveEmptyAttribute flag.

public void
setPreserveSpace(boolean
True if spaces should be preserved
preserve
)

Sets space preserving as the default behavior.

public void
setStandalone(boolean
True if document DTD is standalone
standalone
)

Sets document DTD standalone.

public void
setVersion(String
The output method version, or null
version
)

Sets the version for this output method.

public static String
whichDoctypePublic(Document doc)

Returns the document type public identifier specified for this document, or null.

public static String
whichDoctypeSystem(Document doc)

Returns the document type system identifier specified for this document, or null.

public static String
whichMediaType(String method)

Returns the suitable media format for a document output with the specified method.

public static String

Returns:

The suitable method
whichMethod
(Document
The document to check
doc
)

Determine the output method for the specified document.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_allowJavaNamesback to summary
private boolean _allowJavaNames
_cdataElementsback to summary
private String[] _cdataElements

List of element tag names whose text node children must be output as CDATA.

_doctypePublicback to summary
private String _doctypePublic

The specified document type public identifier, or null.

_doctypeSystemback to summary
private String _doctypeSystem

The specified document type system identifier, or null.

_encodingback to summary
private String _encoding

The encoding to use, if an input stream is used. The default is always UTF-8.

_encodingInfoback to summary
private EncodingInfo _encodingInfo

Deprecated

as a consequence of EncodingInfo being deprecated. See corresponding docs for further information.

The EncodingInfo instance for _encoding.

_indentback to summary
private int _indent

The indentation level, or zero if no indentation was requested.

_lineSeparatorback to summary
private String _lineSeparator

The selected line separator.

_lineWidthback to summary
private int _lineWidth

The line width at which to wrap long lines when indenting.

_mediaTypeback to summary
private String _mediaType

The specified media type or null.

_methodback to summary
private String _method

Holds the output method specified for this document, or null if no method was specified.

_nonEscapingElementsback to summary
private String[] _nonEscapingElements

List of element tag names whose text node children must be output unescaped.

_omitCommentsback to summary
private boolean _omitComments

True if comments should be ommited;

_omitDoctypeback to summary
private boolean _omitDoctype

True if the DOCTYPE declaration should be ommited;

_omitXmlDeclarationback to summary
private boolean _omitXmlDeclaration

True if the XML declaration should be ommited;

_preserveback to summary
private boolean _preserve

True if spaces should be preserved in elements that do not specify otherwise, or specify the default behavior.

_preserveEmptyAttributesback to summary
private boolean _preserveEmptyAttributes

If true, an empty string valued attribute is output as "". If false and and we are using the HTMLSerializer, then only the attribute name is serialized. Defaults to false for backwards compatibility.

_standaloneback to summary
private boolean _standalone

True if the document type should be marked as standalone.

_versionback to summary
private String _version

Specifies the version of the output method.

Constructor Detail

OutputFormatback to summary
public OutputFormat()

Constructs a new output format with the default values.

OutputFormatback to summary
public OutputFormat(String method, String encoding, boolean indenting)

Constructs a new output format with the default values for the specified method and encoding. If indent is true, the document will be pretty printed with the default indentation level and default line wrapping.

Parameters
method:String

The specified output method

encoding:String

The specified encoding

indenting:boolean

True for pretty printing

See Also
setEncoding, setIndenting, setMethod
OutputFormatback to summary
public OutputFormat(Document doc)

Constructs a new output format with the proper method, document type identifiers and media type for the specified document.

Parameters
doc:Document

The document to output

See Also
whichMethod
OutputFormatback to summary
public OutputFormat(Document doc, 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. If indent is true, the document will be pretty printed with the default indentation level and default line wrapping.

Parameters
doc:Document

The document to output

encoding:String

The specified encoding

indenting:boolean

True for pretty printing

See Also
setEncoding, setIndenting, whichMethod

Method Detail

getCDataElementsback to summary
public 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.

getDoctypePublicback to summary
public String getDoctypePublic()

Returns the specified document type public identifier, or null.

getDoctypeSystemback to summary
public String getDoctypeSystem()

Returns the specified document type system identifier, or null.

getEncodingback to summary
public String getEncoding()

Returns the specified encoding. If no encoding was specified, the default is always "UTF-8".

Returns:String

The encoding

getEncodingInfoback to summary
public EncodingInfo getEncodingInfo() throws UnsupportedEncodingException

Deprecated

as a consequence of EncodingInfo being deprecated. See corresponding docs for further information.

Returns an EncodingInfo instance for the encoding.

See Also
setEncoding
getIndentback to summary
public int getIndent()

Returns the indentation specified. If no indentation was specified, zero is returned and the document should not be indented.

Returns:int

The indentation or zero

See Also
setIndenting
getIndentingback to summary
public boolean getIndenting()

Returns true if indentation was specified.

getLastPrintableback to summary
public char getLastPrintable()

Returns the last printable character based on the selected encoding. Control characters and non-printable characters are always printed as character references.

getLineSeparatorback to summary
public String getLineSeparator()

Returns a specific line separator to use. The default is the Web line separator (\n). A string is returned to support double codes (CR + LF).

Returns:String

The specified line separator

getLineWidthback to summary
public int getLineWidth()

Return the selected line width for breaking up long lines. When indenting, and only when indenting, long lines will be broken at space boundaries based on this line width. No line wrapping occurs if this value is zero.

getMediaTypeback to summary
public String getMediaType()

Returns the specified media type, or null. To determine the media type based on the document type, use whichMediaType.

Returns:String

The specified media type, or null

getMethodback to summary
public String getMethod()

Returns the method specified for this output format. Typically the method will be xml, html or text, but it might be other values. If no method was specified, null will be returned and the most suitable method will be determined for the document by calling whichMethod.

Returns:String

The specified output method, or null

getNonEscapingElementsback to summary
public 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.

getOmitCommentsback to summary
public boolean getOmitComments()

Returns true if comments should be ommited. The default is false.

getOmitDocumentTypeback to summary
public boolean getOmitDocumentType()

Returns true if the DOCTYPE declaration should be ommited. The default is false.

getOmitXMLDeclarationback to summary
public boolean getOmitXMLDeclaration()

Returns true if the XML document declaration should be ommited. The default is false.

getPreserveEmptyAttributesback to summary
public boolean getPreserveEmptyAttributes()

Returns the preserveEmptyAttribute flag. If flag is false, then' attributes with empty string values are output as the attribute name only (in HTML mode).

Returns:boolean

preserve the preserve flag

getPreserveSpaceback to summary
public boolean getPreserveSpace()

Returns true if the default behavior for this format is to preserve spaces. All elements that do not specify otherwise or specify the default behavior will be formatted based on this rule. All elements that specify space preserving will always preserve space.

getStandaloneback to summary
public boolean getStandalone()

Returns true if the document type is standalone. The default is false.

getVersionback to summary
public String getVersion()

Returns the version for this output method. If no version was specified, will return null and the default version number will be used. If the serializer does not support that particular version, it should default to a supported version.

Returns:String

The specified method version, or null

isCDataElementback to summary
public boolean isCDataElement(String tagName)

Returns true if the text node children of the given elements should be output as CDATA.

Parameters
tagName:String

The element's tag name

Returns:boolean

True if should serialize as CDATA

isNonEscapingElementback to summary
public boolean isNonEscapingElement(String tagName)

Returns true if the text node children of the given elements should be output unescaped.

Parameters
tagName:String

The element's tag name

Returns:boolean

True if should serialize unescaped

setAllowJavaNamesback to summary
public void setAllowJavaNames(boolean allow)

Sets whether java encoding names are permitted

setAllowJavaNamesback to summary
public boolean setAllowJavaNames()

Returns whether java encoding names are permitted

setCDataElementsback to summary
public void setCDataElements(String[] cdataElements)

Sets the list of elements for which text node children should be output as CDATA.

Parameters
cdataElements:String[]

List of CDATA element tag names

setDoctypeback to summary
public void setDoctype(String publicId, String systemId)

Sets the document type public and system identifiers. Required only if the DOM Document or SAX events do not specify the document type, and one must be present in the serialized document. Any document type specified by the DOM Document or SAX events will override these values.

Parameters
publicId:String

The public identifier, or null

systemId:String

The system identifier, or null

setEncodingback to summary
public void setEncoding(String encoding)

Sets the encoding for this output method. If no encoding was specified, the default is always "UTF-8". Make sure the encoding is compatible with the one used by the java.io.Writer.

Parameters
encoding:String

The encoding, or null

See Also
getEncoding
setEncodingback to summary
public void setEncoding(EncodingInfo encInfo)

Deprecated

as a consequence of EncodingInfo being deprecated. See corresponding docs for further information.

Sets the encoding for this output method with an EncodingInfo instance.

setIndentback to summary
public void setIndent(int indent)

Sets the indentation. The document will not be indented if the indentation is set to zero. Calling setIndenting will reset this value to zero (off) or the default (on).

Parameters
indent:int

The indentation, or zero

setIndentingback to summary
public void setIndenting(boolean on)

Sets the indentation on and off. When set on, the default indentation level and default line wrapping is used (see Defaults#Indent and Defaults#LineWidth). To specify a different indentation level or line wrapping, use setIndent and setLineWidth.

Parameters
on:boolean

True if indentation should be on

setLineSeparatorback to summary
public void setLineSeparator(String lineSeparator)

Sets the line separator. The default is the Web line separator (\n). The machine's line separator can be obtained from the system property line.separator, but is only useful if the document is edited on machines of the same type. For general documents, use the Web line separator.

Parameters
lineSeparator:String

The specified line separator

setLineWidthback to summary
public void setLineWidth(int lineWidth)

Sets the line width. If zero then no line wrapping will occur. Calling setIndenting will reset this value to zero (off) or the default (on).

Parameters
lineWidth:int

The line width to use, zero for default

See Also
getLineWidth, setIndenting
setMediaTypeback to summary
public void setMediaType(String mediaType)

Sets the media type.

Parameters
mediaType:String

The specified media type

See Also
getMediaType
setMethodback to summary
public void setMethod(String method)

Sets the method for this output format.

Parameters
method:String

The output method, or null

See Also
getMethod
setNonEscapingElementsback to summary
public void setNonEscapingElements(String[] nonEscapingElements)

Sets the list of elements for which text node children should be output unescaped (no character references).

Parameters
nonEscapingElements:String[]

List of unescaped element tag names

setOmitCommentsback to summary
public void setOmitComments(boolean omit)

Sets comment omitting on and off.

Parameters
omit:boolean

True if comments should be ommited

setOmitDocumentTypeback to summary
public void setOmitDocumentType(boolean omit)

Sets DOCTYPE declaration omitting on and off.

Parameters
omit:boolean

True if DOCTYPE declaration should be ommited

setOmitXMLDeclarationback to summary
public void setOmitXMLDeclaration(boolean omit)

Sets XML declaration omitting on and off.

Parameters
omit:boolean

True if XML declaration should be ommited

setPreserveEmptyAttributesback to summary
public void setPreserveEmptyAttributes(boolean preserve)

Sets the preserveEmptyAttribute flag. If flag is false, then' attributes with empty string values are output as the attribute name only (in HTML mode).

Parameters
preserve:boolean

the preserve flag

setPreserveSpaceback to summary
public void setPreserveSpace(boolean preserve)

Sets space preserving as the default behavior. The default is space stripping and all elements that do not specify otherwise or use the default value will not preserve spaces.

Parameters
preserve:boolean

True if spaces should be preserved

setStandaloneback to summary
public void setStandalone(boolean standalone)

Sets document DTD standalone. The public and system identifiers must be null for the document to be serialized as standalone.

Parameters
standalone:boolean

True if document DTD is standalone

setVersionback to summary
public void setVersion(String version)

Sets the version for this output method. For XML the value would be "1.0", for HTML it would be "4.0".

Parameters
version:String

The output method version, or null

See Also
getVersion
whichDoctypePublicback to summary
public static String whichDoctypePublic(Document doc)

Returns the document type public identifier specified for this document, or null.

whichDoctypeSystemback to summary
public static String whichDoctypeSystem(Document doc)

Returns the document type system identifier specified for this document, or null.

whichMediaTypeback to summary
public static String whichMediaType(String method)

Returns the suitable media format for a document output with the specified method.

whichMethodback to summary
public static String whichMethod(Document doc)

Determine the output method for the specified document. If the document is an instance of org.w3c.dom.html.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.

Parameters
doc:Document

The document to check

Returns:String

The suitable method

org.apache.xml.serialize back to summary

public Class OutputFormat.Defaults

extends Object
Class Inheritance

Deprecated

This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML and HTML. See the Xerces documentation for more information.

Field Summary

Modifier and TypeField and Description
public static final String
Encoding

The default encoding for Web documents it UTF-8.

public static final int
Indent

If indentation is turned on, the default identation level is 4.

public static final int
LineWidth

The default line width at which to break long lines when identing.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

Encodingback to summary
public static final String Encoding

The default encoding for Web documents it UTF-8.

See Also
getEncoding()
Indentback to summary
public static final int Indent

If indentation is turned on, the default identation level is 4.

See Also
setIndenting(boolean)
LineWidthback to summary
public static final int LineWidth

The default line width at which to break long lines when identing. This is set to 72.

Constructor Detail

Defaultsback to summary
public Defaults()
org.apache.xml.serialize back to summary

public Class OutputFormat.DTD

extends Object
Class Inheritance

Deprecated

This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML and HTML. See the Xerces documentation for more information.

Field Summary

Modifier and TypeField and Description
public static final String
HTMLPublicId

Public identifier for HTML 4.01 (Strict) document type.

public static final String
HTMLSystemId

System identifier for HTML 4.01 (Strict) document type.

public static final String
XHTMLPublicId

Public identifier for XHTML 1.0 (Strict) document type.

public static final String
XHTMLSystemId

System identifier for XHTML 1.0 (Strict) document type.

Constructor Summary

AccessConstructor and Description
public
DTD()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HTMLPublicIdback to summary
public static final String HTMLPublicId

Public identifier for HTML 4.01 (Strict) document type.

HTMLSystemIdback to summary
public static final String HTMLSystemId

System identifier for HTML 4.01 (Strict) document type.

XHTMLPublicIdback to summary
public static final String XHTMLPublicId

Public identifier for XHTML 1.0 (Strict) document type.

XHTMLSystemIdback to summary
public static final String XHTMLSystemId

System identifier for XHTML 1.0 (Strict) document type.

Constructor Detail

DTDback to summary
public DTD()