java.lang.Object
org.tquadrat.foundation.util.internal.Entities
@ClassVersion(sourceVersion="$Id: Entities.java 1060 2023-09-24 19:21:40Z tquadrat $")
@API(status=INTERNAL,
since="0.0.5")
public final class Entities
extends Object
Provides HTML and XML entity utilities.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Thanks to:
- Alexander Day Chaffee (alex@purpletech.com), Gary Gregory (ggregory@seagullsw.com)
- Version:
- $Id: Entities.java 1060 2023-09-24 19:21:40Z tquadrat $
- Since:
- 0.0.5
- See Also:
- Inspired through:
- Some code I found somewhere long time ago, originally written by Alexander Day Chaffee and Gary Gregory
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.util.internal.Entities"
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceLocal interface for the data structure that is used to store the entity mappings.private static classA simple implementation for the interfaceEntities.EntityMap. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name for the resource file that holds the additional XML entities: "apos_entities.data".static final EntitiesThe set of basic entities.static final StringThe name for the resource file that holds the basic entities that are common for both XML and HTML: "basic_entities.data".static final EntitiesThe set of entities supported by HTML 3.2.static final StringThe name for the resource final that holds the entities that were introduced for HTML 3.2: "ISO8859_1_entities.data".static final EntitiesThe set of entities supported by HTML 4.0.static final StringThe name for the resource final that holds the entities that were introduced for HTML 4.0: "html40_entities.data".static final EntitiesThe set of entities supported by HTML 5.0.static final StringThe name for the resource final that holds the entities that were introduced for HTML 5.0: "html50_entities.data".private final Lazy<Entities.EntityMap> The entity mapping.static final EntitiesThe set of entities supported by standard XML. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voiddoUnescape(Appendable buffer, CharSequence source, 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.entityValue(String name) Returns the value of the entity identified by the specified name.final voidescape(Appendable appendable, CharSequence input) Escapes the characters in theStringpassed and writes the result to theAppendablepassed.final Stringescape(CharSequence source) Escapes the characters in aString.
For example, if you have calledaddEntity( "foo", "0xA1" ), a call toescape( "¡" )will return"&foo;".private static final StringformatCodePoint(int codePoint) Converts a code point into the numerical HTML escape format.final String[]Returns a list of all known entities.private static voidloadEntities(Entities.EntityMap entityMap, URL resourceURL) Load the entities from the resource identified by the given URL to the given target entity map.private static voidparseAndAdd(Entities.EntityMap entityMap, String inputLine) Parses the given input line for an entity name and the related code point, and adds both to the given entity map.final voidunescape(Appendable appendable, CharSequence input) Unescapes the escaped entities in theStringpassed and writes the result to theAppendablepassed.final Stringunescape(CharSequence input) Unescapes the entities in aString.
-
Field Details
-
ADDITIONAL_XML_ENTITIES
The name for the resource file that holds the additional XML entities: "apos_entities.data". These entities are not defined for HTML before HTML 5.- See Also:
-
BASIC_ENTITIES
The name for the resource file that holds the basic entities that are common for both XML and HTML: "basic_entities.data".- See Also:
-
HTML32_ENTITIES
The name for the resource final that holds the entities that were introduced for HTML 3.2: "ISO8859_1_entities.data".- See Also:
-
HTML40_ENTITIES
The name for the resource final that holds the entities that were introduced for HTML 4.0: "html40_entities.data".- See Also:
-
HTML50_ENTITIES
The name for the resource final that holds the entities that were introduced for HTML 5.0: "html50_entities.data".- See Also:
-
m_EntityMap
The entity mapping. -
BASIC
The set of basic entities. -
HTML32
The set of entities supported by HTML 3.2. -
HTML40
The set of entities supported by HTML 4.0. -
HTML50
The set of entities supported by HTML 5.0. -
XML
The set of entities supported by standard XML.
-
-
Constructor Details
-
Entities
Creates a newEntitiesinstance.- Parameters:
resourceNames- The names of the resource files with the entity definitions.
-
-
Method Details
-
doUnescape
Underlying unescape method that allows the optimisation of not starting from the 0 index again.- Parameters:
buffer- The buffer to write the results to.source- The sourceStringto unescape.firstAmp- The index of the first ampersand in the source.- Throws:
IOException- Problems on writing to thebuffer.
-
entityName
Returns the name of the entity identified by the specified value.- Parameters:
value- The value to locate.- Returns:
- An instance of
Optionalthat holds the entity name that is associated with the specified value.
-
entityValue
Returns the value of the entity identified by the specified name.- Parameters:
name- The name to locate.- Returns:
- An instance of
Optionalthat holds the entity value associated with the specified name.
-
escape
Escapes the characters in aString.
For example, if you have calledaddEntity( "foo", "0xA1" ), a call toescape( "¡" )will return"&foo;".- Parameters:
source- TheStringto escape.- Returns:
- A new escaped
String.
-
escape
Escapes the characters in theStringpassed and writes the result to theAppendablepassed.- Parameters:
appendable- TheAppendableto write the results of the escaping to.input- TheStringto escape.- Throws:
IOException- whenAppendablepassed throws the exception from calls to theAppendable.append(char)method.- See Also:
-
formatCodePoint
Converts a code point into the numerical HTML escape format.- Parameters:
codePoint- The code point.- Returns:
- The HTML escaped code point.
-
listEntities
Returns a list of all known entities.- Returns:
- An array of String with the entities, there numerical values and the Unicode name of the entity.
-
loadEntities
Load the entities from the resource identified by the given URL to the given target entity map.- Parameters:
entityMap- The map that is the target for the entities.resourceURL- The URL for the resource.
-
parseAndAdd
Parses the given input line for an entity name and the related code point, and adds both to the given entity map.- Parameters:
entityMap- The map that is the target for the entities.inputLine- The input line.
-
unescape
Unescapes the entities in a
String.For example, if you have called
addEntity( "foo", 0xA1 ), a call tounescape( "&foo;")will return"¡".- Parameters:
input- TheStringto escape.- Returns:
- A new escaped
String.
-
unescape
Unescapes the escaped entities in theStringpassed and writes the result to theAppendablepassed.- Parameters:
appendable- TheAppendableto write the results to.input- The sourceStringto unescape.- Throws:
IOException- whenAppendablepassed throws the exception from calls to theAppendable.append(char)method.- See Also:
-
