Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
au.id.jericho.lib.html.Segment
au.id.jericho.lib.html.Tag
StartTag
or EndTag
in a specific source document.
Take the following HTML segment as an example:
<p>This is a sample paragraph.</p>
The "<p>
" is represented by a StartTag
object, and the "</p>
" is represented by an EndTag
object,
both of which are subclasses of the Tag
class.
The whole segment, including the start tag, its corresponding end tag and all of the content in between, is represented by an Element
object.
<
' character found in the source document is considered to be the start of a tag.
The characters following it are compared with the start delimiters
of all the registered tag types, and a list of matching tag types
is determined.
TagType.isValidPosition(Source, int pos, int[] fullSequentialParseData)
method is responsible for this check
and has a common default implementation for all tag types
(although custom tag types can override it if necessary).
Its behaviour differs depending on whether or not a full sequential parse is peformed.
See the documentation of the isValidPosition
method for full details.
TagType.constructTagAt(Source, int pos)
method of the candidate tag type.
This method returns a valid Tag
object if all conditions of the candidate tag type are met, otherwise it returns
null
and the process continues with the next candidate tag type.
>
' character is taken to be an unregistered tag.
Some tag search methods ignore unregistered tags. See the isUnregistered()
method for more information.
See the documentation of the TagType
class for more details on how tags are recognised.
Source
and Segment
classes, and can be generally categorised as follows:
findNextTag()
findPreviousTag()
Segment.findAllElements()
Segment.findAllTags()
Source.getTagAt(int pos)
Source.findPreviousTag(int pos)
Source.findNextTag(int pos)
Source.findEnclosingTag(int pos)
Segment.findAllStartTags()
Source.findPreviousStartTag(int pos)
Source.findNextStartTag(int pos)
Source.findPreviousEndTag(int pos)
Source.findNextEndTag(int pos)
name
name:
Segment.findAllElements(String name)
Segment.findAllStartTags(String name)
Source.findPreviousStartTag(int pos, String name)
Source.findNextStartTag(int pos, String name)
Source.findPreviousEndTag(int pos, String name)
Source.findNextEndTag(int pos, String name)
Source.findNextEndTag(int pos, String name, EndTagType)
tagType
typeStartTagType
TagType
Segment.findAllElements(StartTagType)
Segment.findAllTags(TagType)
Source.findPreviousTag(int pos, TagType)
Source.findNextTag(int pos, TagType)
Source.findEnclosingTag(int pos, TagType)
Source.findNextEndTag(int pos, String name, EndTagType)
Segment.findAllStartTags(String attributeName, String value, boolean valueCaseSensitive)
Source.findNextStartTag(int pos, String attributeName, String value, boolean valueCaseSensitive)
Fields inherited from interface au.id.jericho.lib.html.HTMLElementName | |
A , ABBR , ACRONYM , ADDRESS , APPLET , AREA , B , BASE , BASEFONT , BDO , BIG , BLOCKQUOTE , BODY , BR , BUTTON , CAPTION , CENTER , CITE , CODE , COL , COLGROUP , DD , DEL , DFN , DIR , DIV , DL , DT , EM , FIELDSET , FONT , FORM , FRAME , FRAMESET , H1 , H2 , H3 , H4 , H5 , H6 , HEAD , HR , HTML , I , IFRAME , IMG , INPUT , INS , ISINDEX , KBD , LABEL , LEGEND , LI , LINK , MAP , MENU , META , NOFRAMES , NOSCRIPT , OBJECT , OL , OPTGROUP , OPTION , P , PARAM , PRE , Q , S , SAMP , SCRIPT , SELECT , SMALL , SPAN , STRIKE , STRONG , STYLE , SUB , SUP , TABLE , TBODY , TD , TEXTAREA , TFOOT , TH , THEAD , TITLE , TR , TT , U , UL , VAR |
Method Summary | |
Tag |
|
Tag |
|
abstract Element |
|
String |
|
Segment |
|
abstract TagType |
|
Object |
|
abstract boolean |
|
static boolean | |
static boolean |
|
static boolean |
|
void |
|
abstract String |
|
Methods inherited from class au.id.jericho.lib.html.Segment | |
charAt , compareTo , encloses , encloses , equals , extractText , extractText , findAllCharacterReferences , findAllElements , findAllElements , findAllElements , findAllElements , findAllStartTags , findAllStartTags , findAllStartTags , findAllTags , findAllTags , findFormControls , findFormFields , getBegin , getChildElements , getDebugInfo , getEnd , getRenderer , getTextExtractor , hashCode , ignoreWhenParsing , isWhiteSpace , isWhiteSpace , length , parseAttributes , subSequence , toString |
public Tag findNextTag()
Returns the next tag in the source document. If a full sequential parse has been performed, this method is very efficient. If not, it is equivalent tosource.
findNextTag
(
getBegin()
+1)
. See theTag
class documentation for more details about the behaviour of this method.
- Returns:
- the next tag in the source document, or
null
if this is the last tag.
public Tag findPreviousTag()
Returns the previous tag in the source document. If a full sequential parse has been performed, this method is very efficient. If not, it is equivalent tosource.
findPreviousTag
(
getBegin()
-1)
. See theTag
class documentation for more details about the behaviour of this method.
- Returns:
- the previous tag in the source document, or
null
if this is the first tag.
public abstract Element getElement()
Returns the element that is started or ended by this tag.StartTag.getElement()
is guaranteed notnull
.EndTag.getElement()
can returnnull
if the end tag is not properly matched to a start tag.
- Returns:
- the element that is started or ended by this tag.
public final String getName()
Returns the name of this tag, always in lower case. The name always starts with the name prefix defined in this tag's type. For some tag types, the name consists only of this prefix, while in others it must be followed by a valid XML name (seeStartTagType.isNameAfterPrefixRequired()
). If the name is equal to one of the constants defined in theHTMLElementName
interface, this method is guaranteed to return the constant itself. This allows comparisons to be performed using the==
operator instead of the less efficientString.equals(Object)
method. For example, the following expression can be used to test whether aStartTag
is from aSELECT
element:startTag.getName()==HTMLElementName.SELECT
To get the name of this tag in its original case, usegetNameSegment()
.toString()
.
- Returns:
- the name of this tag, always in lower case.
public Segment getNameSegment()
Returns the segment spanning the name of this tag. The codegetNameSegment().toString()
can be used to retrieve the name of this tag in its original case. Every call to this method constructs a newSegment
object.
- Returns:
- the segment spanning the name of this tag.
- See Also:
getName()
public abstract TagType getTagType()
Returns the type of this tag.
- Returns:
- the type of this tag.
public Object getUserData()
Returns the general purpose user data object that has previously been associated with this tag via thesetUserData(Object)
method. IfsetUserData(Object)
has not been called, this method returnsnull
.
- Returns:
- the generic data object that has previously been associated with this tag via the
setUserData(Object)
method.
public abstract boolean isUnregistered()
Indicates whether this tag has a syntax that does not match any of the registered tag types. The only requirement of an unregistered tag type is that it starts with '<
' and there is a closing '>
' character at some position after it in the source document. The absence or presence of a '/
' character after the initial '<
' determines whether an unregistered tag is respectively aStartTag
with a type ofStartTagType.UNREGISTERED
or anEndTag
with a type ofEndTagType.UNREGISTERED
. There are no restrictions on the characters that might appear between these delimiters, including other '<
' characters. This may result in a '>
' character that is identified as the closing delimiter of two separate tags, one an unregistered tag, and the other a tag of any type that begins in the middle of the unregistered tag. As explained below, unregistered tags are usually only found when specifically looking for them, so it is up to the user to detect and deal with any such nonsensical results. Unregistered tags are only returned by theSource.getTagAt(int pos)
method, named search methods, where the specifiedname
matches the first characters inside the tag, and by tag type search methods, where the specifiedtagType
is eitherStartTagType.UNREGISTERED
orEndTagType.UNREGISTERED
. Open tag searches and other searches always ignore unregistered tags, although every discovery of an unregistered tag is logged by the parser. The logic behind this design is that unregistered tag types are usually the result of a '<
' character in the text that was mistakenly left unencoded, or a less-than operator inside a script, or some other occurrence which is of no interest to the user. By returning unregistered tags in named and tag type search methods, the library allows the user to specifically search for tags with a certain syntax that does not match any existingTagType
. This expediency feature avoids the need for the user to create a custom tag type to define the syntax before searching for these tags. By not returning unregistered tags in the less specific search methods, it is providing only the information that most users are interested in.
- Returns:
true
if this tag has a syntax that does not match any of the registered tag types, otherwisefalse
.
public static final boolean isXMLName(CharSequence text)
Indicates whether the specified text is a valid XML Name. This implementation first checks that the first character of the specified text is a valid XML Name start character as defined by theisXMLNameStartChar(char)
method, and then checks that the rest of the characters are valid XML Name characters as defined by theisXMLNameChar(char)
method. Note that this implementation does not exactly adhere to the formal definition of an XML Name, but the differences are unlikely to be significant in real-world XML or HTML documents.
- Parameters:
text
- the text to test.
- Returns:
true
if the specified text is a valid XML Name, otherwisefalse
.
- See Also:
Source.findNameEnd(int pos)
public static final boolean isXMLNameChar(char ch)
Indicates whether the specified character is valid anywhere in an XML Name. The XML 1.0 specification section 2.3 uses the entityNameChar
to represent this set of characters, which is defined as(Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender)
. This method uses the expressionCharacter.isLetterOrDigit(ch) || ch=='.' || ch=='-' || ch=='_' || ch==':'
. Note that there are many differences between these definitions, but these differences are unlikely to be significant in real-world XML or HTML documents.
- Parameters:
ch
- the character to test.
- Returns:
true
if the specified character is valid anywhere in an XML Name, otherwisefalse
.
- See Also:
Source.findNameEnd(int pos)
public static final boolean isXMLNameStartChar(char ch)
Indicates whether the specified character is valid at the start of an XML Name. The XML 1.0 specification section 2.3 defines aName
as starting with one of the characters(Letter | '_' | ':')
. This method uses the expressionCharacter.isLetter(ch) || ch=='_' || ch==':'
. Note that there are many differences between theCharacter.isLetter()
definition of a Letter and the XML definition of a Letter, but these differences are unlikely to be significant in real-world XML or HTML documents.
- Parameters:
ch
- the character to test.
- Returns:
true
if the specified character is valid at the start of an XML Name, otherwisefalse
.
- See Also:
Source.findNameEnd(int pos)
public void setUserData(Object userData)
Associates the specified general purpose user data object with this tag. This property can be useful for applications that need to associate extra information with tags. The object can be retrieved later via thegetUserData()
method.
- Parameters:
userData
- general purpose user data of any type.
public abstract String tidy()
Returns an XML representation of this tag. This is an abstract method which is implemented in theStartTag
andEndTag
subclasses. See the documentation of theStartTag.tidy()
andEndTag.tidy()
methods for details.
- Returns:
- an XML representation of this tag.