001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.context;
030:
031: import java.io.*;
032:
033: import javax.faces.component.*;
034: import javax.faces.context.*;
035:
036: import javax.servlet.http.*;
037:
038: public class ResponseWriterImpl extends ResponseWriter {
039: private HttpServletResponse _response;
040: private Writer _out;
041: private boolean _inElement;
042:
043: ResponseWriterImpl(HttpServletResponse response, Writer out) {
044: _response = response;
045: _out = out;
046: }
047:
048: public void write(char[] buffer, int offset, int length)
049: throws IOException {
050: _out.write(buffer, offset, length);
051: }
052:
053: public void write(char ch) throws IOException {
054: if (_inElement)
055: closeElement();
056:
057: _out.write(ch);
058: }
059:
060: public String getContentType() {
061: return _response.getContentType();
062: }
063:
064: public String getCharacterEncoding() {
065: return _response.getCharacterEncoding();
066: }
067:
068: public void flush() throws IOException {
069: _out.flush();
070: }
071:
072: public void startDocument() throws IOException {
073: }
074:
075: public void endDocument() throws IOException {
076: }
077:
078: public void startElement(String name, UIComponent component)
079: throws IOException {
080: if (_inElement)
081: closeElement();
082:
083: _out.write("<");
084: _out.write(name);
085: _inElement = true;
086: }
087:
088: public void endElement(String name) throws IOException {
089: if (_inElement)
090: closeElement();
091:
092: _out.write("</");
093: _out.write(name);
094: _out.write(">");
095: }
096:
097: public void writeAttribute(String name, Object value,
098: String property) throws IOException {
099: _out.write(' ');
100: _out.write(name);
101: _out.write("=\"");
102: _out.write(String.valueOf(value));
103: _out.write("\"");
104: }
105:
106: public void writeURIAttribute(String name, Object value,
107: String property) throws IOException {
108: writeAttribute(name, value, property);
109: }
110:
111: public void writeComment(Object comment) throws IOException {
112: if (_inElement)
113: closeElement();
114:
115: _out.write("<!--");
116: _out.write(String.valueOf(comment));
117: _out.write("-->");
118: }
119:
120: public void writeText(Object text, String property)
121: throws IOException {
122: if (_inElement)
123: closeElement();
124:
125: _out.write(String.valueOf(text));
126: }
127:
128: public void writeText(char[] text, int offset, int length)
129: throws IOException {
130: if (_inElement)
131: closeElement();
132:
133: _out.write(text, offset, length);
134: }
135:
136: public ResponseWriter cloneWithWriter(Writer out) {
137: return new ResponseWriterImpl(_response, out);
138: }
139:
140: private void closeElement() throws IOException {
141: _out.write(">");
142: _inElement = false;
143: }
144:
145: public void close() throws IOException {
146: }
147: }
|