org.apache.commons.betwixt
Class XMLUtils

java.lang.Object
  extended by org.apache.commons.betwixt.XMLUtils

public class XMLUtils
extends java.lang.Object

XMLUtils contains basic utility methods for XML.

The code for isWellFormedXMLName(java.lang.String) is based on code in org.apache.xerces.util.XMLChar in Apache Xerces. The authors of this class are credited below.

Since:
0.5
Author:
Glenn Marcy, IBM, Andy Clark, IBM, Eric Ye, IBM, Arnaud Le Hors, IBM, Rahul Srivastava, Sun Microsystems Inc., Robert Burrell Donkin

Field Summary
static java.lang.String AMPERSAND_ENTITY
          Escaped & entity
static java.lang.String APOSTROPHE_ENTITY
          Escaped ' entity
static java.lang.String GREATER_THAN_ENTITY
          Escaped > entity
static java.lang.String LESS_THAN_ENTITY
          Escaped < entity
static java.lang.String QUOTE_ENTITY
          Escaped " entity
 
Constructor Summary
XMLUtils()
          Constructor for use by tools that required JavaBean instances.
 
Method Summary
static java.lang.String escapeAttributeValue(java.lang.Object value)
          Escape the toString of the given object.
static java.lang.String escapeBodyValue(java.lang.Object value)
          Escape the toString of the given object.
static java.lang.String escapeCDATAContent(java.lang.String content)
          Escapes the given content suitable for insertion within a CDATA sequence.
static void escapeCDATAContent(java.lang.StringBuffer bufferedContent)
          Escapes the given content suitable for insertion within a CDATA sequence.
static boolean isNameChar(int c)
          Returns true if the specified character is a valid name character as defined by the XML 1.0 specification.
static boolean isNameStartChar(int c)
          Returns true if the specified character is a valid name start character as defined in the XML 1.0 specification.
static boolean isWellFormedXMLName(java.lang.String name)
          Is this string a well formed xml name?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LESS_THAN_ENTITY

public static final java.lang.String LESS_THAN_ENTITY
Escaped < entity

See Also:
Constant Field Values

GREATER_THAN_ENTITY

public static final java.lang.String GREATER_THAN_ENTITY
Escaped > entity

See Also:
Constant Field Values

AMPERSAND_ENTITY

public static final java.lang.String AMPERSAND_ENTITY
Escaped & entity

See Also:
Constant Field Values

APOSTROPHE_ENTITY

public static final java.lang.String APOSTROPHE_ENTITY
Escaped ' entity

See Also:
Constant Field Values

QUOTE_ENTITY

public static final java.lang.String QUOTE_ENTITY
Escaped " entity

See Also:
Constant Field Values
Constructor Detail

XMLUtils

public XMLUtils()

Constructor for use by tools that required JavaBean instances.

This constructor is public only to permit tools that require a JavaBean instance to operate. XMLUtils instances should not be constructed in standard programming. Instead, the class methods should be called directly.

Method Detail

escapeBodyValue

public static final java.lang.String escapeBodyValue(java.lang.Object value)

Escape the toString of the given object. For use as body text.

Parameters:
value - escape value.toString()
Returns:
text with escaped delimiters

escapeAttributeValue

public static final java.lang.String escapeAttributeValue(java.lang.Object value)

Escape the toString of the given object. For use in an attribute value.

Parameters:
value - escape value.toString()
Returns:
text with characters restricted (for use in attributes) escaped

escapeCDATAContent

public static final java.lang.String escapeCDATAContent(java.lang.String content)
Escapes the given content suitable for insertion within a CDATA sequence. Within a CDATA section, only the CDEnd string ']]>' is recognized as markup.

Parameters:
content - the body content whose character data should be escaped in a way appropriate for use within a CDATA section of xml.
Returns:
escaped character data, not null

escapeCDATAContent

public static final void escapeCDATAContent(java.lang.StringBuffer bufferedContent)
Escapes the given content suitable for insertion within a CDATA sequence. Within a CDATA section, only the CDEnd string ']]>' is recognized as markup.

Parameters:
bufferedContent - the body content within a buffer whose character data should be escaped in a way appropriate for use within a CDATA section of xml

isWellFormedXMLName

public static boolean isWellFormedXMLName(java.lang.String name)

Is this string a well formed xml name?

Only certain characters are allowed in well formed element and attribute names in xml. For example, white space is not allowed in a name.

The code for this method is based on code in org.apache.xerces.util.XMLChar in Apache Xerces. The authors of this class are credited at the top of this class.

Parameters:
name - the String to be checked for use as an xml attribute or element name. Returns false if name is null
Returns:
true if this string would be a well-formed name

isNameChar

public static boolean isNameChar(int c)
Returns true if the specified character is a valid name character as defined by the XML 1.0 specification.

Parameters:
c - The character to check.
Returns:
true if this is an XML name character

isNameStartChar

public static boolean isNameStartChar(int c)
Returns true if the specified character is a valid name start character as defined in the XML 1.0 specification.

Parameters:
c - The character to check.
Returns:
trus if this is an XML name start character


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.