org.zkoss.zk.ui.render
Class SmartWriter

java.lang.Object
  extended by org.zkoss.zk.ui.render.SmartWriter

public final class SmartWriter
extends java.lang.Object

A writer that is used to simplify the output generation of compoennts. It is mainly used to implement ComponentRenderer.

Spec Note: we cannot extend it from Writer, since we want write(String) to return this object, such that the user can write
sw.write("

Since:
3.0.0
Author:
Dennis.Chen, tomyeh

Constructor Summary
SmartWriter(java.io.Writer writer)
           
 
Method Summary
 void close()
           
 void flush()
           
 SmartWriter write(boolean b)
          Writes a boolean.
 SmartWriter write(byte v)
          Writes a byte.
 SmartWriter write(char c)
          Writes a char.
 SmartWriter write(Component comp)
          Write a component.
 SmartWriter write(double v)
          Writes a double.
 SmartWriter write(float v)
          Writes a float.
 SmartWriter write(int v)
          Writes an integer.
 SmartWriter write(short v)
          Writes a short.
 SmartWriter write(java.lang.String str)
          Write a string.
 SmartWriter write(java.lang.String str, boolean trim)
          Write a string.
 SmartWriter writeAttr(java.lang.String name, java.lang.Object val)
          Writes an attribute.
 SmartWriter writeChildren(Component comp)
          Writes all children.
 SmartWriter writeChildren(Component comp, int from, int to)
          Writes children in the specified range.
 SmartWriter writeComponents(java.util.Collection comps)
          Writes a list of components.
 SmartWriter writeComponents(java.util.List comps, int from, int to)
          Writes a list of component in the specified range.
 SmartWriter writeln()
          Write new line.
 SmartWriter writeln(char c)
          Writes a char with a line feed.
 SmartWriter writeln(Component comp)
          Write a component.
 SmartWriter writeln(java.lang.String str)
          Write a string, and then write a new line.
 SmartWriter writeln(java.lang.String str, boolean trim)
          Write a string, and then write a new line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmartWriter

public SmartWriter(java.io.Writer writer)
Method Detail

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException

write

public SmartWriter write(Component comp)
                  throws java.io.IOException
Write a component. It works even if the component is null.

Throws:
java.io.IOException

writeln

public SmartWriter writeln(Component comp)
                    throws java.io.IOException
Write a component. It works even if the component is null.

Throws:
java.io.IOException

writeChildren

public SmartWriter writeChildren(Component comp)
                          throws java.io.IOException
Writes all children.

Throws:
java.io.IOException

writeChildren

public SmartWriter writeChildren(Component comp,
                                 int from,
                                 int to)
                          throws java.io.IOException
Writes children in the specified range.

Parameters:
from - the first index (included).
to - the last index (included).
Throws:
java.io.IOException

writeComponents

public SmartWriter writeComponents(java.util.Collection comps)
                            throws java.io.IOException
Writes a list of components.

Throws:
java.io.IOException

writeComponents

public SmartWriter writeComponents(java.util.List comps,
                                   int from,
                                   int to)
                            throws java.io.IOException
Writes a list of component in the specified range.

Parameters:
from - the first index (included).
to - the last index (included).
Throws:
java.io.IOException

write

public SmartWriter write(java.lang.String str)
                  throws java.io.IOException
Write a string. If str is null, nothing will be written.

Parameters:
str - a string to be written
Returns:
this object
Throws:
java.io.IOException - if failed to write

writeln

public SmartWriter writeln()
                    throws java.io.IOException
Write new line.

Returns:
this object
Throws:
java.io.IOException - if failed to write

writeln

public SmartWriter writeln(java.lang.String str)
                    throws java.io.IOException
Write a string, and then write a new line. If str is null, nothing will be written.

Parameters:
str - a string to be written
Returns:
this object
Throws:
java.io.IOException - if failed to write

write

public SmartWriter write(java.lang.String str,
                         boolean trim)
                  throws java.io.IOException
Write a string. If trim is true, then a trimed string will be written. If str is null, nothing will be written.

Parameters:
str - a string to be written
trim - trim str when write.
Returns:
this object
Throws:
java.io.IOException - if failed to write

writeln

public SmartWriter writeln(java.lang.String str,
                           boolean trim)
                    throws java.io.IOException
Write a string, and then write a new line. If trim is true, then a trimed string will be written. If str is null, nothing will be written.

Parameters:
str - a string to be written
trim - trim str when write.
Returns:
this object
Throws:
java.io.IOException - if failed to write

write

public SmartWriter write(boolean b)
                  throws java.io.IOException
Writes a boolean.

Throws:
java.io.IOException

write

public SmartWriter write(char c)
                  throws java.io.IOException
Writes a char.

Throws:
java.io.IOException

writeln

public SmartWriter writeln(char c)
                    throws java.io.IOException
Writes a char with a line feed.

Throws:
java.io.IOException

write

public SmartWriter write(byte v)
                  throws java.io.IOException
Writes a byte.

Throws:
java.io.IOException

write

public SmartWriter write(short v)
                  throws java.io.IOException
Writes a short.

Throws:
java.io.IOException

write

public SmartWriter write(int v)
                  throws java.io.IOException
Writes an integer.

Throws:
java.io.IOException

write

public SmartWriter write(float v)
                  throws java.io.IOException
Writes a float.

Throws:
java.io.IOException

write

public SmartWriter write(double v)
                  throws java.io.IOException
Writes a double.

Throws:
java.io.IOException

writeAttr

public SmartWriter writeAttr(java.lang.String name,
                             java.lang.Object val)
                      throws java.io.IOException
Writes an attribute. The output is generated only if val is not null (and not empty).

Throws:
java.io.IOException


Copyright © 2005-2009 Potix Corporation. All Rights Reserved.