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