StartTagTypeGenericImplementation
Date: 2016-12-04

net.htmlparser.jericho

## Class StartTagTypeGenericImplementation

- java.lang.Object
- - net.htmlparser.jericho.TagType
  - - net.htmlparser.jericho.StartTagType
    - - net.htmlparser.jericho.StartTagTypeGenericImplementation

-     public class StartTagTypeGenericImplementation
      extends StartTagType

  Provides a generic implementation of the abstract `StartTagType` class based on the most common start tag behaviour.

  This class is only of interest to users who wish to create custom tag types.

  The only external difference between this class and its abstract superclass `StartTagType` is that it provides a default implementation of the `constructTagAt(Source, int pos)` method.

  Most of the predefined start tag types are implemented using this class or a subclass of it.

  See Also:
    `EndTagTypeGenericImplementation`

- - ### Field Summary

    - ### Fields inherited from class net.htmlparser.jericho.StartTagType

      `CDATA_SECTION, COMMENT, DOCTYPE_DECLARATION, MARKUP_DECLARATION, NORMAL, SERVER_COMMON, SERVER_COMMON_COMMENT, SERVER_COMMON_ESCAPED, UNREGISTERED, XML_DECLARATION, XML_PROCESSING_INSTRUCTION`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `StartTagTypeGenericImplementation(java.lang.String description, java.lang.String startDelimiter, java.lang.String closingDelimiter, EndTagType correspondingEndTagType, boolean isServerTag)` Constructs a new `StartTagTypeGenericImplementation` object with the specified properties.
    `protected` | `StartTagTypeGenericImplementation(java.lang.String description, java.lang.String startDelimiter, java.lang.String closingDelimiter, EndTagType correspondingEndTagType, boolean isServerTag, boolean hasAttributes, boolean isNameAfterPrefixRequired)` Constructs a new `StartTagTypeGenericImplementation` object with the specified properties.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected 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.
    `protected int` | `getEnd(Source source, int pos)` Returns the end of a tag of this type, starting from the specified position in the specified source document.

    - ### Methods inherited from class net.htmlparser.jericho.StartTagType

      `atEndOfAttributes, constructStartTag, getCorrespondingEndTagType, hasAttributes, isNameAfterPrefixRequired, parseAttributes`

    - ### Methods inherited from class net.htmlparser.jericho.TagType

      `deregister, getClosingDelimiter, getDescription, getNamePrefix, getRegisteredTagTypes, getStartDelimiter, getTagTypesIgnoringEnclosedMarkup, isServerTag, isValidPosition, register, setTagTypesIgnoringEnclosedMarkup, tagEncloses, toString`

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### StartTagTypeGenericImplementation

          protected StartTagTypeGenericImplementation(java.lang.String description,
                                           java.lang.String startDelimiter,
                                           java.lang.String closingDelimiter,
                                           EndTagType correspondingEndTagType,
                                           boolean isServerTag)

      Constructs a new `StartTagTypeGenericImplementation` object with the specified properties.
      (implementation assistance method)

      This is equivalent to calling
      `new` `StartTagTypeGenericImplementation``(description,startDelimiter,closingDelimiter,correspondingEndTagType,isServerTag,false,false)`.

      Parameters:
        `description` - a description of the new start tag type useful for debugging purposes.
        `startDelimiter` - the start delimiter of the new start tag type.
        `closingDelimiter` - the closing delimiter of the new start tag type.
        `correspondingEndTagType` - the corresponding end tag type of the new start tag type.
        `isServerTag` - indicates whether the new start tag type is a server tag.

    - #### StartTagTypeGenericImplementation

          protected StartTagTypeGenericImplementation(java.lang.String description,
                                           java.lang.String startDelimiter,
                                           java.lang.String closingDelimiter,
                                           EndTagType correspondingEndTagType,
                                           boolean isServerTag,
                                           boolean hasAttributes,
                                           boolean isNameAfterPrefixRequired)

      Constructs a new `StartTagTypeGenericImplementation` object with the specified properties.
      (implementation assistance method)
      Parameters:
        `description` - a description of the new start tag type useful for debugging purposes.
        `startDelimiter` - the start delimiter of the new start tag type.
        `closingDelimiter` - the closing delimiter of the new start tag type.
        `correspondingEndTagType` - the corresponding end tag type of the new start tag type.
        `isServerTag` - indicates whether the new start tag type is a server tag.
        `hasAttributes` - indicates whether the new start tag type has attributes.
        `isNameAfterPrefixRequired` - indicates whether a name is required after the prefix.

  - ### Method Detail

    - #### constructTagAt

          protected 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.
      (default implementation method)

      This default implementation performs the following steps:

      1. If a name is required after the prefix, search for a valid XML tag name directly after the name prefix using the `Source.getNameEnd(int pos)` method. If one is found, set the name to include it, otherwise return `null`.
      2. If the last character of the name prefix is a letter (indicating that the prefix includes the full name of the tag), and the character following the prefix in the source text is also a letter or any other valid XML name character, return `null`.
         Example: the source text "`<?xmlt ?>`" should not be recognised as an XML processing instruction, which has the prefix "`<?xml`".
      3. If the tag type has attributes, call `parseAttributes(source,pos,name)` to parse them. Return `null` if too many errors occur while parsing the attributes.
      4. Find the end of the tag using the `getEnd(Source, int pos)` method, where `pos` is either the end of the attributes segment or the end of the name depending on whether the tag type has attributes. Return `null` if the end of the tag can not be found.
      5. Construct the `StartTag` object using the `constructStartTag(Source, int pos, int end, String name, Attributes)` method with the argument values collected over the previous steps.

      See `TagType.constructTagAt(Source, int pos)` for more important information about this method.

      Specified by:
        `constructTagAt` in class `TagType`
      Parameters:
        `source` - the `Source` document.
        `pos` - the position in the source document.
      Returns:
        a tag of this type at the specified position in the specified source document if it meets all of the required features, or `null` if it does not meet the criteria.

    - #### getEnd

          protected int getEnd(Source source,
                   int pos)

      Returns the end of a tag of this type, starting from the specified position in the specified source document.
      (implementation assistance method)

      This default implementation simply searches for the first occurrence of the closing delimiter after the specified position, and returns the position immediately after the end of it.

      If the closing delimiter is not found, the value `-1` is returned.

      Parameters:
        `source` - the `Source` document.
        `pos` - the position in the source document.
      Returns:
        the end of a tag of this type, starting from the specified position in the specified source document, or `-1` if the end of the tag can not be found.