Class AttributeValues

java.lang.Object
eu.bandm.tools.util.xml.AttributeValues

public class AttributeValues extends Object
Utility class with tests for the validity of Attribute values.
  • Field Details

    • oneBlank

      static final Pattern oneBlank
  • Method Details

    • _checkToken

      @Opt protected static @Opt PreMessage _checkToken(@Opt @Opt String token, boolean mustBeName)
      Checks whether the argument fits the rules for Nmtoken, Name, and similars, in XML 1.0. For details see checkNmToken(java.lang.String).
      Parameters:
      token - the string to check. Null and the empty string fail the test.
      mustBeName - true if the stricter rules for "name" are checked, not only those for NmTokenAttribute.
      Returns:
      null on success, otherwise a text which explains the violation.
    • checkNmToken

      @Opt public static @Opt PreMessage checkNmToken(@Opt @Opt String token)
      Check whether the argument is a legal value for "Nmtoken". This check is only an approximation to the XML rules, see below.

      The flavours of XML names and their relations:

      The rules for a correct xml Nmtoken or xml Name are crucial and complicated, see [XML 1.0], grammar rules [5] and [7].
      Grammar rule [7] defines Nmtoken as a non-empty string from letters, digits and few punctation characters. XML spec lists about hundred of ranges which can serve as "Letter", either defined as "BaseChar" or "Ideographic". [XML 1.0:rules 84-86].
      (XML 1.1 is quite different and lists the code points excluded.)

      Instead of this XML "Letter" definition we use Character.isJavaIdentifierStart(char) as an appproximation, and for "Letter or Digit" we use Character.isJavaIdentifierPart(char). But both after adding "_" and ":" and excluding the "dollar" sign. And further adding "." and "-" to the latter.

      Names are defined by rule [5]. The difference between Nmtokens and Names is, that the very first character of a name must be a "letter" or "_" or ":".
      Names are checked by checkNameToken(String).
      The Name production must be adhered to by the value of all attributes of type Id, IdRef, IdRefs, Entity, Entities and Notation. (The value for "notation" must be defined somewhere else as a "NOTATION"; this is a further global consistency condition currently not checked by tdom.)

      The weaker Nmtoken can be used for NmToken, NmTokens and Enumeration values.

      Further there is NCName (="No-Colon-Name") [NSinXML 1.0:rule 4], which is a Name not containing a colon ":".
      NCNames are checked by checkNCName(String).

      Further there is qname (="qualified Name") [NSinXML 1.0:rule 4], which is one NCName or two NCNames joined by a colon ":". QNames are checked by checkQName(String).

      Further there is PiTarget, which is a Name token which does not start with "(X|x)(M|m)(L|l)" in any combination. PiTargets are checked by checkPITarget(String).

      Further there are the un-reserved namespace prefixes, which are NCNames and do not start with "(X|x)(M|m)(L|l)" in any combination. [NSinXML: NSC:Reserved Prefixes and Namespace Names].

      Parameters:
      token - the string to check. Null and the empty string fail the test.
      Returns:
      null on success, otherwise a text which explains the violation.
    • checkNameToken

      @Opt public static @Opt PreMessage checkNameToken(@Opt @Opt String token)
      Check whether the argument is a legal value for a "Name" token, according to [XML 1.0].
      See checkNmToken(String) for details.
      Parameters:
      token - the string to check. Null and the empty string fail the test.
      Returns:
      null on success, otherwise a text which explains the violation.
    • checkQName

      @Opt public static @Opt PreMessage checkQName(@Opt @Opt String token)
      Check whether the argument is a legal value for a "QName". This is defined by [NSinXML 1.0:rule 7].

      See checkNmToken(String) for further details.

      Parameters:
      token - the string to check. Null and the empty string fail the test.
      Returns:
      null on success, otherwise a text which explains the violation.
    • checkNCName

      @Opt public static @Opt PreMessage checkNCName(@Opt @Opt String token)
      Check whether the argument is a legal value for a "Name" token and does furthermore not contain a colon ":".
      This is defined by [NSinXML 1.0:rule 4], and additionally required for all Attribute Values of type Id/IdRef/IdRefs/Entity/Entities/Notation for a "namespace-valid" document, see [NSinXML 1.0: section 7, last sentence],

      See checkNmToken(String) for further details.

      Parameters:
      token - the string to check. Null and the empty string fail the test.
      Returns:
      null on success, otherwise a text which explains the violation.
    • checkPITarget

      @Opt public static @Opt PreMessage checkPITarget(@Opt @Opt String token)
      Check whether the argument is a legal value for a "Name" token and does not start with the three characters "XML" in any combination of upper/lower case. These can be used as "PI targets" and are allowed as prefices in namespace declarations. See [XML1.0:section 2.6] and [NSinXML 1.0: section 3, last sentence].

      See checkNmToken(String) for further details of all check methods in this class.

      Parameters:
      token - the string to check. Null and empty string fail the test.
      Returns:
      null on success, otherwise a text which explains the violation.
    • checkNameTokens

      @Opt public static @Opt PreMessage checkNameTokens(@Opt @Opt String tokens, @Opt @Opt List<String> list)
      Check whether the argument is a legal value for an attribute of type "NameTokens". This must be a list of NameToken values, joined by one single blank = char(0x20). See [XML 1.0} syntax rule [6].
      Parameters:
      tokens - the string to check. Null and empty string fail the test.
      list - a list where to put the recognized and checked tokens
      Throws:
      IllegalArgumentException - when test fails
    • checkNmTokens

      @Opt public static @Opt PreMessage checkNmTokens(@Opt @Opt String tokens, @Opt @Opt List<String> list)
      Check whether the argument is a legal value for an attribute of type "NmTokens". This must be a list of NmToken values, joined by one single blank = char(0x20). See [XML 1.0} syntax rule [8].
      Parameters:
      tokens - the string to check. Null and empty string fail the test.
      list - a list where to put the recognized and checked tokens
      Throws:
      IllegalArgumentException - when test fails