de.intarsys.tools.reader
Class DirectTagReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.FilterReader
          extended by de.intarsys.tools.reader.DirectTagReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable
Direct Known Subclasses:
EntityDecoder

public class DirectTagReader
extends java.io.FilterReader

A Reader that is aware of embedded tags. An example is processing a JSP page, where java is embededd using "<%...%>". After recognizing such a tag, the associated IDirectTagHandler is informed to handle the tag. After handling, the result of the IDirectTagHandler is streamd as a replacement for the tag itself. After streaming the processed tag content, reading the input continues as normal.


Field Summary
static java.util.Map DefaultEscapeMap
           
static char ESCAPE_CHARACTER
           
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
DirectTagReader(java.io.Reader pReader, IDirectTagHandler handler, java.lang.Object context)
           
DirectTagReader(java.io.Reader pReader, IDirectTagHandler handler, java.lang.Object context, boolean escape)
           
 
Method Summary
protected  int basicRead()
          Read from either the read buffer or the underlying stream.
static java.lang.String escape(java.lang.String value)
           
protected  IDirectTagHandler getHandler()
           
protected  boolean isSpecialTag(java.lang.String tag)
           
 int read()
          Read a character until we encounter a tag.
 int read(char[] cbuf, int off, int len)
           
protected  int scanEndTag()
           
protected  int scanTag()
          Scan the stream for tagged content.
protected  int scanTagContent()
          Scan the content between start and end tag and process the result.
 void setEndTag(java.lang.String tag)
           
 void setStartTag(java.lang.String tag)
           
protected  int tagRead()
          Read the underlying stream until the end tag is encountered.
protected  void unread(char[] chars, int start, int len)
           
protected  void unread(int c)
           
 
Methods inherited from class java.io.FilterReader
close, mark, markSupported, ready, reset, skip
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ESCAPE_CHARACTER

public static final char ESCAPE_CHARACTER
See Also:
Constant Field Values

DefaultEscapeMap

public static final java.util.Map DefaultEscapeMap
Constructor Detail

DirectTagReader

public DirectTagReader(java.io.Reader pReader,
                       IDirectTagHandler handler,
                       java.lang.Object context)

DirectTagReader

public DirectTagReader(java.io.Reader pReader,
                       IDirectTagHandler handler,
                       java.lang.Object context,
                       boolean escape)
Method Detail

escape

public static java.lang.String escape(java.lang.String value)

basicRead

protected int basicRead()
                 throws java.io.IOException
Read from either the read buffer or the underlying stream.

Returns:
The next character available frm the read buffer or underlying stream.
Throws:
java.io.IOException

getHandler

protected IDirectTagHandler getHandler()

isSpecialTag

protected boolean isSpecialTag(java.lang.String tag)

read

public int read()
         throws java.io.IOException
Read a character until we encounter a tag.

Overrides:
read in class java.io.FilterReader
Throws:
java.io.IOException
See Also:
Reader.read()

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.FilterReader
Throws:
java.io.IOException

scanEndTag

protected int scanEndTag()
                  throws java.io.IOException
Throws:
java.io.IOException

scanTag

protected int scanTag()
               throws java.io.IOException
Scan the stream for tagged content. We check the presence of the start tag. If found the stream is read until the presence of the end tag. If the start tag is not completely found, we return the literal stream content.

Returns:
Throws:
java.io.IOException

scanTagContent

protected int scanTagContent()
                      throws java.io.IOException
Scan the content between start and end tag and process the result.

Throws:
java.io.IOException

setEndTag

public void setEndTag(java.lang.String tag)

setStartTag

public void setStartTag(java.lang.String tag)

tagRead

protected int tagRead()
               throws java.io.IOException
Read the underlying stream until the end tag is encountered. When we find the end tag, we return -1, anything else is IOException.

Returns:
next char from stream between tags
Throws:
java.io.IOException

unread

protected void unread(char[] chars,
                      int start,
                      int len)

unread

protected void unread(int c)