org.apache.myfaces.renderkit.html.util
Class ReducedHTMLParser

java.lang.Object
  extended by org.apache.myfaces.renderkit.html.util.ReducedHTMLParser

public class ReducedHTMLParser
extends java.lang.Object

A class which detects the open/close tags in an HTML document and reports them to a listener class.

This is unfortunately necessary when using JSF with JSP, as tags in the body of the document can need to output commands into the document at points earlier than the tag occurred (particularly into the document HEAD section). This can only be implemented by buffering the response and post-processing it to find the relevant HTML tags and modifying the buffer as needed.

This class tries to do the parsing as quickly as possible; many of the details of HTML are not relevant for the purposes this class is used for.

Version:
$Revision: 383052 $ $Date: 2006-03-04 01:26:48 -0500 (Sat, 04 Mar 2006) $

Field Summary
static int BODY_TAG
           
static int HEAD_TAG
           
static int SCRIPT_TAG
           
 
Constructor Summary
ReducedHTMLParser(java.lang.CharSequence s, CallbackListener l)
          Constructor, package-scope for unit testing.
 
Method Summary
(package private)  void closedTag(int startOffset, int endOffset, java.lang.String tagName)
           
(package private)  java.lang.String consumeAttrName()
          Eat up a sequence of chars which form a valid XML attribute name.
(package private)  java.lang.String consumeAttrValue()
          Assuming we have already encountered "attrname=", consume the value part of the attribute definition.
(package private)  java.lang.String consumeElementName()
          Eat up a sequence of chars which form a valid XML element name.
(package private)  void consumeExcept(java.lang.String s)
          Discard all characters in the input until one in the specified string (character-set) is found.
(package private)  boolean consumeMatch(java.lang.String s)
          If the next chars in the input sequence exactly match the specified string then skip over them and return true.
(package private)  java.lang.String consumeNonWhitespace()
          Eat up a sequence of non-whitespace characters and return them.
(package private)  java.lang.String consumeString(char quote)
          Eat up a string which is terminated with the specified quote character.
(package private)  void consumeWhitespace()
          Advance the current parse position over any whitespace characters.
(package private)  int getCurrentLineNumber()
           
(package private)  boolean isFinished()
          Return true if there are no more characters to parse.
(package private)  void openedTag(int startOffset, int endOffset, java.lang.String tagName)
          Invoke a callback method to inform the listener that we have found a start tag.
(package private)  void parse()
          Process the entire input buffer, invoking callbacks on the listener object as appropriate.
static void parse(java.lang.CharSequence seq, CallbackListener l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BODY_TAG

public static final int BODY_TAG
See Also:
Constant Field Values

HEAD_TAG

public static final int HEAD_TAG
See Also:
Constant Field Values

SCRIPT_TAG

public static final int SCRIPT_TAG
See Also:
Constant Field Values
Constructor Detail

ReducedHTMLParser

ReducedHTMLParser(java.lang.CharSequence s,
                  CallbackListener l)
Constructor, package-scope for unit testing.

Parameters:
s - is the sequence of chars to parse.
l - is the listener to invoke callbacks on.
Method Detail

parse

public static void parse(java.lang.CharSequence seq,
                         CallbackListener l)

isFinished

boolean isFinished()
Return true if there are no more characters to parse.


getCurrentLineNumber

int getCurrentLineNumber()

consumeWhitespace

void consumeWhitespace()
Advance the current parse position over any whitespace characters.


consumeNonWhitespace

java.lang.String consumeNonWhitespace()
Eat up a sequence of non-whitespace characters and return them.


consumeMatch

boolean consumeMatch(java.lang.String s)
If the next chars in the input sequence exactly match the specified string then skip over them and return true.

If there is not a match then leave the current parse position unchanged and return false.

Parameters:
s - is the exact string to match.
Returns:
true if the input contains exactly the param s

consumeElementName

java.lang.String consumeElementName()
Eat up a sequence of chars which form a valid XML element name.

TODO: implement this properly in compliance with spec


consumeAttrName

java.lang.String consumeAttrName()
Eat up a sequence of chars which form a valid XML attribute name.

TODO: implement this properly in compliance with spec


consumeString

java.lang.String consumeString(char quote)
Eat up a string which is terminated with the specified quote character. This means handling escaped quote chars within the string.

This method assumes that the leading quote has already been consumed.


consumeAttrValue

java.lang.String consumeAttrValue()
Assuming we have already encountered "attrname=", consume the value part of the attribute definition. Note that unlike XML, HTML doesn't have to quote its attribute values.

Returns:
the attribute value. If the attr-value was quoted, the returned value will not include the quote chars.

consumeExcept

void consumeExcept(java.lang.String s)
Discard all characters in the input until one in the specified string (character-set) is found.

Parameters:
s - is a set of characters that should not be discarded.

parse

void parse()
Process the entire input buffer, invoking callbacks on the listener object as appropriate.


openedTag

void openedTag(int startOffset,
               int endOffset,
               java.lang.String tagName)
Invoke a callback method to inform the listener that we have found a start tag.

Parameters:
startOffset -
endOffset -
tagName -

closedTag

void closedTag(int startOffset,
               int endOffset,
               java.lang.String tagName)


Copyright 2006 Apache Software Foundation. All Rights Reserved.