Class TagType

  • Direct Known Subclasses:
    EndTagType, StartTagType

    public abstract class TagType
    extends java.lang.Object
    Defines the syntax for a tag type that can be recognised by the parser.

    This class is the root abstract class common to all tag types, and contains methods to register and deregister tag types as well as various methods to aid in their implementation.

    Every tag type is represented by a singleton instance of a class that must be a subclass of either StartTagType or EndTagType. These two abstract classes, the only direct descendants of this class, represent the two major classifications under which every tag type exists.

    Because all TagType instaces must be singletons, the '==' operator can be used to test for a particular tag type instead of the equals(Object) method.

    The term predefined tag type refers to any of the tag types defined in this library, including both standard and extended tag types.

    The term standard tag type refers to any of the tag types represented by instances in static fields of the StartTagType and EndTagType subclasses. Standard tag types are registered by default, and define the tags most commonly found in HTML documents.

    The term extended tag type refers to any predefined tag type that is not a standard tag type. The PHPTagTypes and MasonTagTypes classes contain extended tag types related to their respective server platforms. The tag types defined within them must be registered by the user before they are recognised by the parser.

    The term custom tag type refers to any user-defined tag type, or any tag type that is not a predefined tag type.

    The tag recognition process of the parser gives each tag type a precedence level, which is primarily determined by the length of its start delimiter. A tag type with a more specific start delimiter is chosen in preference to one with a less specific start delimiter, assuming they both share the same prefix. If two tag types have exactly the same start delimiter, the one which was registered later has the higher precedence.

    The two special tag types StartTagType.UNREGISTERED and EndTagType.UNREGISTERED represent tags that do not match the syntax of any other tag type. They have the lowest precedence of all the tag types. The Tag.isUnregistered() method provides a detailed explanation of unregistered tags.

    See the documentation of the tag parsing process for more information on how each tag is identified by the parser.

    Note that the standard HTML element names do not represent different tag types. All standard HTML tags have a tag type of StartTagType.NORMAL or EndTagType.NORMAL, and are also referred to as normal tags.

    Apart from the registration related methods, all of the methods in this class and its subclasses relate to the implementation of custom tag types and are not relevant to the majority of users who just use the predefined tag types.

    For perfomance reasons, this library only allows tag types that start with a '<' character. The character following this defines the immediate subclass of the tag type. An EndTagType always has a slash ('/') as the second character, while a StartTagType has any character other than a slash as the second character. This definition means that tag types which are not intuitively classified as either start tag types or end tag types (such as an HTML comment) are mostly classified as start tag types.

    Every method in this and the StartTagType and EndTagType abstract classes can be categorised as one of the following:

    Properties:
    Simple properties (marked final) that were either specified as parameters during construction or are derived from those parameters.
    Abstract implementation methods:
    Methods that must be implemented in a subclass.
    Default implementation methods:
    Methods (not marked final) that implement common behaviour, but may be overridden in a subclass.
    Implementation assistance methods:
    Protected methods that provide low-level functionality and are only of use within other implementation methods.
    Registration related methods:
    Utility methods (marked final) relating to the registration of tag type instances.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract Tag constructTagAt​(Source source, int pos)
      Constructs a tag of this type at the specified position in the specified source document if it matches all of the required features.
      void deregister()
      Deregisters this tag type.
      java.lang.String getClosingDelimiter()
      Returns the character sequence that marks the end of the tag.
      java.lang.String getDescription()
      Returns a description of this tag type useful for debugging purposes.
      protected java.lang.String getNamePrefix()
      Returns the name prefix required by this tag type.
      static java.util.List<TagType> getRegisteredTagTypes()
      Returns a list of all the currently registered tag types in order of lowest to highest precedence.
      java.lang.String getStartDelimiter()
      Returns the character sequence that marks the start of the tag.
      static TagType[] getTagTypesIgnoringEnclosedMarkup()
      Returns an array of all the tag types inside which the parser ignores all non-server tags in parse on demand mode.
      boolean isServerTag()
      Indicates whether this tag type represents a server tag.
      protected boolean isValidPosition​(Source source, int pos, int[] fullSequentialParseData)
      Indicates whether a tag of this type is valid in the specified position of the specified source document.
      void register()
      Registers this tag type for recognition by the parser.
      static void setTagTypesIgnoringEnclosedMarkup​(TagType[] tagTypes)
      Sets the tag types inside which the parser ignores all non-server tags.
      protected boolean tagEncloses​(Source source, int pos)
      Indicates whether a tag of this type encloses the specified position of the specified source document.
      java.lang.String toString()
      Returns a string representation of this object useful for debugging purposes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait