Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.util.xml
Class DOMElementWriter

java.lang.Object
  extended by net.java.sip.communicator.util.xml.DOMElementWriter

public class DOMElementWriter
extends Object

Writes a DOM tree to a given Writer.

Utility class used by XMLUtils and net.java.sip.communicator.slick.runner.SipCommunicatorSlickRunner.

Author:
Lubomir Marinov

Field Summary
protected  String[] knownEntities
          Don't try to be too smart but at least recognize the predefined entities.
 
Constructor Summary
DOMElementWriter()
           
 
Method Summary
static String decodeName(String name)
          Decodes an XML (element) name according to http://www.w3.org/TR/xml/#NT-Name.
 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.
static String encodeName(String value)
          Encodes a specific String so that it is a valid XML (element) name according to http://www.w3.org/TR/xml/#NT-Name.
 boolean isLegalCharacter(char c)
          Is the given character allowed inside an XML document?
 boolean isReference(String ent)
          Is the given argument a character or entity reference?
 void write(Element root, OutputStream out)
          Writes a DOM tree to a stream in UTF8 encoding.
 void write(Node element, Writer out, int indent, 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 String[] knownEntities
Don't try to be too smart but at least recognize the predefined entities.

Constructor Detail

DOMElementWriter

public DOMElementWriter()
Method Detail

decodeName

public static String decodeName(String name)
Decodes an XML (element) name according to http://www.w3.org/TR/xml/#NT-Name.

Parameters:
name - the XML (element) name to be decoded
Returns:
a String which represents name decoded according to http://www.w3.org/TR/xml/#NT-Name

encodeName

public static String encodeName(String value)
Encodes a specific String so that it is a valid XML (element) name according to http://www.w3.org/TR/xml/#NT-Name.

Parameters:
value - the String to be encoded so that it is a valid XML name
Returns:
a String which represents value encoded so that it is a valid XML (element) name

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'?>. 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(Node element,
                  Writer out,
                  int indent,
                  String indentWith)
           throws 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:
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.

Parameters:
value - the value to encode
Returns:
a String containing the encoded element.

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.

Parameters:
value - the value to encode
Returns:
a String containing the encoded value.

isReference

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

Parameters:
ent - the string whose nature we need to determine.
Returns:
true if ent is an entity reference and false otherwise.

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.

Parameters:
c - the character whose nature we'd like to determine.
Returns:
true if c is a legal character and false otherwise
Since:
1.10, Ant 1.5

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.