net.sourceforge.stripes.tag.layout
Class LayoutWriter

java.lang.Object
  extended by java.io.Writer
      extended by net.sourceforge.stripes.tag.layout.LayoutWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class LayoutWriter
extends Writer

A writer that wraps around the normal JSP writer with the ability to silence the output temporarily. This is required to prevent the non-layout contents of a LayoutDefinitionTag from rendering more than once when LayoutRenderTags and LayoutComponentTags are nested within it. The definition tag silences output during a component render phase, and the component that wishes to render turns output back on during its body evaluation.

Since:
Stripes 1.5.4
Author:
Ben Gunter

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
LayoutWriter(JspWriter out)
          Create a new layout writer that wraps the given JSP writer.
 
Method Summary
 void clear()
          Calls JspWriter.clear() on the wrapped JSP writer.
 void close()
           
 String closeBuffer(PageContext pageContext)
          Flush the page context's output buffer and resume sending output to the writer that was receiving output prior to calling openBuffer(PageContext).
 void flush()
           
protected  Writer getOut()
          Get the writer to which output is currently being written.
 boolean isSilent()
          If true, then discard all output.
 void openBuffer(PageContext pageContext)
          Flush the page context's output buffer and redirect output into a buffer.
 void setSilent(boolean silent, PageContext pageContext)
          Enable or disable silent mode.
protected  void tryFlush(PageContext pageContext)
          Try to flush the page context's output buffer.
 void write(char[] cbuf, int off, int len)
           
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayoutWriter

public LayoutWriter(JspWriter out)
Create a new layout writer that wraps the given JSP writer.

Parameters:
out - The JSP writer to which output will be written.
Method Detail

getOut

protected Writer getOut()
Get the writer to which output is currently being written.


isSilent

public boolean isSilent()
If true, then discard all output. If false, then resume sending output to the JSP writer.


setSilent

public void setSilent(boolean silent,
                      PageContext pageContext)
               throws IOException
Enable or disable silent mode. The output buffer for the given page context will be flushed before silent mode is enabled to ensure all buffered data are written.

Parameters:
silent - True to silence output, false to enable output.
pageContext - The page context in use at the time output is to be silenced.
Throws:
IOException - If an error occurs writing to output.

openBuffer

public void openBuffer(PageContext pageContext)
Flush the page context's output buffer and redirect output into a buffer. The buffer can be closed and its contents retrieved by calling closeBuffer(PageContext).


closeBuffer

public String closeBuffer(PageContext pageContext)
Flush the page context's output buffer and resume sending output to the writer that was receiving output prior to calling openBuffer(PageContext).

Returns:
The buffer's contents.

tryFlush

protected void tryFlush(PageContext pageContext)
Try to flush the page context's output buffer. If an exception is thrown, just log it.


close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

clear

public void clear()
           throws IOException
Calls JspWriter.clear() on the wrapped JSP writer.

Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException


© Copyright 2005-2006, Stripes Development Team.