1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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   */
42  public class ResourceResponseImpl
43      extends MimeResponseImpl implements ResourceResponse {
44  
45      public void addDateHeader(String name, long date) {
46          _response.addDateHeader(name, date);
47      }
48  
49      public void addHeader(String name, String value) {
50          _response.addHeader(name, value);
51      }
52  
53      public void addIntHeader(String name, int value) {
54          _response.addIntHeader(name, value);
55      }
56  
57      public void addProperty(Cookie cookie) {
58          _response.addCookie(cookie);
59      }
60  
61      public PortletURL createActionURL() {
62          return super.createActionURL();
63      }
64  
65      public PortletURLImpl createPortletURLImpl(
66          String portletName, String lifecycle) {
67  
68          ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
69  
70          String cacheability = resourceRequest.getCacheability();
71  
72          if (cacheability.equals(ResourceURL.PAGE)) {
73          }
74          else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
75              throw new IllegalStateException(
76                  "Unable to create an action URL from a resource response " +
77                      "when the cacheability is not set to PAGE");
78          }
79          else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
80              throw new IllegalStateException(
81                  "Unable to create a render URL from a resource response when " +
82                      "the cacheability is not set to PAGE");
83          }
84  
85          return super.createPortletURLImpl(portletName, lifecycle);
86      }
87  
88      public PortletURL createRenderURL() {
89          return super.createRenderURL();
90      }
91  
92      public ResourceURL createResourceURL() {
93          return super.createResourceURL();
94      }
95  
96      public String getLifecycle() {
97          return PortletRequest.RESOURCE_PHASE;
98      }
99  
100     public void setCharacterEncoding(String charset) {
101         _response.setCharacterEncoding(charset);
102     }
103 
104     public void setLocale(Locale locale) {
105         _response.setLocale(locale);
106     }
107 
108     public void setContentLength(int length) {
109         _response.setContentLength(length);
110     }
111 
112     public void setDateHeader(String name, long date) {
113         _response.setDateHeader(name, date);
114     }
115 
116     public void setHeader(String name, String value) {
117         _response.setHeader(name, value);
118     }
119 
120     public void setIntHeader(String name, int value) {
121         _response.setIntHeader(name, value);
122     }
123 
124     protected void init(
125         PortletRequestImpl portletRequestImpl, HttpServletResponse response,
126         String portletName, long companyId, long plid) {
127 
128         super.init(portletRequestImpl, response, portletName, companyId, plid);
129 
130         _response = response;
131     }
132 
133     private HttpServletResponse _response;
134 
135 }