Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.novell.xml.util
Class XMLUtil

    java.lang.Object
      com.novell.xml.util.XMLUtil

    public final class XMLUtil

extends Object

utility class for various XML support routines

Field Summary
`static String` | `DIGITS`
`static String` | `HEX_DIGITS`
`static String` | `XML_STYLE_SHEET` Name of the `xml-stylesheet` processing instruction.

Method Summary
`static void` | `encodeAsCData(Writer stream, String value)` Output a text value as a CDATA section
`static void` | `encodeAttribute(Writer stream, String value)` Encode an attribute value as XML to a stream.
`static void` | `encodeText(Writer stream, String text)` Encode character data as XML text: '&' and '<' will be replaced by '&' and '<' ']]>' will be encoded ']]>'
`static String` | `escape(String string)` Returns the specified string with tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences.
`static String` | `escape(String string, int maxLength)` Returns the specified string with tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences.
`static URL` | `filenameToURL(String filename)` Converts the specified filename into a URL that uses the `file` protocol.
`static String` | `getLocalName(String qname)` Returns the local name from a qname.
`static String` | `getPrefix(String qname)` Returns the prefix from a qname.
`static String` | `getPseudoAttribute(String data, String attrName)` Return the value of a pseudo XML attribute from a string.
`static boolean` | `isNamespaceDecl(String name)` Checks an attribute qname to see if it is a namespace declaration
`static boolean` | `isNCName(char c)` returns whether the passed character matches the XML Namespace "NCName" production
`static boolean` | `isNCName(String str)` returns whether the passed string matches the XML Namespace "NCName" production
`static boolean` | `isNCNameChar(char ch)` Returns whether the specified character conforms to the NCNameChar production in the XML Namespace grammar.
`static boolean` | `isPITarget(String name)` Returns whether the passed string conforms to the PITarget production in the XML 1.0 Recommendation.
`static boolean` | `isQName(String name)` Returns whether the passed string conforms to the QName production found in XML Names: http://www.w3.org/TR/REC-xml-names
`static boolean` | `isXMLEncName(String str)` Return true if the passed string conforms to the XML EncName production.
`static boolean` | `isXMLName(char c)` Returns whether the specified char conforms to the Name production in the XML 1.0 grammar.
`static boolean` | `isXMLName(String str)` Returns whether the specified string conforms to the Name production in the XML 1.0 grammar.
`static boolean` | `isXMLNameChar(char ch)` Returns whether the specified character conforms to the NameChar production in the XML 1.0 grammar.
`static boolean` | `isXMLVersionNum(String str)` Return true if the passed string conforms to the XML VersionNum production.
`static boolean` | `isXMLWhitespace(char c)` Returns whether the specified string conforms to the S production in the XML 1.0 grammar.
`static boolean` | `isXMLWhitespace(String str)` Returns whether the specified string conforms to the S production in the XML 1.0 grammar.
`static String` | `normalizeWhitespace(String source)` Normalize whitespace in a string by stripping leading and trailing whitespace, and converting all internal sequences of whitespace into a single space each.
`static String` | `quote(String string)` Returns the specified string enclosed in double-quotes, with double-quotes, tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences.
`static String` | `quote(String string, int maxLength)` Returns the specified string enclosed in double-quotes, with double-quotes, tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences.
`static String` | `replaceBuiltInEntities(String rawString)`
`static String` | `toXML(String rawString)` encodes the passed string in XML-format: '<', '>', '&', '"', '\'' are replaced by "<", ">", "&", """, and "'" In addition, any two-char UTF-16 surrogate chars are replaced by character references
`static String` | `toXML(String rawString, String specials)` encodes the passed string in XML-format: '<', '>', '&', '"', '\'' are replaced by "<", ">", "&", """, and "'" Any chars in rawString found in specials String will be replaced by character references In addition, any two-char UTF-16 surrogate chars are replaced by character references

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### XML_STYLE_SHEET

    public static final String XML_STYLE_SHEET

  Name of the `xml-stylesheet` processing instruction.

  See Also:
    Constant Field Values

### DIGITS

    public static final String DIGITS

See Also:
  Constant Field Values

