KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > tagext > TagLibraryInfo


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17  
18 package javax.servlet.jsp.tagext;
19
20 import javax.servlet.jsp.tagext.TagInfo JavaDoc;
21 import javax.servlet.jsp.tagext.TagFileInfo JavaDoc;
22
23 /**
24  * Translation-time information associated with a taglib directive, and its
25  * underlying TLD file.
26  *
27  * Most of the information is directly from the TLD, except for
28  * the prefix and the uri values used in the taglib directive
29  *
30  *
31  */

32
33 abstract public class TagLibraryInfo {
34
35     /**
36      * Constructor.
37      *
38      * This will invoke the constructors for TagInfo, and TagAttributeInfo
39      * after parsing the TLD file.
40      *
41      * @param prefix the prefix actually used by the taglib directive
42      * @param uri the URI actually used by the taglib directive
43      */

44     protected TagLibraryInfo(String JavaDoc prefix, String JavaDoc uri) {
45     this.prefix = prefix;
46     this.uri = uri;
47     }
48
49     // ==== methods accessing taglib information =======
50

51     /**
52      * The value of the uri attribute from the taglib directive for
53      * this library.
54      *
55      * @return the value of the uri attribute
56      */

57    
58     public String JavaDoc getURI() {
59         return uri;
60     }
61
62     /**
63      * The prefix assigned to this taglib from the taglib directive
64      *
65      * @return the prefix assigned to this taglib from the taglib directive
66      */

67
68     public String JavaDoc getPrefixString() {
69     return prefix;
70     }
71
72     // ==== methods using the TLD data =======
73

74     /**
75      * The preferred short name (prefix) as indicated in the TLD.
76      * This may be used by authoring tools as the preferred prefix
77      * to use when creating an taglib directive for this library.
78      *
79      * @return the preferred short name for the library
80      */

81     public String JavaDoc getShortName() {
82         return shortname;
83     }
84
85     /**
86      * The "reliable" URN indicated in the TLD (the uri element).
87      * This may be used by authoring tools as a global identifier
88      * to use when creating a taglib directive for this library.
89      *
90      * @return a reliable URN to a TLD like this
91      */

92     public String JavaDoc getReliableURN() {
93         return urn;
94     }
95
96
97     /**
98      * Information (documentation) for this TLD.
99      *
100      * @return the info string for this tag lib
101      */

102    
103     public String JavaDoc getInfoString() {
104         return info;
105     }
106
107
108     /**
109      * A string describing the required version of the JSP container.
110      *
111      * @return the (minimal) required version of the JSP container.
112      * @see javax.servlet.jsp.JspEngineInfo
113      */

114    
115     public String JavaDoc getRequiredVersion() {
116         return jspversion;
117     }
118
119
120     /**
121      * An array describing the tags that are defined in this tag library.
122      *
123      * @return the TagInfo objects corresponding to the tags defined by this
124      * tag library, or a zero length array if this tag library
125      * defines no tags
126      */

127     public TagInfo JavaDoc[] getTags() {
128         return tags;
129     }
130
131     /**
132      * An array describing the tag files that are defined in this tag library.
133      *
134      * @return the TagFileInfo objects corresponding to the tag files defined
135      * by this tag library, or a zero length array if this
136      * tag library defines no tags files
137      * @since 2.0
138      */

139     public TagFileInfo JavaDoc[] getTagFiles() {
140         return tagFiles;
141     }
142
143
144     /**
145      * Get the TagInfo for a given tag name, looking through all the
146      * tags in this tag library.
147      *
148      * @param shortname The short name (no prefix) of the tag
149      * @return the TagInfo for the tag with the specified short name, or
150      * null if no such tag is found
151      */

152
153     public TagInfo JavaDoc getTag(String JavaDoc shortname) {
154         TagInfo JavaDoc tags[] = getTags();
155
156         if (tags == null || tags.length == 0) {
157             return null;
158         }
159
160         for (int i=0; i < tags.length; i++) {
161             if (tags[i].getTagName().equals(shortname)) {
162                 return tags[i];
163             }
164         }
165         return null;
166     }
167
168     /**
169      * Get the TagFileInfo for a given tag name, looking through all the
170      * tag files in this tag library.
171      *
172      * @param shortname The short name (no prefix) of the tag
173      * @return the TagFileInfo for the specified Tag file, or null
174      * if no Tag file is found
175      * @since 2.0
176      */

177     public TagFileInfo JavaDoc getTagFile(String JavaDoc shortname) {
178         TagFileInfo JavaDoc tagFiles[] = getTagFiles();
179
180         if (tagFiles == null || tagFiles.length == 0) {
181             return null;
182         }
183
184         for (int i=0; i < tagFiles.length; i++) {
185             if (tagFiles[i].getName().equals(shortname)) {
186                 return tagFiles[i];
187             }
188         }
189         return null;
190     }
191
192     /**
193      * An array describing the functions that are defined in this tag library.
194      *
195      * @return the functions defined in this tag library, or a zero
196      * length array if the tag library defines no functions.
197      * @since 2.0
198      */

199     public FunctionInfo JavaDoc[] getFunctions() {
200         return functions;
201     }
202
203
204     /**
205      * Get the FunctionInfo for a given function name, looking through all the
206      * functions in this tag library.
207      *
208      * @param name The name (no prefix) of the function
209      * @return the FunctionInfo for the function with the given name, or null
210      * if no such function exists
211      * @since 2.0
212      */

213     public FunctionInfo JavaDoc getFunction(String JavaDoc name) {
214
215         if (functions == null || functions.length == 0) {
216             System.err.println("No functions");
217             return null;
218         }
219
220         for (int i=0; i < functions.length; i++) {
221             if (functions[i].getName().equals(name)) {
222                 return functions[i];
223             }
224         }
225         return null;
226     }
227
228
229     /**
230      * Returns an array of TagLibraryInfo objects representing the entire set
231      * of tag libraries (including this TagLibraryInfo) imported by taglib
232      * directives in the translation unit that references this TagLibraryInfo.
233      * If a tag library is imported more than once and bound to different prefices,
234      * only the TagLibraryInfo bound to the first prefix must be included
235      * in the returned array.
236      *
237      * @return Array of TagLibraryInfo objects representing the entire set
238      * of tag libraries (including this TagLibraryInfo) imported by taglib
239      * directives in the translation unit that references this TagLibraryInfo.
240      * @since 2.1
241      */

242     public abstract javax.servlet.jsp.tagext.TagLibraryInfo JavaDoc[] getTagLibraryInfos();
243     
244     
245     // Protected fields
246

247     /**
248      * The prefix assigned to this taglib from the taglib directive.
249      */

250     protected String JavaDoc prefix;
251     
252     /**
253      * The value of the uri attribute from the taglib directive for
254      * this library.
255      */

256     protected String JavaDoc uri;
257     
258     /**
259      * An array describing the tags that are defined in this tag library.
260      */

261     protected TagInfo JavaDoc[] tags;
262     
263     /**
264      * An array describing the tag files that are defined in this tag library.
265      *
266      * @since 2.0
267      */

268     protected TagFileInfo JavaDoc[] tagFiles;
269     
270     /**
271      * An array describing the functions that are defined in this tag library.
272      *
273      * @since 2.0
274      */

275     protected FunctionInfo JavaDoc[] functions;
276
277     // Tag Library Data
278

279     /**
280      * The version of the tag library.
281      */

282     protected String JavaDoc tlibversion; // required
283

284     /**
285      * The version of the JSP specification this tag library is written to.
286      */

287     protected String JavaDoc jspversion; // required
288

289     /**
290      * The preferred short name (prefix) as indicated in the TLD.
291      */

292     protected String JavaDoc shortname; // required
293

294     /**
295      * The "reliable" URN indicated in the TLD.
296      */

297     protected String JavaDoc urn; // required
298

299     /**
300      * Information (documentation) for this TLD.
301      */

302     protected String JavaDoc info; // optional
303
}
304
Popular Tags