Package org.jibx.runtime.impl
Class XMLWriterBase
- java.lang.Object
-
- org.jibx.runtime.impl.XMLWriterNamespaceBase
-
- org.jibx.runtime.impl.XMLWriterBase
-
- All Implemented Interfaces:
IExtensibleWriter,IXMLWriter
- Direct Known Subclasses:
GenericXMLWriter,StreamWriterBase
public abstract class XMLWriterBase extends XMLWriterNamespaceBase implements IExtensibleWriter
Base implementation of XML writer interface. This provides common handling of indentation and formatting that can be used for all forms of text output.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
-
Fields inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
m_prefixes, m_uris
-
-
Constructor Summary
Constructors Constructor Description XMLWriterBase(String[] uris)Constructor.XMLWriterBase(XMLWriterBase base, String[] uris)Copy constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(int index, String name, String value)Add attribute to current open start tag.abstract voidclose()Close document output.voidcloseEmptyTag()Close the current open start tag as an empty element.voidcloseStartTag()Close the current open start tag.voidendTag(int index, String name)Generate end tag.protected voidflagContent()Set up for writing any content to element.protected voidflagTextContent()Set up for writing text content to element.abstract voidflush()Flush document output.protected abstract voidindent(int bias)Request output indent with bias from current element nesting level.voidinit()Initialize writer.voidreset()Reset to initial state for reuse.voidstartTagClosed(int index, String name)Generate closed start tag.voidstartTagNamespaces(int index, String name, int[] nums, String[] prefs)Generate start tag for element with namespaces.voidstartTagOpen(int index, String name)Generate open start tag.protected abstract voidwriteAttributeText(String text)Write attribute text to output.voidwriteComment(String text)Write comment to document.voidwriteDocType(String name, String sys, String pub, String subset)Write DOCTYPE declaration to document.voidwriteEntityRef(String name)Write entity reference to document.protected abstract voidwriteMarkup(char chr)Write markup character to output.protected abstract voidwriteMarkup(String text)Write markup text to output.voidwritePI(String target, String data)Write processing instruction to document.protected abstract voidwritePrefix(int index)Write namespace prefix to output.voidwriteXMLDecl(String version, String encoding, String standalone)Write XML declaration to document.-
Methods inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
decrementNesting, defineNamespace, getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, growArray, incrementNesting, internalNamespacePrefix, internalNamespaceUri, internalSetUris, openNamespaces, popExtensionNamespaces, popTranslationTable, pushExtensionNamespaces, pushTranslationTable, shrinkArray, translateNamespace, undefineNamespace
-
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.IExtensibleWriter
createChildWriter
-
Methods inherited from interface org.jibx.runtime.IXMLWriter
getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, indent, openNamespaces, popExtensionNamespaces, popTranslationTable, pushExtensionNamespaces, pushTranslationTable, setIndentSpaces, writeCData, writeTextContent
-
-
-
-
Constructor Detail
-
XMLWriterBase
public XMLWriterBase(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")
-
XMLWriterBase
public XMLWriterBase(XMLWriterBase base, String[] uris)
Copy constructor. This initializes the extension namespace information from an existing instance.- Parameters:
base- existing instanceuris- ordered array of URIs for namespaces used in document
-
-
Method Detail
-
writeMarkup
protected abstract void writeMarkup(String text) throws IOException
Write markup text to output. Markup text can be written directly to the output without the need for any escaping, but still needs to be properly encoded.- Parameters:
text- markup text to be written- Throws:
IOException- if error writing to document
-
writeMarkup
protected abstract void writeMarkup(char chr) throws IOExceptionWrite markup character to output. Markup text can be written directly to the output without the need for any escaping, but still needs to be properly encoded.- Parameters:
chr- markup character to be written- Throws:
IOException- if error writing to document
-
writePrefix
protected abstract void writePrefix(int index) throws IOExceptionWrite namespace prefix to output. This internal method is used to throw an exception when an undeclared prefix is used.- Parameters:
index- namespace URI index number- Throws:
IOException- if error writing to document
-
writeAttributeText
protected abstract void writeAttributeText(String text) throws IOException
Write attribute text to output. This needs to write the text with any appropriate escaping.- Parameters:
text- attribute value text to be written- Throws:
IOException- if error writing to document
-
indent
protected abstract void indent(int bias) throws IOExceptionRequest output indent with bias from current element nesting level. This is used internally for proper indenting in special cases.- Parameters:
bias- Bias- Throws:
IOException- on error writing to document
-
flagContent
protected final void flagContent() throws IOExceptionSet up for writing any content to element. If the start tag for the element has not been closed, this will close it.- Throws:
IOException- on error writing to document
-
flagTextContent
protected final void flagTextContent() throws IOExceptionSet up for writing text content to element. If the start tag for the element has not been closed, this will close it.- Throws:
IOException- on error writing to document
-
init
public void init()
Initialize writer.- Specified by:
initin interfaceIXMLWriter
-
writeXMLDecl
public void writeXMLDecl(String version, String encoding, String standalone) throws IOException
Write XML declaration to document. This can only be called before any other methods in the interface are called.- Specified by:
writeXMLDeclin interfaceIXMLWriter- Parameters:
version- XML version textencoding- text for encoding attribute (unspecified ifnull)standalone- text for standalone attribute (unspecified ifnull)- Throws:
IOException- on error writing to document
-
startTagOpen
public void startTagOpen(int index, String name) throws IOExceptionGenerate open start tag. This allows attributes to be added to the start tag, but must be followed by acloseStartTag()call.- Specified by:
startTagOpenin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified element name- Throws:
IOException- on error writing to document
-
startTagNamespaces
public void startTagNamespaces(int index, String name, int[] nums, String[] prefs) throws IOExceptionGenerate start tag for element with namespaces. This creates the actual start tag, along with any necessary namespace declarations. Previously active namespace declarations are not duplicated. The tag is left incomplete, allowing other attributes to be added.- Specified by:
startTagNamespacesin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- element namenums- array of namespace indexes defined by this element (must be constant, reference is kept until end of element)prefs- array of namespace prefixes mapped by this element (nonullvalues, use "" for default namespace declaration)- Throws:
IOException- on error writing to document
-
addAttribute
public void addAttribute(int index, String name, String value) throws IOExceptionAdd attribute to current open start tag. This is only valid after a call tostartTagOpen(int, java.lang.String)orstartTagNamespaces(int, java.lang.String, int[], java.lang.String[])and before the corresponding call tocloseStartTag().- Specified by:
addAttributein interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified attribute namevalue- text value for attribute- Throws:
IOException- on error writing to document
-
closeStartTag
public void closeStartTag() throws IOExceptionClose the current open start tag. This is only valid after a call tostartTagOpen(int, java.lang.String).- Specified by:
closeStartTagin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
closeEmptyTag
public void closeEmptyTag() throws IOExceptionClose the current open start tag as an empty element. This is only valid after a call tostartTagOpen(int, java.lang.String).- Specified by:
closeEmptyTagin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
startTagClosed
public void startTagClosed(int index, String name) throws IOExceptionGenerate closed start tag. No attributes or namespaces can be added to a start tag written using this call.- Specified by:
startTagClosedin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified element name- Throws:
IOException- on error writing to document
-
endTag
public void endTag(int index, String name) throws IOExceptionGenerate end tag.- Specified by:
endTagin interfaceIXMLWriter- Parameters:
index- namespace URI index numbername- unqualified element name- Throws:
IOException- on error writing to document
-
writeComment
public void writeComment(String text) throws IOException
Write comment to document.- Specified by:
writeCommentin interfaceIXMLWriter- Parameters:
text- comment text- Throws:
IOException- on error writing to document
-
writeEntityRef
public void writeEntityRef(String name) throws IOException
Write entity reference to document.- Specified by:
writeEntityRefin interfaceIXMLWriter- Parameters:
name- entity name- Throws:
IOException- on error writing to document
-
writeDocType
public void writeDocType(String name, String sys, String pub, String subset) throws IOException
Write DOCTYPE declaration to document.- Specified by:
writeDocTypein interfaceIXMLWriter- Parameters:
name- root element namesys- system ID (nullif none, must be non-nullfor public ID to be used)pub- public ID (nullif none)subset- internal subset (nullif none)- Throws:
IOException- on error writing to document
-
writePI
public void writePI(String target, String data) throws IOException
Write processing instruction to document.- Specified by:
writePIin interfaceIXMLWriter- Parameters:
target- processing instruction target namedata- processing instruction data- Throws:
IOException- on error writing to document
-
flush
public abstract void flush() throws IOExceptionFlush document output. Subclasses must implement this method to force all buffered output to be written. To assure proper handling of an open start tag they should first callflagContent().- Specified by:
flushin interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
close
public abstract void close() throws IOExceptionClose document output. Completes writing of document output, including closing the output medium.- Specified by:
closein interfaceIXMLWriter- Throws:
IOException- on error writing to document
-
reset
public void reset()
Reset to initial state for reuse. The writer is serially reusable, as long as this method is called to clear any retained state information between uses. It is automatically called when output is set.- Specified by:
resetin interfaceIXMLWriter- Overrides:
resetin classXMLWriterNamespaceBase
-
-