Class Entities

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      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.
      java.lang.String escape​(java.lang.String str)
      Escapes the characters in a String.
      (package private) static void fillWithHtml40Entities​(Entities entities)
      Fills the specified entities instance with HTML 40 entities.
      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.
      java.lang.String unescape​(java.lang.String str)
      Unescapes the entities in a String.
      • Methods inherited from class java.lang.Object

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

      • BASIC_ARRAY

        private static final java.lang.String[][] BASIC_ARRAY
      • APOS_ARRAY

        private static final java.lang.String[][] APOS_ARRAY
      • ISO8859_1_ARRAY

        static final java.lang.String[][] ISO8859_1_ARRAY
      • HTML40_ARRAY

        static final java.lang.String[][] HTML40_ARRAY
      • XML

        public static final Entities XML

        The set of entities supported by standard XML.

      • HTML32

        public static final Entities HTML32

        The set of entities supported by HTML 3.2.

      • HTML40

        public static final Entities HTML40

        The set of entities supported by HTML 4.0.

    • Constructor Detail

      • Entities

        public Entities()
        Default constructor.
      • Entities

        Entities​(Entities.EntityMap emap)
        package scoped constructor for testing.
        Parameters:
        emap - entity map.
    • Method Detail

      • fillWithHtml40Entities

        static void fillWithHtml40Entities​(Entities entities)

        Fills the specified entities instance with HTML 40 entities.

        Parameters:
        entities - the instance to be filled.
      • addEntities

        public void addEntities​(java.lang.String[][] entityArray)

        Adds entities to this entity.

        Parameters:
        entityArray - array of entities to be added
      • addEntity

        public void addEntity​(java.lang.String name,
                              int value)

        Add an entity to this entity.

        Parameters:
        name - name of the entity
        value - vale of the entity
      • entityName

        public java.lang.String entityName​(int value)

        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

        public int entityValue​(java.lang.String name)

        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

        public 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;"

        Parameters:
        str - The String to escape.
        Returns:
        A new escaped String.
      • escape

        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.

        Parameters:
        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.
        Throws:
        java.io.IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
        See Also:
        escape(String), Writer
      • unescape

        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 "¡"

        Parameters:
        str - The String to escape.
        Returns:
        A new escaped String.
      • createStringWriter

        private java.io.StringWriter createStringWriter​(java.lang.String str)
        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

        public 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.

        Parameters:
        writer - The Writer to write the results to; assumed to be non-null.
        str - The source String to unescape; assumed to be non-null.
        Throws:
        java.io.IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
        See Also:
        escape(String), Writer
      • doUnescape

        private void doUnescape​(java.io.Writer writer,
                                java.lang.String str,
                                int firstAmp)
                         throws java.io.IOException
        Underlying unescape method that allows the optimisation of not starting from the 0 index again.
        Parameters:
        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.
        Throws:
        java.io.IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.