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