1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.wsrp;
21  
22  import com.liferay.portal.kernel.util.ByteArrayMaker;
23  
24  import java.io.IOException;
25  import java.io.PrintWriter;
26  import java.io.Serializable;
27  import java.io.StringWriter;
28  import java.io.UnsupportedEncodingException;
29  
30  import java.util.Locale;
31  
32  import javax.servlet.ServletOutputStream;
33  import javax.servlet.http.Cookie;
34  import javax.servlet.http.HttpServletResponse;
35  
36  /**
37   * <a href="WSRPServletResponse.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Michael Young
40   *
41   */
42  public class WSRPServletResponse implements HttpServletResponse, Serializable {
43  
44      public static final int DEFAULT_STATUS_CODE = 200;
45  
46      public WSRPServletResponse() {
47          _locale = new Locale("en", "US");
48  
49          setContentType("text/html");
50      }
51  
52      public void setBufferSize(int size) {
53      }
54  
55      public int getBufferSize() {
56          return 4096;
57      }
58  
59      public void setCharacterEncoding(String encoding) {
60          _encoding = encoding;
61      }
62  
63      public String getCharacterEncoding() {
64          return _encoding;
65      }
66  
67      public boolean isCommitted() {
68          return false;
69      }
70  
71      public void setContentLength(int size) {
72      }
73  
74      public void setContentType(String contentType) {
75          _contentType = contentType;
76      }
77  
78      public String getContentType() {
79          return _contentType;
80      }
81  
82      public void setDateHeader(String name, long dateValue) {
83      }
84  
85      public void setHeader(String name, String value) {
86      }
87  
88      public void setIntHeader(String name, int value) {
89      }
90  
91      public void setLocale(Locale locale) {
92          _locale = locale;
93      }
94  
95      public java.util.Locale getLocale() {
96          return _locale;
97      }
98  
99      public ServletOutputStream getOutputStream() {
100         _callGetOutputStream = true;
101 
102         return _sos;
103     }
104 
105     public void setStatus(int statusCode) {
106     }
107 
108     public void setStatus(int statusCode, String message) {
109     }
110 
111     public String getString() throws UnsupportedEncodingException {
112         if (_callGetOutputStream) {
113             return _bam.toString();
114         }
115         else if (_callGetWriter) {
116             return _sw.toString();
117         }
118         else {
119             return "";
120         }
121     }
122 
123     public PrintWriter getWriter() {
124         _callGetWriter = true;
125 
126         return _pw;
127     }
128 
129     public void addCookie(Cookie cookie) {
130     }
131 
132     public void addDateHeader(String name, long dateValue) {
133     }
134 
135     public void addHeader(String name, String value) {
136     }
137 
138     public void addIntHeader(String name, int value) {
139     }
140 
141     public boolean containsHeader(String headerName) {
142         return false;
143     }
144 
145     public String encodeRedirectURL(String url) {
146         return url;
147     }
148 
149     public String encodeRedirectUrl(String url) {
150         return encodeRedirectURL(url);
151     }
152 
153     public String encodeURL(String url) {
154         return url;
155     }
156 
157     public String encodeUrl(String url) {
158         return encodeURL(url);
159     }
160 
161     public void flushBuffer() {
162     }
163 
164     public void reset() {
165     }
166 
167     public void resetBuffer() {
168     }
169 
170     public void sendError(int errorCode) throws IOException {
171     }
172 
173     public void sendError(int errorCode, String message) throws IOException {
174     }
175 
176     public void sendRedirect(String location) {
177     }
178 
179     private ByteArrayMaker _bam = new ByteArrayMaker();
180     private Locale _locale;
181     private ServletOutputStream _sos = new ServletOutputStream() {
182         public void write(int b) throws IOException {
183             _bam.write(b);
184         }
185     };
186 
187     private String _encoding;
188     private StringWriter _sw = new StringWriter();
189     private PrintWriter _pw = new PrintWriter(_sw);
190     private boolean _callGetOutputStream;
191     private boolean _callGetWriter;
192     private String _contentType;
193 
194 }