XML for Java Compatibility API 2.0.13

com.ibm.xml.parser
Class Util

java.lang.Object
  |
  +--com.ibm.xml.parser.Util

public class Util
extends java.lang.Object

Util is a collection of XML4J utility routines which check the conformance of various XML-defined values (XML name, language ID, encoding ID), and which provide services for converting strings to XML format.

Version:
Revision: 09 1.6 src/com/ibm/xml/parser/Util.java, parser, xml4j2, xml4j2_0_13

Constructor Summary
Util()
           
 
Method Summary
static java.lang.String backReference(java.lang.String string, java.lang.String encoding)
          Returns the specified string after substituting &, <, >, , and UTF-16 surrogates for the set of general entities (&amp;, &lt;, &gt;) and numeric character references (&#...) respectively.
static java.lang.String backReference(java.lang.String string, java.lang.String specials, java.lang.String encoding)
          Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
static java.lang.String backReferenceForEntity(java.lang.String string, java.lang.String encoding)
          Returns the specified string after substituting ", ', %, CR, LF, TAB,and UTF-16 surrogates for &#x26;, &#x22;, &#x27;, &#x25;, &#x0D;, &#x0A, &#x09, and &#x...; respectively.
static boolean checkAllSpace(java.lang.String string)
          Returns whether the specified string consists of only XML whitespace.
static boolean checkEncoding(java.lang.String xmlEncoding)
          Returns whether the specified xmlEncoding conforms to an encoding name in XML 1.0.
static boolean checkLanguageID(java.lang.String languageID)
          Returns whether the specified languageID conforms to a language ID in XML 1.0.
static boolean checkName(java.lang.String name)
          Returns whether the specified name conforms to Name in XML 1.0.
static boolean checkNCName(java.lang.String name)
          Returns whether the specified name conforms to NCName in `Namespaces in XML'.
static boolean checkNmtoken(java.lang.String nmtoken)
          Returns whether the specified nmtoken conforms to Nmtoken in XML 1.0.
static boolean checkVersionNum(java.lang.String versionNum)
          Returns whether the specified versionNum conforms to a version numner in XML 1.0.
static int getInvalidURIChar(java.lang.String uri)
          Returns the index of the first invalid character in the specified uri.
static void heapSort(java.lang.String[] pd)
          Sort String array.
static void heapSort(java.lang.String[] pd, int length)
          Sort String array.
static void indent(java.io.Writer pw, int n)
          Prints a newline character and n spaces.
static boolean isURN(java.lang.String uri)
          Returns whether the specified URI string is a URN.
static java.lang.String normalizeURN(java.lang.String urn)
          Returns normalized URN, "urn:" and <NID> are lower-cased.
static void printSpace(java.io.Writer pw, int n)
          Prints n spaces.
static java.util.Vector sortStringVector(java.util.Vector vector)
          Returns a sorted vector of strings; strings are orderred using String#compareTo().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

checkName

public static boolean checkName(java.lang.String name)
Returns whether the specified name conforms to Name in XML 1.0. Refer to the definition of Name for details.
Parameters:
name - Name to be checked as a valid XML Name.
Returns:
=true if name complies with XML spec; otherwise =false.

checkNCName

public static boolean checkNCName(java.lang.String name)
Returns whether the specified name conforms to NCName in `Namespaces in XML'. Refer to the definition of NCName for details.
Parameters:
name - Name to be checked as a valid XML NCName.
Returns:
=true if name complies with XML spec; otherwise =false.

checkNmtoken

public static boolean checkNmtoken(java.lang.String nmtoken)
Returns whether the specified nmtoken conforms to Nmtoken in XML 1.0. Refer to the definition of Nmtoken for details.
Parameters:
nmtoken - NMToken to be checked as a valid XML NMToken.
Returns:
=true if name complies with XML spec; otherwise =false.

checkAllSpace

public static boolean checkAllSpace(java.lang.String string)
Returns whether the specified string consists of only XML whitespace. Refer to the definition of S for details.
Parameters:
string - String to be checked if it constains all XML whitespace.
Returns:
=true if name is all XML whitespace; otherwise =false.

checkEncoding

public static boolean checkEncoding(java.lang.String xmlEncoding)
Returns whether the specified xmlEncoding conforms to an encoding name in XML 1.0. Refer to the definition of EncName for details.

Note that just because enc may be a valid encoding name does not imply the encoding is supported by XML4J.

Parameters:
xmlEncoding - Name to be checked as a valid encoding name.
Returns:
=true if name complies with XML spec; otherwise =false.
See Also:
TXDocument.setEncoding(java.lang.String)

checkLanguageID

public static boolean checkLanguageID(java.lang.String languageID)
Returns whether the specified languageID conforms to a language ID in XML 1.0. Refer to XML 1.0 / 2.12 Language Identification for details.
Parameters:
languageID - ID to be checked as a valid language ID.
Returns:
=true if ID complies with XML spec; otherwise =false.
See Also:
TXElement.getLanguage(), TXText.getLanguage(), GeneralReference.getLanguage()

checkVersionNum

public static boolean checkVersionNum(java.lang.String versionNum)
Returns whether the specified versionNum conforms to a version numner in XML 1.0. Refer to the definition of VersionNum for details.
Parameters:
versionNum - Number to be checked as a valid version number.
Returns:
=true if number complies with XML spec; otherwise =false.

getInvalidURIChar

public static int getInvalidURIChar(java.lang.String uri)
Returns the index of the first invalid character in the specified uri. Refer to RFC2396 for details.
Parameters:
uri - URI to check for validity against RFC2396.
Returns:
0-based index of first invalid URI character, or -1 if URI is valid.

isURN

public static boolean isURN(java.lang.String uri)
Returns whether the specified URI string is a URN.

normalizeURN

public static java.lang.String normalizeURN(java.lang.String urn)
Returns normalized URN, "urn:" and <NID> are lower-cased. Refer to RFC2141.

backReference

public static java.lang.String backReference(java.lang.String string,
                                             java.lang.String encoding)
Returns the specified string after substituting &, <, >, , and UTF-16 surrogates for the set of general entities (&amp;, &lt;, &gt;) and numeric character references (&#...) respectively.

This routine can be used by all DOM and XML4J objects EXCEPT Entity in order to represent their contents in XML format.

Parameters:
string - String to convert to XML format.
encoding - CURRENTLY NOT IMPLEMENTED.
Returns:
XML-formatted string.
See Also:
backReferenceForEntity(java.lang.String, java.lang.String)

backReferenceForEntity

public static java.lang.String backReferenceForEntity(java.lang.String string,
                                                      java.lang.String encoding)
Returns the specified string after substituting ", ', %, CR, LF, TAB,and UTF-16 surrogates for &#x26;, &#x22;, &#x27;, &#x25;, &#x0D;, &#x0A, &#x09, and &#x...; respectively.

This routine can be used by Entity objects in order to represent their contents in XML format.

Parameters:
string - String to convert to XML format.
encoding - CURRENTLY NOT IMPLEMENTED.
Returns:
XML-formatted string.
See Also:
backReference(java.lang.String, java.lang.String)

backReference

public static java.lang.String backReference(java.lang.String string,
                                             java.lang.String specials,
                                             java.lang.String encoding)
Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
Parameters:
string - String to convert to XML format.
specials - Chracters, should be represeted in chracter referenfces.
encoding - CURRENTLY NOT IMPLEMENTED.
Returns:
XML-formatted string.
See Also:
backReference(java.lang.String, java.lang.String)

printSpace

public static void printSpace(java.io.Writer pw,
                              int n)
                       throws java.io.IOException
Prints n spaces.
Parameters:
pw - The character output stream to use.
n - Number of spaces to print.
Throws:
java.io.IOException - Thrown if pw is invalid.

indent

public static void indent(java.io.Writer pw,
                          int n)
                   throws java.io.IOException
Prints a newline character and n spaces.
Parameters:
pw - The character output stream to use.
n - Number of spaces to print.
Throws:
java.io.IOException - Thrown if pw is invalid.

sortStringVector

public static java.util.Vector sortStringVector(java.util.Vector vector)
Returns a sorted vector of strings; strings are orderred using String#compareTo().
Parameters:
vector - The vector to be sorted.
Returns:
The sorted vector.
See Also:
String.compareTo(java.lang.Object)

heapSort

public static void heapSort(java.lang.String[] pd)
Sort String array.

heapSort

public static void heapSort(java.lang.String[] pd,
                            int length)
Sort String array.

XML for Java Compatibility API 2.0.13