KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > portlet > RenderResponse


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.environment.portlet;
17
18 import javax.portlet.PortletPreferences;
19 import javax.portlet.PortletURL;
20
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Locale JavaDoc;
25
26 /**
27  * Implements the {@link org.apache.cocoon.environment.Response} interface for
28  * the JSR-168 (Portlet) environment.
29  *
30  * @author <a HREF="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
31  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
32  * @version CVS $Id: RenderResponse.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

34 public final class RenderResponse extends PortletResponse {
35
36     private String JavaDoc contentType = null;
37
38     /**
39      * Creates a RenderResponse based on a real RenderResponse object
40      */

41     protected RenderResponse(javax.portlet.RenderResponse response,
42                              PortletPreferences preferences) {
43         super(response, preferences);
44     }
45
46
47     public String JavaDoc getCharacterEncoding() {
48         return getRenderResponse().getCharacterEncoding();
49     }
50
51     public Locale JavaDoc getLocale() {
52         return getRenderResponse().getLocale();
53     }
54
55     /**
56      *
57      * @see PortletEnvironment#HEADER_PORTLET_TITLE
58      */

59     public void addHeader(String JavaDoc name, String JavaDoc value) {
60         if (PortletEnvironment.HEADER_PORTLET_TITLE.equals(name)) {
61             getRenderResponse().setTitle(value);
62         } else {
63             super.addHeader(name, value);
64         }
65     }
66
67     /**
68      *
69      * @see PortletEnvironment#HEADER_PORTLET_TITLE
70      */

71     public void setHeader(String JavaDoc name, String JavaDoc value) {
72         if (PortletEnvironment.HEADER_PORTLET_TITLE.equals(name)) {
73             getRenderResponse().setTitle(value);
74         } else {
75             super.setHeader(name, value);
76         }
77     }
78
79
80     // RenderResponse API related methods
81

82     /**
83      * Type cast portletResponse to RenderResponse
84      *
85      * @return type casted portletResponse
86      */

87     public javax.portlet.RenderResponse getRenderResponse() {
88         return (javax.portlet.RenderResponse) getPortletResponse();
89     }
90
91     public PortletURL createActionURL() {
92         return getRenderResponse().createActionURL();
93     }
94
95     public PortletURL createRenderURL() {
96         return getRenderResponse().createRenderURL();
97     }
98
99     public void flushBuffer() throws IOException JavaDoc {
100         getRenderResponse().flushBuffer();
101     }
102
103     public int getBufferSize() {
104         return getRenderResponse().getBufferSize();
105     }
106
107     public String JavaDoc getContentType() {
108         return getRenderResponse().getContentType();
109     }
110
111     public String JavaDoc getNamespace() {
112         return getRenderResponse().getNamespace();
113     }
114
115     public OutputStream JavaDoc getPortletOutputStream() throws IOException JavaDoc {
116         return getRenderResponse().getPortletOutputStream();
117     }
118
119     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
120         return getRenderResponse().getWriter();
121     }
122
123     public boolean isCommitted() {
124         return getRenderResponse().isCommitted();
125     }
126
127     public void reset() {
128         getRenderResponse().reset();
129     }
130
131     public void resetBuffer() {
132         getRenderResponse().resetBuffer();
133     }
134
135     public void setBufferSize(int size) {
136         getRenderResponse().setBufferSize(size);
137     }
138
139     public void setContentType(String JavaDoc type) {
140         this.contentType = type;
141         getRenderResponse().setContentType(type);
142     }
143
144     public void setTitle(String JavaDoc title) {
145         getRenderResponse().setTitle(title);
146     }
147
148
149     // Portlet Environment related methods
150

151     OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
152         // TODO: Why this is needed? What's the purpose?
153
if (this.contentType == null) {
154             setContentType("text/html");
155         }
156
157         return getRenderResponse().getPortletOutputStream();
158     }
159 }
160
Popular Tags