com.waveset.util
Class XmlUtil

java.lang.Object
  extended bycom.waveset.util.XmlUtil

public class XmlUtil
extends java.lang.Object

XML parsing and DOM manipulation utilities.


Field Summary
protected static XmlUtil _singleton
          A handle to a singleton object for the getDefault method.
static java.lang.String code_id
           
static java.lang.String DEFAULT_XML_ENCODING
          The default encoding for XML is "UTF-8".
static char DOUBLE_QUOTE
          *******************************************************************
static char SINGLE_QUOTE
           
static java.lang.String XML_HEADER_FIRST_LINE
           
static java.lang.String XML_HEADER_VERSION
           
 
Constructor Summary
XmlUtil()
          Construct a private utility object.
 
Method Summary
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, boolean value)
          Adds a boolean attribute to the buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, java.util.Date value)
          Adds a date attribute to the buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, double value)
          Adds a double attribute to the buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, float value)
          Adds a float attribute to the buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, int value)
          Adds an integer attribute to the buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, long value)
          Adds a long attribute to the buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, java.lang.Object obj)
          Add an an attribute value using an arbitrary object, by calling its toString method.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, java.lang.String value)
          Adds an attribute name and value to a string buffer.
static void addAttribute(java.lang.StringBuffer b, java.lang.String name, java.lang.String value, boolean tolerateNullValue, char preferredDelimiter)
          Adds an attribute name and value to a string buffer.
static void addCdata(java.lang.StringBuffer b, int indent, java.lang.String s, boolean kludgeDoctype)
          Build a CDATA marked section, escaping as necessary.
static void addCdataContent(java.lang.StringBuffer b, java.lang.String s)
           
static void addCdataContent(java.lang.StringBuffer b, java.lang.String s, boolean kludgeDoctype)
          Add a string of CDATA content kludging around the DOCTYPE token.
static void addContent(java.lang.StringBuffer b, java.lang.Object o)
          Replaces special characters in a string with XML character entities.
static void addElement(java.lang.StringBuffer b, int indent, java.lang.String element, java.lang.String content)
          Adds an element with content to the buffer, being careful to escape content.
static void addEndTag(java.lang.StringBuffer b, int indent, java.lang.String element)
          Adds an element end tag with optional indentation.
static void addIndent(java.lang.StringBuffer b, int indent)
          Internal method to add indentation to string buffers.
static void addObject(java.lang.StringBuffer b, int indent, java.lang.String wrapper, XmlObject obj)
          Adds an object to the buffer, wrapped in some other elemenet.
static void addOpenStartTag(java.lang.StringBuffer b, int indent, java.lang.String element)
          Adds an open element start tag with optional indentation.
static void addStartTag(java.lang.StringBuffer b, int indent, java.lang.String element, boolean newline)
          Adds a closed element start tag with optional indentation.
static void addXmlHeader(java.lang.StringBuffer sb, java.lang.String doctypeName)
          Add the default header, need to be able to customize this better.
static void addXmlHeader(java.lang.StringBuffer sb, java.lang.String doctypeName, java.lang.String encoding)
          Add the default header, need to be able to customize this better.
static boolean areSetEquivalent(org.w3c.dom.Node n1, org.w3c.dom.Node n2)
          Tests the two given nodes for set equivalency (meaning having equal content, but not necessarily in the same order).
static boolean attributesMatch(org.w3c.dom.Node n1, org.w3c.dom.Node n2)
          For attributes only, tests the two given nodes for set equivalency (meaning having equal content, but not necessarily in the same order).
static void closeStartTag(java.lang.StringBuffer b)
          Completes an open element start tag.
static void closeStartTagAndEndElement(java.lang.StringBuffer b)
          Completes an open element start tag and the element in one move.
static java.lang.String encodeAsHTML(java.lang.String s)
          Make an XML string displayable for HTML.
static java.lang.String encodeComment(java.lang.String s)
          Takes what is expected to be an arbitrary blob of XML and processes it so that it can be embedded within an HTML comment.
