View Javadoc

1   /*
2    * Copyright 2003,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /* 
17  
18   */
19  
20  package org.apache.pluto.tags;
21  
22  import javax.portlet.*;
23  
24  import javax.servlet.jsp.*;
25  import javax.servlet.jsp.tagext.*;
26  
27  import org.apache.pluto.Constants;
28  
29  
30  /***
31   * Supporting class for the <CODE>defineObjects</CODE> tag.
32   * Creates the following variables to be used in the JSP:
33   * <UL>
34   * <LI><CODE>renderRequest</CODE>
35   * <LI><CODE>renderResponse</CODE>
36   * <LI><CODE>portletConfig</CODE>
37   * </UL>
38   * @see   javax.portlet.PortletRequest
39   * @see   javax.portlet.RenderResponse
40   * @see   javax.portlet.PortletConfig
41   *
42   */
43  public class DefineObjectsTag extends TagSupport
44  {
45  
46      /***
47       * Processes the <CODE>defineObjects</CODE> tag.
48       * @return <CODE>SKIP_BODY</CODE>
49       */
50      public int doStartTag() throws JspException
51      {
52          PortletRequest renderRequest = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST);
53          RenderResponse renderResponse = (RenderResponse)pageContext.getRequest().getAttribute(Constants.PORTLET_RESPONSE);
54          PortletConfig portletConfig = (PortletConfig)pageContext.getRequest().getAttribute(Constants.PORTLET_CONFIG);
55  
56          if (pageContext.getAttribute("renderRequest") == null)   //Set attributes only once
57          {
58              pageContext.setAttribute("renderRequest",
59                                       renderRequest,
60                                       PageContext.PAGE_SCOPE);
61          }
62  
63          if (pageContext.getAttribute("renderResponse") == null)
64          {
65              pageContext.setAttribute("renderResponse",
66                                       renderResponse,
67                                       PageContext.PAGE_SCOPE);
68          }
69  
70          if (pageContext.getAttribute("portletConfig") == null)
71          {
72              pageContext.setAttribute("portletConfig",
73                                       portletConfig,
74                                       PageContext.PAGE_SCOPE);
75          }
76  
77          return SKIP_BODY;
78      }
79  
80      public static class TEI extends TagExtraInfo
81      {
82  
83          public VariableInfo [] getVariableInfo (TagData tagData)
84          {
85              VariableInfo [] info = new VariableInfo [] {
86                  new VariableInfo("renderRequest",
87                                   "javax.portlet.PortletRequest",
88                                   true,
89                                   VariableInfo.AT_BEGIN),
90                  new VariableInfo("renderResponse",
91                                   "javax.portlet.RenderResponse",
92                                   true,
93                                   VariableInfo.AT_BEGIN),
94                  new VariableInfo("portletConfig",
95                                   "javax.portlet.PortletConfig",
96                                   true,
97                                   VariableInfo.AT_BEGIN)
98              };
99  
100             return info;
101         }
102     }
103 }