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.portal.servlet.taglib.portlet;
24  
25  import com.liferay.portal.kernel.util.JavaConstants;
26  import com.liferay.portlet.PortletConfigImpl;
27  
28  import javax.portlet.PortletPreferences;
29  import javax.portlet.PortletRequest;
30  import javax.portlet.PortletResponse;
31  import javax.portlet.PortletSession;
32  
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.jsp.PageContext;
35  
36  /**
37   * <a href="DefineObjectsTagUtil.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class DefineObjectsTagUtil {
43  
44      public static void doStartTag(PageContext pageContext) {
45          HttpServletRequest request =
46              (HttpServletRequest)pageContext.getRequest();
47  
48          String lifecycle = (String)request.getAttribute(
49              PortletRequest.LIFECYCLE_PHASE);
50  
51          PortletConfigImpl portletConfig =
52              (PortletConfigImpl)request.getAttribute(
53                  JavaConstants.JAVAX_PORTLET_CONFIG);
54  
55          if (portletConfig != null) {
56              pageContext.setAttribute("portletConfig", portletConfig);
57              pageContext.setAttribute(
58                  "portletName", portletConfig.getPortletName());
59          }
60  
61          PortletRequest portletRequest = (PortletRequest)request.getAttribute(
62              JavaConstants.JAVAX_PORTLET_REQUEST);
63  
64          if (portletRequest != null) {
65              String portletRequestAttrName = null;
66  
67              if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
68                  portletRequestAttrName = "actionRequest";
69              }
70              else if (lifecycle.equals(PortletRequest.EVENT_PHASE)) {
71                  portletRequestAttrName = "eventRequest";
72              }
73              else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
74                  portletRequestAttrName = "renderRequest";
75              }
76              else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
77                  portletRequestAttrName = "resourceRequest";
78              }
79  
80              pageContext.setAttribute(portletRequestAttrName, portletRequest);
81  
82              PortletPreferences portletPreferences =
83                  portletRequest.getPreferences();
84  
85              pageContext.setAttribute("portletPreferences", portletPreferences);
86              pageContext.setAttribute(
87                  "portletPreferencesValues", portletPreferences.getMap());
88  
89              PortletSession portletSession = portletRequest.getPortletSession();
90  
91              pageContext.setAttribute("portletSession", portletSession);
92  
93              try {
94                  pageContext.setAttribute(
95                      "portletSessionScope", portletSession.getAttributeMap());
96              }
97              catch (IllegalStateException ise) {
98              }
99          }
100 
101         PortletResponse portletResponse = (PortletResponse)request.getAttribute(
102             JavaConstants.JAVAX_PORTLET_RESPONSE);
103 
104         if (portletResponse != null) {
105             String portletResponseAttrName = null;
106 
107             if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
108                 portletResponseAttrName = "actionResponse";
109             }
110             else if (lifecycle.equals(PortletRequest.EVENT_PHASE)) {
111                 portletResponseAttrName = "eventResponse";
112             }
113             else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
114                 portletResponseAttrName = "renderResponse";
115             }
116             else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
117                 portletResponseAttrName = "resourceResponse";
118             }
119 
120             pageContext.setAttribute(portletResponseAttrName, portletResponse);
121         }
122     }
123 
124 }