static java.lang.String escape(java.lang.String s)
          Replaces special characters in a string with XML character entities.
static void escape(java.lang.StringBuffer b, java.lang.String s, char delim)
          Encode a string, assumed to be in a quoted attribute value.
static java.lang.String escape(java.lang.String s, char delim)
           
static java.lang.String escapeMessage(java.lang.String s)
          Replace special characters in a string with XML character entities, preserving HTML formatting tags we think are "safe".
static org.w3c.dom.Element findElement(org.w3c.dom.Node node, java.lang.String name)
          Search for an element with a given tag name, on or below the given node.
static org.w3c.dom.Element findElement(org.w3c.dom.Node node, java.lang.String elname, java.lang.String attname, java.lang.String attval)
          Search for an element on or below a given node, that has a given tag name and an attribute with a given value.
static java.lang.Object findObject(org.w3c.dom.Node node, boolean ignoreEmpty)
          Recurses til an text or localizable object is found.
static org.w3c.dom.Text findText(org.w3c.dom.Node node, boolean ignoreEmpty)
          Locate the first text node at any level below the given node.
static java.lang.String getAttribute(org.w3c.dom.Element e, java.lang.String name)
          Return the value of an attribute on an element.
static boolean getBooleanAttribute(org.w3c.dom.Element e, java.lang.String name)
          Gets a boolean attribute.
static boolean getBooleanAttribute(org.w3c.dom.Element e, java.lang.String name, boolean dflt)
          Gets a boolean attribute with a specified default.
static boolean getBooleanValue(java.lang.String value)
          Interprets a string value as a boolean.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Node node)
          Find the first child element of a node.
static java.lang.String getContent(org.w3c.dom.Element e)
          Return the content of the given element.
static java.lang.String getContent(org.w3c.dom.Node e, java.lang.String name)
          Return the content of an element with the given tag on or below the given node.
static java.lang.Object getContentObject(org.w3c.dom.Element e)
          Return the content of the given element as an object, if it can be resolved as a recognized object.
static java.util.Date getDateAttribute(org.w3c.dom.Element e, java.lang.String name)
          Gets a date attribute.
static XmlUtil getDefault()
          Get the public singleton utility object.
static char getDelimiter(java.lang.String value)
           
static char getDelimiter(java.lang.String value, char preferredDelim)
           
static double getDoubleAttribute(org.w3c.dom.Element e, java.lang.String name)
          Gets a double attribute.
static double getDoubleAttribute(org.w3c.dom.Element e, java.lang.String name, double deflt)
          Gets an double attribute, returning the specified default value if the attribute does not exist.
static float getFloatAttribute(org.w3c.dom.Element e, java.lang.String name)
          Gets a float attribute.
static float getFloatAttribute(org.w3c.dom.Element e, java.lang.String name, float dflt)
          Gets a float attribute, returning a given default value if the attribute does not exist.
static int getIntAttribute(org.w3c.dom.Element e, java.lang.String name)
          Gets an integer attribute.
static int getIntAttribute(org.w3c.dom.Element e, java.lang.String name, int dflt)
          Gets an integer attribute, returning a given default value if the attribute does not exist.
static long getLongAttribute(org.w3c.dom.Element e, java.lang.String name)
          Gets a long attribute.
static long getLongAttribute(org.w3c.dom.Element e, java.lang.String name, long deflt)
          Gets an integer attribute, returning the specified default value if the attribute does not exist.
static org.w3c.dom.Element getNextElement(org.w3c.dom.Node node)
          Get the next right sibling that is an element.
static java.lang.String getSpecifiedEncoding(java.lang.String xml)
          Scans the specified string for an XML header line.
static boolean isSafeAttributeValue(java.lang.String s)
          Returns true if this string can be stored inside an XML attribute value without corruption.
