1   /**
2    * Copyright (c) 2000-2007 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 com.liferay.portal.kernel.util.JavaConstants;
26  
27  import java.io.BufferedReader;
28  import java.io.IOException;
29  import java.io.InputStream;
30  import java.io.UnsupportedEncodingException;
31  
32  import javax.portlet.ActionRequest;
33  import javax.portlet.ActionResponse;
34  import javax.portlet.PortletConfig;
35  import javax.portlet.PortletPreferences;
36  
37  import org.apache.commons.logging.Log;
38  import org.apache.commons.logging.LogFactory;
39  
40  /**
41   * <a href="ActionRequestImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class ActionRequestImpl
47      extends RenderRequestImpl implements ActionRequest {
48  
49      public PortletPreferences getPreferences() {
50          return new PortletPreferencesWrapper(getPreferencesImpl(), true);
51      }
52  
53      public String getCharacterEncoding() {
54          return getHttpServletRequest().getCharacterEncoding();
55      }
56  
57      public void setCharacterEncoding(String enc)
58          throws UnsupportedEncodingException {
59  
60          if (_calledGetReader) {
61              throw new IllegalStateException();
62          }
63  
64          getHttpServletRequest().setCharacterEncoding(enc);
65      }
66  
67      public int getContentLength() {
68          return getHttpServletRequest().getContentLength();
69      }
70  
71      public String getContentType() {
72          return getHttpServletRequest().getContentType();
73      }
74  
75      public InputStream getPortletInputStream() throws IOException {
76          return getHttpServletRequest().getInputStream();
77      }
78  
79      public BufferedReader getReader()
80          throws IOException, UnsupportedEncodingException {
81  
82          _calledGetReader = true;
83  
84          return getHttpServletRequest().getReader();
85      }
86  
87      public void defineObjects(PortletConfig portletConfig, ActionResponse res) {
88          setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, portletConfig);
89          setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, this);
90          setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, res);
91      }
92  
93      public boolean isAction() {
94          return true;
95      }
96  
97      protected ActionRequestImpl() {
98          if (_log.isDebugEnabled()) {
99              _log.debug("Creating new instance " + hashCode());
100         }
101     }
102 
103     protected void recycle() {
104         if (_log.isDebugEnabled()) {
105             _log.debug("Recycling instance " + hashCode());
106         }
107 
108         super.recycle();
109 
110         _calledGetReader = false;
111     }
112 
113     private static Log _log = LogFactory.getLog(ActionRequestImpl.class);
114 
115     private boolean _calledGetReader;
116 
117 }