org.pf.six
Class XmlStreamWriter

java.lang.Object
  extended by org.pf.six.XmlStreamWriter

public class XmlStreamWriter
extends java.lang.Object

Provides convenience methods to write XML data easily to streams.

Version:
1.5
Author:
Manfred Duchrow

Constructor Summary
XmlStreamWriter()
          Initialize the new instance with default values.
 
Method Summary
 void appendDocumentStart(java.io.Writer writer, java.lang.String encoding)
          Appends the start line of an XML document to the given writer.
 void appendDocumentStart(java.io.Writer writer, java.lang.String encoding, boolean isStandalone)
          Appends the start line of an XML document to the given writer.
 void appendDocumentType(java.io.Writer writer, java.lang.String rootTagName, java.lang.String dtdURL)
          Appends the document type (DOCTYPE) line to the given writer using the SYSTEM parameter to specify the DTD location.
 void appendDocumentType(java.io.Writer writer, java.lang.String rootTagName, java.lang.String schemaName, java.lang.String dtdURL)
          Appends the document type (DOCTYPE) line to the given writer using the PUBLIC parameter if the given schameName is not null or the SYSTEM parameter to just specify the DTD location.
 void appendDOM(org.w3c.dom.Document document, java.io.Writer writer)
          Appends the given document to the specified writer as XML representation.
 void appendSIXElement(Element element, java.io.Writer writer)
          Appends the given element and its children to the specified writer as XML representation.
 void appendStylesheetPI(java.io.Writer writer, java.util.Map attributes)
          Appends a stylesheet processing instruction with the given attributes.
 void appendStylesheetPI(java.io.Writer writer, NamedTextList attributes)
          Appends a stylesheet processing instruction with the given attributes.
 void appendStylesheetPI(java.io.Writer writer, java.lang.String attributes)
          Appends a stylesheet processing instruction with the given attributes.
 void appendWellFormedXML(Element element, java.io.Writer writer, java.lang.String encoding)
          Appends the given element tree as a well formed XML to the given writer.
 void appendWellFormedXML(Element element, java.io.Writer writer, java.lang.String encoding, java.lang.String dtdURL)
          Appends the given element tree as a well formed XML to the given writer.
 void appendWellFormedXML(Element element, java.io.Writer writer, java.lang.String encoding, java.lang.String schemaName, java.lang.String dtdURL)
          Appends the given element tree as a well formed XML to the given writer.
 void appendXslStylesheetPI(java.io.Writer writer, java.lang.String xslFilename)
          Appends an XSL stylesheet processing instruction for the given XSL filename
 int getIndentation()
          Returns the current indentation.