static void main(java.lang.String[] args)
          Parses an XML file, and displays any error or warning messages.
 org.w3c.dom.Document parse(java.lang.String uri)
          Parses the specified URI and returns the document.
 org.w3c.dom.Document parseString(java.lang.String xml)
          Parses a string without validation and returns the Document.
 org.w3c.dom.Document parseString(java.lang.String xml, boolean validation)
          Parses a string with or without validation and returns the Document.
static void println(java.lang.String msg)
           
static void saxParse(java.io.InputStream input, org.xml.sax.ContentHandler handler)
          Parses a stream using a SAX parser.
static void saxParse(java.io.Reader input, org.xml.sax.ContentHandler handler)
          Parses a reader using a SAX parser.
static void saxParse(java.lang.String uri, org.xml.sax.ContentHandler handler)
          Parses the specified URI using a SAX parser.
static void saxParseString(java.lang.String xml, org.xml.sax.ContentHandler handler)
          Parses the specified using a SAX parser.
static void saxParseString(java.lang.String xml, org.xml.sax.ContentHandler handler, org.xml.sax.ErrorHandler errorHandler)
          Parses the specified using a SAX parser.
static java.lang.String serialize(org.w3c.dom.Node node)
          Serialize a node back to an XML string.
static void serialize(java.lang.StringBuffer b, org.w3c.dom.Node node)
          Our own homebrew serializer.
static void setContent(org.w3c.dom.Element e, java.lang.String content)
          Changes an element's content, either to null or to a string of text.
static java.util.Map unpack(java.lang.String summary)
          Given a string buffer containing an object summary, unpack it into an Map object.
static boolean validXmlChar(char ch)
          legal xml chars from http://www.xml.com/axml/testaxml.htm Char::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

DOUBLE_QUOTE

public static final char DOUBLE_QUOTE
*******************************************************************

See Also:
Constant Field Values

SINGLE_QUOTE

public static final char SINGLE_QUOTE
See Also:
Constant Field Values

_singleton

protected static XmlUtil _singleton
A handle to a singleton object for the getDefault method. Now that we use a parser pool, this doesn't realy have to be a singleton.


DEFAULT_XML_ENCODING

public static java.lang.String DEFAULT_XML_ENCODING
The default encoding for XML is "UTF-8".


XML_HEADER_VERSION

public static final java.lang.String XML_HEADER_VERSION
See Also:
Constant Field Values

XML_HEADER_FIRST_LINE

public static final java.lang.String XML_HEADER_FIRST_LINE
See Also:
Constant Field Values
Constructor Detail

XmlUtil

public XmlUtil()
Construct a private utility object.

Method Detail

getDefault

public static XmlUtil getDefault()
Get the public singleton utility object.


getSpecifiedEncoding

public static java.lang.String getSpecifiedEncoding(java.lang.String xml)
Scans the specified string for an XML header line.


addXmlHeader

public static void addXmlHeader(java.lang.StringBuffer sb,
                                java.lang.String doctypeName)
Add the default header, need to be able to customize this better.


addXmlHeader

public static void addXmlHeader(java.lang.StringBuffer sb,
                                java.lang.String doctypeName,
                                java.lang.String encoding)
Add the default header, need to be able to customize this better.


parse

public org.w3c.dom.Document parse(java.lang.String uri)
                           throws WavesetException
Parses the specified URI and returns the document.

This was originally synchronized, now that we're using a parser pool.

Throws:
WavesetException

saxParse

public static void saxParse(java.lang.String uri,
                            org.xml.sax.ContentHandler handler)
                     throws WavesetException
Parses the specified URI using a SAX parser.

SAX handling internally is a bit kludgey since it was added later. XmlParser will do both DOM and SAX parsing, though we could probably refactor these.

Throws:
WavesetException

saxParse

public static void saxParse(java.io.InputStream input,
                            org.xml.sax.ContentHandler handler)
                     throws WavesetException
Parses a stream using a SAX parser.

Throws:
WavesetException

saxParse

