Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-04

oracle.javatools.parser.html
Class TagLexer

java.lang.Object
  extended by oracle.javatools.parser.AbstractLexer
      extended by oracle.javatools.parser.html.TagLexer
All Implemented Interfaces:
TagTokens, Lexer

public class TagLexer
extends AbstractLexer
implements TagTokens

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.

See Also:
Lexer, TagTokens

Nested Class Summary
 
Nested classes/interfaces inherited from class oracle.javatools.parser.AbstractLexer
AbstractLexer.DefaultLexerToken
 
Field Summary
protected  boolean recognizeEmbeddedTags
          Whether to recognize embedded tags.
protected  boolean recognizeJSP
          Whether to recognize JSP tags or not.
 
Fields inherited from class oracle.javatools.parser.AbstractLexer
currentPos, textBuffer
 
Fields inherited from interface oracle.javatools.parser.html.TagTokens
TK_ATTRIBUTE_NAME, TK_ATTRIBUTE_NAME_EMBEDDED, TK_ATTRIBUTE_VALUE, TK_ATTRIBUTE_VALUE_EMBEDDED, TK_ELEMENT_NAME, TK_SYMBOL
 
Fields inherited from interface oracle.javatools.parser.Lexer
TK_EOF, TK_NOT_FOUND
 
Constructor Summary
TagLexer()
          Constructs a default TagLexer with a starting position of 0.
 
Method Summary
 void backup()
          Unlexes the last found token.
protected  boolean isEmbeddedTagStart(int searchPosition)
          Utility routine to determine whether the given search position is the start of an embedded tag.
 int lex(LexerToken lexedToken)
          Scans the text buffer at the current position and returns the token that was found.
 void setPosition(int offset)
          Sets the current lex (read) position to the given offset in the buffer.
 void setRecognizeEmbeddedTags(boolean recognizeEmbeddedTags)
          Sets whether the lexer should recognize embedded HTML or JSP expression tags within an attribute value.
 void setRecognizeJSP(boolean recognizeJSP)
          Sets whether the TagLexer should recognize JSP tag symbols.
 void setRecognizeSlash(boolean recognizeSlash)
          Sets whether the TagLexer should generate a symbol token for the forward slash character
 void setSkipSymbols(boolean skipSymbols)
          Sets whether the TagLexer should generate tokens for Java comments.
protected  void skipEmbeddedTag()
          Utility routine to skip over a found embedded tag.
protected  void skipHTMLTag()
          Utility routine which scans through the text buffer to find the end of an HTML tag.
protected  void skipJSPEL()
          Utility routine which scans through the text buffer to find the end of a JSP EL expression.
protected  void skipJSPScriplet()
          Utility routine which scans through the text buffer to find the end of a JSP scriplet tag.
 int skipNameOrValue(boolean recognizeOpenSquareBracket)
          Utility routine which scans through the text buffer to find the end of a name or value based on whitespace.
static java.lang.String tokenToString(int token)
          Utility routine to map the token to a string representation of the token (for debug printing.)
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.)
 
Methods inherited from class oracle.javatools.parser.AbstractLexer
createLexerToken, getTextBuffer, setTextBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

recognizeJSP

protected boolean recognizeJSP
Whether to recognize JSP tags or not.


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

Parameters:
recognizeSlash - true to generate a symbol token for slash

lex

public int lex(LexerToken lexedToken)
Scans the text buffer at the current position and returns the token that was found. The token and offset information is also stored in the lexedToken instance passed in to the call.

Specified by:
lex in interface Lexer
Specified by:
lex in class AbstractLexer
Parameters:
lexedToken - the instance passed in where token info is stored
Returns:
the token that was found, same as calling lexedToken.getToken() (for convenience)

backup

public void backup()
Unlexes the last found token. The next call to lex() will return the last token and offset information found.

Specified by:
backup in interface Lexer
Specified by:
backup in class AbstractLexer

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.

Specified by:
setPosition in interface Lexer
Overrides:
setPosition in class AbstractLexer
Parameters:
offset - the offset for the next lex() operation.

skipNameOrValue

public int skipNameOrValue(boolean recognizeOpenSquareBracket)
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.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1)

E13403-04

Copyright © 1997, 2010, Oracle. All rights reserved.