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.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.ServletRequest;
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          ServletRequest req = pageContext.getRequest();
46  
47          String lifecycle = (String)req.getAttribute(
48              PortletRequest.LIFECYCLE_PHASE);
49  
50          PortletConfigImpl portletConfig = (PortletConfigImpl)req.getAttribute(
51              JavaConstants.JAVAX_PORTLET_CONFIG);
52  
53          if (portletConfig != null) {
54              pageContext.setAttribute("portletConfig", portletConfig);
55              pageContext.setAttribute(
56                  "portletName", portletConfig.getPortletName());
57          }
58  
59          PortletRequest portletRequest = (PortletRequest)req.getAttribute(
60              JavaConstants.JAVAX_PORTLET_REQUEST);
61  
62          if (portletRequest != null) {
63              String portletRequestAttrName = null;
64  
65              if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
66                  portletRequestAttrName = "actionRequest";
67              }
68              else if (lifecycle.equals(PortletRequest.EVENT_PHASE)) {
69                  portletRequestAttrName = "eventRequest";
70              }
71              else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
72                  portletRequestAttrName = "renderRequest";
73              }
74              else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
75                  portletRequestAttrName = "resourceRequest";
76              }
77  
78              pageContext.setAttribute(portletRequestAttrName, portletRequest);
79  
80              PortletPreferences portletPreferences =
81                  portletRequest.getPreferences();
82  
83              pageContext.setAttribute("portletPreferences", portletPreferences);
84              pageContext.setAttribute(
85                  "portletPreferencesValues", portletPreferences.getMap());
86  
87              PortletSession portletSession = portletRequest.getPortletSession();
88  
89              pageContext.setAttribute("portletSession", portletSession);
90  
91              try {
92                  pageContext.setAttribute(
93                      "portletSessionScope", portletSession.getAttributeMap());
94              }
95              catch (IllegalStateException ise) {
96              }
97          }
98  
99          PortletResponse portletResponse = (PortletResponse)req.getAttribute(
100             JavaConstants.JAVAX_PORTLET_RESPONSE);
101 
102         if (portletResponse != null) {
103             String portletResponseAttrName = null;
104 
105             if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
106                 portletResponseAttrName = "actionResponse";
107             }
108             else if (lifecycle.equals(PortletRequest.EVENT_PHASE)) {
109                 portletResponseAttrName = "eventResponse";
110             }
111             else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
112                 portletResponseAttrName = "renderResponse";
113             }
114             else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
115                 portletResponseAttrName = "resourceResponse";
116             }
117 
118             pageContext.setAttribute(portletResponseAttrName, portletResponse);
119         }
120     }
121 
122 }