Class CharEntities

java.lang.Object
com.codename1.xml.CharEntities

public final class CharEntities extends Object

The character entity tables of the XML and HTML parsers, and the lookups over them.

It lives here rather than in com.codename1.ui.html so that XMLParser can decode entities without linking any UI class: the parser is shared with the server runtime. com.codename1.ui.html.HTMLUtils delegates to it, so the lenient HTML behaviour is unchanged.

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    convert(String charEntity, boolean lookupHTMLentities, Hashtable userDefinedCharEntities)
    Converts a char entity to the matching character, the lenient way the HTML parser always has: the XML names match ignoring case, and a numeric reference is truncated to one char.
    static String
    decodeXml(String ref, Hashtable userDefinedCharEntities)
    Decodes a reference the way XML defines it: the five predefined names, matched exactly, a decimal or hexadecimal character reference to a legal code point (a supplementary one becomes a surrogate pair), or a name in userDefinedCharEntities.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • convert

      public static String convert(String charEntity, boolean lookupHTMLentities, Hashtable userDefinedCharEntities)

      Converts a char entity to the matching character, the lenient way the HTML parser always has: the XML names match ignoring case, and a numeric reference is truncated to one char.

      Parameters
      • charEntity: The char entity to convert (Not including the & and ;)

      • lookupHTMLentities: true to include the basic HTML named char entities (unicode 160-255), false otherwise

      • userDefinedCharEntities: A hashtable containing (String,int) denoting the char entity name and its unicode

      Returns

      A string containing a single char

      Throws
      • IllegalArgumentException: if the entity is unknown
    • decodeXml

      public static String decodeXml(String ref, Hashtable userDefinedCharEntities)

      Decodes a reference the way XML defines it: the five predefined names, matched exactly, a decimal or hexadecimal character reference to a legal code point (a supplementary one becomes a surrogate pair), or a name in userDefinedCharEntities. Entities a document declares itself are never consulted, so nothing a document says can be expanded.

      Parameters
      • ref: the reference without the & and ;

      • userDefinedCharEntities: names the application added, or null

      Returns

      the decoded characters, or null when the reference is undefined or invalid