1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. */
  55. package javax.servlet.jsp.tagext;
  56. /**
  57. * Tag information for a tag in a Tag Library;
  58. * This class is instantiated from the Tag Library Descriptor file (TLD)
  59. * and is available only at translation time.
  60. *
  61. *
  62. */
  63. public class TagInfo {
  64. /**
  65. * static constant for getBodyContent() when it is JSP
  66. */
  67. public static final String BODY_CONTENT_JSP = "JSP";
  68. /**
  69. * static constant for getBodyContent() when it is Tag dependent
  70. */
  71. public static final String BODY_CONTENT_TAG_DEPENDENT = "TAGDEPENDENT";
  72. /**
  73. * static constant for getBodyContent() when it is empty
  74. */
  75. public static final String BODY_CONTENT_EMPTY = "EMPTY";
  76. /**
  77. * Constructor for TagInfo from data in the JSP 1.1 format for TLD.
  78. * This class is to be instantiated only from the TagLibrary code
  79. * under request from some JSP code that is parsing a
  80. * TLD (Tag Library Descriptor).
  81. *
  82. * Note that, since TagLibibraryInfo reflects both TLD information
  83. * and taglib directive information, a TagInfo instance is
  84. * dependent on a taglib directive. This is probably a
  85. * design error, which may be fixed in the future.
  86. *
  87. * @param tagName The name of this tag
  88. * @param tagClassName The name of the tag handler class
  89. * @param bodycontent Information on the body content of these tags
  90. * @param infoString The (optional) string information for this tag
  91. * @param taglib The instance of the tag library that contains us.
  92. * @param tagExtraInfo The instance providing extra Tag info. May be null
  93. * @param attributeInfo An array of AttributeInfo data from descriptor.
  94. * May be null;
  95. *
  96. */
  97. public TagInfo(String tagName,
  98. String tagClassName,
  99. String bodycontent,
  100. String infoString,
  101. TagLibraryInfo taglib,
  102. TagExtraInfo tagExtraInfo,
  103. TagAttributeInfo[] attributeInfo) {
  104. this.tagName = tagName;
  105. this.tagClassName = tagClassName;
  106. this.bodyContent = bodycontent;
  107. this.infoString = infoString;
  108. this.tagLibrary = taglib;
  109. this.tagExtraInfo = tagExtraInfo;
  110. this.attributeInfo = attributeInfo;
  111. if (tagExtraInfo != null)
  112. tagExtraInfo.setTagInfo(this);
  113. }
  114. /**
  115. * Constructor for TagInfo from data in the JSP 1.2 format for TLD.
  116. * This class is to be instantiated only from the TagLibrary code
  117. * under request from some JSP code that is parsing a
  118. * TLD (Tag Library Descriptor).
  119. *
  120. * Note that, since TagLibibraryInfo reflects both TLD information
  121. * and taglib directive information, a TagInfo instance is
  122. * dependent on a taglib directive. This is probably a
  123. * design error, which may be fixed in the future.
  124. *
  125. * @param tagName The name of this tag
  126. * @param tagClassName The name of the tag handler class
  127. * @param bodycontent Information on the body content of these tags
  128. * @param infoString The (optional) string information for this tag
  129. * @param taglib The instance of the tag library that contains us.
  130. * @param tagExtraInfo The instance providing extra Tag info. May be null
  131. * @param attributeInfo An array of AttributeInfo data from descriptor.
  132. * May be null;
  133. * @param displayName A short name to be displayed by tools
  134. * @param smallIcon Path to a small icon to be displayed by tools
  135. * @param largeIcon Path to a large icon to be displayed by tools
  136. * @param tagVariableInfo An array of a TagVariableInfo (or null)
  137. */
  138. public TagInfo(String tagName,
  139. String tagClassName,
  140. String bodycontent,
  141. String infoString,
  142. TagLibraryInfo taglib,
  143. TagExtraInfo tagExtraInfo,
  144. TagAttributeInfo[] attributeInfo,
  145. String displayName,
  146. String smallIcon,
  147. String largeIcon,
  148. TagVariableInfo[] tvi) {
  149. this.tagName = tagName;
  150. this.tagClassName = tagClassName;
  151. this.bodyContent = bodycontent;
  152. this.infoString = infoString;
  153. this.tagLibrary = taglib;
  154. this.tagExtraInfo = tagExtraInfo;
  155. this.attributeInfo = attributeInfo;
  156. this.displayName = displayName;
  157. this.smallIcon = smallIcon;
  158. this.largeIcon = largeIcon;
  159. this.tagVariableInfo = tvi;
  160. if (tagExtraInfo != null)
  161. tagExtraInfo.setTagInfo(this);
  162. }
  163. /**
  164. * The name of the Tag.
  165. *
  166. * @return The (short) name of the tag.
  167. */
  168. public String getTagName() {
  169. return tagName;
  170. }
  171. /**
  172. * Attribute information (in the TLD) on this tag.
  173. * The return is an array describing the attributes of this tag, as
  174. * indicated in the TLD.
  175. * A null return means no attributes.
  176. *
  177. * @return The array of TagAttributeInfo for this tag.
  178. */
  179. public TagAttributeInfo[] getAttributes() {
  180. return attributeInfo;
  181. }
  182. /**
  183. * Information on the scripting objects created by this tag at runtime.
  184. * This is a convenience method on the associated TagExtraInfo class.
  185. * <p>
  186. * Default is null if the tag has no "id" attribute,
  187. * otherwise, {"id", Object}
  188. *
  189. * @param data TagData describing this action.
  190. * @return Array of VariableInfo elements.
  191. */
  192. public VariableInfo[] getVariableInfo(TagData data) {
  193. TagExtraInfo tei = getTagExtraInfo();
  194. if (tei == null) {
  195. return null;
  196. }
  197. return tei.getVariableInfo(data);
  198. }
  199. /**
  200. * Translation-time validation of the attributes.
  201. * This is a convenience method on the associated TagExtraInfo class.
  202. *
  203. * @param data The translation-time TagData instance.
  204. * @return Whether the data is valid.
  205. */
  206. public boolean isValid(TagData data) {
  207. TagExtraInfo tei = getTagExtraInfo();
  208. if (tei == null) {
  209. return true;
  210. }
  211. return tei.isValid(data);
  212. }
  213. /**
  214. * Set the instance for extra tag information
  215. *
  216. * @param tei the TagExtraInfo instance
  217. */
  218. public void setTagExtraInfo(TagExtraInfo tei) {
  219. tagExtraInfo = tei;
  220. }
  221. /**
  222. * The instance (if any) for extra tag information
  223. *
  224. * @return The TagExtraInfo instance, if any.
  225. */
  226. public TagExtraInfo getTagExtraInfo() {
  227. return tagExtraInfo;
  228. }
  229. /**
  230. * Name of the class that provides the handler for this tag.
  231. *
  232. * @return The name of the tag handler class.
  233. */
  234. public String getTagClassName() {
  235. return tagClassName;
  236. }
  237. /**
  238. * The bodycontent information for this tag.
  239. *
  240. * @return the body content string.
  241. */
  242. public String getBodyContent() {
  243. return bodyContent;
  244. }
  245. /**
  246. * The information string for the tag.
  247. *
  248. * @return the info string
  249. */
  250. public String getInfoString() {
  251. return infoString;
  252. }
  253. /**
  254. * Set the TagLibraryInfo property.
  255. *
  256. * Note that a TagLibraryInfo element is dependent
  257. * not just on the TLD information but also on the
  258. * specific taglib instance used. This means that
  259. * a fair amount of work needs to be done to construct
  260. * and initialize TagLib objects.
  261. *
  262. * If used carefully, this setter can be used to avoid having to
  263. * create new TagInfo elements for each taglib directive.
  264. *
  265. * @param tl the TagLibraryInfo to assign
  266. */
  267. public void setTagLibrary(TagLibraryInfo tl) {
  268. tagLibrary = tl;
  269. }
  270. /**
  271. * The instance of TabLibraryInfo we belong to.
  272. *
  273. * @return the tab library instance we belong to.
  274. */
  275. public TagLibraryInfo getTagLibrary() {
  276. return tagLibrary;
  277. }
  278. // ============== JSP 1.2 TLD Information ========
  279. /**
  280. * Get the displayName
  281. *
  282. * @return A short name to be displayed by tools
  283. */
  284. public String getDisplayName() {
  285. return displayName;
  286. }
  287. /**
  288. * Get the path to the small icon
  289. *
  290. * @return Path to a small icon to be displayed by tools
  291. */
  292. public String getSmallIcon() {
  293. return smallIcon;
  294. }
  295. /**
  296. * Get the path to the large icon
  297. *
  298. * @return Path to a large icon to be displayed by tools
  299. */
  300. public String getLargeIcon() {
  301. return largeIcon;
  302. }
  303. /**
  304. * Get TagVariableInfo objects associated with this TagInfo
  305. *
  306. * @return A TagVariableInfo object associated with this
  307. */
  308. public TagVariableInfo[] getTagVariableInfos() {
  309. return tagVariableInfo;
  310. }
  311. // ============== Probably does not belong here =======
  312. /**
  313. * Stringify for debug purposes...
  314. */
  315. public String toString() {
  316. StringBuffer b = new StringBuffer();
  317. b.append("name = "+tagName+" ");
  318. b.append("class = "+tagClassName+" ");
  319. b.append("body = "+bodyContent+" ");
  320. b.append("info = "+infoString+" ");
  321. b.append("attributes = {\n");
  322. for(int i = 0; i < attributeInfo.length; i++)
  323. b.append("\t"+attributeInfo[i].toString());
  324. b.append("\n}\n");
  325. return b.toString();
  326. }
  327. /*
  328. * private fields for 1.1 info
  329. */
  330. private String tagName; // the name of the tag
  331. private String tagClassName;
  332. private String bodyContent;
  333. private String infoString;
  334. private TagLibraryInfo tagLibrary;
  335. private TagExtraInfo tagExtraInfo; // instance of TagExtraInfo
  336. private TagAttributeInfo[] attributeInfo;
  337. /*
  338. * private fields for 1.2 info
  339. */
  340. private String displayName;
  341. private String smallIcon;
  342. private String largeIcon;
  343. private TagVariableInfo[] tagVariableInfo;
  344. }