KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > http > portlets > StringBufferRenderResponse


1 /*
2   Copyright (C) 2003-2006 Know Gate S.L. All rights reserved.
3                            C/Oņa, 107 1š2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.http.portlets;
34
35 import java.util.Hashtable JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.Properties JavaDoc;
38 import java.util.Map JavaDoc;
39 import java.util.Locale JavaDoc;
40 import java.util.Locale JavaDoc;
41
42 import java.io.IOException JavaDoc;
43 import java.io.PrintWriter JavaDoc;
44 import java.io.OutputStream JavaDoc;
45 import java.io.ByteArrayOutputStream JavaDoc;
46 import java.io.UnsupportedEncodingException JavaDoc;
47
48 import javax.portlet.PortletURL;
49 import javax.portlet.RenderResponse;
50
51 import javax.servlet.http.HttpServletResponse JavaDoc;
52
53 import com.knowgate.misc.Gadgets;
54
55 /**
56  * RenderResponse implementation with output to a StringBuffer
57  * @author Sergio Montoro Ten
58  * @version 1.0
59  */

60
61 public class StringBufferRenderResponse implements RenderResponse {
62
63   private Properties JavaDoc oProps;
64   private ByteArrayOutputStream JavaDoc oBuf;
65   private PrintWriter JavaDoc oWrt;
66   private int iBufSize;
67   private String JavaDoc sEncoding;
68
69   public StringBufferRenderResponse (String JavaDoc encoding) {
70     sEncoding = encoding;
71     iBufSize = 4000;
72     oProps = new Properties JavaDoc();
73     oBuf = new ByteArrayOutputStream JavaDoc(iBufSize);
74     oWrt = new PrintWriter JavaDoc(oBuf);
75   }
76
77   public void setProperty(String JavaDoc key, String JavaDoc value) {
78     oProps.setProperty (key, value);
79   }
80
81   public void addProperty(String JavaDoc key, String JavaDoc value) {
82     String JavaDoc sProp = oProps.getProperty(key);
83
84     if (sProp==null)
85       oProps.setProperty (key, value);
86     else {
87       oProps.remove(key);
88       oProps.setProperty(key, sProp + ";" + value);
89     }
90   }
91
92   public String JavaDoc encodeURL (String JavaDoc path) {
93     return Gadgets.URLEncode(path);
94   }
95
96   public String JavaDoc getContentType () {
97     throw new UnsupportedOperationException JavaDoc ("getContentType() not implemented HipergateRenderRequest");
98   }
99
100   public PortletURL createRenderURL () {
101     throw new UnsupportedOperationException JavaDoc ("createRenderURL() not implemented HipergateRenderRequest");
102   }
103
104   public PortletURL createActionURL () {
105     throw new UnsupportedOperationException JavaDoc ("createActionURL() not implemented HipergateRenderRequest");
106   }
107
108   public String JavaDoc getNamespace () {
109     throw new UnsupportedOperationException JavaDoc ("getNamespace() not implemented HipergateRenderRequest");
110   }
111
112   public void setTitle(String JavaDoc title) {
113     throw new UnsupportedOperationException JavaDoc ("setTitle() not implemented HipergateRenderRequest");
114   }
115
116   public void setContentType(String JavaDoc type) {
117     throw new UnsupportedOperationException JavaDoc ("setContentType() not implemented HipergateRenderRequest");
118   }
119
120    public String JavaDoc getCharacterEncoding() {
121      return sEncoding;
122    }
123
124    public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
125      return oWrt;
126    }
127
128    public Locale JavaDoc getLocale() {
129      throw new UnsupportedOperationException JavaDoc ("getLocale() not implemented HipergateRenderRequest");
130    }
131
132    public void setBufferSize(int size) {
133      throw new UnsupportedOperationException JavaDoc ("setBufferSize() not implemented HipergateRenderRequest");
134    }
135
136    public int getBufferSize() {
137      return iBufSize;
138    }
139
140    public void setCharacterEncoding(String JavaDoc encoding) {
141      sEncoding = encoding;
142    }
143
144    public void flushBuffer() throws IOException JavaDoc {
145      oWrt.flush();
146    }
147
148    public void resetBuffer() {
149      oBuf.reset();
150    }
151
152    public boolean isCommitted() {
153      throw new UnsupportedOperationException JavaDoc ("isCommitted() not implemented HipergateRenderRequest");
154    }
155
156    public void reset() {
157      oBuf.reset();
158    }
159
160    public OutputStream JavaDoc getPortletOutputStream() throws IOException JavaDoc {
161      return oBuf;
162    }
163
164    public String JavaDoc toString() {
165      String JavaDoc sRetVal;
166
167      try {
168        sRetVal = new String JavaDoc(oBuf.toByteArray(), sEncoding);
169      }
170      catch (UnsupportedEncodingException JavaDoc uee) {
171        sRetVal = new String JavaDoc(oBuf.toByteArray());
172      }
173
174      return sRetVal;
175    } // toString()
176
}
177
Popular Tags