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          super.addDateHeader(name, date);
47  
48          _response.addDateHeader(name, date);
49      }
50  
51      public void addHeader(String name, String value) {
52          super.addHeader(name, value);
53  
54          _response.addHeader(name, value);
55      }
56  
57      public void addIntHeader(String name, int value) {
58          super.addIntHeader(name, value);
59  
60          _response.addIntHeader(name, value);
61      }
62  
63      public void addProperty(Cookie cookie) {
64          super.addProperty(cookie);
65  
66          _response.addCookie(cookie);
67      }
68  
69      public PortletURL createActionURL() {
70          return super.createActionURL();
71      }
72  
73      public PortletURLImpl createPortletURLImpl(
74          String portletName, String lifecycle) {
75  
76          ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
77  
78          String cacheability = resourceRequest.getCacheability();
79  
80          if (cacheability.equals(ResourceURL.PAGE)) {
81          }
82          else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
83              throw new IllegalStateException(
84                  "Unable to create an action URL from a resource response " +
85                      "when the cacheability is not set to PAGE");
86          }
87          else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
88              throw new IllegalStateException(
89                  "Unable to create a render URL from a resource response when " +
90                      "the cacheability is not set to PAGE");
91          }
92  
93          return super.createPortletURLImpl(portletName, lifecycle);
94      }
95  
96      public PortletURL createRenderURL() {
97          return super.createRenderURL();
98      }
99  
100     public ResourceURL createResourceURL() {
101         return super.createResourceURL();
102     }
103 
104     public String getLifecycle() {
105         return PortletRequest.RESOURCE_PHASE;
106     }
107 
108     public void setCharacterEncoding(String charset) {
109         _response.setCharacterEncoding(charset);
110     }
111 
112     public void setLocale(Locale locale) {
113         _response.setLocale(locale);
114     }
115 
116     public void setContentLength(int length) {
117         _response.setContentLength(length);
118     }
119 
120     public void setDateHeader(String name, long date) {
121         super.setDateHeader(name, date);
122 
123         _response.setDateHeader(name, date);
124     }
125 
126     public void setHeader(String name, String value) {
127         super.setHeader(name, value);
128 
129         _response.setHeader(name, value);
130     }
131 
132     public void setIntHeader(String name, int value) {
133         super.setIntHeader(name, value);
134 
135         _response.setIntHeader(name, value);
136     }
137 
138     protected void init(
139         PortletRequestImpl portletRequestImpl, HttpServletResponse response,
140         String portletName, long companyId, long plid) {
141 
142         super.init(portletRequestImpl, response, portletName, companyId, plid);
143 
144         _response = response;
145     }
146 
147     private HttpServletResponse _response;
148 
149 }