com.funambol.util
Class XmlUtil

java.lang.Object
  extended by com.funambol.util.XmlUtil

public class XmlUtil
extends java.lang.Object

Utility class that XML manipulation functions.


Method Summary
static void addElement(java.lang.StringBuffer out, java.lang.String tag)
          Add an empty tag to the StringBuffer out.
static void addElement(java.lang.StringBuffer out, java.lang.String tag, java.lang.String content)
          Add a tag to the StringBuffer out.
static void addElementNewLine(java.lang.StringBuffer out, java.lang.String tag, java.lang.String content, boolean escape)
          This function builds a simple Tag with newline char after the close tag.
static void addElementNewLineWithTagAttr(java.lang.StringBuffer out, java.lang.String tag, java.lang.String content, boolean escape, java.lang.String[] attr)
          This function builds a simple Tag with newline char after the close tag.
static void addElementWithTagAttr(java.lang.StringBuffer out, java.lang.String tag, java.lang.String content, java.lang.String[] attr)
          Add a tag with attributes to the StringBuffer out.
static java.lang.String createCloseTag(java.lang.String tagname)
           
static java.lang.String createCloseTagNewLine(java.lang.String tagname)
           
static java.lang.String createOpenTag(java.lang.String tagname)
           
static java.lang.String createOpenTagNewLine(java.lang.String tagname)
           
static java.lang.String escapeXml(java.lang.String str)
          Escapes the characters in a String using XML entities.
static int getTag(ChunkedString xml, java.lang.String tag)
          Return the index of tag, validating also the presence of the end tag.
static java.util.Hashtable getTagAttributes(ChunkedString xml, java.lang.String tag)
           
static ChunkedString getTagValue(ChunkedString xml, java.lang.String tag)
          Make a String by value of tag.
static java.util.Vector getTagValues(ChunkedString xmlInput, java.lang.String tag)
          Return a Vector of String with tags matching the search tag.
static java.util.Vector getTagValues(java.util.Vector xmlInput, java.lang.String tag)
          Return a Vector of String with tags matching the search tag.
static java.lang.String unescapeXml(java.lang.String str)
          Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

escapeXml

public static java.lang.String escapeXml(java.lang.String str)

Escapes the characters in a String using XML entities.

Supports only the four basic XML entities (gt, lt, quot, amp). Does not support DTDs or external entities.

Parameters:
str - the String to escape, may be null
Returns:
a new escaped String, null if null string input

unescapeXml

public static java.lang.String unescapeXml(java.lang.String str)

Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the four basic XML entities (gt, lt, quot, amp). Does not support DTDs or external entities.

Parameters:
str - the String to unescape, may be null
Returns:
a new unescaped String, null if null string input

getTag

public static int getTag(ChunkedString xml,
                         java.lang.String tag)
Return the index of tag, validating also the presence of the end tag.

Parameters:
xml - xml msg
tag - tag to find
Returns:
tag index or -1 if the tag is not found.

getTagAttributes

public static java.util.Hashtable getTagAttributes(ChunkedString xml,
                                                   java.lang.String tag)

getTagValue

public static ChunkedString getTagValue(ChunkedString xml,
                                        java.lang.String tag)
                                 throws XmlException
Make a String by value of tag.

Parameters:
xml - xml msg
tag - tag to find + sourceType +
Returns:
tag value
Throws:
XmlException

getTagValues

public static java.util.Vector getTagValues(java.util.Vector xmlInput,
                                            java.lang.String tag)
                                     throws XmlException
Return a Vector of String with tags matching the search tag.

Parameters:
xmlInput - Vector of XML tags to search in
tag - to find
Returns:
found tags (empty if no one found)
Throws:
XmlException

getTagValues

public static java.util.Vector getTagValues(ChunkedString xmlInput,
                                            java.lang.String tag)
                                     throws XmlException
Return a Vector of String with tags matching the search tag.

Parameters:
xmlInput - XML document to search in
tag - to find
Returns:
find tags
Throws:
XmlException

addElement

public static void addElement(java.lang.StringBuffer out,
                              java.lang.String tag)
Add an empty tag to the StringBuffer out.

Parameters:
out - the buffer to append to
tag - tag to be appended

addElement

public static void addElement(java.lang.StringBuffer out,
                              java.lang.String tag,
                              java.lang.String content)
Add a tag to the StringBuffer out.

Parameters:
out - the buffer to append to
tag - tag to be appended

addElementNewLine

public static void addElementNewLine(java.lang.StringBuffer out,
                                     java.lang.String tag,
                                     java.lang.String content,
                                     boolean escape)
This function builds a simple Tag with newline char after the close tag.

Parameters:
out - StringBuffer to store output
tag - The Tag will be generated
content - The content data of the Tag
escape - Flag to tell if data need to be escaped

addElementWithTagAttr

public static void addElementWithTagAttr(java.lang.StringBuffer out,
                                         java.lang.String tag,
                                         java.lang.String content,
                                         java.lang.String[] attr)
Add a tag with attributes to the StringBuffer out.

Parameters:
out - the buffer to append to
tag - tag to be appended
content - The content data of the Tag
attr - The attributes array

addElementNewLineWithTagAttr

public static void addElementNewLineWithTagAttr(java.lang.StringBuffer out,
                                                java.lang.String tag,
                                                java.lang.String content,
                                                boolean escape,
                                                java.lang.String[] attr)
This function builds a simple Tag with newline char after the close tag.

Parameters:
out - StringBuffer to store output
tag - The Tag will be generated
content - The content data of the Tag
escape - Flag to tell if data need to be escaped
attr - The attributes array

createOpenTag

public static java.lang.String createOpenTag(java.lang.String tagname)

createOpenTagNewLine

public static java.lang.String createOpenTagNewLine(java.lang.String tagname)

createCloseTag

public static java.lang.String createCloseTag(java.lang.String tagname)

createCloseTagNewLine

public static java.lang.String createCloseTagNewLine(java.lang.String tagname)


Copyright © 2001-2009 Funambol.