KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > html > HtmlResponseWriter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * Resin Open Source 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, or any warranty
16  * of NON-INFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Resin Open Source; if not, write to the
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsf.html;
30
31 import java.io.*;
32
33 import javax.faces.component.*;
34 import javax.faces.context.*;
35 import javax.faces.render.*;
36
37 public class HtmlResponseWriter extends ResponseWriter
38 {
39   private String JavaDoc _contentType;
40   private String JavaDoc _encoding;
41   
42   private Writer _out;
43   private boolean _inElement;
44
45   HtmlResponseWriter(Writer out, String JavaDoc contentType, String JavaDoc encoding)
46   {
47     _out = out;
48     _contentType = contentType;
49     _encoding = encoding;
50   }
51
52   public void write(char []buffer, int offset, int length)
53     throws IOException
54   {
55     if (_inElement)
56       closeElement();
57     
58     _out.write(buffer, offset, length);
59   }
60
61   public void write(char ch)
62     throws IOException
63   {
64     if (_inElement)
65       closeElement();
66     
67     _out.write(ch);
68   }
69
70   public void write(String JavaDoc v)
71     throws IOException
72   {
73     if (_inElement)
74       closeElement();
75     
76     _out.write(v);
77   }
78   
79   public String JavaDoc getContentType()
80   {
81     return _contentType;
82   }
83
84   public String JavaDoc getCharacterEncoding()
85   {
86     return _encoding;
87   }
88
89   public void flush()
90     throws IOException
91   {
92     _out.flush();
93   }
94
95   public void startDocument()
96     throws IOException
97   {
98   }
99
100   public void endDocument()
101     throws IOException
102   {
103   }
104
105   public void startElement(String JavaDoc name, UIComponent component)
106     throws IOException
107   {
108     if (_inElement)
109       closeElement();
110     
111     _out.write("<");
112     _out.write(name);
113     _inElement = true;
114   }
115
116   public void endElement(String JavaDoc name)
117     throws IOException
118   {
119     if (_inElement)
120       closeElement();
121     
122     _out.write("</");
123     _out.write(name);
124     _out.write(">");
125   }
126
127   public void writeAttribute(String JavaDoc name,
128                  Object JavaDoc value,
129                  String JavaDoc property)
130     throws IOException
131   {
132     _out.write(' ');
133     _out.write(name);
134     _out.write("=\"");
135     _out.write(String.valueOf(value));
136     _out.write("\"");
137   }
138
139   public void writeURIAttribute(String JavaDoc name,
140                 Object JavaDoc value,
141                 String JavaDoc property)
142     throws IOException
143   {
144     writeAttribute(name, value, property);
145   }
146
147   public void writeComment(Object JavaDoc comment)
148     throws IOException
149   {
150     if (_inElement)
151       closeElement();
152     
153     _out.write("<!--");
154     _out.write(String.valueOf(comment));
155     _out.write("-->");
156   }
157
158   public void writeText(Object JavaDoc text,
159             String JavaDoc property)
160     throws IOException
161   {
162     if (_inElement)
163       closeElement();
164     
165     _out.write(String.valueOf(text));
166   }
167
168   public void writeText(char []text, int offset, int length)
169     throws IOException
170   {
171     if (_inElement)
172       closeElement();
173     
174     _out.write(text, offset, length);
175   }
176
177   public ResponseWriter cloneWithWriter(Writer out)
178   {
179     return new HtmlResponseWriter(out, _contentType, _encoding);
180   }
181
182   private void closeElement()
183     throws IOException
184   {
185     _out.write(">");
186     _inElement = false;
187   }
188
189   public void close()
190     throws IOException
191   {
192   }
193
194   public String JavaDoc toString()
195   {
196     return "HtmlResponseWriter[]";
197   }
198 }
199
Popular Tags