org.stringer.util
Class XMLKit

java.lang.Object
  |
  +--org.stringer.util.XMLKit

public class XMLKit
extends java.lang.Object

Static XML helper methods.

Author:
R. Kevin Cole kcole@users.sourceforge.net

Field Summary
private static java.lang.String EMPTY_STRING
           
private static char TAG_END
          A tag end marker.
private static char TAG_START
          A tag start marker.
private static java.lang.String UTF8
          The string "UTF-8".
private static java.lang.String[][] XML_ESCAPES
          Mapping between XML chars prohibited in some contexts and their escaped equivalents.
private static java.lang.String XML_PI_START
          The start of an XML processing instruction.
private static java.util.HashMap xmlEscapes
          The actual Map used to store escaped-to-prohibited mappings.
private static java.util.HashMap xmlProhibited
          The actual Map used to store prohibited-to-escaped mappings.
 
Constructor Summary
private XMLKit()
          This class has a private constructor to prevent it from being instantiated.
 
Method Summary
static java.lang.String convertXMLUnicodeEntities(java.lang.String input)
           Converts XML Unicode character entities into their character equivalents within a given string.
static java.lang.String encodeLink(java.lang.String link)
           
static java.lang.String escapeXMLChars(java.lang.String input)
          Replaces the following characters with their "escaped" equivalents: & with &amp; < with &lt; > with &gt; ' with &apos; " with &quot;
private static java.lang.String filterXML(java.lang.String input)
          Removes all characters that are not considered XML characters from the input.
static java.lang.String removeMarkup(java.lang.String input)
          Removes all tags from a string (retains character content of tags, however).
static java.lang.String unescapeXMLChars(java.lang.String input)
           Replaces common escape sequences found in an html/xml file with their character equivalents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_START

private static final char TAG_START
A tag start marker.

See Also:
Constant Field Values

EMPTY_STRING

private static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

TAG_END

private static final char TAG_END
A tag end marker.

See Also:
Constant Field Values

XML_ESCAPES

private static final java.lang.String[][] XML_ESCAPES
Mapping between XML chars prohibited in some contexts and their escaped equivalents.


xmlProhibited

private static java.util.HashMap xmlProhibited
The actual Map used to store prohibited-to-escaped mappings.


xmlEscapes

private static java.util.HashMap xmlEscapes
The actual Map used to store escaped-to-prohibited mappings.


UTF8

private static final java.lang.String UTF8
The string "UTF-8".

See Also:
Constant Field Values

XML_PI_START

private static final java.lang.String XML_PI_START
The start of an XML processing instruction.

See Also:
Constant Field Values
Constructor Detail

XMLKit

private XMLKit()
This class has a private constructor to prevent it from being instantiated.

Method Detail

unescapeXMLChars

public static java.lang.String unescapeXMLChars(java.lang.String input)

Replaces common escape sequences found in an html/xml file with their character equivalents.

  • &amp; with &
  • &lt; with <
  • &gt; with >
  • &apos; with '
  • &quot; with "

Parameters:
input - the string on which to perform the replacement
Returns:
the string with entities replaced

escapeXMLChars

public static java.lang.String escapeXMLChars(java.lang.String input)
Replaces the following characters with their "escaped" equivalents:
  • & with &amp;
  • < with &lt;
  • > with &gt;
  • ' with &apos;
  • " with &quot;

Parameters:
input - the string on which to perform the replacement
Returns:
the string with entities replaced

filterXML

private static java.lang.String filterXML(java.lang.String input)
Removes all characters that are not considered XML characters from the input.

Parameters:
input - the input to filter
Returns:
the input with all non-XML characters removed

convertXMLUnicodeEntities

public static java.lang.String convertXMLUnicodeEntities(java.lang.String input)

Converts XML Unicode character entities into their character equivalents within a given string.

This will handle entities in the form &#xxxx; (decimal character code, where xxxx is a valid character code), or &#xxxxx (hexadecimal character code, where xxxx is a valid character code).

Parameters:
input - the string to process
Returns:
the input with all XML Unicode character entity codes replaced

removeMarkup

public static java.lang.String removeMarkup(java.lang.String input)
Removes all tags from a string (retains character content of tags, however).

Parameters:
input - the string from which to remove markup
Returns:
the input without tags

encodeLink

public static java.lang.String encodeLink(java.lang.String link)


Copyright © R. Kevin Cole. All Rights Reserved.