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 java.util.ArrayList;
25 import java.util.List;
26
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.tagext.TagSupport;
29
30 import org.apache.struts.tiles.AttributeDefinition;
31 import org.apache.struts.tiles.UntypedAttribute;
32
33
34
35
36 public class PutListTag
37 extends TagSupport
38 implements ComponentConstants, AddTagParent, PutListTagParent {
39
40
41
42
43 private String attributeName = null;
44
45
46
47
48 private List list = null;
49
50
51
52
53 private String role = null;
54
55
56
57
58 public PutListTag() {
59 super();
60 }
61
62
63
64
65 public void release() {
66 super.release();
67 attributeName = null;
68 role = null;
69 }
70
71
72
73
74 protected void releaseInternal() {
75 list = null;
76 }
77
78
79
80
81 public void setName(String name) {
82 this.attributeName = name;
83 }
84
85
86
87
88 public String getName() {
89 return attributeName;
90 }
91
92
93
94
95
96 public void setRole(String role) {
97 this.role = role;
98 }
99
100
101
102
103 public String getRole() {
104 return role;
105 }
106
107
108
109
110 public List getList() {
111 return list;
112 }
113
114
115
116
117 public void addElement(Object value) {
118 if (list == null) {
119 list = new ArrayList();
120 }
121
122 list.add(value);
123 }
124
125
126
127
128
129
130
131
132 public void processNestedTag(PutListTag nestedTag) throws JspException {
133
134
135
136 Object attributeValue = nestedTag.getList();
137
138 if (nestedTag.getRole() != null) {
139 AttributeDefinition def = new UntypedAttribute(attributeValue);
140 def.setRole(nestedTag.getRole());
141 attributeValue = def;
142 }
143
144
145 addElement(attributeValue);
146 }
147
148
149
150
151
152
153
154
155 public void processNestedTag(AddTag nestedTag) throws JspException {
156
157
158
159 Object attributeValue = nestedTag.getRealValue();
160 AttributeDefinition def;
161
162 if (nestedTag.getRole() != null) {
163 try {
164 def = ((AttributeDefinition) attributeValue);
165 } catch (ClassCastException ex) {
166 def = new UntypedAttribute(attributeValue);
167 }
168 def.setRole(nestedTag.getRole());
169 attributeValue = def;
170 }
171
172
173 addElement(attributeValue);
174 }
175
176
177
178
179 public int doStartTag() throws JspException {
180 return EVAL_BODY_INCLUDE;
181 }
182
183
184
185
186 public int doEndTag() throws JspException {
187 PutListTagParent enclosingParent = findEnclosingParent();
188 enclosingParent.processNestedTag(this);
189
190 releaseInternal();
191 return EVAL_PAGE;
192 }
193
194
195
196
197
198 protected PutListTagParent findEnclosingParent() throws JspException {
199 try {
200 PutListTagParent parent =
201 (PutListTagParent) findAncestorWithClass(this,
202 PutListTagParent.class);
203
204 if (parent == null) {
205 throw new JspException("Error - tag putList : enclosing tag doesn't accept 'putList' tag.");
206 }
207
208 return parent;
209
210 } catch (ClassCastException ex) {
211 throw new JspException("Error - tag putList : enclosing tag doesn't accept 'putList' tag.", ex);
212 }
213 }
214
215 }