001: /*
002: * $Id: $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.portlet.servlet;
022:
023: import java.io.IOException;
024: import java.io.PrintWriter;
025: import java.util.Locale;
026:
027: import javax.portlet.PortletResponse;
028: import javax.portlet.RenderResponse;
029: import javax.servlet.ServletOutputStream;
030: import javax.servlet.http.Cookie;
031: import javax.servlet.http.HttpServletResponse;
032:
033: public class PortletServletResponse implements HttpServletResponse {
034:
035: private PortletResponse portletResponse;
036:
037: public PortletServletResponse(PortletResponse portletResponse) {
038: this .portletResponse = portletResponse;
039: }
040:
041: public void addCookie(Cookie cookie) {
042: throw new IllegalStateException("Not allowed in a portlet");
043: }
044:
045: public void addDateHeader(String name, long date) {
046: throw new IllegalStateException("Not allowed in a portlet");
047: }
048:
049: public void addHeader(String name, String value) {
050: throw new IllegalStateException("Not allowed in a portlet");
051: }
052:
053: public void addIntHeader(String name, int value) {
054: throw new IllegalStateException("Not allowed in a portlet");
055: }
056:
057: public boolean containsHeader(String name) {
058: throw new IllegalStateException("Not allowed in a portlet");
059: }
060:
061: public String encodeRedirectURL(String url) {
062: throw new IllegalStateException("Not allowed in a portlet");
063: }
064:
065: public String encodeRedirectUrl(String url) {
066: throw new IllegalStateException("Not allowed in a portlet");
067: }
068:
069: public String encodeURL(String url) {
070: throw new IllegalStateException("Not allowed in a portlet");
071: }
072:
073: public String encodeUrl(String url) {
074: throw new IllegalStateException("Not allowed in a portlet");
075: }
076:
077: public void sendError(int sc) throws IOException {
078: throw new IllegalStateException("Not allowed in a portlet");
079: }
080:
081: public void sendError(int sc, String msg) throws IOException {
082: throw new IllegalStateException("Not allowed in a portlet");
083: }
084:
085: public void sendRedirect(String location) throws IOException {
086: throw new IllegalStateException("Not allowed in a portlet");
087: }
088:
089: public void setDateHeader(String name, long date) {
090: throw new IllegalStateException("Not allowed in a portlet");
091: }
092:
093: public void setHeader(String name, String value) {
094: throw new IllegalStateException("Not allowed in a portlet");
095: }
096:
097: public void setIntHeader(String name, int value) {
098: throw new IllegalStateException("Not allowed in a portlet");
099: }
100:
101: public void setStatus(int sc) {
102: throw new IllegalStateException("Not allowed in a portlet");
103: }
104:
105: public void setStatus(int sc, String sm) {
106: throw new IllegalStateException("Not allowed in a portlet");
107: }
108:
109: public void flushBuffer() throws IOException {
110: if (portletResponse instanceof RenderResponse) {
111: ((RenderResponse) portletResponse).flushBuffer();
112: } else {
113: throw new IllegalStateException(
114: "Not allowed in event phase");
115: }
116: }
117:
118: public int getBufferSize() {
119: if (portletResponse instanceof RenderResponse) {
120: return ((RenderResponse) portletResponse).getBufferSize();
121: } else {
122: throw new IllegalStateException(
123: "Not allowed in event phase");
124: }
125: }
126:
127: public String getCharacterEncoding() {
128: if (portletResponse instanceof RenderResponse) {
129: return ((RenderResponse) portletResponse)
130: .getCharacterEncoding();
131: } else {
132: throw new IllegalStateException(
133: "Not allowed in event phase");
134: }
135: }
136:
137: public String getContentType() {
138: if (portletResponse instanceof RenderResponse) {
139: return ((RenderResponse) portletResponse).getContentType();
140: } else {
141: throw new IllegalStateException(
142: "Not allowed in event phase");
143: }
144: }
145:
146: public Locale getLocale() {
147: if (portletResponse instanceof RenderResponse) {
148: return ((RenderResponse) portletResponse).getLocale();
149: } else {
150: throw new IllegalStateException(
151: "Not allowed in event phase");
152: }
153: }
154:
155: public ServletOutputStream getOutputStream() throws IOException {
156: if (portletResponse instanceof RenderResponse) {
157: return new PortletServletOutputStream(
158: ((RenderResponse) portletResponse)
159: .getPortletOutputStream());
160: } else {
161: throw new IllegalStateException(
162: "Not allowed in event phase");
163: }
164: }
165:
166: public PrintWriter getWriter() throws IOException {
167: if (portletResponse instanceof RenderResponse) {
168: return ((RenderResponse) portletResponse).getWriter();
169: } else {
170: throw new IllegalStateException(
171: "Not allowed in event phase");
172: }
173: }
174:
175: public boolean isCommitted() {
176: if (portletResponse instanceof RenderResponse) {
177: return ((RenderResponse) portletResponse).isCommitted();
178: } else {
179: throw new IllegalStateException(
180: "Not allowed in event phase");
181: }
182: }
183:
184: public void reset() {
185: if (portletResponse instanceof RenderResponse) {
186: ((RenderResponse) portletResponse).reset();
187: } else {
188: throw new IllegalStateException(
189: "Not allowed in event phase");
190: }
191: }
192:
193: public void resetBuffer() {
194: if (portletResponse instanceof RenderResponse) {
195: ((RenderResponse) portletResponse).resetBuffer();
196: } else {
197: throw new IllegalStateException(
198: "Not allowed in event phase");
199: }
200: }
201:
202: public void setBufferSize(int size) {
203: if (portletResponse instanceof RenderResponse) {
204: ((RenderResponse) portletResponse).setBufferSize(size);
205: } else {
206: throw new IllegalStateException(
207: "Not allowed in event phase");
208: }
209: }
210:
211: public void setCharacterEncoding(String charset) {
212: throw new IllegalStateException("Not allowed in a portlet");
213: }
214:
215: public void setContentLength(int len) {
216: throw new IllegalStateException("Not allowed in a portlet");
217: }
218:
219: public void setContentType(String type) {
220: if (portletResponse instanceof RenderResponse) {
221: ((RenderResponse) portletResponse).setContentType(type);
222: } else {
223: throw new IllegalStateException(
224: "Not allowed in event phase");
225: }
226: }
227:
228: public void setLocale(Locale loc) {
229: throw new IllegalStateException("Not allowed in a portlet");
230: }
231:
232: public PortletResponse getPortletResponse() {
233: return portletResponse;
234: }
235:
236: }
|