oracle.javatools.parser.html
Class TagLexer

The TagLexer is an implementation of the
Lexer interface for lexing an HTML tag. Specifically,
it is used for retrieving the pieces that make up an HTML tag, such
as the element name, the attribute name, or attribute value.

For the purposes of syntax highlighting, the '>', '<' and '='
characters can be returned as tokens by calling
setSkipSymbols(false). For parsing purposes, when you
wish to ignore these delimiter characters, call
setSkipSymbols(true).

Note that even when you enable recognition of JSP tags, you still
need to enable recognition of embedded tags also. This means that
it will properly handle an embedded tag found in an attribute value
while scanning an HTML tag. This does not however check if it is
legal for the embedded tag to be present - that is beyond the scope
of this lexer. It is the caller's responsibility to do so.

Note, if the tags that you are examing with this lexer include
JSP directive tags, make sure to enable JSP recognition, so that
the '*@' characters are recognized as symbol characters instead
of as part of the element names.

recognizeJSP

recognizeEmbeddedTags

protected boolean recognizeEmbeddedTags

Whether to recognize embedded tags.

Constructor Detail

TagLexer

public TagLexer()

Constructs a default TagLexer with a starting
position of 0. Clients must call setTextBuffer() to
initialize the text buffer used for the Lexer. To start lexing
from an offset other than 0, call setPosition().

Method Detail

setSkipSymbols

public void setSkipSymbols(boolean skipSymbols)

Sets whether the TagLexer should generate tokens
for Java comments.

Parameters:

skipSymbols - true to ignore comments in token generation

setRecognizeSlash

public void setRecognizeSlash(boolean recognizeSlash)

Sets whether the TagLexer should generate a symbol
token for the forward slash character

setPosition

public void setPosition(int offset)

Sets the current lex (read) position to the given offset in the
buffer. It is the clients responsibility to ensure that this
offset corresponds to the start of a token, otherwise unexpected
(and incorrect) results may occur.

skipNameOrValue

Utility routine which scans through the text buffer to find the
end of a name or value based on whitespace. Sets the current
position following the end of the name or value, or at the end of
the file.

Returns:

current position following the end of the name or value,
or at the end of the file.

tokenToString

public static java.lang.String tokenToString(int token)

Utility routine to map the token to a string representation of
the token (for debug printing.)

Parameters:

token - the token to map

Returns:

a printable representation of the token

tokenToText

public static java.lang.String tokenToText(int token)

Utility routine to map the token to the original text (if
retrievable) of the token (for debug printing.)

Parameters:

token - the token to map

Returns:

a printable representation of the token

setRecognizeJSP

public void setRecognizeJSP(boolean recognizeJSP)

Sets whether the TagLexer should recognize JSP
tag symbols.

Parameters:

recognizeJSP - true to recognize JSP tag symbol characters

setRecognizeEmbeddedTags

public void setRecognizeEmbeddedTags(boolean recognizeEmbeddedTags)

Sets whether the lexer should recognize embedded HTML or JSP
expression tags within an attribute value. Note, this lexer
simply determines whether an attribute value contains an embedded
tag, it does not determine whether it is legal for it to do so.
Whether it is legal or not is up to the client to determine

Parameters:

recognizeEmbeddedTags - whether to recognize embedded tags

skipHTMLTag

protected void skipHTMLTag()

Utility routine which scans through the text buffer to find
the end of an HTML tag. Sets the current position following
the trailing '>', or at the end of the file.

isEmbeddedTagStart

protected boolean isEmbeddedTagStart(int searchPosition)

Utility routine to determine whether the given search
position is the start of an embedded tag. This only searches
for whether it is the start of a non-comment HTML tag, or
the start of a JSP expression tag.

Parameters:

searchPosition - the offset in the buffer to check for the start

Returns:

true if the offset is the start of an embedded tag

skipEmbeddedTag

protected void skipEmbeddedTag()

Utility routine to skip over a found embedded tag. This assumes
that the caller already found an embedded tag start with
isEmbeddedTagStart(), and that the current position
is still at the start of the embedded tag. This will place the
position at the character after the end of the tag.

skipJSPScriplet

protected void skipJSPScriplet()

Utility routine which scans through the text buffer to find
the end of a JSP scriplet tag. Note that for JSP tags that contain
scriplet code, the %> immediately ends the tag, even if it
is in a String or comment. Note that if the String or comment
is unterminated, the translated *.java file will probably not
be compilable.

skipJSPEL

protected void skipJSPEL()

Utility routine which scans through the text buffer to find
the end of a JSP EL expression. Note that for JSP tags that contain
EL, the '}' immediately ends the tag, even if it
is in a String or comment. Note that if the String or comment
is unterminated, the translated *.java file will probably not
be compilable.