1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19 package javax.servlet.jsp.tagext;
20
21 /**
22 * Tag information for a tag in a Tag Library;
23 * This class is instantiated from the Tag Library Descriptor file (TLD)
24 * and is available only at translation time.
25 *
26 *
27 */
28
29 public class TagInfo {
30
31 /**
32 * Static constant for getBodyContent() when it is JSP.
33 */
34
35 public static final String BODY_CONTENT_JSP = "JSP";
36
37 /**
38 * Static constant for getBodyContent() when it is Tag dependent.
39 */
40
41 public static final String BODY_CONTENT_TAG_DEPENDENT = "tagdependent";
42
43
44 /**
45 * Static constant for getBodyContent() when it is empty.
46 */
47
48 public static final String BODY_CONTENT_EMPTY = "empty";
49
50 /**
51 * Static constant for getBodyContent() when it is scriptless.
52 *
53 * @since 2.0
54 */
55 public static final String BODY_CONTENT_SCRIPTLESS = "scriptless";
56
57 /**
58 * Constructor for TagInfo from data in the JSP 1.1 format for TLD.
59 * This class is to be instantiated only from the TagLibrary code
60 * under request from some JSP code that is parsing a
61 * TLD (Tag Library Descriptor).
62 *
63 * Note that, since TagLibibraryInfo reflects both TLD information
64 * and taglib directive information, a TagInfo instance is
65 * dependent on a taglib directive. This is probably a
66 * design error, which may be fixed in the future.
67 *
68 * @param tagName The name of this tag
69 * @param tagClassName The name of the tag handler class
70 * @param bodycontent Information on the body content of these tags
71 * @param infoString The (optional) string information for this tag
72 * @param taglib The instance of the tag library that contains us.
73 * @param tagExtraInfo The instance providing extra Tag info. May be null
74 * @param attributeInfo An array of AttributeInfo data from descriptor.
75 * May be null;
76 *
77 */
78 public TagInfo(String tagName,
79 String tagClassName,
80 String bodycontent,
81 String infoString,
82 TagLibraryInfo taglib,
83 TagExtraInfo tagExtraInfo,
84 TagAttributeInfo[] attributeInfo) {
85 this.tagName = tagName;
86 this.tagClassName = tagClassName;
87 this.bodyContent = bodycontent;
88 this.infoString = infoString;
89 this.tagLibrary = taglib;
90 this.tagExtraInfo = tagExtraInfo;
91 this.attributeInfo = attributeInfo;
92
93 if (tagExtraInfo != null)
94 tagExtraInfo.setTagInfo(this);
95 }
96
97 /**
98 * Constructor for TagInfo from data in the JSP 1.2 format for TLD.
99 * This class is to be instantiated only from the TagLibrary code
100 * under request from some JSP code that is parsing a
101 * TLD (Tag Library Descriptor).
102 *
103 * Note that, since TagLibibraryInfo reflects both TLD information
104 * and taglib directive information, a TagInfo instance is
105 * dependent on a taglib directive. This is probably a
106 * design error, which may be fixed in the future.
107 *
108 * @param tagName The name of this tag
109 * @param tagClassName The name of the tag handler class
110 * @param bodycontent Information on the body content of these tags
111 * @param infoString The (optional) string information for this tag
112 * @param taglib The instance of the tag library that contains us.
113 * @param tagExtraInfo The instance providing extra Tag info. May be null
114 * @param attributeInfo An array of AttributeInfo data from descriptor.
115 * May be null;
116 * @param displayName A short name to be displayed by tools
117 * @param smallIcon Path to a small icon to be displayed by tools
118 * @param largeIcon Path to a large icon to be displayed by tools
119 * @param tvi An array of a TagVariableInfo (or null)
120 */
121 public TagInfo(String tagName,
122 String tagClassName,
123 String bodycontent,
124 String infoString,
125 TagLibraryInfo taglib,
126 TagExtraInfo tagExtraInfo,
127 TagAttributeInfo[] attributeInfo,
128 String displayName,
129 String smallIcon,
130 String largeIcon,
131 TagVariableInfo[] tvi) {
132 this.tagName = tagName;
133 this.tagClassName = tagClassName;
134 this.bodyContent = bodycontent;
135 this.infoString = infoString;
136 this.tagLibrary = taglib;
137 this.tagExtraInfo = tagExtraInfo;
138 this.attributeInfo = attributeInfo;
139 this.displayName = displayName;
140 this.smallIcon = smallIcon;
141 this.largeIcon = largeIcon;
142 this.tagVariableInfo = tvi;
143
144 if (tagExtraInfo != null)
145 tagExtraInfo.setTagInfo(this);
146 }
147
148 /**
149 * Constructor for TagInfo from data in the JSP 2.0 format for TLD.
150 * This class is to be instantiated only from the TagLibrary code
151 * under request from some JSP code that is parsing a
152 * TLD (Tag Library Descriptor).
153 *
154 * Note that, since TagLibibraryInfo reflects both TLD information
155 * and taglib directive information, a TagInfo instance is
156 * dependent on a taglib directive. This is probably a
157 * design error, which may be fixed in the future.
158 *
159 * @param tagName The name of this tag
160 * @param tagClassName The name of the tag handler class
161 * @param bodycontent Information on the body content of these tags
162 * @param infoString The (optional) string information for this tag
163 * @param taglib The instance of the tag library that contains us.
164 * @param tagExtraInfo The instance providing extra Tag info. May be null
165 * @param attributeInfo An array of AttributeInfo data from descriptor.
166 * May be null;
167 * @param displayName A short name to be displayed by tools
168 * @param smallIcon Path to a small icon to be displayed by tools
169 * @param largeIcon Path to a large icon to be displayed by tools
170 * @param tvi An array of a TagVariableInfo (or null)
171 * @param dynamicAttributes True if supports dynamic attributes
172 *
173 * @since 2.0
174 */
175 public TagInfo(String tagName,
176 String tagClassName,
177 String bodycontent,
178 String infoString,
179 TagLibraryInfo taglib,
180 TagExtraInfo tagExtraInfo,
181 TagAttributeInfo[] attributeInfo,
182 String displayName,
183 String smallIcon,
184 String largeIcon,
185 TagVariableInfo[] tvi,
186 boolean dynamicAttributes) {
187 this.tagName = tagName;
188 this.tagClassName = tagClassName;
189 this.bodyContent = bodycontent;
190 this.infoString = infoString;
191 this.tagLibrary = taglib;
192 this.tagExtraInfo = tagExtraInfo;
193 this.attributeInfo = attributeInfo;
194 this.displayName = displayName;
195 this.smallIcon = smallIcon;
196 this.largeIcon = largeIcon;
197 this.tagVariableInfo = tvi;
198 this.dynamicAttributes = dynamicAttributes;
199
200 if (tagExtraInfo != null)
201 tagExtraInfo.setTagInfo(this);
202 }
203
204 /**
205 * The name of the Tag.
206 *
207 * @return The (short) name of the tag.
208 */
209
210 public String getTagName() {
211 return tagName;
212 }
213
214 /**
215 * Attribute information (in the TLD) on this tag.
216 * The return is an array describing the attributes of this tag, as
217 * indicated in the TLD.
218 *
219 * @return The array of TagAttributeInfo for this tag, or a
220 * zero-length array if the tag has no attributes.
221 */
222
223 public TagAttributeInfo[] getAttributes() {
224 return attributeInfo;
225 }
226
227 /**
228 * Information on the scripting objects created by this tag at runtime.
229 * This is a convenience method on the associated TagExtraInfo class.
230 *
231 * @param data TagData describing this action.
232 * @return if a TagExtraInfo object is associated with this TagInfo, the
233 * result of getTagExtraInfo().getVariableInfo( data ), otherwise
234 * null.
235 */
236 public VariableInfo[] getVariableInfo(TagData data) {
237 VariableInfo[] result = null;
238 TagExtraInfo tei = getTagExtraInfo();
239 if (tei != null) {
240 result = tei.getVariableInfo( data );
241 }
242 return result;
243 }
244
245 /**
246 * Translation-time validation of the attributes.
247 * This is a convenience method on the associated TagExtraInfo class.
248 *
249 * @param data The translation-time TagData instance.
250 * @return Whether the data is valid.
251 */
252 public boolean isValid(TagData data) {
253 TagExtraInfo tei = getTagExtraInfo();
254 if (tei == null) {
255 return true;
256 }
257 return tei.isValid(data);
258 }
259
260 /**
261 * Translation-time validation of the attributes.
262 * This is a convenience method on the associated TagExtraInfo class.
263 *
264 * @param data The translation-time TagData instance.
265 * @return A null object, or zero length array if no errors, an
266 * array of ValidationMessages otherwise.
267 * @since 2.0
268 */
269 public ValidationMessage[] validate( TagData data ) {
270 TagExtraInfo tei = getTagExtraInfo();
271 if( tei == null ) {
272 return null;
273 }
274 return tei.validate( data );
275 }
276
277 /**
278 * Set the instance for extra tag information.
279 *
280 * @param tei the TagExtraInfo instance
281 */
282 public void setTagExtraInfo(TagExtraInfo tei) {
283 tagExtraInfo = tei;
284 }
285
286
287 /**
288 * The instance (if any) for extra tag information.
289 *
290 * @return The TagExtraInfo instance, if any.
291 */
292 public TagExtraInfo getTagExtraInfo() {
293 return tagExtraInfo;
294 }
295
296
297 /**
298 * Name of the class that provides the handler for this tag.
299 *
300 * @return The name of the tag handler class.
301 */
302
303 public String getTagClassName() {
304 return tagClassName;
305 }
306
307
308 /**
309 * The bodycontent information for this tag.
310 * If the bodycontent is not defined for this
311 * tag, the default of JSP will be returned.
312 *
313 * @return the body content string.
314 */
315
316 public String getBodyContent() {
317 return bodyContent;
318 }
319
320
321 /**
322 * The information string for the tag.
323 *
324 * @return the info string, or null if
325 * not defined
326 */
327
328 public String getInfoString() {
329 return infoString;
330 }
331
332
333 /**
334 * Set the TagLibraryInfo property.
335 *
336 * Note that a TagLibraryInfo element is dependent
337 * not just on the TLD information but also on the
338 * specific taglib instance used. This means that
339 * a fair amount of work needs to be done to construct
340 * and initialize TagLib objects.
341 *
342 * If used carefully, this setter can be used to avoid having to
343 * create new TagInfo elements for each taglib directive.
344 *
345 * @param tl the TagLibraryInfo to assign
346 */
347
348 public void setTagLibrary(TagLibraryInfo tl) {
349 tagLibrary = tl;
350 }
351
352 /**
353 * The instance of TabLibraryInfo we belong to.
354 *
355 * @return the tag library instance we belong to
356 */
357
358 public TagLibraryInfo getTagLibrary() {
359 return tagLibrary;
360 }
361
362
363 // ============== JSP 2.0 TLD Information ========
364
365
366 /**
367 * Get the displayName.
368 *
369 * @return A short name to be displayed by tools,
370 * or null if not defined
371 */
372
373 public String getDisplayName() {
374 return displayName;
375 }
376
377 /**
378 * Get the path to the small icon.
379 *
380 * @return Path to a small icon to be displayed by tools,
381 * or null if not defined
382 */
383
384 public String getSmallIcon() {
385 return smallIcon;
386 }
387
388 /**
389 * Get the path to the large icon.
390 *
391 * @return Path to a large icon to be displayed by tools,
392 * or null if not defined
393 */
394
395 public String getLargeIcon() {
396 return largeIcon;
397 }
398
399 /**
400 * Get TagVariableInfo objects associated with this TagInfo.
401 *
402 * @return Array of TagVariableInfo objects corresponding to
403 * variables declared by this tag, or a zero length
404 * array if no variables have been declared
405 */
406
407 public TagVariableInfo[] getTagVariableInfos() {
408 return tagVariableInfo;
409 }
410
411
412 // ============== JSP 2.0 TLD Information ========
413
414 /**
415 * Get dynamicAttributes associated with this TagInfo.
416 *
417 * @return True if tag handler supports dynamic attributes
418 * @since 2.0
419 */
420 public boolean hasDynamicAttributes() {
421 return dynamicAttributes;
422 }
423
424 /*
425 * private fields for 1.1 info
426 */
427 private String tagName; // the name of the tag
428 private String tagClassName;
429 private String bodyContent;
430 private String infoString;
431 private TagLibraryInfo tagLibrary;
432 private TagExtraInfo tagExtraInfo; // instance of TagExtraInfo
433 private TagAttributeInfo[] attributeInfo;
434
435 /*
436 * private fields for 1.2 info
437 */
438 private String displayName;
439 private String smallIcon;
440 private String largeIcon;
441 private TagVariableInfo[] tagVariableInfo;
442
443 /*
444 * Additional private fields for 2.0 info
445 */
446 private boolean dynamicAttributes;
447 }