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.

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


Field Summary
protected  java.lang.String[] knownEntities
          Don't try to be too smart but at least recognize the predefined entities.
 
Constructor Summary
DOMElementWriter()
           
 
Method Summary
 java.lang.String encode(java.lang.String value)
          Escape <, > & ', " as their entities and drop characters that are illegal in XML documents.
 java.lang.String encodedata(java.lang.String value)
          Drop characters that are illegal in XML documents.
 boolean isLegalCharacter(char c)
          Is the given character allowed inside an XML document?
 boolean isReference(java.lang.String ent)
          Is the given argument a character or entity reference?
 void write(org.w3c.dom.Element root, java.io.OutputStream out)
          Writes a DOM tree to a stream in UTF8 encoding.
 void write(org.w3c.dom.Element element, java.io.Writer out, int indent, java.lang.String indentWith)
          Writes a DOM tree to a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

knownEntities

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

Constructor Detail

DOMElementWriter

public DOMElementWriter()
Method Detail

write

public void write(org.w3c.dom.Element root,
                  java.io.OutputStream out)
           throws java.io.IOException
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:
java.io.IOException - if an error happens while writing to the stream.

write

public void write(org.w3c.dom.Element element,
                  java.io.Writer out,
                  int indent,
                  java.lang.String indentWith)
           throws java.io.IOException
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:
java.io.IOException - if an error happens while writing to the stream.

encode

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


encodedata

public java.lang.String encodedata(java.lang.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.


isReference

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


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


Copyright © 2000-2004 Apache Software Foundation. All Rights Reserved.