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