Package org.jitsi.util.xml
Class DOMElementWriter
- java.lang.Object
-
- org.jitsi.util.xml.DOMElementWriter
-
-
Field Summary
Fields Modifier and Type Field Description protected String[]knownEntitiesDon't try to be too smart but at least recognize the predefined entities.
-
Constructor Summary
Constructors Constructor Description DOMElementWriter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringdecodeName(String name)Decodes an XML (element) name according to http://www.w3.org/TR/xml/#NT-Name.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.static StringencodeName(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.booleanisLegalCharacter(char c)Is the given character allowed inside an XML document?booleanisReference(String ent)Is the given argument a character or entity reference?voidwrite(Element root, OutputStream out)Writes a DOM tree to a stream in UTF8 encoding.voidwrite(Node 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
-
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 treeout- where to send the outputindent- number ofindentWith- 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 ]]>.
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
-
-