public class DOMElementWriter
extends java.lang.Object
Utility class used by XMLUtils
and
net.java.sip.communicator.slick.runner.SipCommunicatorSlickRunner
.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
knownEntities
Don't try to be too smart but at least recognize the predefined
entities.
|
Constructor and Description |
---|
DOMElementWriter() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decodeName(java.lang.String name)
Decodes an XML (element) name according to
http://www.w3.org/TR/xml/#NT-Name.
|
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.
|
static java.lang.String |
encodeName(java.lang.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(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.Node element,
java.io.Writer out,
int indent,
java.lang.String indentWith)
Writes a DOM tree to a stream.
|
protected java.lang.String[] knownEntities
public static java.lang.String decodeName(java.lang.String name)
name
- the XML (element) name to be decodedpublic static java.lang.String encodeName(java.lang.String value)
value
- the String to be encoded so that it is a valid XML
namepublic void write(org.w3c.dom.Element root, java.io.OutputStream out) throws java.io.IOException
root
- the root element of the DOM tree.out
- the outputstream to write to.java.io.IOException
- if an error happens while writing to the stream.public void write(org.w3c.dom.Node element, java.io.Writer out, int indent, java.lang.String indentWith) throws java.io.IOException
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.java.io.IOException
- if an error happens while writing to the stream.public java.lang.String encode(java.lang.String value)
value
- the value to encodepublic java.lang.String encodedata(java.lang.String value)
Also ensure that we are not including an ]]> marker by replacing that sequence with ]]>.
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.
value
- the value to encodepublic boolean isReference(java.lang.String ent)
ent
- the string whose nature we need to determine.public boolean isLegalCharacter(char c)
See XML 1.0 2.2 http://www.w3.org/TR/1998/REC-xml-19980210#charsets.
c
- the character whose nature we'd like to determine.
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.