Class Entities
- java.lang.Object
-
- org.apache.commons.lang.Entities
-
class Entities extends java.lang.Object
Provides 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 class
Entities.ArrayEntityMap
(package private) static class
Entities.BinaryEntityMap
(package private) static interface
Entities.EntityMap
(package private) static class
Entities.HashEntityMap
(package private) static class
Entities.LookupEntityMap
(package private) static class
Entities.MapIntMap
(package private) static class
Entities.PrimitiveEntityMap
(package private) static class
Entities.TreeEntityMap
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[][]
APOS_ARRAY
private static java.lang.String[][]
BASIC_ARRAY
static Entities
HTML32
The set of entities supported by HTML 3.2.static Entities
HTML40
The set of entities supported by HTML 4.0.(package private) static java.lang.String[][]
HTML40_ARRAY
(package private) static java.lang.String[][]
ISO8859_1_ARRAY
private Entities.EntityMap
map
static Entities
XML
The 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 void
addEntities(java.lang.String[][] entityArray)
Adds entities to this entity.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 writerprivate 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.java.lang.String
entityName(int value)
Returns the name of the entity identified by the specified value.int
entityValue(java.lang.String name)
Returns the value of the entity identified by the specified name.void
escape(java.io.Writer writer, java.lang.String str)
Escapes the characters in theString
passed and writes the result to theWriter
passed.java.lang.String
escape(java.lang.String str)
Escapes the characters in aString
.(package private) static void
fillWithHtml40Entities(Entities entities)
Fills the specified entities instance with HTML 40 entities.void
unescape(java.io.Writer writer, java.lang.String str)
Unescapes the escaped entities in theString
passed and writes the result to theWriter
passed.java.lang.String
unescape(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
- TheString
to escape.- Returns:
- A new escaped
String
.
-
escape
public void escape(java.io.Writer writer, java.lang.String str) throws java.io.IOException
Escapes the characters in the
String
passed and writes the result to theWriter
passed.- Parameters:
writer
- TheWriter
to write the results of the escaping to. Assumed to be a non-null value.str
- TheString
to escape. Assumed to be a non-null value.- Throws:
java.io.IOException
- whenWriter
passed 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
- TheString
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 theWriter
passed.- Parameters:
writer
- TheWriter
to write the results to; assumed to be non-null.str
- The sourceString
to unescape; assumed to be non-null.- Throws:
java.io.IOException
- whenWriter
passed 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.IOException
Underlying unescape method that allows the optimisation of not starting from the 0 index again.- Parameters:
writer
- TheWriter
to write the results to; assumed to be non-null.str
- The sourceString
to unescape; assumed to be non-null.firstAmp
- Theint
index of the first ampersand in the source String.- Throws:
java.io.IOException
- whenWriter
passed throws the exception from calls to theWriter.write(int)
methods.
-
-