KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > bean > PageTag


1 /*
2  * $Id: PageTag.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.struts.taglib.bean;
21
22
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25 import org.apache.struts.util.MessageResources;
26 import org.apache.struts.taglib.TagUtils;
27
28
29 /**
30  * Define a scripting variable that exposes the requested page context
31  * item as a scripting variable and a page scope bean.
32  *
33  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
34  */

35
36 public class PageTag extends TagSupport JavaDoc {
37
38
39     // ------------------------------------------------------------- Properties
40

41
42     /**
43      * The name of the scripting variable that will be exposed as a page
44      * scope attribute.
45      */

46     protected String JavaDoc id = null;
47
48     public String JavaDoc getId() {
49         return (this.id);
50     }
51
52     public void setId(String JavaDoc id) {
53         this.id = id;
54     }
55
56
57     /**
58      * The message resources for this package.
59      */

60     protected static MessageResources messages =
61         MessageResources.getMessageResources
62         ("org.apache.struts.taglib.bean.LocalStrings");
63
64
65     /**
66      * The name of the page context property to be retrieved.
67      */

68     protected String JavaDoc property = null;
69
70     public String JavaDoc getProperty() {
71         return (this.property);
72     }
73
74     public void setProperty(String JavaDoc property) {
75         this.property = property;
76     }
77
78
79     // --------------------------------------------------------- Public Methods
80

81
82     /**
83      * Retrieve the required configuration object and expose it as a
84      * scripting variable.
85      *
86      * @exception JspException if a JSP exception has occurred
87      */

88     public int doStartTag() throws JspException JavaDoc {
89
90         // Retrieve the requested object to be exposed
91
Object JavaDoc object = null;
92         if ("application".equalsIgnoreCase(property))
93             object = pageContext.getServletContext();
94         else if ("config".equalsIgnoreCase(property))
95             object = pageContext.getServletConfig();
96         else if ("request".equalsIgnoreCase(property))
97             object = pageContext.getRequest();
98         else if ("response".equalsIgnoreCase(property))
99             object = pageContext.getResponse();
100         else if ("session".equalsIgnoreCase(property))
101             object = pageContext.getSession();
102         else {
103             JspException JavaDoc e = new JspException JavaDoc
104                 (messages.getMessage("page.selector", property));
105             TagUtils.getInstance().saveException(pageContext, e);
106             throw e;
107         }
108
109         // Expose this value as a scripting variable
110
pageContext.setAttribute(id, object);
111         return (SKIP_BODY);
112
113     }
114
115
116     /**
117      * Release all allocated resources.
118      */

119     public void release() {
120
121         super.release();
122         id = null;
123         property = null;
124
125     }
126
127
128 }
129
Popular Tags