1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.taglib.bean;
19
20 import org.apache.struts.taglib.TagUtils;
21 import org.apache.struts.util.MessageResources;
22
23 import javax.servlet.jsp.JspException;
24 import javax.servlet.jsp.tagext.TagSupport;
25
26 /***
27 * Define a scripting variable that exposes the requested page context item as
28 * a scripting variable and a page scope bean.
29 *
30 * @version $Rev: 376840 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
31 * $
32 */
33 public class PageTag extends TagSupport {
34 /***
35 * The message resources for this package.
36 */
37 protected static MessageResources messages =
38 MessageResources.getMessageResources(
39 "org.apache.struts.taglib.bean.LocalStrings");
40
41
42
43 /***
44 * The name of the scripting variable that will be exposed as a page scope
45 * attribute.
46 */
47 protected String id = null;
48
49 /***
50 * The name of the page context property to be retrieved.
51 */
52 protected String property = null;
53
54 public String getId() {
55 return (this.id);
56 }
57
58 public void setId(String id) {
59 this.id = id;
60 }
61
62 public String getProperty() {
63 return (this.property);
64 }
65
66 public void setProperty(String property) {
67 this.property = property;
68 }
69
70
71
72 /***
73 * Retrieve the required configuration object and expose it as a scripting
74 * variable.
75 *
76 * @throws JspException if a JSP exception has occurred
77 */
78 public int doStartTag() throws JspException {
79
80 Object object = null;
81
82 if ("application".equalsIgnoreCase(property)) {
83 object = pageContext.getServletContext();
84 } else if ("config".equalsIgnoreCase(property)) {
85 object = pageContext.getServletConfig();
86 } else if ("request".equalsIgnoreCase(property)) {
87 object = pageContext.getRequest();
88 } else if ("response".equalsIgnoreCase(property)) {
89 object = pageContext.getResponse();
90 } else if ("session".equalsIgnoreCase(property)) {
91 object = pageContext.getSession();
92 } else {
93 JspException e =
94 new JspException(messages.getMessage("page.selector", property));
95
96 TagUtils.getInstance().saveException(pageContext, e);
97 throw e;
98 }
99
100
101 pageContext.setAttribute(id, object);
102
103 return (SKIP_BODY);
104 }
105
106 /***
107 * Release all allocated resources.
108 */
109 public void release() {
110 super.release();
111 id = null;
112 property = null;
113 }
114 }