static XmlStreamWriter n()
          Returns a new instance of this class
 void setIndentation(int newValue)
          Sets the current indentation.
 void useDoubleQuotes()
          Configures this writer to use double quotes (") to enclose XML attribute values.
 void useSingleQuotes()
          Configures this writer to use single quotes (') to enclose XML attribute values.
 boolean withNamespacePrefix()
          Returns whether or not the namespace prefix is written as well.
 void withNamespacePrefix(boolean newValue)
          Sets whether or not the namespace prefix is written as well.
static void writeDocumentStart(java.io.Writer writer, java.lang.String encoding)
          Writes the start line of an XML document to the given writer.
static void writeDocumentStart(java.io.Writer writer, java.lang.String encoding, boolean isStandalone)
          Writes the start line of an XML document to the given writer.
static void writeDocumentType(java.io.Writer writer, java.lang.String rootTagName, java.lang.String dtdURL)
          Writes the document type line to the given writer.
static void writeDocumentType(java.io.Writer writer, java.lang.String rootTagName, java.lang.String schemaName, java.lang.String dtdURL)
          Writes the document type line to the given writer.
static void writeDOM(org.w3c.dom.Document document, java.io.Writer writer)
          Write the given document to the specified writer as XML representation.
static void writeSIXElement(Element element, java.io.Writer writer)
          Write the given element and its children to the specified writer as XML representation.
static void writeWellFormedXML(Element element, java.io.Writer writer, java.lang.String encoding)
          Writes the given element tree as a well formed XML stream.
static void writeWellFormedXML(Element element, java.io.Writer writer, java.lang.String encoding, java.lang.String dtdURL)
          Writes the given element tree as a well formed XML stream.
static void writeWellFormedXML(Element element, java.io.Writer writer, java.lang.String encoding, java.lang.String schemaName, java.lang.String dtdURL)
          Writes the given element tree as a well formed XML to the given writer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlStreamWriter

public XmlStreamWriter()
Initialize the new instance with default values.

Method Detail

withNamespacePrefix

public boolean withNamespacePrefix()
Returns whether or not the namespace prefix is written as well.


withNamespacePrefix

public void withNamespacePrefix(boolean newValue)
Sets whether or not the namespace prefix is written as well.


getIndentation

public int getIndentation()
Returns the current indentation. That is the number of spaces that are prepended to each new level. If not changed the default is 2.


setIndentation

public void setIndentation(int newValue)
Sets the current indentation. That is the number of spaces that are prepended to each new level.


writeWellFormedXML

public static void writeWellFormedXML(Element element,
                                      java.io.Writer writer,
                                      java.lang.String encoding)
Writes the given element tree as a well formed XML stream. This does not include a document type.

Parameters:
element - The root element of an XML tree.
writer - The writer that receives the output.
encoding - A valid encoding name or null to omit the attribute.

writeWellFormedXML

public static void writeWellFormedXML(Element element,
                                      java.io.Writer writer,
                                      java.lang.String encoding,
                                      java.lang.String dtdURL)
Writes the given element tree as a well formed XML stream. If the dtdURL is null, no document type will be written.

Parameters:
element - The root element of an XML tree.
writer - The writer that receives the output.
encoding - A valid encoding name or null to omit the attribute.
dtdURL - The url to locate the document's DTD (might be null).

writeWellFormedXML

public static void writeWellFormedXML(Element element,
                                      java.io.Writer writer,
                                      java.lang.String encoding,
                                      java.lang.String schemaName,
                                      java.lang.String dtdURL)
Writes the given element tree as a well formed XML to the given writer. If the dtdURL is null, no document type (DOCTYPE) will be added. If dtdURL is not null then the document type (DOCTYPE) will be added with the SYSTEM definition or if also the schemaName is not null with the PUBLIC definition.

Parameters:
element - The root element of an XML tree (must not be null).
writer - The writer that receives the output (must not be null).
encoding - A valid encoding name or null to omit the attribute.
schemaName - The logical name of the schema for the DOCTYPE PUBLIC definition (might be null).
dtdURL - The URL to locate the document's DTD in the DOCTYPE SYSTEM or PUBLIC definition (might be null).

writeDocumentStart

public static void writeDocumentStart(java.io.Writer writer,
                                      java.lang.String encoding)
Writes the start line of an XML document to the given writer. If the specified encoding is not null it will be written as encoding="..." attribute of the start line.

Parameters:
writer - The writer that receives the output.
encoding - A valid encoding name or null to omit the attribute.

writeDocumentStart

public static void writeDocumentStart(java.io.Writer writer,
                                      java.lang.String encoding,
                                      boolean isStandalone)
Writes the start line of an XML document to the given writer. If the specified encoding is not null it will be written as encoding="..." attribute of the start line.

Parameters:
writer - The writer that receives the output
encoding - A valid encoding name or null to omit the attribute.
isStandalone - If true the standalone="yes" attribute will be added.

writeDocumentType

public static void writeDocumentType(java.io.Writer writer,
                                     java.lang.String rootTagName,
                                     java.lang.String dtdURL)
Writes the document type line to the given writer.

Parameters:
writer - The writer that receives the output (must not be null).
rootTagName - The name of the document's root tag (must not be null).
dtdURL - The URL to locate the document's DTD (must not be null).

writeDocumentType

public static void writeDocumentType(java.io.Writer writer,
                                     java.lang.String rootTagName,
                                     java.lang.String schemaName,
                                     java.lang.String dtdURL)
Writes the document type line to the given writer.

Parameters:
writer - The writer that receives the output (must not be null).
rootTagName - The name of the document's root tag (must not be null).
schemaName - The logical name of the schema (e.g. "-//W3C//DTD XHTML 1.0 Strict//EN"). This parameter may be null or blank which means SYSTEM will be used rather than PUBLIC.
dtdURL - The URL to locate the document's DTD (must not be null).

writeSIXElement

public static void writeSIXElement(Element element,
                                   java.io.Writer writer)
Write the given element and its children to the specified writer as XML representation.

Parameters:
element - Usually the root element of an XML tree
writer - The writer that will receive the output

writeDOM

public static void writeDOM(org.w3c.dom.Document document,
                            java.io.Writer writer)
Write the given document to the specified writer as XML representation. Be aware that only the XML data of the DOM will be written. The start line of a valid XML stream <?xml version="1.0" ?> is not written by this method.

Parameters:
document - A valid DOM tree
writer - The writer that will receive the output

n

public static XmlStreamWriter n()
Returns a new instance of this class


useSingleQuotes

public void useSingleQuotes()
Configures this writer to use single quotes (') to enclose XML attribute values.


useDoubleQuotes

public void useDoubleQuotes()
Configures this writer to use double quotes (") to enclose XML attribute values.


appendWellFormedXML

public void appendWellFormedXML(Element element,
                                java.io.Writer writer,
                                java.lang.String encoding)
Appends the given element tree as a well formed XML to the given writer. This does not include a document type.

Parameters:
element - The root element of an XML tree
writer - The writer that receives the output
encoding - A valid encoding name or null to omit the attribute

appendWellFormedXML

public void appendWellFormedXML(Element element,
                                java.io.Writer writer,
                                java.lang.String encoding,
                                java.lang.String dtdURL)
Appends the given element tree as a well formed XML to the given writer. If the dtdURL is null, no document type will be written.

Parameters:
element - The root element of an XML tree
writer - The writer that receives the output
encoding - A valid encoding name or null to omit the attribute
dtdURL - The URL to locate the document's DTD (might be null)

appendWellFormedXML

public void appendWellFormedXML(Element element,
                                java.io.Writer writer,
                                java.lang.String encoding,
                                java.lang.String schemaName,
                                java.lang.String dtdURL)
Appends the given element tree as a well formed XML to the given writer. If the dtdURL is null, no document type (DOCTYPE) will be added. If dtdURL is not null then the document type (DOCTYPE) will be added with the SYSTEM definition or if also the schemaName is not null with the PUBLIC definition.

Parameters:
element - The root element of an XML tree (must not be null).
writer - The writer that receives the output (must not be null).
encoding - A valid encoding name or null to omit the attribute.
schemaName - The logical name of the schema for the DOCTYPE PUBLIC definition (might be null).
dtdURL - The URL to locate the document's DTD in the DOCTYPE SYSTEM or PUBLIC definition (might be null).

appendDocumentStart

public void appendDocumentStart(java.io.Writer writer,
                                java.lang.String encoding)
Appends the start line of an XML document to the given writer. If the specified encoding is not null it will be written as encoding="..." attribute of the start line.

Parameters:
writer - The writer that receives the output
encoding - A valid encoding name or null to omit the attribute

appendDocumentStart

public void appendDocumentStart(java.io.Writer writer,
                                java.lang.String encoding,
                                boolean isStandalone)
Appends the start line of an XML document to the given writer. If the specified encoding is not null it will be written as encoding="..." attribute of the start line.

Parameters:
writer - The writer that receives the output
encoding - A valid encoding name or null to omit the attribute
isStandalone - If true the standalone="yes" attribute will be added

appendXslStylesheetPI

public void appendXslStylesheetPI(java.io.Writer writer,
                                  java.lang.String xslFilename)
Appends an XSL stylesheet processing instruction for the given XSL filename

Parameters:
writer - The writer that receives the output
xslFilename - The name of an XSL file to refer to

appendStylesheetPI

public void appendStylesheetPI(java.io.Writer writer,
                               java.lang.String attributes)
Appends a stylesheet processing instruction with the given attributes. The attributes are key/value pairs separated by comma.
Example: "href=mystyle.css,type=text/css,title=Compact"

Parameters:
writer - The writer that receives the output
attributes - The attributes for this instruction

appendStylesheetPI

public void appendStylesheetPI(java.io.Writer writer,
                               java.util.Map attributes)
Appends a stylesheet processing instruction with the given attributes. The attributes are key/value pairs separated by comma.

Parameters:
writer - The writer that receives the output
attributes - The attributes for this instruction

appendStylesheetPI

public void appendStylesheetPI(java.io.Writer writer,
                               NamedTextList attributes)
Appends a stylesheet processing instruction with the given attributes.

Parameters:
writer - The writer that receives the output
attributes - The attributes for this instruction

appendDocumentType

public void appendDocumentType(java.io.Writer writer,
                               java.lang.String rootTagName,
                               java.lang.String dtdURL)
Appends the document type (DOCTYPE) line to the given writer using the SYSTEM parameter to specify the DTD location.

Parameters:
writer - The writer that receives the output (must not be null)
rootTagName - The name of the document's root tag (must not be null)
dtdURL - The url to locate the document's DTD (must not be null)

appendDocumentType

public void appendDocumentType(java.io.Writer writer,
                               java.lang.String rootTagName,
                               java.lang.String schemaName,
                               java.lang.String dtdURL)
Appends the document type (DOCTYPE) line to the given writer using the PUBLIC parameter if the given schameName is not null or the SYSTEM parameter to just specify the DTD location.

Parameters:
writer - The writer that receives the output (must not be null)
rootTagName - The name of the document's root tag (must not be null)
schemaName - The logical name of the schema (e.g. "-//W3C//DTD XHTML 1.0 Strict//EN"). This parameter may be null or blank which means SYSTEM will be used rather than PUBLIC.
dtdURL - The URL to locate the document's DTD (must not be null)

appendSIXElement

public void appendSIXElement(Element element,
                             java.io.Writer writer)
Appends the given element and its children to the specified writer as XML representation.

Parameters:
element - Usually the root element of an XML tree
writer - The writer that will receive the output

appendDOM

public void appendDOM(org.w3c.dom.Document document,
                      java.io.Writer writer)
Appends the given document to the specified writer as XML representation. Be aware that only the XML data of the DOM will be written. The start line of a valid XML stream <?xml version="1.0" ?> is not written by this method.

Parameters:
document - A valid DOM tree
writer - The writer that will receive the output