1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet;
24  
25  import java.util.Locale;
26  
27  import javax.portlet.PortletRequest;
28  import javax.portlet.PortletURL;
29  import javax.portlet.ResourceRequest;
30  import javax.portlet.ResourceResponse;
31  import javax.portlet.ResourceURL;
32  
33  import javax.servlet.http.Cookie;
34  import javax.servlet.http.HttpServletResponse;
35  
36  /**
37   * <a href="ResourceResponseImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class ResourceResponseImpl
42      extends MimeResponseImpl implements ResourceResponse {
43  
44      public void addDateHeader(String name, long date) {
45          _response.addDateHeader(name, date);
46      }
47  
48      public void addHeader(String name, String value) {
49          _response.addHeader(name, value);
50      }
51  
52      public void addIntHeader(String name, int value) {
53          _response.addIntHeader(name, value);
54      }
55  
56      public void addProperty(Cookie cookie) {
57          _response.addCookie(cookie);
58      }
59  
60      public PortletURL createActionURL() {
61          return super.createActionURL();
62      }
63  
64      public PortletURLImpl createPortletURLImpl(
65          String portletName, String lifecycle) {
66  
67          ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
68  
69          String cacheability = resourceRequest.getCacheability();
70  
71          if (cacheability.equals(ResourceURL.PAGE)) {
72          }
73          else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
74              throw new IllegalStateException(
75                  "Unable to create an action URL from a resource response " +
76                      "when the cacheability is not set to PAGE");
77          }
78          else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
79              throw new IllegalStateException(
80                  "Unable to create a render URL from a resource response when " +
81                      "the cacheability is not set to PAGE");
82          }
83  
84          return super.createPortletURLImpl(portletName, lifecycle);
85      }
86  
87      public PortletURL createRenderURL() {
88          return super.createRenderURL();
89      }
90  
91      public ResourceURL createResourceURL() {
92          return super.createResourceURL();
93      }
94  
95      public String getLifecycle() {
96          return PortletRequest.RESOURCE_PHASE;
97      }
98  
99      public void setCharacterEncoding(String charset) {
100         _response.setCharacterEncoding(charset);
101     }
102 
103     public void setLocale(Locale locale) {
104         _response.setLocale(locale);
105     }
106 
107     public void setContentLength(int length) {
108         _response.setContentLength(length);
109     }
110 
111     public void setDateHeader(String name, long date) {
112         _response.setDateHeader(name, date);
113     }
114 
115     public void setHeader(String name, String value) {
116         _response.setHeader(name, value);
117     }
118 
119     public void setIntHeader(String name, int value) {
120         _response.setIntHeader(name, value);
121     }
122 
123     protected void init(
124         PortletRequestImpl portletRequestImpl, HttpServletResponse response,
125         String portletName, long companyId, long plid) {
126 
127         super.init(portletRequestImpl, response, portletName, companyId, plid);
128 
129         _response = response;
130     }
131 
132     private HttpServletResponse _response;
133 
134 }