org.apache.tools.ant.util

Class DOMElementWriter

public class DOMElementWriter extends Object

Writes a DOM tree to a given Writer.

Utility class used by {@link org.apache.tools.ant.XmlLogger XmlLogger} and org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter XMLJUnitResultFormatter}.

Field Summary
protected String[]knownEntities
Don't try to be too smart but at least recognize the predefined entities.
Method Summary
voidcloseElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren)
Writes a DOM tree to a stream.
Stringencode(String value)
Escape <, > & ', " as their entities and drop characters that are illegal in XML documents.
Stringencodedata(String value)
Drop characters that are illegal in XML documents.
booleanisLegalCharacter(char c)
Is the given character allowed inside an XML document?
booleanisReference(String ent)
Is the given argument a character or entity reference?
voidopenElement(Element element, Writer out, int indent, String indentWith)
Writes the opening tag - including all attributes - correspondong to a DOM element.
voidwrite(Element root, OutputStream out)
Writes a DOM tree to a stream in UTF8 encoding.
voidwrite(Element element, Writer out, int indent, String indentWith)
Writes a DOM tree to a stream.

Field Detail

knownEntities

protected String[] knownEntities
Don't try to be too smart but at least recognize the predefined entities.

Method Detail

closeElement

public void closeElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren)
Writes a DOM tree to a stream.

Parameters: element the Root DOM element of the tree out where to send the output indent number of indentWith string that should be used to indent the corresponding tag.

Throws: IOException if an error happens while writing to the stream.

encode

public String encode(String value)
Escape <, > & ', " as their entities and drop characters that are illegal in XML documents.

encodedata

public String encodedata(String value)
Drop characters that are illegal in XML documents.

Also ensure that we are not including an ]]> marker by replacing that sequence with &#x5d;&#x5d;&gt;.

See XML 1.0 2.2 http://www.w3.org/TR/1998/REC-xml-19980210#charsets and 2.7 http://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect.

isLegalCharacter

public 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.

Since: 1.10, Ant 1.5

isReference

public boolean isReference(String ent)
Is the given argument a character or entity reference?

openElement

public void openElement(Element element, Writer out, int indent, String indentWith)
Writes the opening tag - including all attributes - correspondong to a DOM element.

Parameters: element the DOM element to write out where to send the output indent number of indentWith string that should be used to indent the corresponding tag.

Throws: IOException if an error happens while writing to the stream.

write

public void write(Element root, OutputStream out)
Writes a DOM tree to a stream in UTF8 encoding. Note that it prepends the <?xml version='1.0' encoding='UTF-8'?>. The indent number is set to 0 and a 2-space indent.

Parameters: root the root element of the DOM tree. out the outputstream to write to.

Throws: IOException if an error happens while writing to the stream.

write

public void write(Element element, Writer out, int indent, String indentWith)
Writes a DOM tree to a stream.

Parameters: element the Root DOM element of the tree out where to send the output indent number of indentWith string that should be used to indent the corresponding tag.

Throws: IOException if an error happens while writing to the stream.

Copyright B) 2000-2007 Apache Software Foundation. All Rights Reserved.