Package org.jibx.runtime.impl
Class GenericXMLWriter
- java.lang.Object
-
- org.jibx.runtime.impl.XMLWriterNamespaceBase
-
- org.jibx.runtime.impl.XMLWriterBase
-
- org.jibx.runtime.impl.GenericXMLWriter
-
- All Implemented Interfaces:
IExtensibleWriter
,IXMLWriter
public class GenericXMLWriter extends XMLWriterBase
Generic handler for marshalling text document to a writer. This is the most general output handler since it can be used with any character encoding and and output writer.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private ICharacterEscaper
m_escaper
Escaper for character data content output.private boolean
m_indent
Indent tags for pretty-printed text.private int
m_indentBase
Base number of characters in indent sequence (end of line only).private int
m_indentPerLevel
Number of extra characters in indent sequence per level of nesting.private char[]
m_indentSequence
Raw text for indentation sequences.private java.io.Writer
m_writer
Writer for text output.-
Fields inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
m_prefixes, m_uris
-
-
Constructor Summary
Constructors Constructor Description GenericXMLWriter(java.lang.String[] uris)
Constructor.GenericXMLWriter(GenericXMLWriter base, java.lang.String[] uris)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close document output.IXMLWriter
createChildWriter(java.lang.String[] uris)
Create a child writer instance to be used for a separate binding.protected void
defineNamespace(int index, java.lang.String prefix)
Report that namespace has been defined.void
flush()
Flush document output.void
indent()
Request output indent.void
indent(int bias)
Request output indent.void
setIndentSpaces(int count, java.lang.String newline, char indent)
Set nesting indentation.void
setOutput(java.io.Writer outw, ICharacterEscaper escaper)
Set output writer and escaper.protected void
undefineNamespace(int index)
Report that namespace has been undefined.protected void
writeAttributeText(java.lang.String text)
Write attribute text to output.void
writeCData(java.lang.String text)
Write CDATA text to document.protected void
writeMarkup(char chr)
Write markup character to output.protected void
writeMarkup(java.lang.String text)
Write markup text to output.protected void
writePrefix(int index)
Write namespace prefix to output.void
writeTextContent(java.lang.String text)
Write ordinary character data text content to document.-
Methods inherited from class org.jibx.runtime.impl.XMLWriterBase
addAttribute, closeEmptyTag, closeStartTag, endTag, flagContent, flagTextContent, init, reset, startTagClosed, startTagNamespaces, startTagOpen, writeComment, writeDocType, writeEntityRef, writePI, writeXMLDecl
-
Methods inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
decrementNesting, getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, growArray, incrementNesting, internalNamespacePrefix, internalNamespaceUri, internalSetUris, openNamespaces, popExtensionNamespaces, popTranslationTable, pushExtensionNamespaces, pushTranslationTable, shrinkArray, translateNamespace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jibx.runtime.IXMLWriter
getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, openNamespaces, popExtensionNamespaces, popTranslationTable, pushExtensionNamespaces, pushTranslationTable
-
-
-
-
Field Detail
-
m_writer
private java.io.Writer m_writer
Writer for text output.
-
m_escaper
private ICharacterEscaper m_escaper
Escaper for character data content output.
-
m_indent
private boolean m_indent
Indent tags for pretty-printed text.
-
m_indentBase
private int m_indentBase
Base number of characters in indent sequence (end of line only).
-
m_indentPerLevel
private int m_indentPerLevel
Number of extra characters in indent sequence per level of nesting.
-
m_indentSequence
private char[] m_indentSequence
Raw text for indentation sequences.
-
-
Constructor Detail
-
GenericXMLWriter
public GenericXMLWriter(java.lang.String[] uris)
Constructor.- Parameters:
uris
- ordered array of URIs for namespaces used in document (must be constant; the value in position 0 must always be the empty string "", and the value in position 1 must always be the XML namespace "http://www.w3.org/XML/1998/namespace")
-
GenericXMLWriter
public GenericXMLWriter(GenericXMLWriter base, java.lang.String[] uris)
Copy constructor. This takes the writer from a supplied instance, while setting a new array of namespace URIs. It's intended for use when invoking one binding from within another binding.- Parameters:
base
- instance to be used as base for writeruris
- ordered array of URIs for namespaces used in document (seeGenericXMLWriter(String[])
)
-
-
Method Detail
-
setOutput
public void setOutput(java.io.Writer outw, ICharacterEscaper escaper)
Set output writer and escaper. If an output writer is currently open when this is called the existing writer is flushed and closed, with any errors ignored.- Parameters:
outw
- writer for document data outputescaper
- character escaper for chosen encoding
-
setIndentSpaces
public void setIndentSpaces(int count, java.lang.String newline, char indent)
Set nesting indentation. This is advisory only, and implementations of this interface are free to ignore it. The intent is to indicate that the generated output should use indenting to illustrate element nesting.- Parameters:
count
- number of character to indent per level, or disable indentation if negative (zero means new line only)newline
- sequence of characters used for a line ending (null
means use the single character '\n')indent
- whitespace character used for indentation
-
writeMarkup
protected void writeMarkup(java.lang.String text) throws java.io.IOException
Write markup text to output. Markup text can be written directly to the output without the need for any escaping.- Specified by:
writeMarkup
in classXMLWriterBase
- Parameters:
text
- markup text to be written- Throws:
java.io.IOException
- if error writing to document
-
writeMarkup
protected void writeMarkup(char chr) throws java.io.IOException
Write markup character to output. Markup text can be written directly to the output without the need for any escaping.- Specified by:
writeMarkup
in classXMLWriterBase
- Parameters:
chr
- markup character to be written- Throws:
java.io.IOException
- if error writing to document
-
defineNamespace
protected void defineNamespace(int index, java.lang.String prefix)
Report that namespace has been defined.- Specified by:
defineNamespace
in classXMLWriterNamespaceBase
- Parameters:
index
- post-translation namespace URI index numberprefix
- prefix used for namespace
-
undefineNamespace
protected void undefineNamespace(int index)
Report that namespace has been undefined.- Specified by:
undefineNamespace
in classXMLWriterNamespaceBase
- Parameters:
index
- post-translation namespace URI index number
-
writePrefix
protected void writePrefix(int index) throws java.io.IOException
Write namespace prefix to output. This internal method is used to handle translation of namespace indexes to internal form, and also to throw an exception when an undeclared prefix is used.- Specified by:
writePrefix
in classXMLWriterBase
- Parameters:
index
- namespace URI index number- Throws:
java.io.IOException
- if error writing to document
-
writeAttributeText
protected void writeAttributeText(java.lang.String text) throws java.io.IOException
Write attribute text to output. This needs to write the text with any appropriate escaping.- Specified by:
writeAttributeText
in classXMLWriterBase
- Parameters:
text
- attribute value text to be written- Throws:
java.io.IOException
- if error writing to document
-
writeTextContent
public void writeTextContent(java.lang.String text) throws java.io.IOException
Write ordinary character data text content to document. This needs to write the text with any appropriate escaping.- Parameters:
text
- content value text- Throws:
java.io.IOException
- on error writing to document
-
writeCData
public void writeCData(java.lang.String text) throws java.io.IOException
Write CDATA text to document. This needs to write the text with any appropriate escaping.- Parameters:
text
- content value text- Throws:
java.io.IOException
- on error writing to document
-
indent
public void indent(int bias) throws java.io.IOException
Request output indent. Output the line end sequence followed by the appropriate number of indent characters.- Specified by:
indent
in classXMLWriterBase
- Parameters:
bias
- indent depth difference (positive or negative) from current element nesting depth- Throws:
java.io.IOException
- on error writing to document
-
indent
public void indent() throws java.io.IOException
Request output indent. Output the line end sequence followed by the appropriate number of indent characters for the current nesting level.- Throws:
java.io.IOException
- on error writing to document
-
flush
public void flush() throws java.io.IOException
Flush document output. Forces out all output generated to this point.- Specified by:
flush
in interfaceIXMLWriter
- Specified by:
flush
in classXMLWriterBase
- Throws:
java.io.IOException
- on error writing to document
-
close
public void close() throws java.io.IOException
Close document output. Completes writing of document output, including closing the output medium.- Specified by:
close
in interfaceIXMLWriter
- Specified by:
close
in classXMLWriterBase
- Throws:
java.io.IOException
- on error writing to document
-
createChildWriter
public IXMLWriter createChildWriter(java.lang.String[] uris)
Create a child writer instance to be used for a separate binding. The child writer inherits the stream and encoding from this writer, while using the supplied namespace URIs.- Parameters:
uris
- ordered array of URIs for namespaces used in document (seeGenericXMLWriter(String[])
)- Returns:
- child writer
-
-