Class Entities
- java.lang.Object
-
- org.apache.commons.lang.Entities
-
class Entities extends java.lang.ObjectProvides HTML and XML entity utilities.
- Since:
- 2.0
- Version:
- $Id: Entities.java 1057037 2011-01-09 21:35:32Z niallp $
- 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
Nested Classes Modifier and Type Class Description (package private) static classEntities.ArrayEntityMap(package private) static classEntities.BinaryEntityMap(package private) static interfaceEntities.EntityMap(package private) static classEntities.HashEntityMap(package private) static classEntities.LookupEntityMap(package private) static classEntities.MapIntMap(package private) static classEntities.PrimitiveEntityMap(package private) static classEntities.TreeEntityMap
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[][]APOS_ARRAYprivate static java.lang.String[][]BASIC_ARRAYstatic EntitiesHTML32The set of entities supported by HTML 3.2.static EntitiesHTML40The set of entities supported by HTML 4.0.(package private) static java.lang.String[][]HTML40_ARRAY(package private) static java.lang.String[][]ISO8859_1_ARRAYprivate Entities.EntityMapmapstatic EntitiesXMLThe set of entities supported by standard XML.
-
Constructor Summary
Constructors Constructor Description Entities()Default constructor.Entities(Entities.EntityMap emap)package scoped constructor for testing.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEntities(java.lang.String[][] entityArray)Adds entities to this entity.voidaddEntity(java.lang.String name, int value)Add an entity to this entity.private java.io.StringWritercreateStringWriter(java.lang.String str)Make the StringWriter 10% larger than the source String to avoid growing the writerprivate voiddoUnescape(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.java.lang.StringentityName(int value)Returns the name of the entity identified by the specified value.intentityValue(java.lang.String name)Returns the value of the entity identified by the specified name.voidescape(java.io.Writer writer, java.lang.String str)Escapes the characters in theStringpassed and writes the result to theWriterpassed.java.lang.Stringescape(java.lang.String str)Escapes the characters in aString.(package private) static voidfillWithHtml40Entities(Entities entities)Fills the specified entities instance with HTML 40 entities.voidunescape(java.io.Writer writer, java.lang.String str)Unescapes the escaped entities in theStringpassed and writes the result to theWriterpassed.java.lang.Stringunescape(java.lang.String str)Unescapes the entities in aString.
-
-
-
Field Detail
-
BASIC_ARRAY
private static final java.lang.String[][] BASIC_ARRAY
-
APOS_ARRAY
private static final java.lang.String[][] APOS_ARRAY
-
ISO8859_1_ARRAY
static final java.lang.String[][] ISO8859_1_ARRAY
-
HTML40_ARRAY
static final java.lang.String[][] HTML40_ARRAY
-
XML
public static final Entities XML
The set of entities supported by standard XML.
-
HTML32
public static final Entities HTML32
The set of entities supported by HTML 3.2.
-
HTML40
public static final Entities HTML40
The set of entities supported by HTML 4.0.
-
map
private final Entities.EntityMap map
-
-
Constructor Detail
-
Entities
public Entities()
Default constructor.
-
Entities
Entities(Entities.EntityMap emap)
package scoped constructor for testing.- Parameters:
emap- entity map.
-
-
Method Detail
-
fillWithHtml40Entities
static void fillWithHtml40Entities(Entities entities)
Fills the specified entities instance with HTML 40 entities.
- Parameters:
entities- the instance to be filled.
-
addEntities
public void addEntities(java.lang.String[][] entityArray)
Adds entities to this entity.
- Parameters:
entityArray- array of entities to be added
-
addEntity
public void addEntity(java.lang.String name, int value)Add an entity to this entity.
- Parameters:
name- name of the entityvalue- vale of the entity
-
entityName
public java.lang.String entityName(int value)
Returns the name of the entity identified by the specified value.
- Parameters:
value- the value to locate- Returns:
- entity name associated with the specified value
-
entityValue
public 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
-
escape
public java.lang.String escape(java.lang.String str)
Escapes the characters in a
String.For example, if you have called addEntity("foo", 0xA1), escape("¡") will return "&foo;"
- Parameters:
str- TheStringto escape.- Returns:
- A new escaped
String.
-
escape
public void escape(java.io.Writer writer, java.lang.String str) throws java.io.IOExceptionEscapes the characters in the
Stringpassed and writes the result to theWriterpassed.- Parameters:
writer- TheWriterto write the results of the escaping to. Assumed to be a non-null value.str- TheStringto escape. Assumed to be a non-null value.- Throws:
java.io.IOException- whenWriterpassed throws the exception from calls to theWriter.write(int)methods.- See Also:
escape(String),Writer
-
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- TheStringto 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.IOExceptionUnescapes the escaped entities in the
Stringpassed and writes the result to theWriterpassed.- Parameters:
writer- TheWriterto write the results to; assumed to be non-null.str- The sourceStringto unescape; assumed to be non-null.- Throws:
java.io.IOException- whenWriterpassed throws the exception from calls to theWriter.write(int)methods.- See Also:
escape(String),Writer
-
doUnescape
private void doUnescape(java.io.Writer writer, java.lang.String str, int firstAmp) throws java.io.IOExceptionUnderlying unescape method that allows the optimisation of not starting from the 0 index again.- Parameters:
writer- TheWriterto write the results to; assumed to be non-null.str- The sourceStringto unescape; assumed to be non-null.firstAmp- Theintindex of the first ampersand in the source String.- Throws:
java.io.IOException- whenWriterpassed throws the exception from calls to theWriter.write(int)methods.
-
-