1   /**
2    * Copyright (c) 2000-2008 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.ResourceResponse;
30  import javax.portlet.ResourceURL;
31  
32  import javax.servlet.http.HttpServletResponse;
33  
34  import org.apache.commons.logging.Log;
35  import org.apache.commons.logging.LogFactory;
36  
37  /**
38   * <a href="ResourceResponseImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   *
42   */
43  public class ResourceResponseImpl
44      extends MimeResponseImpl implements ResourceResponse {
45  
46      public PortletURL createActionURL() {
47          return super.createActionURL();
48      }
49  
50      public PortletURLImpl createPortletURLImpl(
51          String portletName, String lifecycle) {
52  
53          if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
54              throw new IllegalStateException(
55                  "Unable to create an action URL from a resource response");
56          }
57          else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
58              throw new IllegalStateException(
59                  "Unable to create a render URL from a resource response");
60          }
61  
62          return super.createPortletURLImpl(portletName, lifecycle);
63      }
64  
65      public PortletURL createRenderURL() {
66          return super.createRenderURL();
67      }
68  
69      public ResourceURL createResourceURL() {
70          return super.createResourceURL();
71      }
72  
73      public int getBufferSize() {
74          return 0;
75      }
76  
77      public String getLifecycle() {
78          return PortletRequest.RESOURCE_PHASE;
79      }
80  
81      public void setCharacterEncoding(String charset) {
82          _res.setCharacterEncoding(charset);
83      }
84  
85      public void setLocale(Locale locale) {
86          _res.setLocale(locale);
87      }
88  
89      public void setContentLength(int length) {
90          _res.setContentLength(length);
91      }
92  
93      protected ResourceResponseImpl() {
94          if (_log.isDebugEnabled()) {
95              _log.debug("Creating new instance " + hashCode());
96          }
97      }
98  
99      protected void init(
100         PortletRequestImpl req, HttpServletResponse res, String portletName,
101         long companyId, long plid) {
102 
103         super.init(req, res, portletName, companyId, plid);
104 
105         _res = res;
106     }
107 
108     protected void recycle() {
109         if (_log.isDebugEnabled()) {
110             _log.debug("Recycling instance " + hashCode());
111         }
112 
113         super.recycle();
114 
115         _res = null;
116     }
117 
118     private static Log _log = LogFactory.getLog(ResourceResponseImpl.class);
119 
120     private HttpServletResponse _res;
121 
122 }