|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.ociweb.xml.WAX
public class WAX
This class provides methods that make outputting XML easy, fast and efficient in terms of memory utilization.
A WAX object should not be used from multiple threads!
For more information, see http://www.ociweb.com/wax/.
Copyright (c) 2008, R. Mark Volkmann
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
| Field Summary | |
|---|---|
static java.lang.String |
MAC_LINE_SEPARATOR
|
static java.lang.String |
UNIX_LINE_SEPARATOR
|
static java.lang.String |
WINDOWS_LINE_SEPARATOR
|
| Constructor Summary | |
|---|---|
WAX()
Creates a WAX that writes to stdout. |
|
WAX(java.io.OutputStream os)
Creates a WAX that writes to a given OutputStream. |
|
WAX(java.io.OutputStream os,
Version version)
|
|
WAX(java.lang.String filePath)
Creates a WAX that writes to a given file path. |
|
WAX(java.lang.String filePath,
Version version)
|
|
WAX(Version version)
|
|
WAX(java.io.Writer writer)
Creates a WAX that writes to a given Writer. |
|
WAX(java.io.Writer writer,
Version version)
|
|
| Method Summary | |
|---|---|
StartTagWAX |
attr(java.lang.String name,
java.lang.Object value)
Writes an attribute for the currently open element start tag. |
StartTagWAX |
attr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value)
Writes an attribute for the currently open element start tag. |
StartTagWAX |
attr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value,
boolean newLine)
Writes an attribute for the currently open element start tag. |
ElementWAX |
blankLine()
Writes a blank line to increase readability of the XML. |
ElementWAX |
cdata(java.lang.String text)
Writes a CDATA section in the content of the current element. |
ElementWAX |
cdata(java.lang.String text,
boolean newLine)
Writes a CDATA section in the content of the current element. |
ElementWAX |
child(java.lang.String name)
A convenience method that is a shortcut for start(name).end(). |
ElementWAX |
child(java.lang.String name,
java.lang.String text)
A convenience method that is a shortcut for start(name).text(text).end(). |
ElementWAX |
child(java.lang.String prefix,
java.lang.String name,
java.lang.String text)
A convenience method that is a shortcut for start(prefix, name).text(text).end(). |
void |
close()
Terminates all unterminated elements, closes the Writer that is being used to output XML, and insures that nothing else can be written. |
PrologOrElementWAX |
comment(java.lang.String text)
Writes a comment (<!-- text -->). |
PrologOrElementWAX |
comment(java.lang.String text,
boolean newLine)
Writes a comment (<!-- text -->). |
StartTagWAX |
commentedStart(java.lang.String name)
Writes a commented start tag for a given element name, but doesn't terminate it. |
StartTagWAX |
commentedStart(java.lang.String prefix,
java.lang.String name)
Writes a commented start tag for a given element name, but doesn't terminate it. |
StartTagWAX |
defaultNamespace(java.lang.String uri)
Writes a namespace declaration for the default namespace in the start tag of the current element. |
StartTagWAX |
defaultNamespace(java.lang.String uri,
java.lang.String schemaPath)
Writes a namespace declaration for the default namespace in the start tag of the current element. |
StartTagWAX |
defaultNS(java.lang.String uri)
Shorthand name for the defaultNamespace method. |
StartTagWAX |
defaultNS(java.lang.String uri,
java.lang.String schemaPath)
Shorthand name for the defaultNamespace method. |
PrologWAX |
dtd(java.lang.String systemId)
Writes a DOCTYPE that associates a DTD with the XML document. |
PrologWAX |
dtd(java.lang.String publicId,
java.lang.String systemId)
Writes a DOCTYPE that associates a DTD with the XML document. |
ElementWAX |
end()
Terminates the current element. |
ElementWAX |
end(boolean verbose)
Terminates the current element. |
PrologWAX |
entityDef(java.lang.String name,
java.lang.String value)
Adds an entity definition to the internal subset of the DOCTYPE. |
WAX |
excludeFinalNewline()
Indicate that WAX should not add a final newline when closing this WAX. |
PrologWAX |
externalEntityDef(java.lang.String name,
java.lang.String filePath)
Adds an external entity definition to the internal subset of the DOCTYPE. |
java.lang.String |
getIndent()
Gets the indentation characters being used. |
java.lang.String |
getLineSeparator()
Gets the line separator characters currently being used. |
java.lang.String |
getSchemaVersion()
Gets the part of the xsi namespace URI that specifies the version of XML Schema being used. |
WAX |
includeFinalNewline()
Indicate that WAX should add a final newline when closing this WAX. |
boolean |
isSpaceInEmptyElements()
Indicates whether a space is added before the slash in empty elements. |
boolean |
isTrustMe()
Gets whether "trust me" mode is enabled. |
StartTagWAX |
namespace(java.lang.String prefix,
java.lang.String uri)
Writes a namespace declaration in the start tag of the current element. |
StartTagWAX |
namespace(java.lang.String prefix,
java.lang.String uri,
java.lang.String schemaPath)
Writes a namespace declaration in the start tag of the current element. |
void |
noIndentsOrLineSeparators()
Don't output indent output or write line separators. |
StartTagWAX |
ns(java.lang.String prefix,
java.lang.String uri)
Shorthand name for the namespace method. |
StartTagWAX |
ns(java.lang.String prefix,
java.lang.String uri,
java.lang.String schemaPath)
Shorthand name for the namespace method. |
PrologOrElementWAX |
pi(java.lang.String target,
java.lang.String data)
Shorthand name for the processingInstruction method. |
PrologOrElementWAX |
processingInstruction(java.lang.String target,
java.lang.String data)
Writes a processing instruction. |
void |
setIndent(int numSpaces)
Sets the number of spaces to use for indentation. |
void |
setIndent(java.lang.String indent)
Sets the indentation characters to use. |
void |
setLineSeparator(java.lang.String lineSeparator)
Sets the line separator characters to be used. |
void |
setSchemaVersion(java.lang.String version)
Sets the part of the xsi namespace URI that specifies the version of XML Schema being used. |
void |
setSpaceInEmptyElements(boolean spaceInEmptyElements)
Sets whether a space will be added before the closing slash in empty elements. |
void |
setTrustMe(boolean trustMe)
Sets whether "trust me" mode is enabled. |
StartTagWAX |
start(java.lang.String name)
Writes the start tag for a given element name, but doesn't terminate it. |
StartTagWAX |
start(java.lang.String prefix,
java.lang.String name)
Writes the start tag for a given element name, but doesn't terminate it. |
ElementWAX |
text(java.lang.String text)
Writes text inside the content of the current element. |
ElementWAX |
text(java.lang.String text,
boolean newLine)
Writes text inside the content of the current element. |
StartTagWAX |
unescapedAttr(java.lang.String name,
java.lang.Object value)
Same as the attr method, but special characters in the value aren't escaped. |
StartTagWAX |
unescapedAttr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value)
Same as the attr method, but special characters in the value aren't escaped. |
StartTagWAX |
unescapedAttr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value,
boolean newLine)
Same as the attr method, but special characters in the value aren't escaped. |
ElementWAX |
unescapedText(java.lang.String text)
Same as the text method, but special characters in the value aren't escaped. |
ElementWAX |
unescapedText(java.lang.String text,
boolean newLine)
Same as the text method, but special characters in the value aren't escaped. |
PrologWAX |
xslt(java.lang.String filePath)
Writes an "xml-stylesheet" processing instruction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String MAC_LINE_SEPARATOR
public static final java.lang.String UNIX_LINE_SEPARATOR
public static final java.lang.String WINDOWS_LINE_SEPARATOR
| Constructor Detail |
|---|
public WAX()
public WAX(Version version)
public WAX(java.io.OutputStream os)
os - the OutputStream
public WAX(java.io.OutputStream os,
Version version)
public WAX(java.lang.String filePath)
filePath - the file path
WAXIOException - if the named file exists but is a directory rather than a
regular file, does not exist but cannot be created, or cannot
be opened for any other reason.
public WAX(java.lang.String filePath,
Version version)
public WAX(java.io.Writer writer)
writer - the Writer
public WAX(java.io.Writer writer,
Version version)
| Method Detail |
|---|
public WAX includeFinalNewline()
public WAX excludeFinalNewline()
public StartTagWAX attr(java.lang.String name,
java.lang.Object value)
attr in interface StartTagWAXname - the attribute namevalue - the attribute value
attr(String, Object)
public StartTagWAX attr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value)
attr in interface StartTagWAXprefix - the namespace prefix for the attributename - the attribute namevalue - the attribute value
attr(String, String, Object)
public StartTagWAX attr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value,
boolean newLine)
attr in interface StartTagWAXprefix - the namespace prefix for the attributename - the attribute namevalue - the attribute valuenewLine - true to write on a new line; false otherwise
java.lang.IllegalStateException - unless we have a start tag open, for writing XML attributes.attr(String, String, Object, boolean)public ElementWAX blankLine()
blankLine in interface ElementWAXblankLine()public ElementWAX cdata(java.lang.String text)
cdata in interface ElementWAXtext - the text
cdata(String)
public ElementWAX cdata(java.lang.String text,
boolean newLine)
cdata in interface ElementWAXtext - the textnewLine - true to output the text on a new line; false otherwise
java.lang.IllegalStateException - if before the beginning or after end of writing the root
Element.cdata(String, boolean)public ElementWAX child(java.lang.String name)
child in interface ElementWAXname - the child element name
child(String)
public ElementWAX child(java.lang.String name,
java.lang.String text)
child in interface ElementWAXname - the child element nametext - the child element text content
child(String, String)
public ElementWAX child(java.lang.String prefix,
java.lang.String name,
java.lang.String text)
child in interface ElementWAXprefix - the namespace prefix of the child elementname - the child element nametext - the child element text content
java.lang.IllegalStateException - if after end of writing the root Element.child(String, String, String)public void close()
close in interface ElementWAXjava.lang.IllegalStateException - if WAX had already been closed, or
if we have not yet written a root Element.
WAXIOException - if an I/O error occurs.close()public PrologOrElementWAX comment(java.lang.String text)
comment in interface CommonWAXtext - the comment text (cannot contain "--")
comment(String)
public PrologOrElementWAX comment(java.lang.String text,
boolean newLine)
comment in interface CommonWAXtext - the comment text (cannot contain "--")newLine - true to output the text on a new line; false otherwise
java.lang.IllegalArgumentException - if text is null or contains two
sequential dash characters ("--").comment(String, boolean)public StartTagWAX commentedStart(java.lang.String name)
commentedStart in interface CommonWAXname - the element name
commentedStart(String)
public StartTagWAX commentedStart(java.lang.String prefix,
java.lang.String name)
commentedStart in interface CommonWAXprefix - the namespace prefix to used on the elementname - the element name
commentedStart(String, String)public StartTagWAX defaultNamespace(java.lang.String uri)
defaultNamespace in interface StartTagWAXuri - the namespace URI
defaultNamespace(String)
public StartTagWAX defaultNamespace(java.lang.String uri,
java.lang.String schemaPath)
defaultNamespace in interface StartTagWAXuri - the namespace URIschemaPath - the path to the XML Schema
defaultNamespace(String, String)public StartTagWAX defaultNS(java.lang.String uri)
defaultNS in interface StartTagWAXuri - the namespace URI
defaultNamespace(String)
public StartTagWAX defaultNS(java.lang.String uri,
java.lang.String schemaPath)
defaultNS in interface StartTagWAXuri - the namespace URIschemaPath - the path to the XML Schema
defaultNamespace(String, String)public PrologWAX dtd(java.lang.String systemId)
dtd in interface PrologWAXsystemId - the file path or URL to the DTD
dtd(String)
public PrologWAX dtd(java.lang.String publicId,
java.lang.String systemId)
dtd in interface PrologWAXpublicId - the public ID of the DTDsystemId - the file path or URL to the DTD
java.lang.IllegalStateException - if this method is called more than once, or
if we have already started writing XML Elements.
java.lang.IllegalArgumentException - if systemId is not a valid URI.dtd(String, String)public ElementWAX end()
end in interface ElementWAXend()public ElementWAX end(boolean verbose)
end in interface ElementWAXverbose - true to not consider shorthand way; false to consider it
java.lang.IllegalStateException - if before the beginning or after end of writing the root
Element.end(boolean)
public PrologWAX entityDef(java.lang.String name,
java.lang.String value)
entityDef in interface PrologWAXname - value -
java.lang.IllegalStateException - if we have already started writing XML Elements.entityDef(String, String)
public PrologWAX externalEntityDef(java.lang.String name,
java.lang.String filePath)
externalEntityDef in interface PrologWAXname - the namefilePath - the filePath
externalEntityDef(String, String)public java.lang.String getIndent()
setIndent(String),
setIndent(int)public java.lang.String getLineSeparator()
public java.lang.String getSchemaVersion()
public boolean isSpaceInEmptyElements()
setSpaceInEmptyElements(boolean)public boolean isTrustMe()
setTrustMe(boolean)
public StartTagWAX namespace(java.lang.String prefix,
java.lang.String uri)
namespace in interface StartTagWAXprefix - the namespace prefixuri - the namespace URI
namespace(String, String)
public StartTagWAX namespace(java.lang.String prefix,
java.lang.String uri,
java.lang.String schemaPath)
namespace in interface StartTagWAXprefix - the namespace prefixuri - the namespace URIschemaPath - the path to the XML Schema
java.lang.IllegalStateException - unless we have a start tag open, for writing XML attributes.
java.lang.IllegalArgumentException - if prefix is not a valid XML name token, or
if uri or schemaPath are not a
valid URIs, or
when one attempts to define the same namespace
prefix more than once within the same start XML
Element.namespace(String, String, String)
public StartTagWAX ns(java.lang.String prefix,
java.lang.String uri)
ns in interface StartTagWAXprefix - the namespace prefixuri - the namespace URI
namespace(String, String)
public StartTagWAX ns(java.lang.String prefix,
java.lang.String uri,
java.lang.String schemaPath)
ns in interface StartTagWAXprefix - the namespace prefixuri - the namespace URIschemaPath - the path to the XML Schema
namespace(String, String, String)
public PrologOrElementWAX pi(java.lang.String target,
java.lang.String data)
pi in interface CommonWAXtarget - the processing instruction targetdata - the processing instruction data
pi(String, String)
public PrologOrElementWAX processingInstruction(java.lang.String target,
java.lang.String data)
processingInstruction in interface CommonWAXtarget - the processing instruction targetdata - the processing instruction data
java.lang.IllegalArgumentException - if target is not a valid XML name token.processingInstruction(String, String)public void setIndent(java.lang.String indent)
java.lang.IllegalArgumentException - if the indent string does not follow the rules
above
(and the "trust me" flag isn't true).public void setIndent(int numSpaces)
numSpaces - the number of spaces
java.lang.IllegalArgumentException - if numSpaces is negative or more than four.public void noIndentsOrLineSeparators()
public void setLineSeparator(java.lang.String lineSeparator)
lineSeparator - the line separator characters
java.lang.IllegalStateException - if data has already been written.
java.lang.IllegalArgumentException - if the lineSeparator sequence is not one of the
recognized (Mac, Unix or Windows) line terminator/separator
character sequences.public void setSchemaVersion(java.lang.String version)
version - typically "1999" or "2001"public void setSpaceInEmptyElements(boolean spaceInEmptyElements)
spaceInEmptyElements - true to include a space; false otherwiseisSpaceInEmptyElements()public void setTrustMe(boolean trustMe)
trustMe - true to disable error checking; false to enable itisTrustMe()public StartTagWAX start(java.lang.String name)
start in interface CommonWAXname - the element name
start(String)
public StartTagWAX start(java.lang.String prefix,
java.lang.String name)
start in interface CommonWAXprefix - the namespace prefix to used on the elementname - the element name
java.lang.IllegalStateException - if the root XML Element has been closed.start(String, String)public ElementWAX text(java.lang.String text)
text in interface ElementWAXtext - the text
text(String)
public ElementWAX text(java.lang.String text,
boolean newLine)
text in interface ElementWAXtext - the textnewLine - true to output the text on a new line; false otherwise
java.lang.IllegalStateException - if before the beginning or after end of writing the root
Element.text(String, boolean)
public StartTagWAX unescapedAttr(java.lang.String name,
java.lang.Object value)
unescapedAttr in interface StartTagWAXname - the attribute namevalue - the attribute value
attr(String, Object)
public StartTagWAX unescapedAttr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value)
unescapedAttr in interface StartTagWAXprefix - the namespace prefix for the attributename - the attribute namevalue - the attribute value
attr(String, String, Object)
public StartTagWAX unescapedAttr(java.lang.String prefix,
java.lang.String name,
java.lang.Object value,
boolean newLine)
unescapedAttr in interface StartTagWAXprefix - the namespace prefix for the attributename - the attribute namevalue - the attribute valuenewLine - true to write on a new line; false otherwise
attr(String, String, Object, boolean)public ElementWAX unescapedText(java.lang.String text)
unescapedText in interface ElementWAXtext - the text
unescapedText(String)
public ElementWAX unescapedText(java.lang.String text,
boolean newLine)
unescapedText in interface ElementWAXtext - the textnewLine - true to output the text on a new line; false otherwise
unescapedText(String, boolean)public PrologWAX xslt(java.lang.String filePath)
xslt in interface PrologWAXfilePath - the path to the XSLT stylesheet
java.lang.IllegalStateException - if a stylesheet has already been specified, or
if we have already started writing XML Elements.
java.lang.IllegalArgumentException - if filePath is not a valid URI.xslt(String)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||