treebolic.provider.xml.fast
Class Entities

java.lang.Object
  extended by treebolic.provider.xml.fast.Entities

 class Entities
extends java.lang.Object

Provides HTML and XML entity utilities.

Since:
2.0
Version:
$Id: Entities.java,v 1.1 2008/07/01 14:56:04 bbou Exp $
Author:
Alexander Day Chaffee, Gary Gregory
See Also:
ISO Entities, HTML 3.2 Character Entities for ISO Latin-1, HTML 4.0 Character entity references, HTML 4.01 Character References, HTML 4.01 Code positions

Nested Class Summary
(package private) static interface Entities.EntityMap
           
(package private) static class Entities.HashEntityMap
           
(package private) static class Entities.MapIntMap
           
 
Field Summary
private static java.lang.String[][] APOS_ARRAY
           
private static java.lang.String[][] BASIC_ARRAY
           
private  Entities.EntityMap map
           
static Entities XML
           The set of entities supported by standard XML.
 
Constructor Summary
Entities()
           
 
Method Summary
private  void addEntities(java.lang.String[][] entityArray)
           Adds entities to this entity.
private  void addEntity(java.lang.String name, int value)
           Add an entity to this entity.
private  java.io.StringWriter createStringWriter(java.lang.String str)
          Make the StringWriter 10% larger than the source String to avoid growing the writer
private  void doUnescape(java.io.Writer writer, java.lang.String str, int firstAmp)
          Underlying unescape method that allows the optimisation of not starting from the 0 index again.
private  int entityValue(java.lang.String name)
           Returns the value of the entity identified by the specified name.
 java.lang.String unescape(java.lang.String str)
           Unescapes the entities in a String.
 void unescape(java.io.Writer writer, java.lang.String str)
           Unescapes the escaped entities in the String passed and writes the result to the Writer passed.
static java.lang.String unescapeXml(java.lang.String str)
           Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASIC_ARRAY

private static final java.lang.String[][] BASIC_ARRAY

APOS_ARRAY

private static final java.lang.String[][] APOS_ARRAY

XML

public static final Entities XML

The set of entities supported by standard XML.


map

private Entities.EntityMap map
Constructor Detail

Entities

Entities()
Method Detail

addEntities

private void addEntities(java.lang.String[][] entityArray)

Adds entities to this entity.

Parameters:
entityArray - array of entities to be added

addEntity

private void addEntity(java.lang.String name,
                       int value)

Add an entity to this entity.

Parameters:
name - name of the entity
value - vale of the entity

entityValue

private int entityValue(java.lang.String name)

Returns the value of the entity identified by the specified name.

Parameters:
name - the name to locate
Returns:
entity value associated with the specified name

unescape

public java.lang.String unescape(java.lang.String str)

Unescapes the entities in a String.

For example, if you have called addEntity("foo", 0xA1), unescape("&foo;") will return "ยก"

Parameters:
str - The String to escape.
Returns:
A new escaped String.

createStringWriter

private java.io.StringWriter createStringWriter(java.lang.String str)
Make the StringWriter 10% larger than the source String to avoid growing the writer

Parameters:
str - The source string
Returns:
A newly created StringWriter

unescape

public void unescape(java.io.Writer writer,
                     java.lang.String str)
              throws java.io.IOException

Unescapes the escaped entities in the String passed and writes the result to the Writer passed.

Parameters:
writer - The Writer to write the results to; assumed to be non-null.
str - The source String to unescape; assumed to be non-null.
Throws:
java.io.IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
See Also:
Writer

doUnescape

private void doUnescape(java.io.Writer writer,
                        java.lang.String str,
                        int firstAmp)
                 throws java.io.IOException
Underlying unescape method that allows the optimisation of not starting from the 0 index again.

Parameters:
writer - The Writer to write the results to; assumed to be non-null.
str - The source String to unescape; assumed to be non-null.
firstAmp - The int index of the first ampersand in the source String.
Throws:
java.io.IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.

unescapeXml

public static java.lang.String unescapeXml(java.lang.String str)

Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.

Note that numerical \\u unicode codes are unescaped to their respective unicode characters. This may change in future releases.

Parameters:
str - the String to unescape, may be null
Returns:
a new unescaped String, null if null string input