1 package org.apache.velocity.tools.plugin.taglib.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import javax.servlet.jsp.tagext.SimpleTag;
26
27 import org.apache.commons.digester.annotations.rules.BeanPropertySetter;
28 import org.apache.commons.digester.annotations.rules.ObjectCreate;
29 import org.apache.commons.digester.annotations.rules.SetNext;
30 import org.apache.velocity.tools.view.jsp.jspimpl.VelocityToolsJspException;
31
32
33
34
35 @ObjectCreate(pattern = "taglib/tag")
36 public class Tag
37 {
38
39
40
41
42 @BeanPropertySetter(pattern = "taglib/tag/name")
43 private String name;
44
45
46
47
48 @BeanPropertySetter(pattern = "taglib/tag/description")
49 private String description;
50
51
52
53
54 @BeanPropertySetter(pattern = "taglib/tag/tag-class")
55 private String tagClass;
56
57
58
59
60 @BeanPropertySetter(pattern = "taglib/tag/body-content")
61 private String bodyContent;
62
63
64
65
66 private List<Attribute> attributes = new ArrayList<Attribute>();
67
68
69
70
71
72
73 public String getName()
74 {
75 return name;
76 }
77
78
79
80
81
82
83 public void setName(String name)
84 {
85 this.name = name;
86 }
87
88
89
90
91
92
93 public String getDescription()
94 {
95 return description;
96 }
97
98
99
100
101
102
103 public void setDescription(String description)
104 {
105 this.description = description;
106 }
107
108
109
110
111
112
113 public String getTagClass()
114 {
115 return tagClass;
116 }
117
118
119
120
121
122
123 public void setTagClass(String tagClass)
124 {
125 this.tagClass = tagClass;
126 }
127
128
129
130
131
132
133 public String getBodyContent()
134 {
135 return bodyContent;
136 }
137
138
139
140
141
142
143 public void setBodyContent(String bodyContent)
144 {
145 this.bodyContent = bodyContent;
146 }
147
148
149
150
151
152
153 public List<Attribute> getAttributes()
154 {
155 return attributes;
156 }
157
158
159
160
161
162
163 @SetNext
164 public void addAttribute(Attribute attribute)
165 {
166 attributes.add(attribute);
167 }
168
169
170
171
172
173
174 public boolean isSimpleTag() {
175 return SimpleTag.class.isAssignableFrom(getReflectedTagClass());
176 }
177
178
179
180
181
182
183 public boolean hasBody() {
184 return !"empty".equals(bodyContent);
185 }
186
187
188
189
190
191
192 public Class<?> getReflectedTagClass()
193 {
194 Class<?> clazz;
195 try
196 {
197 clazz = Class.forName(tagClass);
198 } catch (ClassNotFoundException e)
199 {
200 throw new VelocityToolsJspException("Problems obtaining class: " + tagClass, e);
201 }
202 return clazz;
203 }
204
205 @Override
206 public String toString()
207 {
208 return "Tag [name=" + name + ", description=" + description
209 + ", tagClass=" + tagClass + ", bodyContent=" + bodyContent
210 + ", attributes=" + attributes + "]";
211 }
212
213 }