View Javadoc
1   package org.andromda.cartridges.jsf.portlet.myfaces.tomahawk.support;
2   
3   import java.io.IOException;
4   import java.io.OutputStream;
5   import java.io.PrintWriter;
6   import java.util.Locale;
7   import javax.portlet.PortletURL;
8   import javax.portlet.RenderResponse;
9   import javax.servlet.ServletOutputStream;
10  import javax.servlet.http.Cookie;
11  import javax.servlet.http.HttpServletResponse;
12  
13  /**
14   * This class is a dummy HttpServletResponse.
15   *
16   * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
17   */
18  public class HttpServletResponseWrapper
19      implements HttpServletResponse, RenderResponse
20  {
21      private final RenderResponse renderResponse;
22  
23      /**
24       * @param renderResponse
25       */
26      public HttpServletResponseWrapper(
27          final RenderResponse renderResponse)
28      {
29          this.renderResponse = renderResponse;
30      }
31  
32      /**
33       * @return renderResponse.getWriter()
34       * @throws IOException
35       * @see javax.servlet.ServletResponseWrapper#getWriter()
36       */
37      public PrintWriter getWriter() throws IOException
38      {
39          return renderResponse.getWriter();
40      }
41  
42      /**
43       * Returns writer to which MyFaces' AddResource stores elements.
44       *
45       * @return writer which has elements, such as &lt;script&gt; and
46       *         &lt;link&gt; public StringWriter getStringWriter() { return
47       *         (StringWriter) writer; }
48       */
49  
50      /**
51       * @see javax.servlet.ServletResponse#flushBuffer()
52       */
53      public void flushBuffer() throws IOException
54      {
55          if (renderResponse != null)
56          {
57              renderResponse.flushBuffer();
58          }
59      }
60  
61      /**
62       * @see javax.servlet.ServletResponse#getBufferSize()
63       */
64      public int getBufferSize()
65      {
66          if (renderResponse != null)
67          {
68              return renderResponse.getBufferSize();
69          }
70          return 0;
71      }
72  
73      /**
74       * @see javax.servlet.ServletResponse#getCharacterEncoding()
75       */
76      public String getCharacterEncoding()
77      {
78          if (renderResponse != null)
79          {
80              return renderResponse.getCharacterEncoding();
81          }
82          return null;
83      }
84  
85      /**
86       * @see javax.servlet.ServletResponse#getLocale()
87       */
88      public Locale getLocale()
89      {
90          if (renderResponse != null)
91          {
92              return renderResponse.getLocale();
93          }
94          return null;
95      }
96  
97      /**
98       * @see javax.servlet.ServletResponse#getOutputStream()
99       */
100     public ServletOutputStream getOutputStream() throws IOException
101     {
102         if (renderResponse != null)
103         {
104             return new ServletOutputStreamWrapper(renderResponse.getPortletOutputStream());
105         }
106         return null;
107     }
108 
109     /**
110      * @see javax.servlet.ServletResponse#isCommitted()
111      */
112     public boolean isCommitted()
113     {
114         if (renderResponse != null)
115         {
116             return renderResponse.isCommitted();
117         }
118         return false;
119     }
120 
121     /**
122      * @see javax.servlet.ServletResponse#reset()
123      */
124     public void reset()
125     {
126         if (renderResponse != null)
127         {
128             renderResponse.reset();
129         }
130     }
131 
132     /**
133      * @see javax.servlet.ServletResponse#resetBuffer()
134      */
135     public void resetBuffer()
136     {
137         if (renderResponse != null)
138         {
139             renderResponse.resetBuffer();
140         }
141 
142     }
143 
144     /**
145      * @see javax.servlet.ServletResponse#setBufferSize(int)
146      */
147     public void setBufferSize(final int arg0)
148     {
149         renderResponse.setBufferSize(arg0);
150     }
151 
152     /**
153      * @see javax.servlet.ServletResponse#setContentLength(int)
154      */
155     public void setContentLength(final int arg0)
156     {
157 
158 
159     }
160 
161     /**
162      * @see javax.servlet.ServletResponse#setContentType(String)
163      */
164     public void setContentType(final String arg0)
165     {
166         if (renderResponse != null)
167         {
168             renderResponse.setContentType(arg0);
169         }
170     }
171 
172     /**
173      * @see javax.servlet.ServletResponse#setLocale(java.util.Locale)
174      */
175     public void setLocale(final Locale arg0)
176     {
177 
178 
179     }
180 
181     /**
182      * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie)
183      */
184     public void addCookie(final Cookie arg0)
185     {
186 
187 
188     }
189 
190     /**
191      * @see javax.servlet.http.HttpServletResponse#addDateHeader(String,
192      *      long)
193      */
194     public void addDateHeader(final String arg0, final long arg1)
195     {
196 
197     }
198 
199     /**
200      * @see javax.servlet.http.HttpServletResponse#addHeader(String,
201      *      String)
202      */
203     public void addHeader(final String arg0, final String arg1)
204     {
205 
206     }
207 
208     /**
209      * @see javax.servlet.http.HttpServletResponse#addIntHeader(String,
210      *      int)
211      */
212     public void addIntHeader(final String arg0, final int arg1)
213     {
214 
215     }
216 
217     /**
218      * @see javax.servlet.http.HttpServletResponse#containsHeader(String)
219      */
220     public boolean containsHeader(final String arg0)
221     {
222         return false;
223     }
224 
225     /**
226      * @see javax.servlet.http.HttpServletResponse#encodeRedirectUrl(String)
227      * @deprecated
228      */
229     @Deprecated
230     public String encodeRedirectUrl(final String arg0)
231     {
232         return null;
233     }
234 
235     /**
236      * @see javax.servlet.http.HttpServletResponse#encodeRedirectURL(String)
237      */
238     public String encodeRedirectURL(final String arg0)
239     {
240         return null;
241     }
242 
243     /**
244      * @see javax.servlet.http.HttpServletResponse#encodeUrl(String)
245      * @deprecated
246      */
247     @Deprecated
248     public String encodeUrl(final String arg0)
249     {
250         if (renderResponse != null)
251         {
252             return renderResponse.encodeURL(arg0);
253         }
254         return null;
255     }
256 
257     /**
258      * @see javax.servlet.http.HttpServletResponse#encodeURL(String)
259      */
260     public String encodeURL(final String arg0)
261     {
262         return renderResponse.encodeURL(arg0);
263     }
264 
265     /**
266      * @see javax.servlet.http.HttpServletResponse#sendError(int,
267      *      String)
268      */
269     public void sendError(final int arg0, final String arg1) throws IOException
270     {
271 
272     }
273 
274     /**
275      * @see javax.servlet.http.HttpServletResponse#sendError(int)
276      */
277     public void sendError(final int arg0) throws IOException
278     {
279 
280     }
281 
282     /**
283      * @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
284      */
285     public void sendRedirect(final String arg0) throws IOException
286     {
287 
288     }
289 
290     /**
291      * @see javax.servlet.http.HttpServletResponse#setDateHeader(String,
292      *      long)
293      */
294     public void setDateHeader(final String arg0, final long arg1)
295     {
296 
297     }
298 
299     /**
300      * @see javax.servlet.http.HttpServletResponse#setHeader(String,
301      *      String)
302      */
303     public void setHeader(final String arg0, final String arg1)
304     {
305 
306     }
307 
308     /**
309      * @see javax.servlet.http.HttpServletResponse#setIntHeader(String,
310      *      int)
311      */
312     public void setIntHeader(final String arg0, final int arg1)
313     {
314 
315     }
316 
317     /**
318      * @see javax.servlet.http.HttpServletResponse#setStatus(int,
319      *      String)
320      * @deprecated
321      */
322     @Deprecated
323     public void setStatus(final int arg0, final String arg1)
324     {
325 
326     }
327 
328     /**
329      * @see javax.servlet.http.HttpServletResponse#setStatus(int)
330      */
331     public void setStatus(final int arg0)
332     {
333 
334     }
335 
336     /**
337      * @see javax.portlet.PortletResponse#addProperty(String,
338      *      String)
339      */
340     public void addProperty(final String arg0, final String arg1)
341     {
342         renderResponse.addProperty(arg0, arg1);
343     }
344 
345     /**
346      * @see javax.portlet.PortletResponse#setProperty(String,
347      *      String)
348      */
349     public void setProperty(final String arg0, final String arg1)
350     {
351         renderResponse.setProperty(arg0, arg1);
352     }
353 
354     /**
355      * @see javax.servlet.ServletResponse#getContentType()
356      */
357     public String getContentType()
358     {
359         if (renderResponse != null)
360         {
361             return renderResponse.getContentType();
362         }
363         return null;
364     }
365 
366     /**
367      * @see javax.servlet.ServletResponse#setCharacterEncoding(String)
368      */
369     public void setCharacterEncoding(final String arg0)
370     {
371     }
372 
373     /**
374      * @see javax.portlet.RenderResponse#createActionURL()
375      */
376     public PortletURL createActionURL()
377     {
378         return renderResponse.createActionURL();
379     }
380 
381     /**
382      * @see javax.portlet.RenderResponse#createRenderURL()
383      */
384     public PortletURL createRenderURL()
385     {
386         return renderResponse.createRenderURL();
387     }
388 
389     /**
390      * @see javax.portlet.RenderResponse#getNamespace()
391      */
392     public String getNamespace()
393     {
394         return renderResponse.getNamespace();
395     }
396 
397     /**
398      * @see javax.portlet.RenderResponse#getPortletOutputStream()
399      */
400     public OutputStream getPortletOutputStream() throws IOException
401     {
402         return renderResponse.getPortletOutputStream();
403     }
404 
405     /**
406      * @see javax.portlet.RenderResponse#setTitle(String)
407      */
408     public void setTitle(final String title)
409     {
410         renderResponse.setTitle(title);
411     }
412 
413     /**
414      * @return renderResponse
415      */
416     public RenderResponse getResponse()
417     {
418         return renderResponse;
419     }
420 }