1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
18  
19  import java.util.Locale;
20  
21  import javax.portlet.PortletRequest;
22  import javax.portlet.PortletURL;
23  import javax.portlet.ResourceRequest;
24  import javax.portlet.ResourceResponse;
25  import javax.portlet.ResourceURL;
26  
27  import javax.servlet.http.Cookie;
28  import javax.servlet.http.HttpServletResponse;
29  
30  /**
31   * <a href="ResourceResponseImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class ResourceResponseImpl
36      extends MimeResponseImpl implements ResourceResponse {
37  
38      public void addDateHeader(String name, long date) {
39          _response.addDateHeader(name, date);
40      }
41  
42      public void addHeader(String name, String value) {
43          _response.addHeader(name, value);
44      }
45  
46      public void addIntHeader(String name, int value) {
47          _response.addIntHeader(name, value);
48      }
49  
50      public void addProperty(Cookie cookie) {
51          _response.addCookie(cookie);
52      }
53  
54      public PortletURL createActionURL() {
55          return super.createActionURL();
56      }
57  
58      public LiferayPortletURL createLiferayPortletURL(
59          String portletName, String lifecycle) {
60  
61          ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
62  
63          String cacheability = resourceRequest.getCacheability();
64  
65          if (cacheability.equals(ResourceURL.PAGE)) {
66          }
67          else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
68              throw new IllegalStateException(
69                  "Unable to create an action URL from a resource response " +
70                      "when the cacheability is not set to PAGE");
71          }
72          else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
73              throw new IllegalStateException(
74                  "Unable to create a render URL from a resource response when " +
75                      "the cacheability is not set to PAGE");
76          }
77  
78          return super.createLiferayPortletURL(portletName, lifecycle);
79      }
80  
81      public PortletURL createRenderURL() {
82          return super.createRenderURL();
83      }
84  
85      public ResourceURL createResourceURL() {
86          return super.createResourceURL();
87      }
88  
89      public String getLifecycle() {
90          return PortletRequest.RESOURCE_PHASE;
91      }
92  
93      public void setCharacterEncoding(String charset) {
94          _response.setCharacterEncoding(charset);
95      }
96  
97      public void setLocale(Locale locale) {
98          _response.setLocale(locale);
99      }
100 
101     public void setContentLength(int length) {
102         _response.setContentLength(length);
103     }
104 
105     public void setDateHeader(String name, long date) {
106         _response.setDateHeader(name, date);
107     }
108 
109     public void setHeader(String name, String value) {
110         _response.setHeader(name, value);
111     }
112 
113     public void setIntHeader(String name, int value) {
114         _response.setIntHeader(name, value);
115     }
116 
117     protected void init(
118         PortletRequestImpl portletRequestImpl, HttpServletResponse response,
119         String portletName, long companyId, long plid) {
120 
121         super.init(portletRequestImpl, response, portletName, companyId, plid);
122 
123         _response = response;
124     }
125 
126     private HttpServletResponse _response;
127 
128 }