001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 // 021 // This source code implements specifications defined by the Java 022 // Community Process. In order to remain compliant with the specification 023 // DO NOT add / change / or delete method signatures! 024 // 025 026 package javax.servlet.jsp.tagext; 027 028 /** 029 * Tag information for a tag in a Tag Library; 030 * This class is instantiated from the Tag Library Descriptor file (TLD) 031 * and is available only at translation time. 032 * 033 * 034 */ 035 036 public class TagInfo { 037 038 /** 039 * Static constant for getBodyContent() when it is JSP. 040 */ 041 042 public static final String BODY_CONTENT_JSP = "JSP"; 043 044 /** 045 * Static constant for getBodyContent() when it is Tag dependent. 046 */ 047 048 public static final String BODY_CONTENT_TAG_DEPENDENT = "TAGDEPENDENT"; 049 050 051 /** 052 * Static constant for getBodyContent() when it is empty. 053 */ 054 055 public static final String BODY_CONTENT_EMPTY = "EMPTY"; 056 057 /** 058 * Static constant for getBodyContent() when it is scriptless. 059 * 060 * @since 2.0 061 */ 062 public static final String BODY_CONTENT_SCRIPTLESS = "SCRIPTLESS"; 063 064 /** 065 * Constructor for TagInfo from data in the JSP 1.1 format for TLD. 066 * This class is to be instantiated only from the TagLibrary code 067 * under request from some JSP code that is parsing a 068 * TLD (Tag Library Descriptor). 069 * 070 * Note that, since TagLibibraryInfo reflects both TLD information 071 * and taglib directive information, a TagInfo instance is 072 * dependent on a taglib directive. This is probably a 073 * design error, which may be fixed in the future. 074 * 075 * @param tagName The name of this tag 076 * @param tagClassName The name of the tag handler class 077 * @param bodycontent Information on the body content of these tags 078 * @param infoString The (optional) string information for this tag 079 * @param taglib The instance of the tag library that contains us. 080 * @param tagExtraInfo The instance providing extra Tag info. May be null 081 * @param attributeInfo An array of AttributeInfo data from descriptor. 082 * May be null; 083 * 084 */ 085 public TagInfo(String tagName, 086 String tagClassName, 087 String bodycontent, 088 String infoString, 089 TagLibraryInfo taglib, 090 TagExtraInfo tagExtraInfo, 091 TagAttributeInfo[] attributeInfo) { 092 this.tagName = tagName; 093 this.tagClassName = tagClassName; 094 this.bodyContent = bodycontent; 095 this.infoString = infoString; 096 this.tagLibrary = taglib; 097 this.tagExtraInfo = tagExtraInfo; 098 this.attributeInfo = attributeInfo; 099 100 if (tagExtraInfo != null) 101 tagExtraInfo.setTagInfo(this); 102 } 103 104 /** 105 * Constructor for TagInfo from data in the JSP 1.2 format for TLD. 106 * This class is to be instantiated only from the TagLibrary code 107 * under request from some JSP code that is parsing a 108 * TLD (Tag Library Descriptor). 109 * 110 * Note that, since TagLibibraryInfo reflects both TLD information 111 * and taglib directive information, a TagInfo instance is 112 * dependent on a taglib directive. This is probably a 113 * design error, which may be fixed in the future. 114 * 115 * @param tagName The name of this tag 116 * @param tagClassName The name of the tag handler class 117 * @param bodycontent Information on the body content of these tags 118 * @param infoString The (optional) string information for this tag 119 * @param taglib The instance of the tag library that contains us. 120 * @param tagExtraInfo The instance providing extra Tag info. May be null 121 * @param attributeInfo An array of AttributeInfo data from descriptor. 122 * May be null; 123 * @param displayName A short name to be displayed by tools 124 * @param smallIcon Path to a small icon to be displayed by tools 125 * @param largeIcon Path to a large icon to be displayed by tools 126 * @param tvi An array of a TagVariableInfo (or null) 127 */ 128 public TagInfo(String tagName, 129 String tagClassName, 130 String bodycontent, 131 String infoString, 132 TagLibraryInfo taglib, 133 TagExtraInfo tagExtraInfo, 134 TagAttributeInfo[] attributeInfo, 135 String displayName, 136 String smallIcon, 137 String largeIcon, 138 TagVariableInfo[] tvi) { 139 this.tagName = tagName; 140 this.tagClassName = tagClassName; 141 this.bodyContent = bodycontent; 142 this.infoString = infoString; 143 this.tagLibrary = taglib; 144 this.tagExtraInfo = tagExtraInfo; 145 this.attributeInfo = attributeInfo; 146 this.displayName = displayName; 147 this.smallIcon = smallIcon; 148 this.largeIcon = largeIcon; 149 this.tagVariableInfo = tvi; 150 151 if (tagExtraInfo != null) 152 tagExtraInfo.setTagInfo(this); 153 } 154 155 /** 156 * Constructor for TagInfo from data in the JSP 2.0 format for TLD. 157 * This class is to be instantiated only from the TagLibrary code 158 * under request from some JSP code that is parsing a 159 * TLD (Tag Library Descriptor). 160 * 161 * Note that, since TagLibibraryInfo reflects both TLD information 162 * and taglib directive information, a TagInfo instance is 163 * dependent on a taglib directive. This is probably a 164 * design error, which may be fixed in the future. 165 * 166 * @param tagName The name of this tag 167 * @param tagClassName The name of the tag handler class 168 * @param bodycontent Information on the body content of these tags 169 * @param infoString The (optional) string information for this tag 170 * @param taglib The instance of the tag library that contains us. 171 * @param tagExtraInfo The instance providing extra Tag info. May be null 172 * @param attributeInfo An array of AttributeInfo data from descriptor. 173 * May be null; 174 * @param displayName A short name to be displayed by tools 175 * @param smallIcon Path to a small icon to be displayed by tools 176 * @param largeIcon Path to a large icon to be displayed by tools 177 * @param tvi An array of a TagVariableInfo (or null) 178 * @param dynamicAttributes True if supports dynamic attributes 179 * 180 * @since 2.0 181 */ 182 public TagInfo(String tagName, 183 String tagClassName, 184 String bodycontent, 185 String infoString, 186 TagLibraryInfo taglib, 187 TagExtraInfo tagExtraInfo, 188 TagAttributeInfo[] attributeInfo, 189 String displayName, 190 String smallIcon, 191 String largeIcon, 192 TagVariableInfo[] tvi, 193 boolean dynamicAttributes) { 194 this.tagName = tagName; 195 this.tagClassName = tagClassName; 196 this.bodyContent = bodycontent; 197 this.infoString = infoString; 198 this.tagLibrary = taglib; 199 this.tagExtraInfo = tagExtraInfo; 200 this.attributeInfo = attributeInfo; 201 this.displayName = displayName; 202 this.smallIcon = smallIcon; 203 this.largeIcon = largeIcon; 204 this.tagVariableInfo = tvi; 205 this.dynamicAttributes = dynamicAttributes; 206 207 if (tagExtraInfo != null) 208 tagExtraInfo.setTagInfo(this); 209 } 210 211 /** 212 * The name of the Tag. 213 * 214 * @return The (short) name of the tag. 215 */ 216 217 public String getTagName() { 218 return tagName; 219 } 220 221 /** 222 * Attribute information (in the TLD) on this tag. 223 * The return is an array describing the attributes of this tag, as 224 * indicated in the TLD. 225 * 226 * @return The array of TagAttributeInfo for this tag, or a 227 * zero-length array if the tag has no attributes. 228 */ 229 230 public TagAttributeInfo[] getAttributes() { 231 return attributeInfo; 232 } 233 234 /** 235 * Information on the scripting objects created by this tag at runtime. 236 * This is a convenience method on the associated TagExtraInfo class. 237 * 238 * @param data TagData describing this action. 239 * @return if a TagExtraInfo object is associated with this TagInfo, the 240 * result of getTagExtraInfo().getVariableInfo( data ), otherwise 241 * null. 242 */ 243 public VariableInfo[] getVariableInfo(TagData data) { 244 VariableInfo[] result = null; 245 TagExtraInfo tei = getTagExtraInfo(); 246 if (tei != null) { 247 result = tei.getVariableInfo( data ); 248 } 249 return result; 250 } 251 252 /** 253 * Translation-time validation of the attributes. 254 * This is a convenience method on the associated TagExtraInfo class. 255 * 256 * @param data The translation-time TagData instance. 257 * @return Whether the data is valid. 258 */ 259 public boolean isValid(TagData data) { 260 TagExtraInfo tei = getTagExtraInfo(); 261 if (tei == null) { 262 return true; 263 } 264 return tei.isValid(data); 265 } 266 267 /** 268 * Translation-time validation of the attributes. 269 * This is a convenience method on the associated TagExtraInfo class. 270 * 271 * @param data The translation-time TagData instance. 272 * @return A null object, or zero length array if no errors, an 273 * array of ValidationMessages otherwise. 274 * @since 2.0 275 */ 276 public ValidationMessage[] validate( TagData data ) { 277 TagExtraInfo tei = getTagExtraInfo(); 278 if( tei == null ) { 279 return null; 280 } 281 return tei.validate( data ); 282 } 283 284 /** 285 * Set the instance for extra tag information. 286 * 287 * @param tei the TagExtraInfo instance 288 */ 289 public void setTagExtraInfo(TagExtraInfo tei) { 290 tagExtraInfo = tei; 291 } 292 293 294 /** 295 * The instance (if any) for extra tag information. 296 * 297 * @return The TagExtraInfo instance, if any. 298 */ 299 public TagExtraInfo getTagExtraInfo() { 300 return tagExtraInfo; 301 } 302 303 304 /** 305 * Name of the class that provides the handler for this tag. 306 * 307 * @return The name of the tag handler class. 308 */ 309 310 public String getTagClassName() { 311 return tagClassName; 312 } 313 314 315 /** 316 * The bodycontent information for this tag. 317 * If the bodycontent is not defined for this 318 * tag, the default of JSP will be returned. 319 * 320 * @return the body content string. 321 */ 322 323 public String getBodyContent() { 324 return bodyContent; 325 } 326 327 328 /** 329 * The information string for the tag. 330 * 331 * @return the info string, or null if 332 * not defined 333 */ 334 335 public String getInfoString() { 336 return infoString; 337 } 338 339 340 /** 341 * Set the TagLibraryInfo property. 342 * 343 * Note that a TagLibraryInfo element is dependent 344 * not just on the TLD information but also on the 345 * specific taglib instance used. This means that 346 * a fair amount of work needs to be done to construct 347 * and initialize TagLib objects. 348 * 349 * If used carefully, this setter can be used to avoid having to 350 * create new TagInfo elements for each taglib directive. 351 * 352 * @param tl the TagLibraryInfo to assign 353 */ 354 355 public void setTagLibrary(TagLibraryInfo tl) { 356 tagLibrary = tl; 357 } 358 359 /** 360 * The instance of TabLibraryInfo we belong to. 361 * 362 * @return the tag library instance we belong to 363 */ 364 365 public TagLibraryInfo getTagLibrary() { 366 return tagLibrary; 367 } 368 369 370 // ============== JSP 2.0 TLD Information ======== 371 372 373 /** 374 * Get the displayName. 375 * 376 * @return A short name to be displayed by tools, 377 * or null if not defined 378 */ 379 380 public String getDisplayName() { 381 return displayName; 382 } 383 384 /** 385 * Get the path to the small icon. 386 * 387 * @return Path to a small icon to be displayed by tools, 388 * or null if not defined 389 */ 390 391 public String getSmallIcon() { 392 return smallIcon; 393 } 394 395 /** 396 * Get the path to the large icon. 397 * 398 * @return Path to a large icon to be displayed by tools, 399 * or null if not defined 400 */ 401 402 public String getLargeIcon() { 403 return largeIcon; 404 } 405 406 /** 407 * Get TagVariableInfo objects associated with this TagInfo. 408 * 409 * @return Array of TagVariableInfo objects corresponding to 410 * variables declared by this tag, or a zero length 411 * array if no variables have been declared 412 */ 413 414 public TagVariableInfo[] getTagVariableInfos() { 415 return tagVariableInfo; 416 } 417 418 419 // ============== JSP 2.0 TLD Information ======== 420 421 /** 422 * Get dynamicAttributes associated with this TagInfo. 423 * 424 * @return True if tag handler supports dynamic attributes 425 * @since 2.0 426 */ 427 public boolean hasDynamicAttributes() { 428 return dynamicAttributes; 429 } 430 431 /* 432 * private fields for 1.1 info 433 */ 434 private String tagName; // the name of the tag 435 private String tagClassName; 436 private String bodyContent; 437 private String infoString; 438 private TagLibraryInfo tagLibrary; 439 private TagExtraInfo tagExtraInfo; // instance of TagExtraInfo 440 private TagAttributeInfo[] attributeInfo; 441 442 /* 443 * private fields for 1.2 info 444 */ 445 private String displayName; 446 private String smallIcon; 447 private String largeIcon; 448 private TagVariableInfo[] tagVariableInfo; 449 450 /* 451 * Additional private fields for 2.0 info 452 */ 453 private boolean dynamicAttributes; 454 }