1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.tiles.taglib;
23
24 import javax.servlet.jsp.JspException;
25 import javax.servlet.jsp.PageContext;
26 import javax.servlet.jsp.tagext.TagSupport;
27
28 import org.apache.struts.tiles.taglib.util.TagUtils;
29 import org.apache.struts.tiles.ComponentContext;
30
31
32
33
34
35
36 public class UseAttributeTag extends TagSupport {
37
38
39
40
41
42
43
44
45 private String classname = null;
46
47
48
49
50
51 private String scopeName = null;
52
53
54
55
56 private int scope = PageContext.PAGE_SCOPE;
57
58
59
60
61
62
63 private String attributeName = null;
64
65
66
67
68
69
70 protected boolean isErrorIgnored = false;
71
72
73
74
75
76
77
78
79 public void release() {
80
81 super.release();
82 attributeName = null;
83 classname = null;
84 scope = PageContext.PAGE_SCOPE;
85 scopeName = null;
86 isErrorIgnored = false;
87
88
89 id = null;
90 }
91
92
93
94
95 public String getClassname() {
96
97 return (this.classname);
98
99 }
100
101
102
103
104
105
106
107 public void setClassname(String name) {
108
109 this.classname = name;
110
111 }
112
113
114
115
116 public void setName(String value){
117 this.attributeName = value;
118 }
119
120
121
122
123 public String getName()
124 {
125 return attributeName;
126 }
127
128
129
130
131
132
133 public void setScope(String scope) {
134 this.scopeName = scope;
135 }
136
137
138
139
140 public String getScope()
141 {
142 return scopeName;
143 }
144
145
146
147
148 public void setIgnore(boolean ignore)
149 {
150 this.isErrorIgnored = ignore;
151 }
152
153
154
155
156 public boolean getIgnore()
157 {
158 return isErrorIgnored;
159 }
160
161
162
163
164
165
166
167
168
169 public int doStartTag() throws JspException
170 {
171
172 String localId=this.id;
173 if( localId==null )
174 localId=attributeName;
175
176 ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
177 if( compContext == null )
178 throw new JspException ( "Error - tag useAttribute : no tiles context found." );
179
180 Object value = compContext.getAttribute(attributeName);
181
182 if( value == null )
183 if(!isErrorIgnored)
184 throw new JspException ( "Error - tag useAttribute : attribute '"+ attributeName + "' not found in context. Check tag syntax" );
185 else
186 return SKIP_BODY;
187
188 if( scopeName != null )
189 {
190 scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
191 if(scope!=ComponentConstants.COMPONENT_SCOPE)
192 pageContext.setAttribute(localId, value, scope);
193 }
194 else
195 pageContext.setAttribute(localId, value);
196
197
198 return SKIP_BODY;
199 }
200
201
202
203
204
205
206
207
208
209 public int doEndTag() throws JspException
210 {
211 return (EVAL_PAGE);
212 }
213
214 }