1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.portlet.servlet;
23
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.util.Locale;
27
28 import javax.portlet.PortletResponse;
29 import javax.portlet.RenderResponse;
30 import javax.servlet.ServletOutputStream;
31 import javax.servlet.http.Cookie;
32 import javax.servlet.http.HttpServletResponse;
33
34 public class PortletServletResponse implements HttpServletResponse {
35
36 private PortletResponse portletResponse;
37
38 public PortletServletResponse(PortletResponse portletResponse) {
39 this.portletResponse = portletResponse;
40 }
41
42 public void addCookie(Cookie cookie) {
43 throw new IllegalStateException("Not allowed in a portlet");
44 }
45
46 public void addDateHeader(String name, long date) {
47 throw new IllegalStateException("Not allowed in a portlet");
48 }
49
50 public void addHeader(String name, String value) {
51 throw new IllegalStateException("Not allowed in a portlet");
52 }
53
54 public void addIntHeader(String name, int value) {
55 throw new IllegalStateException("Not allowed in a portlet");
56 }
57
58 public boolean containsHeader(String name) {
59 throw new IllegalStateException("Not allowed in a portlet");
60 }
61
62 public String encodeRedirectURL(String url) {
63 throw new IllegalStateException("Not allowed in a portlet");
64 }
65
66 public String encodeRedirectUrl(String url) {
67 throw new IllegalStateException("Not allowed in a portlet");
68 }
69
70 public String encodeURL(String url) {
71 throw new IllegalStateException("Not allowed in a portlet");
72 }
73
74 public String encodeUrl(String url) {
75 throw new IllegalStateException("Not allowed in a portlet");
76 }
77
78 public void sendError(int sc) throws IOException {
79 throw new IllegalStateException("Not allowed in a portlet");
80 }
81
82 public void sendError(int sc, String msg) throws IOException {
83 throw new IllegalStateException("Not allowed in a portlet");
84 }
85
86 public void sendRedirect(String location) throws IOException {
87 throw new IllegalStateException("Not allowed in a portlet");
88 }
89
90 public void setDateHeader(String name, long date) {
91 throw new IllegalStateException("Not allowed in a portlet");
92 }
93
94 public void setHeader(String name, String value) {
95 throw new IllegalStateException("Not allowed in a portlet");
96 }
97
98 public void setIntHeader(String name, int value) {
99 throw new IllegalStateException("Not allowed in a portlet");
100 }
101
102 public void setStatus(int sc) {
103 throw new IllegalStateException("Not allowed in a portlet");
104 }
105
106 public void setStatus(int sc, String sm) {
107 throw new IllegalStateException("Not allowed in a portlet");
108 }
109
110 public void flushBuffer() throws IOException {
111 if(portletResponse instanceof RenderResponse) {
112 ((RenderResponse)portletResponse).flushBuffer();
113 }
114 else {
115 throw new IllegalStateException("Not allowed in event phase");
116 }
117 }
118
119 public int getBufferSize() {
120 if(portletResponse instanceof RenderResponse) {
121 return ((RenderResponse)portletResponse).getBufferSize();
122 }
123 else {
124 throw new IllegalStateException("Not allowed in event phase");
125 }
126 }
127
128 public String getCharacterEncoding() {
129 if(portletResponse instanceof RenderResponse) {
130 return ((RenderResponse)portletResponse).getCharacterEncoding();
131 }
132 else {
133 throw new IllegalStateException("Not allowed in event phase");
134 }
135 }
136
137 public String getContentType() {
138 if(portletResponse instanceof RenderResponse) {
139 return ((RenderResponse)portletResponse).getContentType();
140 }
141 else {
142 throw new IllegalStateException("Not allowed in event phase");
143 }
144 }
145
146 public Locale getLocale() {
147 if(portletResponse instanceof RenderResponse) {
148 return ((RenderResponse)portletResponse).getLocale();
149 }
150 else {
151 throw new IllegalStateException("Not allowed in event phase");
152 }
153 }
154
155 public ServletOutputStream getOutputStream() throws IOException {
156 if(portletResponse instanceof RenderResponse) {
157 return new PortletServletOutputStream(((RenderResponse)portletResponse).getPortletOutputStream());
158 }
159 else {
160 throw new IllegalStateException("Not allowed in event phase");
161 }
162 }
163
164 public PrintWriter getWriter() throws IOException {
165 if(portletResponse instanceof RenderResponse) {
166 return ((RenderResponse)portletResponse).getWriter();
167 }
168 else {
169 throw new IllegalStateException("Not allowed in event phase");
170 }
171 }
172
173 public boolean isCommitted() {
174 if(portletResponse instanceof RenderResponse) {
175 return ((RenderResponse)portletResponse).isCommitted();
176 }
177 else {
178 throw new IllegalStateException("Not allowed in event phase");
179 }
180 }
181
182 public void reset() {
183 if(portletResponse instanceof RenderResponse) {
184 ((RenderResponse)portletResponse).reset();
185 }
186 else {
187 throw new IllegalStateException("Not allowed in event phase");
188 }
189 }
190
191 public void resetBuffer() {
192 if(portletResponse instanceof RenderResponse) {
193 ((RenderResponse)portletResponse).resetBuffer();
194 }
195 else {
196 throw new IllegalStateException("Not allowed in event phase");
197 }
198 }
199
200 public void setBufferSize(int size) {
201 if(portletResponse instanceof RenderResponse) {
202 ((RenderResponse)portletResponse).setBufferSize(size);
203 }
204 else {
205 throw new IllegalStateException("Not allowed in event phase");
206 }
207 }
208
209 public void setCharacterEncoding(String charset) {
210 throw new IllegalStateException("Not allowed in a portlet");
211 }
212
213 public void setContentLength(int len) {
214 throw new IllegalStateException("Not allowed in a portlet");
215 }
216
217 public void setContentType(String type) {
218 if(portletResponse instanceof RenderResponse) {
219 ((RenderResponse)portletResponse).setContentType(type);
220 }
221 else {
222 throw new IllegalStateException("Not allowed in event phase");
223 }
224 }
225
226 public void setLocale(Locale loc) {
227 throw new IllegalStateException("Not allowed in a portlet");
228 }
229
230 public PortletResponse getPortletResponse() {
231 return portletResponse;
232 }
233
234 }