Package org.jibx.extras
Class JDOMWriter
java.lang.Object
org.jibx.runtime.impl.XMLWriterNamespaceBase
org.jibx.extras.JDOMWriter
- All Implemented Interfaces:
IXMLWriter
JDOM implementation of XML writer interface. The
Document
that is
created can be accessed by using getDocument()
.- Version:
- 1.0
- Author:
- Andreas Brenk
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Element
The currently openElement
that is used for add* methods.private Document
The JDOMDocument
this writer is creating.Fields inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
m_prefixes, m_uris
-
Constructor Summary
ConstructorsConstructorDescriptionJDOMWriter
(String[] namespaces) Creates a new instance with the given namespace URIs.JDOMWriter
(String[] namespaces, Document document) Creates a new instance with the given Document as target for marshalling.JDOMWriter
(String[] namespaces, Element currentElement) Creates a new instance with the given Element as target for marshalling. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(int index, String name, String value) Add attribute to current open start tag.void
close()
Does nothing.void
Close the current open start tag as an empty element.void
Close the current open start tag.protected void
defineNamespace
(int index, String prefix) Does nothing.void
Generate end tag.void
flush()
Does nothing.Document
private Namespace
getNamespace
(int index) This will retrieve (if in existence) or create (if not) aNamespace
for the supplied namespace index.void
indent()
Does nothing.void
init()
Does nothing.void
reset()
Reset to initial state for reuse.void
setIndentSpaces
(int count, String newline, char indent) Does nothing.void
startTagClosed
(int index, String name) Generate closed start tag.void
startTagNamespaces
(int index, String name, int[] nums, String[] prefs) Generate start tag for element with namespaces.void
startTagOpen
(int index, String name) Generate open start tag.protected void
undefineNamespace
(int index) Does nothing.void
writeCData
(String text) Write CDATA text to document.void
writeComment
(String text) Write comment to document.void
writeDocType
(String name, String sys, String pub, String subset) Write DOCTYPE declaration to document.void
writeEntityRef
(String name) Write entity reference to document.void
Write processing instruction to document.void
writeTextContent
(String text) Write ordinary character data text content to document.void
writeXMLDecl
(String version, String encoding, String standalone) Does nothing.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
-
Field Details
-
document
private Document documentThe JDOMDocument
this writer is creating. -
currentElement
private Element currentElementThe currently openElement
that is used for add* methods.
-
-
Constructor Details
-
JDOMWriter
Creates a new instance with the given namespace URIs. -
JDOMWriter
Creates a new instance with the given Document as target for marshalling.- Parameters:
document
- must not be null
-
JDOMWriter
Creates a new instance with the given Element as target for marshalling.- Parameters:
currentElement
- must not be null
-
-
Method Details
-
init
public void init()Does nothing. -
setIndentSpaces
Does nothing.- 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
-
writeXMLDecl
Does nothing.- 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
Description copied from interface:IXMLWriter
Generate open start tag. This allows attributes and/or namespace declarations to be added to the start tag, but must be followed by aIXMLWriter.closeStartTag()
call.- 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 IOException Description copied from interface:IXMLWriter
Generate 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.- 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 (nonull
values, use "" for default namespace declaration)- Throws:
IOException
- on error writing to document
-
addAttribute
Description copied from interface:IXMLWriter
Add attribute to current open start tag. This is only valid after a call toIXMLWriter.startTagOpen(int, java.lang.String)
and before the corresponding call toIXMLWriter.closeStartTag()
.- Parameters:
index
- namespace URI index numbername
- unqualified attribute namevalue
- text value for attribute- Throws:
IOException
- on error writing to document
-
closeStartTag
Description copied from interface:IXMLWriter
Close the current open start tag. This is only valid after a call toIXMLWriter.startTagOpen(int, java.lang.String)
.- Throws:
IOException
- on error writing to document
-
closeEmptyTag
Description copied from interface:IXMLWriter
Close the current open start tag as an empty element. This is only valid after a call toIXMLWriter.startTagOpen(int, java.lang.String)
.- Throws:
IOException
- on error writing to document
-
startTagClosed
Description copied from interface:IXMLWriter
Generate closed start tag. No attributes or namespaces can be added to a start tag written using this call.- Parameters:
index
- namespace URI index numbername
- unqualified element name- Throws:
IOException
- on error writing to document
-
endTag
Description copied from interface:IXMLWriter
Generate end tag.- Parameters:
index
- namespace URI index numbername
- unqualified element name- Throws:
IOException
- on error writing to document
-
writeTextContent
Description copied from interface:IXMLWriter
Write ordinary character data text content to document.- Parameters:
text
- content value text (must not benull
)- Throws:
IOException
- on error writing to document
-
writeCData
Description copied from interface:IXMLWriter
Write CDATA text to document.- Parameters:
text
- content value text (must not benull
)- Throws:
IOException
- on error writing to document
-
writeComment
Description copied from interface:IXMLWriter
Write comment to document.- Parameters:
text
- comment text (must not benull
)- Throws:
IOException
- on error writing to document
-
writeEntityRef
Description copied from interface:IXMLWriter
Write entity reference to document.- Parameters:
name
- entity name (must not benull
)- Throws:
IOException
- on error writing to document
-
writeDocType
Description copied from interface:IXMLWriter
Write DOCTYPE declaration to document.- Parameters:
name
- root element namesys
- system ID (null
if none, must be non-null
for public ID to be used)pub
- public ID (null
if none)subset
- internal subset (null
if none)- Throws:
IOException
- on error writing to document
-
writePI
Description copied from interface:IXMLWriter
Write processing instruction to document.- Parameters:
target
- processing instruction target name (must not benull
)data
- processing instruction data (must not benull
)- Throws:
IOException
- on error writing to document
-
indent
Does nothing.- Throws:
IOException
- on error writing to document
-
flush
Does nothing.- Throws:
IOException
- on error writing to document
-
close
Does nothing.- Throws:
IOException
- on error writing to document
-
reset
public void reset()Description copied from class:XMLWriterNamespaceBase
Reset to initial state for reuse. Subclasses overriding this method need to call this base class implementation during their processing.- Specified by:
reset
in interfaceIXMLWriter
- Overrides:
reset
in classXMLWriterNamespaceBase
-
getDocument
public Document getDocument()- Returns:
- the JDOM
Document
this writer created.
-
defineNamespace
Does nothing.- Specified by:
defineNamespace
in classXMLWriterNamespaceBase
- Parameters:
index
- post-translation namespace URI index numberprefix
- prefix used for namespace- Throws:
IOException
- if error writing to document
-
undefineNamespace
protected void undefineNamespace(int index) Does nothing.- Specified by:
undefineNamespace
in classXMLWriterNamespaceBase
- Parameters:
index
- post-translation namespace URI index number
-
getNamespace
private Namespace getNamespace(int index) This will retrieve (if in existence) or create (if not) aNamespace
for the supplied namespace index.
-