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.portlet;
21  
22  import java.util.Locale;
23  
24  import javax.portlet.PortletRequest;
25  import javax.portlet.PortletURL;
26  import javax.portlet.ResourceRequest;
27  import javax.portlet.ResourceResponse;
28  import javax.portlet.ResourceURL;
29  
30  import javax.servlet.http.Cookie;
31  import javax.servlet.http.HttpServletResponse;
32  
33  /**
34   * <a href="ResourceResponseImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class ResourceResponseImpl
40      extends MimeResponseImpl implements ResourceResponse {
41  
42      public void addDateHeader(String name, long date) {
43          _response.addDateHeader(name, date);
44      }
45  
46      public void addHeader(String name, String value) {
47          _response.addHeader(name, value);
48      }
49  
50      public void addIntHeader(String name, int value) {
51          _response.addIntHeader(name, value);
52      }
53  
54      public void addProperty(Cookie cookie) {
55          _response.addCookie(cookie);
56      }
57  
58      public PortletURL createActionURL() {
59          return super.createActionURL();
60      }
61  
62      public PortletURLImpl createPortletURLImpl(
63          String portletName, String lifecycle) {
64  
65          ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
66  
67          String cacheability = resourceRequest.getCacheability();
68  
69          if (cacheability.equals(ResourceURL.PAGE)) {
70          }
71          else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
72              throw new IllegalStateException(
73                  "Unable to create an action URL from a resource response " +
74                      "when the cacheability is not set to PAGE");
75          }
76          else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
77              throw new IllegalStateException(
78                  "Unable to create a render URL from a resource response when " +
79                      "the cacheability is not set to PAGE");
80          }
81  
82          return super.createPortletURLImpl(portletName, lifecycle);
83      }
84  
85      public PortletURL createRenderURL() {
86          return super.createRenderURL();
87      }
88  
89      public ResourceURL createResourceURL() {
90          return super.createResourceURL();
91      }
92  
93      public String getLifecycle() {
94          return PortletRequest.RESOURCE_PHASE;
95      }
96  
97      public void setCharacterEncoding(String charset) {
98          _response.setCharacterEncoding(charset);
99      }
100 
101     public void setLocale(Locale locale) {
102         _response.setLocale(locale);
103     }
104 
105     public void setContentLength(int length) {
106         _response.setContentLength(length);
107     }
108 
109     public void setDateHeader(String name, long date) {
110         _response.setDateHeader(name, date);
111     }
112 
113     public void setHeader(String name, String value) {
114         _response.setHeader(name, value);
115     }
116 
117     public void setIntHeader(String name, int value) {
118         _response.setIntHeader(name, value);
119     }
120 
121     protected void init(
122         PortletRequestImpl portletRequestImpl, HttpServletResponse response,
123         String portletName, long companyId, long plid) {
124 
125         super.init(portletRequestImpl, response, portletName, companyId, plid);
126 
127         _response = response;
128     }
129 
130     private HttpServletResponse _response;
131 
132 }