KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > format > render > AbstractRenderer


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9
10 package org.jboss.portal.format.render;
11
12 import java.io.IOException JavaDoc;
13 import java.io.Writer JavaDoc;
14
15 import org.apache.log4j.Logger;
16
17 /**
18  * An abstract renderer.
19  */

20 public abstract class AbstractRenderer
21 {
22    
23
24    /** The logger. */
25    protected final Logger log = Logger.getLogger(getClass());
26
27    /** Hold the final result. */
28    protected Writer JavaDoc writer = null;
29
30    /** Render. */
31    public abstract void render(char[] chars, int offset, int length);
32
33
34    /** Render. */
35    public void render(String JavaDoc string) {
36       char[] tmp = string.toCharArray();
37       render(tmp, 0, tmp.length);
38    }
39    
40    /**
41     * Set the write that will hold the rendered result.
42     */

43    public final void setWriter(Writer JavaDoc writer)
44    {
45       this.writer = writer;
46    }
47
48    /**
49     * Helper method that catch any IOException throw by the write.
50     */

51    protected final void write(String JavaDoc s)
52    {
53       try
54       {
55          writer.write(s);
56       }
57       catch (IOException JavaDoc e)
58       {
59          log.error("Cannot write to output", e);
60       }
61    }
62
63    /**
64     * @see #write(java.lang.String)
65     */

66    protected final void write(char[] chars, int offset, int length)
67    {
68       try
69       {
70          writer.write(chars, offset, length);
71       }
72       catch (IOException JavaDoc e)
73       {
74          log.error("Cannot write to output", e);
75       }
76    }
77    
78    
79    
80    
81 }
82
Popular Tags