001: /*
002: * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.servlet.jsp.tagext;
030:
031: /**
032: * Represents the tag information from the tld. TagExtraInfo classes
033: * can use this to help in validation or in variable creation.
034: *
035: * <code><pre>
036: * <tag>
037: * <name>foo</name>
038: * <tagclass>com.caucho.tags.FooTag</tagclass>
039: * <teiclass>com.caucho.tags.FooTagInfo</teiclass>
040: * <bodycontent>jsp</bodycontent>
041: *
042: * <attribute>
043: * ...
044: * </attribute>
045: * </tag>
046: * </pre></code>
047: */
048: public class TagInfo {
049: /**
050: * Constant for the "empty" body content
051: */
052: public static final String BODY_CONTENT_EMPTY = "empty";
053: /**
054: * Constant for standard "jsp" processed body content
055: */
056: public static final String BODY_CONTENT_JSP = "JSP";
057: /**
058: * Constant for tags which forbid scripts
059: */
060: public static final String BODY_CONTENT_SCRIPTLESS = "scriptless";
061: /**
062: * Constant for "tag-dependent" unprocessed verbatim body content
063: */
064: public static final String BODY_CONTENT_TAG_DEPENDENT = "tagdependent";
065:
066: private String bodyContent;
067: private String infoString;
068: private String tagClassName;
069: private TagExtraInfo tagExtraInfo;
070: private TagLibraryInfo tagLibrary;
071: private String tagName;
072: private TagAttributeInfo[] attributeInfo;
073: private String displayName;
074: private String smallIcon;
075: private String largeIcon;
076: private TagVariableInfo[] tvi;
077: private boolean dynamicAttributes;
078:
079: /**
080: * Constructor for TagInfo. Created by the JSP engine at compile time
081: * for the benefit of TagExtraInfo classes.
082: *
083: * @param tagName tag name
084: * @param tagClassName the tag's class name
085: * @param bodyContent description of the expected body contents
086: * @param infoString informatino string of the tag
087: * @param taglib pointer to the TagLibraryInfo
088: * @param tagExtraInfo the tag's custom TagExtraInfo.
089: * @param tagAttributeInfo information about the tags attribute from the tld.
090: */
091: public TagInfo(String tagName, String tagClassName,
092: String bodyContent, String infoString,
093: TagLibraryInfo taglib, TagExtraInfo tagExtraInfo,
094: TagAttributeInfo[] attributeInfo) {
095: this .tagName = tagName;
096: this .tagClassName = tagClassName;
097: this .bodyContent = bodyContent;
098: this .infoString = infoString;
099: this .tagLibrary = taglib;
100: this .tagExtraInfo = tagExtraInfo;
101: this .attributeInfo = attributeInfo;
102:
103: if (tagExtraInfo != null)
104: tagExtraInfo.setTagInfo(this );
105: }
106:
107: /**
108: * Constructor for TagInfo. Created by the JSP engine at compile time
109: * for the benefit of TagExtraInfo classes.
110: *
111: * @param tagName tag name
112: * @param tagClassName the tag's class name
113: * @param bodyContent description of the expected body contents
114: * @param infoString informatino string of the tag
115: * @param taglib pointer to the TagLibraryInfo
116: * @param tagExtraInfo the tag's custom TagExtraInfo.
117: * @param tagAttributeInfo information about the tags attribute from the tld.
118: * @param displayName the GUI builder's display name
119: * @param smallIcon small icon for a GUI builder
120: * @param largeIcon large icon for a GUI builder
121: * @param tvi variable info in the tld
122: */
123: public TagInfo(String tagName, String tagClassName,
124: String bodyContent, String infoString,
125: TagLibraryInfo taglib, TagExtraInfo tagExtraInfo,
126: TagAttributeInfo[] attributeInfo, String displayName,
127: String smallIcon, String largeIcon, TagVariableInfo[] tvi) {
128: this (tagName, tagClassName, bodyContent, infoString, taglib,
129: tagExtraInfo, attributeInfo);
130:
131: this .displayName = displayName;
132: this .smallIcon = smallIcon;
133: this .largeIcon = largeIcon;
134: this .tvi = tvi;
135: }
136:
137: /**
138: * Constructor for TagInfo. Created by the JSP engine at compile time
139: * for the benefit of TagExtraInfo classes.
140: *
141: * @param tagName tag name
142: * @param tagClassName the tag's class name
143: * @param bodyContent description of the expected body contents
144: * @param infoString informatino string of the tag
145: * @param taglib pointer to the TagLibraryInfo
146: * @param tagExtraInfo the tag's custom TagExtraInfo.
147: * @param tagAttributeInfo information about the tags attribute from the tld.
148: * @param displayName the GUI builder's display name
149: * @param smallIcon small icon for a GUI builder
150: * @param largeIcon large icon for a GUI builder
151: * @param tvi variable info in the tld
152: */
153: public TagInfo(String tagName, String tagClassName,
154: String bodyContent, String infoString,
155: TagLibraryInfo taglib, TagExtraInfo tagExtraInfo,
156: TagAttributeInfo[] attributeInfo, String displayName,
157: String smallIcon, String largeIcon, TagVariableInfo[] tvi,
158: boolean dynamicAttributes) {
159: this (tagName, tagClassName, bodyContent, infoString, taglib,
160: tagExtraInfo, attributeInfo, displayName, smallIcon,
161: largeIcon, tvi);
162:
163: this .dynamicAttributes = dynamicAttributes;
164: }
165:
166: /**
167: * Returns the tag's name.
168: */
169: public String getTagName() {
170: return this .tagName;
171: }
172:
173: /**
174: * Returns the tag's infomation string.
175: */
176: public String getInfoString() {
177: return this .infoString;
178: }
179:
180: /**
181: * Returns the tag's class name.
182: */
183: public String getTagClassName() {
184: return this .tagClassName;
185: }
186:
187: /**
188: * Returns the body content type.
189: *
190: * <ul>
191: * <li>empty - the tag must be empty
192: * <li>jsp - the body is processed as normal jsp
193: * <li>tag-dependent - the body copied as verbatim text.
194: * </ul>
195: */
196: public String getBodyContent() {
197: return this .bodyContent;
198: }
199:
200: /**
201: * Returns the display name to be displayed by tools.
202: */
203: public String getDisplayName() {
204: return this .displayName;
205: }
206:
207: /**
208: * Returns the path to the large icon to be displayed by the tools.
209: */
210: public String getLargeIcon() {
211: return this .largeIcon;
212: }
213:
214: /**
215: * Returns the path to the small icon to be displayed by the tools.
216: */
217: public String getSmallIcon() {
218: return this .smallIcon;
219: }
220:
221: /**
222: * Returns information about the tags allowed attributes.
223: */
224: public TagAttributeInfo[] getAttributes() {
225: return this .attributeInfo;
226: }
227:
228: /**
229: * Returns the tag variable info in the tld
230: */
231: public TagVariableInfo[] getTagVariableInfos() {
232: return this .tvi;
233: }
234:
235: /**
236: * Information about the variables created by the tag at runtime.
237: *
238: * @param data information about the tag instance
239: */
240: public VariableInfo[] getVariableInfo(TagData data) {
241: if (this .tagExtraInfo == null)
242: return null;
243: else
244: return this .tagExtraInfo.getVariableInfo(data);
245: }
246:
247: /**
248: * Retursn true if dynamic attributes are supported.
249: */
250: public boolean hasDynamicAttributes() {
251: return this .dynamicAttributes;
252: }
253:
254: /**
255: * Returns true if the tag instance is valid.
256: *
257: * @param data information about the tag instance
258: */
259: public boolean isValid(TagData data) {
260: if (this .tagExtraInfo == null)
261: return true;
262: else
263: return this .tagExtraInfo.isValid(data);
264: }
265:
266: /**
267: * Returns the tag extra info for the tag.
268: */
269: public TagExtraInfo getTagExtraInfo() {
270: return this .tagExtraInfo;
271: }
272:
273: /**
274: * Sets the tag extra info for the tag.
275: */
276: public void setTagExtraInfo(TagExtraInfo tei) {
277: this .tagExtraInfo = tei;
278: }
279:
280: /**
281: * Returns the TagLibraryInfo for the tag.
282: */
283: public TagLibraryInfo getTagLibrary() {
284: return this .tagLibrary;
285: }
286:
287: /**
288: * Sets the TagLibraryInfo for the tag.
289: */
290: public void setTagLibrary(TagLibraryInfo info) {
291: this .tagLibrary = info;
292: }
293:
294: /**
295: * Validate attributes.
296: */
297: public ValidationMessage[] validate(TagData data) {
298: if (this.tagExtraInfo == null)
299: return null;
300: else
301: return this.tagExtraInfo.validate(data);
302: }
303: }
|