public static void saxParse(java.io.Reader input,
                            org.xml.sax.ContentHandler handler)
                     throws WavesetException
Parses a reader using a SAX parser.

Throws:
WavesetException

saxParseString

public static void saxParseString(java.lang.String xml,
                                  org.xml.sax.ContentHandler handler)
                           throws WavesetException
Parses the specified using a SAX parser.

Throws:
WavesetException

saxParseString

public static void saxParseString(java.lang.String xml,
                                  org.xml.sax.ContentHandler handler,
                                  org.xml.sax.ErrorHandler errorHandler)
                           throws WavesetException
Parses the specified using a SAX parser.

Throws:
WavesetException

parseString

public org.w3c.dom.Document parseString(java.lang.String xml,
                                        boolean validation)
                                 throws WavesetException
Parses a string with or without validation and returns the Document.

Throws:
WavesetException

parseString

public org.w3c.dom.Document parseString(java.lang.String xml)
                                 throws WavesetException
Parses a string without validation and returns the Document.

Throws:
WavesetException

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element e,
                                            java.lang.String name)
Return the value of an attribute on an element.

The DOM getAttribute method returns an empty string if the attribute doesn't exist. Here, we detect this and return null.


getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Node node)
Find the first child element of a node.


getNextElement

public static org.w3c.dom.Element getNextElement(org.w3c.dom.Node node)
Get the next right sibling that is an element.


findElement

public static org.w3c.dom.Element findElement(org.w3c.dom.Node node,
                                              java.lang.String name)
Search for an element with a given tag name, on or below the given node.


findElement

public static org.w3c.dom.Element findElement(org.w3c.dom.Node node,
                                              java.lang.String elname,
                                              java.lang.String attname,
                                              java.lang.String attval)
Search for an element on or below a given node, that has a given tag name and an attribute with a given value.


findText

public static org.w3c.dom.Text findText(org.w3c.dom.Node node,
                                        boolean ignoreEmpty)
Locate the first text node at any level below the given node. If the ignoreEmpty flag is true, we will ignore text nodes that contain only whitespace characteres.

Note that if you're trying to extract element content, you probably don't want this since parser's can break up pcdata into multiple adjacent text nodes. See getContent() for a more useful method.


findObject

public static java.lang.Object findObject(org.w3c.dom.Node node,
                                          boolean ignoreEmpty)
Recurses til an text or localizable object is found.


getContentObject

public static java.lang.Object getContentObject(org.w3c.dom.Element e)
Return the content of the given element as an object, if it can be resolved as a recognized object.


getContent

public static java.lang.String getContent(org.w3c.dom.Node e,
                                          java.lang.String name)
Return the content of an element with the given tag on or below the given node. We will descend an arbitrary depth looking for the first non-empty text node.


getContent

public static java.lang.String getContent(org.w3c.dom.Element e)
Return the content of the given element.

We will descend to an arbitrary depth looking for the first non-empty text node.

Note that the parser may break what was originally a single string of pcdata into multiple adjacent text nodes. Xerces appears to do this when it encounters a '$' in the text, not sure if there is specified behavior, or if its parser specific.

Here, we will congeal adjacent text nodes.

We will NOT ignore text nodes that have only whitespace.


setContent

public static void setContent(org.w3c.dom.Element e,
                              java.lang.String content)
Changes an element's content, either to null or to a string of text.


serialize

public static java.lang.String serialize(org.w3c.dom.Node node)
                                  throws WavesetException
Serialize a node back to an XML string.

Throws:
WavesetException

serialize

public static void serialize(java.lang.StringBuffer b,
                             org.w3c.dom.Node node)
Our own homebrew serializer. Emits to a string buffer. Only handles text, element, but easy to extend.


println

public static void println(java.lang.String msg)

escape

public static java.lang.String escape(java.lang.String s)
Replaces special characters in a string with XML character entities.

The characters replaced are '&' and '<'. This should be when building strings intended to be the values of XML attributes or XML element content.


escape

