Class DirectTagReader

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

public class DirectTagReader extends FilterReader
A Reader that is aware of embedded tags. An example is processing a JSP page, where java is embededd using "invalid input: '<'%...%>". 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 Details

    • ESCAPE_CHARACTER

      public static final char ESCAPE_CHARACTER
      See Also:
    • DefaultEscapeMap

      public static final Map DefaultEscapeMap
  • Constructor Details

  • Method Details

    • escape

      public static String escape(String value)
    • basicRead

      protected int basicRead() throws IOException
      Read from either the read buffer or the underlying stream.
      Returns:
      The next character available frm the read buffer or underlying stream.
      Throws:
      IOException
    • getHandler

      protected IDirectTagHandler getHandler()
    • isSpecialTag

      protected boolean isSpecialTag(String tag)
    • read

      public int read() throws IOException
      Read a character until we encounter a tag.
      Overrides:
      read in class FilterReader
      Throws:
      IOException
      See Also:
    • read

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

      protected int scanEndTag() throws IOException
      Throws:
      IOException
    • scanTag

      protected int scanTag() throws 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:
      IOException
    • scanTagContent

      protected int scanTagContent() throws IOException
      Scan the content between start and end tag and process the result.
      Throws:
      IOException
    • setEndTag

      public void setEndTag(String tag)
    • setStartTag

      public void setStartTag(String tag)
    • tagRead

      protected int tagRead() throws 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:
      IOException
    • unread

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

      protected void unread(int c)