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