Class StartTagTypeGenericImplementation
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:
-
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
ConstructorsModifierConstructorDescriptionprotected
StartTagTypeGenericImplementation
(String description, String startDelimiter, String closingDelimiter, EndTagType correspondingEndTagType, boolean isServerTag) Constructs a newStartTagTypeGenericImplementation
object with the specified properties.protected
StartTagTypeGenericImplementation
(String description, String startDelimiter, String closingDelimiter, EndTagType correspondingEndTagType, boolean isServerTag, boolean hasAttributes, boolean isNameAfterPrefixRequired) Constructs a newStartTagTypeGenericImplementation
object with the specified properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
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
-
Constructor Details
-
StartTagTypeGenericImplementation
protected StartTagTypeGenericImplementation(String description, String startDelimiter, String closingDelimiter, EndTagType correspondingEndTagType, boolean isServerTag) Constructs a newStartTagTypeGenericImplementation
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(String description, String startDelimiter, String closingDelimiter, EndTagType correspondingEndTagType, boolean isServerTag, boolean hasAttributes, boolean isNameAfterPrefixRequired) Constructs a newStartTagTypeGenericImplementation
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 Details
-
constructTagAt
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:
-
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 returnnull
. -
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
". -
If the tag type has attributes, call
parseAttributes(source,pos,name)
to parse them. Returnnull
if too many errors occur while parsing the attributes. -
Find the end of the tag using the
getEnd(Source, int pos)
method, wherepos
is either the end of the attributes segment or the end of the name depending on whether the tag type has attributes. Returnnull
if the end of the tag can not be found. -
Construct the
StartTag
object using theconstructStartTag(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 classTagType
- Parameters:
source
- theSource
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.
-
If a name is required after the prefix, search for a valid
XML tag name directly after the
name prefix using the
-
getEnd
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.
-