Class EntityResolver

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AMP_ESCAPE
      Escape for "&" (ampersand)
      static java.lang.String APOS_ESCAPE
      Escape for "'" (single quote or apostrophe)
      private CharValidator charValidator  
      static java.lang.String GT_ESCAPE
      Escape for ">" (greater than)
      static java.lang.String LT_ESCAPE
      Escape for "<" (less than)
      private EntityResolver parent  
      static java.lang.String QUOT_ESCAPE
      Escape for '"' (double quote)
      protected java.util.Map<java.lang.String,​java.lang.String> resolveMap  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String name, java.lang.String replacementText)
      Add a new entity
      void clear()
      Remove all definitions from the map except the standard XML entities (&lt;, &gt;, ...)
      java.lang.String encode​(java.lang.String input)
      Replace text in a string with entity references
      java.lang.String expand​(java.lang.String entity)
      Expand an entity reference.
      int expandNumericEntity​(java.lang.String entity)
      Returns the character value of a numeric entity.
      CharValidator getCharValidator()  
      EntityResolver getParent()  
      boolean isDefined​(java.lang.String name)
      Check if an entity is defined.
      java.lang.String resolve​(java.lang.String name)
      Resolve an entity reference.
      EntityResolver setCharValidator​(CharValidator charValidator)  
      protected java.lang.String stripName​(java.lang.String name)  
      void validateEntity​(java.lang.String entity)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • AMP_ESCAPE

        public static final java.lang.String AMP_ESCAPE
        Escape for "&" (ampersand)
        See Also:
        Constant Field Values
      • LT_ESCAPE

        public static final java.lang.String LT_ESCAPE
        Escape for "<" (less than)
        See Also:
        Constant Field Values
      • GT_ESCAPE

        public static final java.lang.String GT_ESCAPE
        Escape for ">" (greater than)
        See Also:
        Constant Field Values
      • QUOT_ESCAPE

        public static final java.lang.String QUOT_ESCAPE
        Escape for '"' (double quote)
        See Also:
        Constant Field Values
      • APOS_ESCAPE

        public static final java.lang.String APOS_ESCAPE
        Escape for "'" (single quote or apostrophe)
        See Also:
        Constant Field Values
      • resolveMap

        protected java.util.Map<java.lang.String,​java.lang.String> resolveMap
    • Constructor Detail

      • EntityResolver

        public EntityResolver()
    • Method Detail

      • clear

        public void clear()
        Remove all definitions from the map except the standard XML entities (&lt;, &gt;, ...)
      • add

        public void add​(java.lang.String name,
                        java.lang.String replacementText)
        Add a new entity
        Parameters:
        name - for example "lt"
        replacementText - for example "<"
      • isDefined

        public boolean isDefined​(java.lang.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 java.lang.String resolve​(java.lang.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
      • stripName

        protected java.lang.String stripName​(java.lang.String name)
      • expand

        public java.lang.String expand​(java.lang.String entity)
        Expand an entity reference. If the reference is unknown, the method will null.

        Valid inputs are entity names or entity references (i.e. it will work with "lt" and "<")

      • encode

        public java.lang.String encode​(java.lang.String input)
        Replace text in a string with entity references
      • expandNumericEntity

        public int expandNumericEntity​(java.lang.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:
        java.lang.IllegalArgumentException - if the numeric entity has the wrong format, or the value is too low or high.
      • validateEntity

        public void validateEntity​(java.lang.String entity)