### HEX_DIGITS

    public static final String HEX_DIGITS

See Also:
  Constant Field Values

Method Detail

### filenameToURL

    public static URL filenameToURL(String filename)
                             throws MalformedURLException

  Converts the specified filename into a URL that uses the `file` protocol.

  Parameters:
    `filename` - the filename to be converted
  Returns:
    the resulting URL
  Throws:
    `MalformedURLException`

### escape

    public static String escape(String string)

  Returns the specified string with tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences. If the string is `null`, the six-character string `"(null)"` is returned.

  Parameters:
    `string` - the string to escape
  Returns:
    the escaped string

### escape

    public static String escape(String string,
                                int maxLength)

  Returns the specified string with tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences. If the string is `null`, the six-character string `"(null)"` is returned.

  If necessary, the returned string is truncated to force it to be no longer than the specified maximum length. A truncated string ends with the three characters `"..."`.

  Parameters:
    `string` - the string to escape
    `maxLength` - the escaped string's maximum length
  Returns:
    the escaped string

### quote

    public static String quote(String string)

  Returns the specified string enclosed in double-quotes, with double-quotes, tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences. If the string is `null`, the unquoted six-character string `"(null)"` is returned.

  Parameters:
    `string` - the string to quote
  Returns:
    the quoted string

### quote

    public static String quote(String string,
                               int maxLength)

  Returns the specified string enclosed in double-quotes, with double-quotes, tabs, carriage returns, line feeds, and ampersands translated to XML-style `&#`nn`;` sequences. If the string is `null`, the unquoted six-character string `"(null)"` is returned.

  If necessary, the returned string is truncated to force it to be no longer than the specified maximum length. A truncated string has its last three characters replaced with `"..."`.

  Parameters:
    `string` - the string to quote
    `maxLength` - the quoted string's maximum length
  Returns:
    the quoted string

### normalizeWhitespace

    public static String normalizeWhitespace(String source)

  Normalize whitespace in a string by stripping leading and trailing whitespace, and converting all internal sequences of whitespace into a single space each.

  Parameters:
    `source` - The string to be normalized
  Returns:
    The normalized string

### isXMLName

    public static boolean isXMLName(String str)

  Returns whether the specified string conforms to the Name production in the XML 1.0 grammar.

  Parameters:
    `str` - the string to be checked
  Returns:
    `true` if the string is an XML 1.0 Name, `false` if it is not

### isXMLName

    public static boolean isXMLName(char c)

  Returns whether the specified char conforms to the Name production in the XML 1.0 grammar.

  Parameters:
    `c` - the char to be checked
  Returns:
    `true` if the string is an XML 1.0 Name, `false` if it is not

### isXMLNameChar

    public static boolean isXMLNameChar(char ch)

  Returns whether the specified character conforms to the NameChar production in the XML 1.0 grammar. Such a character is allowed as the second or subsequent character in an XML 1.0 name.

  Parameters:
    `ch` - the character to be checked
  Returns:
    `true` if the character is an XML 1.0 NameChar, `false` if it is not

### isNCName

    public static boolean isNCName(char c)

  returns whether the passed character matches the XML Namespace "NCName" production

  Parameters:
    `c` - character to check
  Returns:
    true if character matches the XML Namespace "NCName" production

### isNCName

    public static boolean isNCName(String str)

  returns whether the passed string matches the XML Namespace "NCName" production

  Parameters:
    `str` - string to check
  Returns:
    true if string matches the XML Namespace "NCName" production

### isNCNameChar

    public static boolean isNCNameChar(char ch)

  Returns whether the specified character conforms to the NCNameChar production in the XML Namespace grammar. Such a character is allowed as the second or subsequent character in an XML 1.0 name.

  Parameters:
    `ch` - the character to be checked
  Returns:
    `true` if the character is an XML 1.0 NameChar, `false` if it is not

### isQName

    public static boolean isQName(String name)

  Returns whether the passed string conforms to the QName production found in XML Names: http://www.w3.org/TR/REC-xml-names

  Parameters:
    `name` - The string to check for conformance to QName.
  Returns:
    True if the string conforms to the QName production.

