01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.format.render;
23:
24: import org.apache.log4j.Logger;
25:
26: import java.io.IOException;
27: import java.io.Writer;
28:
29: /** An abstract renderer. */
30: public abstract class AbstractRenderer {
31:
32: /** The logger. */
33: protected final Logger log = Logger.getLogger(getClass());
34:
35: /** Hold the final result. */
36: protected Writer writer = null;
37:
38: /** Render. */
39: public abstract void render(char[] chars, int offset, int length);
40:
41: /** Render. */
42: public void render(String string) {
43: char[] tmp = string.toCharArray();
44: render(tmp, 0, tmp.length);
45: }
46:
47: /** Set the write that will hold the rendered result. */
48: public final void setWriter(Writer writer) {
49: this .writer = writer;
50: }
51:
52: /** Helper method that catch any IOException throw by the write. */
53: protected final void write(String s) {
54: try {
55: writer.write(s);
56: } catch (IOException e) {
57: log.error("Cannot write to output", e);
58: }
59: }
60:
61: /** @see #write(java.lang.String) */
62: protected final void write(char[] chars, int offset, int length) {
63: try {
64: writer.write(chars, offset, length);
65: } catch (IOException e) {
66: log.error("Cannot write to output", e);
67: }
68: }
69:
70: }
|