class Entities
extends java.lang.Object
Provides HTML and XML entity utilities.
Modifier and Type | Class and 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 |
Modifier and Type | Field and 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 and Description |
---|
Entities()
Default constructor.
|
Entities(Entities.EntityMap emap)
package scoped constructor for testing.
|
Modifier and Type | Method and 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 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.
|
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.
|
java.lang.String |
escape(java.lang.String str)
Escapes the characters in a
String . |
void |
escape(java.io.Writer writer,
java.lang.String str)
Escapes the characters in the
String passed and writes the result to the Writer
passed. |
(package private) static void |
fillWithHtml40Entities(Entities entities)
Fills the specified entities instance with HTML 40 entities.
|
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. |
private static final java.lang.String[][] BASIC_ARRAY
private static final java.lang.String[][] APOS_ARRAY
static final java.lang.String[][] ISO8859_1_ARRAY
static final java.lang.String[][] HTML40_ARRAY
public static final Entities XML
The set of entities supported by standard XML.
public static final Entities HTML32
The set of entities supported by HTML 3.2.
public static final Entities HTML40
The set of entities supported by HTML 4.0.
private final Entities.EntityMap map
public Entities()
Entities(Entities.EntityMap emap)
emap
- entity map.static void fillWithHtml40Entities(Entities entities)
Fills the specified entities instance with HTML 40 entities.
entities
- the instance to be filled.public void addEntities(java.lang.String[][] entityArray)
Adds entities to this entity.
entityArray
- array of entities to be addedpublic void addEntity(java.lang.String name, int value)
Add an entity to this entity.
name
- name of the entityvalue
- vale of the entitypublic java.lang.String entityName(int value)
Returns the name of the entity identified by the specified value.
value
- the value to locatepublic int entityValue(java.lang.String name)
Returns the value of the entity identified by the specified name.
name
- the name to locatepublic 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;"
str
- The String
to escape.String
.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 the Writer
passed.
writer
- The Writer
to write the results of the escaping to. Assumed to be a non-null value.str
- The String
to escape. Assumed to be a non-null value.java.io.IOException
- when Writer
passed throws the exception from calls to the Writer.write(int)
methods.escape(String)
,
Writer
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 "¡"
str
- The String
to escape.String
.private java.io.StringWriter createStringWriter(java.lang.String str)
str
- The source stringpublic 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.
writer
- The Writer
to write the results to; assumed to be non-null.str
- The source String
to unescape; assumed to be non-null.java.io.IOException
- when Writer
passed throws the exception from calls to the Writer.write(int)
methods.escape(String)
,
Writer
private void doUnescape(java.io.Writer writer, java.lang.String str, int firstAmp) throws java.io.IOException
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.java.io.IOException
- when Writer
passed throws the exception from calls to the Writer.write(int)
methods.