### isPITarget

    public static boolean isPITarget(String name)

  Returns whether the passed string conforms to the PITarget production in the XML 1.0 Recommendation.

  Parameters:
    `name` - String to check
  Returns:
    True if passed string conforms to PITarget

### isXMLWhitespace

    public static boolean isXMLWhitespace(String str)

  Returns whether the specified string conforms to the S production in the XML 1.0 grammar. Such a string consists only of XML whitespace.

  Parameters:
    `str` - the string to be checked
  Returns:
    `true` if the string consists only of XML whitespace, `false` if it does not

### isXMLWhitespace

    public static boolean isXMLWhitespace(char c)

  Returns whether the specified string conforms to the S production in the XML 1.0 grammar. Such a string consists only of XML whitespace.

  Parameters:
    `c` - the char to be checked
  Returns:
    `true` if the char is an XML 'S' production character

### isXMLVersionNum

    public static boolean isXMLVersionNum(String str)

  Return true if the passed string conforms to the XML VersionNum production. [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+

  Parameters:
    `str` - The string to check.
  Returns:
    True if the passed string conforms to the XML VersionNum production.

### isXMLEncName

    public static boolean isXMLEncName(String str)

  Return true if the passed string conforms to the XML EncName production. [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*

  Parameters:
    `str` - The string to check.
  Returns:
    `true` if the passed string conforms to the XML EncName production.

### isNamespaceDecl

    public static boolean isNamespaceDecl(String name)

  Checks an attribute qname to see if it is a namespace declaration

  Parameters:
    `name` - the attribute qname
  Returns:
    true/false

### toXML

    public static String toXML(String rawString)

  encodes the passed string in XML-format: '<', '>', '&', '"', '\'' are replaced by "<", ">", "&", """, and "'" In addition, any two-char UTF-16 surrogate chars are replaced by character references

  Parameters:
    `rawString` - string to convert to XML format
  Returns:
    converted String

### toXML

    public static String toXML(String rawString,
                               String specials)

  encodes the passed string in XML-format: '<', '>', '&', '"', '\'' are replaced by "<", ">", "&", """, and "'" Any chars in rawString found in specials String will be replaced by character references In addition, any two-char UTF-16 surrogate chars are replaced by character references

  Parameters:
    `rawString` - string to convert to XML format
    `specials` - collection of chars to use char references for
  Returns:
    converted String

### encodeText

    public static void encodeText(Writer stream,
                                  String text)
                           throws IOException

  Encode character data as XML text: '&' and '<' will be replaced by '&' and '<' ']]>' will be encoded ']]>'

  Parameters:
    `stream` - The output stream to which to send the data
    `text` - The text to encode
  Throws:
    `IOException`

### encodeAttribute

    public static void encodeAttribute(Writer stream,
                                       String value)
                                throws IOException

  Encode an attribute value as XML to a stream.

  Parameters:
    `stream` - The stream to which to write the attribute value.
    `value` - The attribute value.
  Throws:
    `IOException`

### encodeAsCData

    public static void encodeAsCData(Writer stream,
                                     String value)
                              throws IOException

  Output a text value as a CDATA section

  Parameters:
    `stream` - The writer to which to serialize the CDATA section
    `value` - The text value to output
  Throws:
    `IOException`

### replaceBuiltInEntities

    public static String replaceBuiltInEntities(String rawString)

### getPseudoAttribute

    public static String getPseudoAttribute(String data,
                                            String attrName)

  Return the value of a pseudo XML attribute from a string. A pseudo attribute has the same syntax as an XML element attribute but is not from an element. For example, the xml-stylesheet processing instruction has pseudo attributes.

  Parameters:
    `data` - The data to parse for the attribute value
    `attrName` - The name of the pseudo attribute

### getLocalName

    public static String getLocalName(String qname)

  Returns the local name from a qname.

  Parameters:
    `qname` - the qname whose local name is to be returned
  Returns:
    the qname's local name

### getPrefix

    public static String getPrefix(String qname)

  Returns the prefix from a qname.

  Parameters:
    `qname` - the qname whose local name is to be returned
  Returns:
    the qname's local name or empty string if no prefix

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD