1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.struts.tiles.taglib;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.TagSupport;
24
25 import org.apache.struts.tiles.taglib.util.TagUtils;
26 import org.apache.struts.tiles.ComponentContext;
27
28
29 /***
30 * Custom tag that puts component's attributes in a scope (request, page, ...).
31 * @deprecated Is it still in use ?
32 */
33 public final class AttributeToScopeTag extends TagSupport {
34
35
36
37
38
39 /***
40 * The scope name.
41 */
42 private String scopeName = null;
43
44 /***
45 * The scope value.
46 */
47 private int scope = PageContext.PAGE_SCOPE;
48
49
50
51 /***
52 * The property name to be exposed.
53 */
54 private String property = null;
55
56
57
58
59
60
61 /***
62 * Return the property name.
63 */
64 public String getProperty()
65 {
66 return (this.property);
67 }
68
69
70 /***
71 * Set the property name.
72 *
73 * @param property The property name
74 */
75 public void setProperty(String property)
76 {
77 this.property = property;
78 }
79
80 /***
81 * Set the scope.
82 *
83 * @param scope The new scope
84 */
85 public void setScope(String scope)
86 {
87 this.scopeName = scope;
88 }
89
90
91
92
93 /***
94 * Expose the requested property from component context.
95 *
96 * @exception JspException if a JSP exception has occurred
97 */
98 public int doStartTag() throws JspException
99 {
100 if( id==null )
101 id=property;
102
103 ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
104
105 if( compContext == null )
106 throw new JspException ( "Error - tag.useProperty : component context is not defined. Check tag syntax" );
107
108 Object value = compContext.getAttribute(property);
109 if( value == null )
110 throw new JspException ( "Error - tag.useProperty : property '"+ property + "' not found in context. Check tag syntax" );
111
112 if( scopeName != null )
113 {
114 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
115 pageContext.setAttribute(id, value, scope);
116 }
117 else
118 pageContext.setAttribute(id, value);
119
120
121 return SKIP_BODY;
122 }
123
124
125
126
127 /***
128 * Clean up after processing this enumeration.
129 *
130 * @exception JspException if a JSP exception has occurred
131 */
132 public int doEndTag() throws JspException
133 {
134 return (EVAL_PAGE);
135 }
136
137 /***
138 * Release all allocated resources.
139 */
140 public void release() {
141
142 super.release();
143 property = null;
144 scopeName = null;
145 scope = PageContext.PAGE_SCOPE;
146 }
147
148 }