public static java.lang.String escape(java.lang.String s,
                                      char delim)

escapeMessage

public static java.lang.String escapeMessage(java.lang.String s)
Replace special characters in a string with XML character entities, preserving HTML formatting tags we think are "safe".

In order to address Cross-Site-Scripting vulnerabilities (bug#5374), we typically escape values that could have been specified by an attacker as a parameter to the HTTP request. However, this includes common parameters such as "error" and "message" that by convention contain messages from other pages. Escaping these messages neutralizes the HTML formatting commonly included in messages.


encodeAsHTML

public static java.lang.String encodeAsHTML(java.lang.String s)
Make an XML string displayable for HTML. Basically just escapes it and translates newlines into
, spaces and tabs into  


encodeComment

public static java.lang.String encodeComment(java.lang.String s)
Takes what is expected to be an arbitrary blob of XML and processes it so that it can be embedded within an HTML comment. < and & are ok, what we have to be careful of is --> which will be seen as a premature end of comment. Technically an XML comment isn't supposed to contain -- unless its part of the --> token, I'm no sure HTML has the same restriction. All we do is convert -- to == if we see it.

In practice, this happens only when a serialized WavesetResult contains errors. The serialization of a nested WavesetException uses "-->" to prefix the text of a nested exception.


isSafeAttributeValue

public static boolean isSafeAttributeValue(java.lang.String s)
Returns true if this string can be stored inside an XML attribute value without corruption. XML parsers must normalize an attribute value such that whitespace characters #x20, #xD, #xA, and #x9 are all converted to #x20, and the common newline sequence #xD#xA is converted to a single #x20.

The declaration of this attribute is assumed to be CDATA, which will preserve leading and trailing whitespace so we don't check for that here.

You should call this whenever you need to store a string value for which preservation of newlines and tabs is important. If this returns false, then you need to use an element, such as .

Update: After doing this, its really just as easy to escape these in the addAttribute() method and that avoids another pass over the string.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                java.lang.String value)
Adds an attribute name and value to a string buffer.

Performs any necessary escaping on the value. This should be used when you're building the XML for something, and its possible for an attribute value to have any of the characters &, ', or ".

For XML, we prefer the single-quote character as the value delimiter. In XML, it is illegal for an attribute to have no value.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                java.lang.String value,
                                boolean tolerateNullValue,
                                char preferredDelimiter)
Adds an attribute name and value to a string buffer.

Performs any necessary escaping on the value. This should be used when you're building the XML for something, and its possible for an attribute value to have any of the characters &, ', or "


getDelimiter

public static char getDelimiter(java.lang.String value)
Returns:
the best delimiter with which to surround a value.

For XML, we prefer the single-quote character. However, if the specified value contains more single-quotes than double-quotes, this returns the double-quote character.


getDelimiter

public static char getDelimiter(java.lang.String value,
                                char preferredDelim)
Parameters:
preferredDelim - - The delimiter we hope to get back.

All things being equal, this returns the suggested character-- e.g., single-quote--as delimiter. However, if the input value contains more single-quote than double-quote characters, this method returns the double-quote character.

Returns:
the best delimiter with which to surround a value.

escape

public static void escape(java.lang.StringBuffer b,
                          java.lang.String s,
                          char delim)
Encode a string, assumed to be in a quoted attribute value. Assumes single quotes surround the value. Double quote has a character entity " but for single quotes you have to use '

UPDATE: Added escaping of newlines and tabs, since these are desired if we're dealing with a multiline text area such as free form comments. You can also call isSafeAttributeValue above and use a element instead, but there is a lot of code that doesn't do that.

Since this method is at the inner loop of a lot of the XML serialization, it was optimized to not do as many StringBuffer#append operations. The original method is preserved as the package-access escapeOrig. The XmlUtilTest method ensures that the new method behaves identically to escapeOrig (except it's faster).


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                java.lang.Object obj)
Add an an attribute value using an arbitrary object, by calling its toString method.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                boolean value)
Adds a boolean attribute to the buffer.

