Class Entities
Provides HTML and XML entity utilities.
- Since:
- 2.0
- Version:
- $Id: Entities.java 1057037 2011-01-09 21:35:32Z niallp $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static class(package private) static interface(package private) static class(package private) static class(package private) static class(package private) static class(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String[][]private static final String[][]static final EntitiesThe set of entities supported by HTML 3.2.static final EntitiesThe set of entities supported by HTML 4.0.(package private) static final String[][](package private) static final String[][]private final Entities.EntityMapstatic final EntitiesThe set of entities supported by standard XML. -
Constructor Summary
ConstructorsConstructorDescriptionEntities()Default constructor.Entities(Entities.EntityMap emap) package scoped constructor for testing. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEntities(String[][] entityArray) Adds entities to this entity.voidAdd an entity to this entity.private StringWritercreateStringWriter(String str) Make the StringWriter 10% larger than the source String to avoid growing the writerprivate voiddoUnescape(Writer writer, String str, int firstAmp) Underlying unescape method that allows the optimisation of not starting from the 0 index again.entityName(int value) Returns the name of the entity identified by the specified value.intentityValue(String name) Returns the value of the entity identified by the specified name.voidEscapes the characters in theStringpassed and writes the result to theWriterpassed.Escapes the characters in aString.(package private) static voidfillWithHtml40Entities(Entities entities) Fills the specified entities instance with HTML 40 entities.voidUnescapes the escaped entities in theStringpassed and writes the result to theWriterpassed.Unescapes the entities in aString.
-
Field Details
-
BASIC_ARRAY
-
APOS_ARRAY
-
ISO8859_1_ARRAY
-
HTML40_ARRAY
-
XML
The set of entities supported by standard XML.
-
HTML32
The set of entities supported by HTML 3.2.
-
HTML40
The set of entities supported by HTML 4.0.
-
map
-
-
Constructor Details
-
Entities
public Entities()Default constructor. -
Entities
Entities(Entities.EntityMap emap) package scoped constructor for testing.- Parameters:
emap- entity map.
-
-
Method Details
-
fillWithHtml40Entities
Fills the specified entities instance with HTML 40 entities.
- Parameters:
entities- the instance to be filled.
-
addEntities
Adds entities to this entity.
- Parameters:
entityArray- array of entities to be added
-
addEntity
Add an entity to this entity.
- Parameters:
name- name of the entityvalue- vale of the entity
-
entityName
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
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
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
Escapes 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:
IOException- whenWriterpassed throws the exception from calls to theWriter.write(int)methods.- See Also:
-
unescape
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
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
Unescapes 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:
IOException- whenWriterpassed throws the exception from calls to theWriter.write(int)methods.- See Also:
-
doUnescape
Underlying 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:
IOException- whenWriterpassed throws the exception from calls to theWriter.write(int)methods.
-