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
26 import org.apache.struts.tiles.taglib.util.TagUtils;
27 import org.apache.struts.tiles.AttributeDefinition;
28 import org.apache.struts.tiles.ComponentDefinition;
29 import org.apache.struts.tiles.UntypedAttribute;
30
31
32
33
34
35
36
37
38 public class DefinitionTag
39 extends DefinitionTagSupport
40 implements PutTagParent, PutListTagParent {
41
42
43
44
45
46 private String id = null;
47
48
49
50
51 private String scope = null;
52
53
54
55
56 private String extendsDefinition = null;
57
58
59
60
61
62 private ComponentDefinition definition = null;
63
64
65
66
67
68 public void release() {
69 super.release();
70 id = null;
71 page = null;
72 scope = null;
73 role = null;
74 extendsDefinition = null;
75 }
76
77
78
79
80 protected void releaseInternal() {
81 definition = null;
82 }
83
84
85
86
87
88
89 public void putAttribute(String name, Object content) {
90 definition.putAttribute(name, content);
91 }
92
93
94
95
96
97
98
99
100 public void processNestedTag(PutTag nestedTag) throws JspException {
101
102
103
104 Object attributeValue = nestedTag.getRealValue();
105 AttributeDefinition def;
106
107 if (nestedTag.getRole() != null) {
108 try {
109 def = ((AttributeDefinition) attributeValue);
110 } catch (ClassCastException ex) {
111 def = new UntypedAttribute(attributeValue);
112 }
113 def.setRole(nestedTag.getRole());
114 attributeValue = def;
115 }
116
117
118 putAttribute(nestedTag.getName(), attributeValue);
119 }
120
121
122
123
124
125
126
127
128 public void processNestedTag(PutListTag nestedTag) throws JspException {
129
130
131
132 Object attributeValue = nestedTag.getList();
133
134 if (nestedTag.getRole() != null) {
135 AttributeDefinition def = new UntypedAttribute(attributeValue);
136 def.setRole(nestedTag.getRole());
137 attributeValue = def;
138 }
139
140
141 if (nestedTag.getName() == null) {
142 throw new JspException("Error - PutList : attribute name is not defined. It is mandatory as the list is added to a 'definition'.");
143 }
144
145
146 putAttribute(nestedTag.getName(), attributeValue);
147 }
148
149
150
151
152
153 public String getId() {
154 return id;
155 }
156
157
158
159
160
161 public void setId(String id) {
162 this.id = id;
163 }
164
165
166
167
168
169 public String getScope() {
170 return scope;
171 }
172
173
174
175
176
177 public void setScope(String aScope) {
178 scope = aScope;
179 }
180
181
182
183
184
185 public void setExtends(String definitionName) {
186 this.extendsDefinition = definitionName;
187 }
188
189
190
191
192
193 public String getExtends() {
194 return extendsDefinition;
195 }
196
197
198
199
200
201 public int doStartTag() throws JspException {
202
203 if (extendsDefinition != null && !extendsDefinition.equals("")) {
204 ComponentDefinition parentDef =
205 TagUtils.getComponentDefinition(extendsDefinition, pageContext);
206
207 definition = new ComponentDefinition(parentDef);
208
209 } else {
210 definition = new ComponentDefinition();
211 }
212
213
214 if (page != null) {
215 definition.setTemplate(page);
216 }
217
218 if (role != null) {
219 definition.setRole(role);
220 }
221
222 return EVAL_BODY_INCLUDE;
223 }
224
225
226
227
228
229 public int doEndTag() throws JspException {
230 TagUtils.setAttribute(pageContext, id, definition, scope);
231
232 releaseInternal();
233 return EVAL_PAGE;
234 }
235
236 }