If the value is false, the attribute is suppressed.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                long value)
Adds a long attribute to the buffer.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                int value)
Adds an integer attribute to the buffer.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                double value)
Adds a double attribute to the buffer.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                float value)
Adds a float attribute to the buffer.


addAttribute

public static void addAttribute(java.lang.StringBuffer b,
                                java.lang.String name,
                                java.util.Date value)
Adds a date attribute to the buffer.

If the value is false, the attribute is suppressed.


getBooleanAttribute

public static boolean getBooleanAttribute(org.w3c.dom.Element e,
                                          java.lang.String name)
Gets a boolean attribute. Absence of the attribute is considered false.

The value must be equal to the string "true" to be considered true. KLUDGE: accept "1" as true for backward compatibility with some older objects.


getBooleanAttribute

public static boolean getBooleanAttribute(org.w3c.dom.Element e,
                                          java.lang.String name,
                                          boolean dflt)
Gets a boolean attribute with a specified default.

The value must be equal to the string "true" to be considered true. KLUDGE: accept "1" as true for backward compatibility with some older objects.


getBooleanValue

public static boolean getBooleanValue(java.lang.String value)
Interprets a string value as a boolean.

The value must be equal to the string "true" to be considered true. Accept "1" as true for backward compatibility with some older objects.


getIntAttribute

public static int getIntAttribute(org.w3c.dom.Element e,
                                  java.lang.String name)
Gets an integer attribute. Absence of the attribute is considered zero.


getIntAttribute

public static int getIntAttribute(org.w3c.dom.Element e,
                                  java.lang.String name,
                                  int dflt)
Gets an integer attribute, returning a given default value if the attribute does not exist.


getLongAttribute

public static long getLongAttribute(org.w3c.dom.Element e,
                                    java.lang.String name)
Gets a long attribute. Absence of the attribute is considered zero.


getLongAttribute

public static long getLongAttribute(org.w3c.dom.Element e,
                                    java.lang.String name,
                                    long deflt)
Gets an integer attribute, returning the specified default value if the attribute does not exist.


getFloatAttribute

public static float getFloatAttribute(org.w3c.dom.Element e,
                                      java.lang.String name)
Gets a float attribute. Absence of the attribute is considered zero.


getFloatAttribute

public static float getFloatAttribute(org.w3c.dom.Element e,
                                      java.lang.String name,
                                      float dflt)
Gets a float attribute, returning a given default value if the attribute does not exist.


getDoubleAttribute

public static double getDoubleAttribute(org.w3c.dom.Element e,
                                        java.lang.String name)
Gets a double attribute. Absence of the attribute is considered zero.


getDoubleAttribute

public static double getDoubleAttribute(org.w3c.dom.Element e,
                                        java.lang.String name,
                                        double deflt)
Gets an double attribute, returning the specified default value if the attribute does not exist.


getDateAttribute

public static java.util.Date getDateAttribute(org.w3c.dom.Element e,
                                              java.lang.String name)
                                       throws WavesetException
Gets a date attribute. Absence of the attribute is considered null.

Throws:
WavesetException

validXmlChar

public static boolean validXmlChar(char ch)
legal xml chars from http://www.xml.com/axml/testaxml.htm Char::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]


addContent

public static void addContent(java.lang.StringBuffer b,
                              java.lang.Object o)
Replaces special characters in a string with XML character entities. The characters replaced are '&' and '<'. This should be when building strings intended to be the values of XML attributes or XML element content.


addCdata

public static void addCdata(java.lang.StringBuffer b,
                            int indent,
                            java.lang.String s,
                            boolean kludgeDoctype)
Build a CDATA marked section, escaping as necessary. Xerces seems to really dislike finding the string DOCTYPE inside a CDATA section. The following example fails to parse: I think this is a bug, a kludge workaround is to convert it into a pseudo entity reference, but the receiver will need to to undo the transformation.


