com.opensymphony.module.sitemesh.html.tokenizer
Class Parser

java.lang.Object
  extended byLexer
      extended bycom.opensymphony.module.sitemesh.html.tokenizer.Parser
All Implemented Interfaces:
Tag, Text

class Parser
extends Lexer
implements Text, Tag

Looks for patterns of tokens in the Lexer and translates these to calls to pass to the TokenHandler.

Author:
Joe Walnes
See Also:
TagTokenizer

Field Summary
private  CharArray attributeBuffer
           
private  List attributes
           
static short EQUALS
           
static short GT
           
private  TokenHandler handler
           
private  char[] input
           
private  int length
           
static short LT
           
static short LT_CLOSE_MAGIC_COMMENT
           
static short LT_OPEN_MAGIC_COMMENT
           
private  String name
           
private  int position
           
private  String pushbackText
           
private  int pushbackToken
           
static short QUOTE
           
static short QUOTED
           
static short SLASH
           
static short TEXT
           
private  int type
           
static short WHITESPACE
           
static short WORD
           
 
Fields inherited from interface com.opensymphony.module.sitemesh.html.Tag
CLOSE, CLOSE_MAGIC_COMMENT, EMPTY, OPEN, OPEN_MAGIC_COMMENT
 
Constructor Summary
Parser(char[] input, TokenHandler handler)
           
 
Method Summary
 int getAttributeCount()
           
 String getAttributeName(int index)
           
 String getAttributeValue(int index)
           
 String getAttributeValue(String name)
           
 String getContents()
          Get the complete contents of the text block, preserving original formatting.
 String getName()
          Name of tag (ie.
 int getType()
          Type of tag:
<blah> - Type.OPEN
</blah> - Type.CLOSE
<blah/> - Type.EMPTY
 boolean hasAttribute(String name)
           
private  void parseAttribute()
           
 void parsedAttribute(String name, String value, boolean quoted)
           
 void parsedTag(int type, String name, int start, int length)
           
 void parsedText(int position, int length)
           
private  void parseFullTag(int type, String name, int start)
           
private  void parseTag(int type)
           
private  void pushBack(int next)
           
protected  void reportError(String message, int line, int column)
           
private  void skipWhiteSpace()
           
 void start()
           
private  String text()
           
 void writeTo(CharArray out)
          Write out the complete contents of the text block, preserving original formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributeBuffer

private final CharArray attributeBuffer

pushbackToken

private int pushbackToken

pushbackText

private String pushbackText

SLASH

public static final short SLASH
See Also:
Constant Field Values

WHITESPACE

public static final short WHITESPACE
See Also:
Constant Field Values

EQUALS

public static final short EQUALS
See Also:
Constant Field Values

QUOTE

public static final short QUOTE
See Also:
Constant Field Values

WORD

public static final short WORD
See Also:
Constant Field Values

TEXT

public static final short TEXT
See Also:
Constant Field Values

QUOTED

public static final short QUOTED
See Also:
Constant Field Values

LT

public static final short LT
See Also:
Constant Field Values

GT

public static final short GT
See Also:
Constant Field Values

LT_OPEN_MAGIC_COMMENT

public static final short LT_OPEN_MAGIC_COMMENT
See Also:
Constant Field Values

LT_CLOSE_MAGIC_COMMENT

public static final short LT_CLOSE_MAGIC_COMMENT
See Also:
Constant Field Values

input

private final char[] input

handler

private TokenHandler handler

position

private int position

length

private int length

name

private String name

type

private int type

attributes

private final List attributes
Constructor Detail

Parser

public Parser(char[] input,
              TokenHandler handler)
Method Detail

text

private String text()

skipWhiteSpace

private void skipWhiteSpace()
                     throws IOException
Throws:
IOException

pushBack

private void pushBack(int next)

start

public void start()

parseTag

private void parseTag(int type)
               throws IOException
Throws:
IOException

parseFullTag

private void parseFullTag(int type,
                          String name,
                          int start)
                   throws IOException
Throws:
IOException

parseAttribute

private void parseAttribute()
                     throws IOException
Throws:
IOException

parsedText

public void parsedText(int position,
                       int length)

parsedTag

public void parsedTag(int type,
                      String name,
                      int start,
                      int length)

parsedAttribute

public void parsedAttribute(String name,
                            String value,
                            boolean quoted)

reportError

protected void reportError(String message,
                           int line,
                           int column)

getName

public String getName()
Description copied from interface: Tag
Name of tag (ie. element name).

Specified by:
getName in interface Tag

getType

public int getType()
Description copied from interface: Tag
Type of tag:
<blah> - Type.OPEN
</blah> - Type.CLOSE
<blah/> - Type.EMPTY

Specified by:
getType in interface Tag

getContents

public String getContents()
Description copied from interface: Text
Get the complete contents of the text block, preserving original formatting. This has a slight overhead in that it needs to construct a String. For improved performance, use writeTo() instead.

Specified by:
getContents in interface Text
See Also:
Text.writeTo(com.opensymphony.module.sitemesh.html.util.CharArray)

writeTo

public void writeTo(CharArray out)
Description copied from interface: Text
Write out the complete contents of the text block, preserving original formatting.

Specified by:
writeTo in interface Text

getAttributeCount

public int getAttributeCount()
Specified by:
getAttributeCount in interface Tag

getAttributeName

public String getAttributeName(int index)
Specified by:
getAttributeName in interface Tag

getAttributeValue

public String getAttributeValue(int index)
Specified by:
getAttributeValue in interface Tag

getAttributeValue

public String getAttributeValue(String name)
Specified by:
getAttributeValue in interface Tag

hasAttribute

public boolean hasAttribute(String name)
Specified by:
hasAttribute in interface Tag

www.opensymphony.com/sitemesh/