Package de.intarsys.tools.reader
Class DirectTagReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.FilterReader
-
- de.intarsys.tools.reader.DirectTagReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
- Direct Known Subclasses:
EntityDecoder
public class DirectTagReader extends java.io.FilterReaderAReaderthat is aware of embedded tags. An example is processing a JSP page, where java is embededd using "<%...%>". After recognizing such a tag, the associatedIDirectTagHandleris informed to handle the tag. After handling, the result of theIDirectTagHandleris streamd as a replacement for the tag itself. After streaming the processed tag content, reading the input continues as normal.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.MapDefaultEscapeMapstatic charESCAPE_CHARACTER
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intbasicRead()Read from either the read buffer or the underlying stream.static java.lang.Stringescape(java.lang.String value)protected IDirectTagHandlergetHandler()protected booleanisSpecialTag(java.lang.String tag)intread()Read a character until we encounter a tag.intread(char[] cbuf, int off, int len)protected intscanEndTag()protected intscanTag()Scan the stream for tagged content.protected intscanTagContent()Scan the content between start and end tag and process the result.voidsetEndTag(java.lang.String tag)voidsetStartTag(java.lang.String tag)protected inttagRead()Read the underlying stream until the end tag is encountered.protected voidunread(char[] chars, int start, int len)protected voidunread(int c)
-
-
-
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.IOExceptionRead 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.IOExceptionRead a character until we encounter a tag.- Overrides:
readin classjava.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:
readin classjava.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.IOExceptionScan 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.IOExceptionScan 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.IOExceptionRead 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)
-
-