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.tiles.jsp.taglib;
23
24 import java.io.IOException;
25
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.tagext.SimpleTagSupport;
28 import javax.servlet.jsp.tagext.TagData;
29 import javax.servlet.jsp.tagext.TagExtraInfo;
30 import javax.servlet.jsp.tagext.VariableInfo;
31
32 import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
33 import org.apache.tiles.request.Request;
34 import org.apache.tiles.template.ImportAttributeModel;
35
36
37
38
39
40
41
42 public class UseAttributeTag extends SimpleTagSupport {
43
44
45
46
47 private ImportAttributeModel model = new ImportAttributeModel();
48
49
50
51
52 private String id;
53
54
55
56
57 private String scopeName = null;
58
59
60
61
62 private String name = null;
63
64
65
66
67 private boolean ignore = false;
68
69
70
71
72 private String classname = null;
73
74
75
76
77
78
79
80 public String getId() {
81 return id;
82 }
83
84
85
86
87
88
89
90
91 public void setId(String id) {
92 this.id = id;
93 }
94
95
96
97
98
99
100
101 public void setScope(String scope) {
102 this.scopeName = scope;
103 }
104
105
106
107
108
109
110 public String getScope() {
111 return scopeName;
112 }
113
114
115
116
117
118
119 public String getName() {
120 return name;
121 }
122
123
124
125
126
127
128
129 public void setName(String name) {
130 this.name = name;
131 }
132
133
134
135
136
137
138
139
140
141
142 public void setIgnore(boolean ignore) {
143 this.ignore = ignore;
144 }
145
146
147
148
149
150
151
152
153
154 public boolean isIgnore() {
155 return ignore;
156 }
157
158
159
160
161
162
163 public String getClassname() {
164 return classname;
165
166 }
167
168
169
170
171
172
173
174 public void setClassname(String name) {
175 this.classname = name;
176 }
177
178
179 @Override
180 public void doTag() throws JspException, IOException {
181 AutotagRuntime<Request> runtime = new org.apache.tiles.request.jsp.autotag.JspAutotagRuntime();
182 if (runtime instanceof SimpleTagSupport) {
183 SimpleTagSupport tag = (SimpleTagSupport) runtime;
184 tag.setJspContext(getJspContext());
185 tag.setJspBody(getJspBody());
186 tag.setParent(getParent());
187 tag.doTag();
188 }
189 Request request = runtime.createRequest();
190 model.execute(name, scopeName, id, ignore, request);
191 }
192
193
194
195
196
197
198 public String getScriptingVariable() {
199 return id == null ? getName() : id;
200 }
201
202
203
204
205
206 public static class Tei extends TagExtraInfo {
207
208
209 @Override
210 public VariableInfo[] getVariableInfo(TagData data) {
211 String classname = data.getAttributeString("classname");
212 if (classname == null) {
213 classname = "java.lang.Object";
214 }
215
216 String id = data.getAttributeString("id");
217 if (id == null) {
218 id = data.getAttributeString("name");
219 }
220
221 return new VariableInfo[] { new VariableInfo(id, classname, true,
222 VariableInfo.AT_END) };
223
224 }
225 }
226 }