org.apache.tools.ant.util
Class DOMElementWriter
java.lang.Object
org.apache.tools.ant.util.DOMElementWriter
public class DOMElementWriter
extends java.lang.Object
Writes a DOM tree to a given Writer.
warning: this utility currently does not declare XML Namespaces.
Utility class used by
XmlLogger
and
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
XMLJUnitResultFormatter}.
protected String[] | knownEntities - Don't try to be too smart but at least recognize the predefined
entities.
|
void | closeElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren) - Writes a DOM tree to a stream.
|
String | encode(String value) - Escape <, > & ', " as their entities and
drop characters that are illegal in XML documents.
|
String | encodedata(String value) - Drop characters that are illegal in XML documents.
|
boolean | isLegalCharacter(char c) - Is the given character allowed inside an XML document?
See XML 1.0 2.2
http://www.w3.org/TR/1998/REC-xml-19980210#charsets.
|
boolean | isReference(String ent) - Is the given argument a character or entity reference?
|
void | openElement(Element element, Writer out, int indent, String indentWith) - Writes the opening tag - including all attributes -
corresponding to a DOM element.
|
void | openElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren) - Writes the opening tag - including all attributes -
corresponding to a DOM element.
|
void | write(Element root, OutputStream out) - Writes a DOM tree to a stream in UTF8 encoding.
|
void | write(Element element, Writer out, int indent, String indentWith) - Writes a DOM tree to a stream.
|
void | writeXMLDeclaration(Writer wri) - Writes the XML declaration if xmlDeclaration is true.
|
knownEntities
protected String[] knownEntities
Don't try to be too smart but at least recognize the predefined
entities.
DOMElementWriter
public DOMElementWriter()
Create an element writer.
The ?xml? declaration will be included, namespaces ignored.
DOMElementWriter
public DOMElementWriter(boolean xmlDeclaration)
Create an element writer
XML namespaces will be ignored.
xmlDeclaration
- flag to indicate whether the ?xml? declaration
should be included.
DOMElementWriter
public DOMElementWriter(boolean xmlDeclaration,
DOMElementWriter.XmlNamespacePolicy namespacePolicy)
Create an element writer
XML namespaces will be ignored.
xmlDeclaration
- flag to indicate whether the ?xml? declaration
should be included.namespacePolicy
- the policy to use.
closeElement
public void closeElement(Element element,
Writer out,
int indent,
String indentWith,
boolean hasChildren)
throws IOException
Writes a DOM tree to a stream.
element
- the Root DOM element of the treeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.hasChildren
- if true indent.
encode
public String encode(String value)
Escape <, > & ', " as their entities and
drop characters that are illegal in XML documents.
value
- the string to encode.
encodedata
public String encodedata(String value)
value
- the value to be encoded.
isLegalCharacter
public boolean isLegalCharacter(char c)
c
- the character to test.
- true if the character is allowed.
isReference
public boolean isReference(String ent)
Is the given argument a character or entity reference?
ent
- the value to be checked.
openElement
public void openElement(Element element,
Writer out,
int indent,
String indentWith)
throws IOException
Writes the opening tag - including all attributes -
corresponding to a DOM element.
element
- the DOM element to writeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.
openElement
public void openElement(Element element,
Writer out,
int indent,
String indentWith,
boolean hasChildren)
throws IOException
Writes the opening tag - including all attributes -
corresponding to a DOM element.
element
- the DOM element to writeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.hasChildren
- whether this element has children.
write
public void write(Element root,
OutputStream out)
throws IOException
Writes a DOM tree to a stream in UTF8 encoding. Note that
it prepends the <?xml version='1.0' encoding='UTF-8'?> if
the xmlDeclaration field is true.
The indent number is set to 0 and a 2-space indent.
root
- the root element of the DOM tree.out
- the outputstream to write to.
write
public void write(Element element,
Writer out,
int indent,
String indentWith)
throws IOException
Writes a DOM tree to a stream.
element
- the Root DOM element of the treeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.
writeXMLDeclaration
public void writeXMLDeclaration(Writer wri)
throws IOException
Writes the XML declaration if xmlDeclaration is true.
wri
- the writer to write to.