001: /*
002: Copyright (C) 2003-2006 Know Gate S.L. All rights reserved.
003: C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.http.portlets;
034:
035: import java.util.Hashtable;
036: import java.util.Enumeration;
037: import java.util.Properties;
038: import java.util.Map;
039: import java.util.Locale;
040: import java.util.Locale;
041:
042: import java.io.IOException;
043: import java.io.PrintWriter;
044: import java.io.OutputStream;
045: import java.io.ByteArrayOutputStream;
046: import java.io.UnsupportedEncodingException;
047:
048: import javax.portlet.PortletURL;
049: import javax.portlet.RenderResponse;
050:
051: import javax.servlet.http.HttpServletResponse;
052:
053: import com.knowgate.misc.Gadgets;
054:
055: /**
056: * RenderResponse implementation with output to a StringBuffer
057: * @author Sergio Montoro Ten
058: * @version 1.0
059: */
060:
061: public class StringBufferRenderResponse implements RenderResponse {
062:
063: private Properties oProps;
064: private ByteArrayOutputStream oBuf;
065: private PrintWriter oWrt;
066: private int iBufSize;
067: private String sEncoding;
068:
069: public StringBufferRenderResponse(String encoding) {
070: sEncoding = encoding;
071: iBufSize = 4000;
072: oProps = new Properties();
073: oBuf = new ByteArrayOutputStream(iBufSize);
074: oWrt = new PrintWriter(oBuf);
075: }
076:
077: public void setProperty(String key, String value) {
078: oProps.setProperty(key, value);
079: }
080:
081: public void addProperty(String key, String value) {
082: String sProp = oProps.getProperty(key);
083:
084: if (sProp == null)
085: oProps.setProperty(key, value);
086: else {
087: oProps.remove(key);
088: oProps.setProperty(key, sProp + ";" + value);
089: }
090: }
091:
092: public String encodeURL(String path) {
093: return Gadgets.URLEncode(path);
094: }
095:
096: public String getContentType() {
097: throw new UnsupportedOperationException(
098: "getContentType() not implemented HipergateRenderRequest");
099: }
100:
101: public PortletURL createRenderURL() {
102: throw new UnsupportedOperationException(
103: "createRenderURL() not implemented HipergateRenderRequest");
104: }
105:
106: public PortletURL createActionURL() {
107: throw new UnsupportedOperationException(
108: "createActionURL() not implemented HipergateRenderRequest");
109: }
110:
111: public String getNamespace() {
112: throw new UnsupportedOperationException(
113: "getNamespace() not implemented HipergateRenderRequest");
114: }
115:
116: public void setTitle(String title) {
117: throw new UnsupportedOperationException(
118: "setTitle() not implemented HipergateRenderRequest");
119: }
120:
121: public void setContentType(String type) {
122: throw new UnsupportedOperationException(
123: "setContentType() not implemented HipergateRenderRequest");
124: }
125:
126: public String getCharacterEncoding() {
127: return sEncoding;
128: }
129:
130: public PrintWriter getWriter() throws IOException {
131: return oWrt;
132: }
133:
134: public Locale getLocale() {
135: throw new UnsupportedOperationException(
136: "getLocale() not implemented HipergateRenderRequest");
137: }
138:
139: public void setBufferSize(int size) {
140: throw new UnsupportedOperationException(
141: "setBufferSize() not implemented HipergateRenderRequest");
142: }
143:
144: public int getBufferSize() {
145: return iBufSize;
146: }
147:
148: public void setCharacterEncoding(String encoding) {
149: sEncoding = encoding;
150: }
151:
152: public void flushBuffer() throws IOException {
153: oWrt.flush();
154: }
155:
156: public void resetBuffer() {
157: oBuf.reset();
158: }
159:
160: public boolean isCommitted() {
161: throw new UnsupportedOperationException(
162: "isCommitted() not implemented HipergateRenderRequest");
163: }
164:
165: public void reset() {
166: oBuf.reset();
167: }
168:
169: public OutputStream getPortletOutputStream() throws IOException {
170: return oBuf;
171: }
172:
173: public String toString() {
174: String sRetVal;
175:
176: try {
177: sRetVal = new String(oBuf.toByteArray(), sEncoding);
178: } catch (UnsupportedEncodingException uee) {
179: sRetVal = new String(oBuf.toByteArray());
180: }
181:
182: return sRetVal;
183: } // toString()
184: }
|