Class XercesXMLChar

java.lang.Object
org.apache.jena.ext.xerces.util.XercesXMLChar

public class XercesXMLChar extends Object
This class defines the basic XML character properties. The data in this class can be used to verify that a character is a valid XML character or if the character is a space, name start, or name character.

A series of convenience methods are supplied to ease the burden of the developer. Because inlining the checks can improve per character performance, the tables of character properties are public. Using the character as an index into the CHARS array and applying the appropriate mask flag (e.g. MASK_VALID), yields the same results as calling the convenience methods. There is one exception: check the comments for the isValid method for details.

Version:
$Id: XMLChar.java 674378 2008-07-07 00:52:45Z mrglavas $
Author:
Glenn Marcy, IBM, Andy Clark, IBM, Eric Ye, IBM, Arnaud Le Hors, IBM, Michael Glavassevich, IBM, Rahul Srivastava, Sun Microsystems Inc.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Content character mask.
    static final int
    Name character mask.
    static final int
    Name start character mask.
    static final int
    NCName character mask.
    static final int
    NCName start character mask.
    static final int
    Pubid character mask.
    static final int
    Space character mask.
    static final int
    Valid character mask.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isName(int c)
    Returns true if the specified character is a valid name character as defined by production [4] in the XML 1.0 specification.
    static boolean
    isNameStart(int c)
    Returns true if the specified character is a valid name start character as defined by production [5] in the XML 1.0 specification.
    static boolean
    isNCName(int c)
    Returns true if the specified character is a valid NCName character as defined by production [5] in Namespaces in XML recommendation.
    static boolean
    Returns true if the specified character is a valid NCName start character as defined by production [4] in Namespaces in XML recommendation.
    static boolean
    isSpace(int c)
    Returns true if the specified character is a space character as defined by production [3] in the XML 1.0 specification.
    static boolean
    Check to see if a string is a valid Name according to [5] in the XML 1.0 Recommendation
    static boolean
    Check to see if a string is a valid NCName according to [4] from the XML Namespaces 1.0 Recommendation
    static boolean
    Check to see if a string is a valid Nmtoken according to [7] in the XML 1.0 Recommendation
    static String
    trim(String value)
    Trims space characters as defined by production [3] in the XML 1.0 specification from both ends of the given string.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MASK_VALID

      public static final int MASK_VALID
      Valid character mask.
      See Also:
    • MASK_SPACE

      public static final int MASK_SPACE
      Space character mask.
      See Also:
    • MASK_NAME_START

      public static final int MASK_NAME_START
      Name start character mask.
      See Also:
    • MASK_NAME

      public static final int MASK_NAME
      Name character mask.
      See Also:
    • MASK_PUBID

      public static final int MASK_PUBID
      Pubid character mask.
      See Also:
    • MASK_CONTENT

      public static final int MASK_CONTENT
      Content character mask. Special characters are those that can be considered the start of markup, such as '<' and '&'. The various newline characters are considered special as well. All other valid XML characters can be considered content.

      This is an optimization for the inner loop of character scanning.

      See Also:
    • MASK_NCNAME_START

      public static final int MASK_NCNAME_START
      NCName start character mask.
      See Also:
    • MASK_NCNAME

      public static final int MASK_NCNAME
      NCName character mask.
      See Also:
  • Constructor Details

    • XercesXMLChar

      public XercesXMLChar()
  • Method Details

    • isSpace

      public static boolean isSpace(int c)
      Returns true if the specified character is a space character as defined by production [3] in the XML 1.0 specification.
      Parameters:
      c - The character to check.
    • isNameStart

      public static boolean isNameStart(int c)
      Returns true if the specified character is a valid name start character as defined by production [5] in the XML 1.0 specification.
      Parameters:
      c - The character to check.
    • isName

      public static boolean isName(int c)
      Returns true if the specified character is a valid name character as defined by production [4] in the XML 1.0 specification.
      Parameters:
      c - The character to check.
    • isNCNameStart

      public static boolean isNCNameStart(int c)
      Returns true if the specified character is a valid NCName start character as defined by production [4] in Namespaces in XML recommendation.
      Parameters:
      c - The character to check.
    • isNCName

      public static boolean isNCName(int c)
      Returns true if the specified character is a valid NCName character as defined by production [5] in Namespaces in XML recommendation.
      Parameters:
      c - The character to check.
    • isValidName

      public static boolean isValidName(String name)
      Check to see if a string is a valid Name according to [5] in the XML 1.0 Recommendation
      Parameters:
      name - string to check
      Returns:
      true if name is a valid Name
    • isValidNCName

      public static boolean isValidNCName(String ncName)
      Check to see if a string is a valid NCName according to [4] from the XML Namespaces 1.0 Recommendation
      Parameters:
      ncName - string to check
      Returns:
      true if name is a valid NCName
    • isValidNmtoken

      public static boolean isValidNmtoken(String nmtoken)
      Check to see if a string is a valid Nmtoken according to [7] in the XML 1.0 Recommendation
      Parameters:
      nmtoken - string to check
      Returns:
      true if nmtoken is a valid Nmtoken
    • trim

      public static String trim(String value)
      Trims space characters as defined by production [3] in the XML 1.0 specification from both ends of the given string.
      Parameters:
      value - the string to be trimmed
      Returns:
      the given string with the space characters trimmed from both ends