KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > tags > DefineObjectsTag


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.PortletConfig;
23 import javax.portlet.PortletRequest;
24 import javax.portlet.RenderResponse;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import javax.servlet.jsp.PageContext JavaDoc;
27 import javax.servlet.jsp.tagext.TagData JavaDoc;
28 import javax.servlet.jsp.tagext.TagExtraInfo JavaDoc;
29 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
30 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
31
32 import org.apache.pluto.Constants;
33
34
35 /**
36  * Supporting class for the <CODE>defineObjects</CODE> tag.
37  * Creates the following variables to be used in the JSP:
38  * <UL>
39  * <LI><CODE>renderRequest</CODE>
40  * <LI><CODE>renderResponse</CODE>
41  * <LI><CODE>portletConfig</CODE>
42  * </UL>
43  * @see javax.portlet.PortletRequest
44  * @see javax.portlet.RenderResponse
45  * @see javax.portlet.PortletConfig
46  *
47  */

48 public class DefineObjectsTag extends TagSupport JavaDoc
49 {
50
51     /**
52      * Processes the <CODE>defineObjects</CODE> tag.
53      * @return <CODE>SKIP_BODY</CODE>
54      */

55     public int doStartTag() throws JspException JavaDoc
56     {
57         PortletRequest renderRequest = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST);
58         RenderResponse renderResponse = (RenderResponse)pageContext.getRequest().getAttribute(Constants.PORTLET_RESPONSE);
59         PortletConfig portletConfig = (PortletConfig)pageContext.getRequest().getAttribute(Constants.PORTLET_CONFIG);
60
61         if (pageContext.getAttribute("renderRequest") == null) //Set attributes only once
62
{
63             pageContext.setAttribute("renderRequest",
64                                      renderRequest,
65                                      PageContext.PAGE_SCOPE);
66         }
67
68         if (pageContext.getAttribute("renderResponse") == null)
69         {
70             pageContext.setAttribute("renderResponse",
71                                      renderResponse,
72                                      PageContext.PAGE_SCOPE);
73         }
74
75         if (pageContext.getAttribute("portletConfig") == null)
76         {
77             pageContext.setAttribute("portletConfig",
78                                      portletConfig,
79                                      PageContext.PAGE_SCOPE);
80         }
81
82         return SKIP_BODY;
83     }
84
85     public static class TEI extends TagExtraInfo JavaDoc
86     {
87
88         public VariableInfo JavaDoc [] getVariableInfo (TagData JavaDoc tagData)
89         {
90             VariableInfo JavaDoc [] info = new VariableInfo JavaDoc [] {
91                 new VariableInfo JavaDoc("renderRequest",
92                                  "javax.portlet.PortletRequest",
93                                  true,
94                                  VariableInfo.AT_BEGIN),
95                 new VariableInfo JavaDoc("renderResponse",
96                                  "javax.portlet.RenderResponse",
97                                  true,
98                                  VariableInfo.AT_BEGIN),
99                 new VariableInfo JavaDoc("portletConfig",
100                                  "javax.portlet.PortletConfig",
101                                  true,
102                                  VariableInfo.AT_BEGIN)
103             };
104
105             return info;
106         }
107     }
108 }
109
Popular Tags