KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsf > context > ResponseWriterImpl


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