Class Entities

java.lang.Object
org.apache.commons.lang.Entities

class Entities extends Object

Provides HTML and XML entity utilities.

Since:
2.0
Version:
$Id: Entities.java 1057037 2011-01-09 21:35:32Z niallp $
See Also:
  • Field Details

    • BASIC_ARRAY

      private static final String[][] BASIC_ARRAY
    • APOS_ARRAY

      private static final String[][] APOS_ARRAY
    • ISO8859_1_ARRAY

      static final String[][] ISO8859_1_ARRAY
    • HTML40_ARRAY

      static final 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.

    • map

      private final Entities.EntityMap 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

      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(String[][] entityArray)

      Adds entities to this entity.

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

      public void addEntity(String name, int value)

      Add an entity to this entity.

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

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

      public String unescape(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 StringWriter createStringWriter(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(Writer writer, String str) throws 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:
      IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
      See Also:
    • doUnescape

      private void doUnescape(Writer writer, String str, int firstAmp) throws 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:
      IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.