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