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.xmlDefinition;
23
24 import org.apache.struts.tiles.DefinitionNameAttribute;
25 import org.apache.struts.tiles.DirectStringAttribute;
26 import org.apache.struts.tiles.PathAttribute;
27 import org.apache.struts.tiles.UntypedAttribute;
28
29
30
31
32 public class XmlAttribute {
33
34
35
36
37 private String name = null;
38
39
40
41
42
43 private Object value = null;
44
45
46
47
48 private String direct = null;
49
50
51
52
53 private String valueType = null;
54
55
56
57
58 private String role = null;
59
60
61
62
63
64
65 private Object realValue = null;
66
67
68
69
70 public XmlAttribute() {
71 super();
72 }
73
74
75
76
77 public XmlAttribute(String name, Object value) {
78 this.name = name;
79 this.value = value;
80 }
81
82
83
84
85
86
87 public String getName() {
88 return name;
89 }
90
91
92
93
94
95
96 public void setRole(String role) {
97 this.role = role;
98 }
99
100
101
102
103
104
105 public String getRole() {
106 return role;
107 }
108
109
110
111
112
113
114 public void setName(String aName) {
115 name = aName;
116 }
117
118
119
120
121
122
123 public String getAttribute() {
124 return name;
125 }
126
127
128
129
130
131
132 public void setAttribute(String aName) {
133 name = aName;
134 }
135
136
137
138
139
140
141
142 public Object getValue() {
143
144 if (this.realValue == null) {
145 this.realValue = this.computeRealValue();
146 }
147
148 return this.realValue;
149 }
150
151
152
153
154
155
156 public void setValue(Object aValue) {
157 realValue = null;
158 value = aValue;
159 }
160
161
162
163
164
165
166 public void setContent(Object aValue) {
167 setValue(aValue);
168 }
169
170
171
172
173
174
175 public void setBody(String body) {
176 if (body.length() == 0) {
177 return;
178 }
179
180 setValue(body);
181 }
182
183
184
185
186
187
188 public void setDirect(String value) {
189 this.direct = value;
190 }
191
192
193
194
195
196
197 public void setType(String value) {
198 this.valueType = value;
199 }
200
201
202
203
204 protected Object computeRealValue() {
205 Object realValue = value;
206
207
208
209 if (direct != null) {
210 this.valueType =
211 Boolean.valueOf(direct).booleanValue() ? "string" : "path";
212 }
213
214 if (value != null && valueType != null) {
215 String strValue = value.toString();
216
217 if (valueType.equalsIgnoreCase("string")) {
218 realValue = new DirectStringAttribute(strValue);
219
220 } else if (valueType.equalsIgnoreCase("page")) {
221 realValue = new PathAttribute(strValue);
222
223 } else if (valueType.equalsIgnoreCase("template")) {
224 realValue = new PathAttribute(strValue);
225
226 } else if (valueType.equalsIgnoreCase("instance")) {
227 realValue = new DefinitionNameAttribute(strValue);
228 }
229
230
231 if (role != null) {
232 ((UntypedAttribute) realValue).setRole(role);
233 }
234 }
235
236
237
238 if (role != null && value != null && valueType == null) {
239 realValue = new UntypedAttribute(value.toString(), role);
240 }
241
242 return realValue;
243 }
244 }