public class TransformerFactoryHelper extends Object
OutputUtil
, but may be useful
on its own.
To use, create an instance, call one or more of the configuration methods
(which follow the builder pattern, so can be chained), and then call
newTransformer()
. Be aware that the underlying transformer factories
are not guaranteed to be thread-safe, so you must manually synchronize this
method across instances of this class (and across any other transformer
creation).
There are a bunch of private static methods to support different transformer implementation classes. These contain ugly code, typically "if" statements based on implementation classname. Default behavior of each method supports the Sun JDK 1.5 implementation (a port of Xerces).
Constructor and Description |
---|
TransformerFactoryHelper() |
Modifier and Type | Method and Description |
---|---|
Transformer |
newTransformer()
Creates a new transformer instance that supports the requested output
configuration.
|
TransformerFactoryHelper |
setIndent(int indentLevel)
Enables indentation of the output, with the specified number of
spaces at each level.
|
TransformerFactoryHelper |
setPrologue()
Enables output of a prologue, without specifying an encoding (this
means that the output must be encoded as UTF-8).
|
TransformerFactoryHelper |
setPrologue(String encoding)
Enables output of a prologue with specified encoding.
|
public TransformerFactoryHelper setPrologue()
public TransformerFactoryHelper setPrologue(String encoding)
public TransformerFactoryHelper setIndent(int indentLevel)
javax.xml.transform
API does not
provide a method to set indent level, and not all transformers
may support such a setting.public Transformer newTransformer()