addCdataContent

public static void addCdataContent(java.lang.StringBuffer b,
                                   java.lang.String s,
                                   boolean kludgeDoctype)
Add a string of CDATA content kludging around the DOCTYPE token. Obviously could be more efficient here.


addCdataContent

public static void addCdataContent(java.lang.StringBuffer b,
                                   java.lang.String s)

addIndent

public static void addIndent(java.lang.StringBuffer b,
                             int indent)
Internal method to add indentation to string buffers. Might want to be able to globally disable this, or think of ways to make it more efficient.


addOpenStartTag

public static void addOpenStartTag(java.lang.StringBuffer b,
                                   int indent,
                                   java.lang.String element)
Adds an open element start tag with optional indentation. Typically used when you have element name constants, since if you're hard coding the names, you can just use a longer string literal.


closeStartTag

public static void closeStartTag(java.lang.StringBuffer b)
Completes an open element start tag. addOpenStartTag(b, indent, Whatever.ELEMENT); XmlUtil.addAttribute(b,"attr1", _attr1); XmlUtil.addAttribute(b,"attr2", _attr2); if ( childElements==null || childElements.size()==0 ) { XmlUtil.closeStartTagAndEndElement(b); } else { closeStartTag(b); ... // format child elements ... XmlUtil.addEndTag(b, indent, Whatever.ELEMENT); }

See Also:
addOpenStartTag(java.lang.StringBuffer, int, java.lang.String)

closeStartTagAndEndElement

public static void closeStartTagAndEndElement(java.lang.StringBuffer b)
Completes an open element start tag and the element in one move. addOpenStartTag(b, indent, Whatever.ELEMENT); XmlUtil.addAttribute(b,"attr1", _attr1); XmlUtil.addAttribute(b,"attr2", _attr2); if ( childElements==null || childElements.size()==0 ) { XmlUtil.closeStartTagAndEndElement(b); } else { closeStartTag(b); ... // format child elements ... XmlUtil.addEndTag(b, indent, Whatever.ELEMENT); }

See Also:
addOpenStartTag(java.lang.StringBuffer, int, java.lang.String)

addStartTag

public static void addStartTag(java.lang.StringBuffer b,
                               int indent,
                               java.lang.String element,
                               boolean newline)
Adds a closed element start tag with optional indentation. Typically used when you have element name constants, since if you're hard coding the names, you can just use a longer string literal. Newline is optional, should be false if you have mixed content, true otherwise.


addEndTag

public static void addEndTag(java.lang.StringBuffer b,
                             int indent,
                             java.lang.String element)
Adds an element end tag with optional indentation. Typically used when you have element name constants, since if you're hard coding the names, you can just use a longer string literal.


addElement

public static void addElement(java.lang.StringBuffer b,
                              int indent,
                              java.lang.String element,
                              java.lang.String content)
Adds an element with content to the buffer, being careful to escape content.


addObject

public static void addObject(java.lang.StringBuffer b,
                             int indent,
                             java.lang.String wrapper,
                             XmlObject obj)
Adds an object to the buffer, wrapped in some other elemenet.


main

public static void main(java.lang.String[] args)
Parses an XML file, and displays any error or warning messages. on the console.


areSetEquivalent

public static boolean areSetEquivalent(org.w3c.dom.Node n1,
                                       org.w3c.dom.Node n2)
Tests the two given nodes for set equivalency (meaning having equal content, but not necessarily in the same order). Added for testing purposes but can be improved for more general usage. Thus its placement here. [DLJ].


attributesMatch

public static boolean attributesMatch(org.w3c.dom.Node n1,
                                      org.w3c.dom.Node n2)
For attributes only, tests the two given nodes for set equivalency (meaning having equal content, but not necessarily in the same order). Added for testing purposes but can be improved for more general usage. Thus its placement here. [DLJ].


unpack

public static java.util.Map unpack(java.lang.String summary)
Given a string buffer containing an object summary, unpack it into an Map object.