Package de.pdark.decentxml
Class EntityResolver
- java.lang.Object
-
- de.pdark.decentxml.EntityResolver
-
- Direct Known Subclasses:
DocTypeEntityResolver,HTMLEntityResolver
public class EntityResolver extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringAMP_ESCAPEEscape for "&" (ampersand)static StringAPOS_ESCAPEEscape for "'" (single quote or apostrophe)static StringGT_ESCAPEEscape for ">" (greater than)static StringLT_ESCAPEEscape for "<" (less than)static StringQUOT_ESCAPEEscape for '"' (double quote)protected Map<String,String>resolveMap
-
Constructor Summary
Constructors Constructor Description EntityResolver()EntityResolver(EntityResolver parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String name, String replacementText)Add a new entityvoidclear()Remove all definitions from the map except the standard XML entities (<, >, ...)Stringencode(String input)Replace text in a string with entity referencesStringexpand(String entity)Expand an entity reference.intexpandNumericEntity(String entity)Returns the character value of a numeric entity.CharValidatorgetCharValidator()EntityResolvergetParent()booleanisDefined(String name)Check if an entity is defined.Stringresolve(String name)Resolve an entity reference.EntityResolversetCharValidator(CharValidator charValidator)protected StringstripName(String name)voidvalidateEntity(String entity)
-
-
-
Field Detail
-
AMP_ESCAPE
public static final String AMP_ESCAPE
Escape for "&" (ampersand)- See Also:
- Constant Field Values
-
LT_ESCAPE
public static final String LT_ESCAPE
Escape for "<" (less than)- See Also:
- Constant Field Values
-
GT_ESCAPE
public static final String GT_ESCAPE
Escape for ">" (greater than)- See Also:
- Constant Field Values
-
QUOT_ESCAPE
public static final String QUOT_ESCAPE
Escape for '"' (double quote)- See Also:
- Constant Field Values
-
APOS_ESCAPE
public static final String APOS_ESCAPE
Escape for "'" (single quote or apostrophe)- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EntityResolver
public EntityResolver()
-
EntityResolver
public EntityResolver(EntityResolver parent)
-
-
Method Detail
-
getParent
public EntityResolver getParent()
-
getCharValidator
public CharValidator getCharValidator()
-
setCharValidator
public EntityResolver setCharValidator(CharValidator charValidator)
-
clear
public void clear()
Remove all definitions from the map except the standard XML entities (<, >, ...)
-
add
public void add(String name, String replacementText)
Add a new entity- Parameters:
name- for example "lt"replacementText- for example "<"
-
isDefined
public boolean isDefined(String name)
Check if an entity is defined.- Parameters:
name- The name of an entity ("lt" or "<").- Returns:
- the value of the entity or
null
-
resolve
public String resolve(String name)
Resolve an entity reference.This returns the text stored for this entity reference. No recursive expansion takes place.
- Parameters:
name- The name of an entity ("lt" or "<").- Returns:
- the value of the entity or
null
-
expand
public String expand(String entity)
Expand an entity reference. If the reference is unknown, the method willnull.Valid inputs are entity names or entity references (i.e. it will work with "lt" and "<")
-
expandNumericEntity
public int expandNumericEntity(String entity)
Returns the character value of a numeric entity.NOTE: This method returns a "code point", not a character. One "code point" can map to one or two Java characters!
- Throws:
IllegalArgumentException- if the numeric entity has the wrong format, or the value is too low or high.
-
validateEntity
public void validateEntity(String entity)
-
-