001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.servlet.jsp.tagext;
019:
020: import javax.servlet.jsp.tagext.TagInfo;
021: import javax.servlet.jsp.tagext.TagFileInfo;
022:
023: /**
024: * Translation-time information associated with a taglib directive, and its
025: * underlying TLD file.
026: *
027: * Most of the information is directly from the TLD, except for
028: * the prefix and the uri values used in the taglib directive
029: *
030: *
031: */
032:
033: abstract public class TagLibraryInfo {
034:
035: /**
036: * Constructor.
037: *
038: * This will invoke the constructors for TagInfo, and TagAttributeInfo
039: * after parsing the TLD file.
040: *
041: * @param prefix the prefix actually used by the taglib directive
042: * @param uri the URI actually used by the taglib directive
043: */
044: protected TagLibraryInfo(String prefix, String uri) {
045: this .prefix = prefix;
046: this .uri = uri;
047: }
048:
049: // ==== methods accessing taglib information =======
050:
051: /**
052: * The value of the uri attribute from the taglib directive for
053: * this library.
054: *
055: * @return the value of the uri attribute
056: */
057:
058: public String getURI() {
059: return uri;
060: }
061:
062: /**
063: * The prefix assigned to this taglib from the taglib directive
064: *
065: * @return the prefix assigned to this taglib from the taglib directive
066: */
067:
068: public String getPrefixString() {
069: return prefix;
070: }
071:
072: // ==== methods using the TLD data =======
073:
074: /**
075: * The preferred short name (prefix) as indicated in the TLD.
076: * This may be used by authoring tools as the preferred prefix
077: * to use when creating an taglib directive for this library.
078: *
079: * @return the preferred short name for the library
080: */
081: public String getShortName() {
082: return shortname;
083: }
084:
085: /**
086: * The "reliable" URN indicated in the TLD (the uri element).
087: * This may be used by authoring tools as a global identifier
088: * to use when creating a taglib directive for this library.
089: *
090: * @return a reliable URN to a TLD like this
091: */
092: public String getReliableURN() {
093: return urn;
094: }
095:
096: /**
097: * Information (documentation) for this TLD.
098: *
099: * @return the info string for this tag lib
100: */
101:
102: public String getInfoString() {
103: return info;
104: }
105:
106: /**
107: * A string describing the required version of the JSP container.
108: *
109: * @return the (minimal) required version of the JSP container.
110: * @see javax.servlet.jsp.JspEngineInfo
111: */
112:
113: public String getRequiredVersion() {
114: return jspversion;
115: }
116:
117: /**
118: * An array describing the tags that are defined in this tag library.
119: *
120: * @return the TagInfo objects corresponding to the tags defined by this
121: * tag library, or a zero length array if this tag library
122: * defines no tags
123: */
124: public TagInfo[] getTags() {
125: return tags;
126: }
127:
128: /**
129: * An array describing the tag files that are defined in this tag library.
130: *
131: * @return the TagFileInfo objects corresponding to the tag files defined
132: * by this tag library, or a zero length array if this
133: * tag library defines no tags files
134: * @since 2.0
135: */
136: public TagFileInfo[] getTagFiles() {
137: return tagFiles;
138: }
139:
140: /**
141: * Get the TagInfo for a given tag name, looking through all the
142: * tags in this tag library.
143: *
144: * @param shortname The short name (no prefix) of the tag
145: * @return the TagInfo for the tag with the specified short name, or
146: * null if no such tag is found
147: */
148:
149: public TagInfo getTag(String shortname) {
150: TagInfo tags[] = getTags();
151:
152: if (tags == null || tags.length == 0) {
153: return null;
154: }
155:
156: for (int i = 0; i < tags.length; i++) {
157: if (tags[i].getTagName().equals(shortname)) {
158: return tags[i];
159: }
160: }
161: return null;
162: }
163:
164: /**
165: * Get the TagFileInfo for a given tag name, looking through all the
166: * tag files in this tag library.
167: *
168: * @param shortname The short name (no prefix) of the tag
169: * @return the TagFileInfo for the specified Tag file, or null
170: * if no Tag file is found
171: * @since 2.0
172: */
173: public TagFileInfo getTagFile(String shortname) {
174: TagFileInfo tagFiles[] = getTagFiles();
175:
176: if (tagFiles == null || tagFiles.length == 0) {
177: return null;
178: }
179:
180: for (int i = 0; i < tagFiles.length; i++) {
181: if (tagFiles[i].getName().equals(shortname)) {
182: return tagFiles[i];
183: }
184: }
185: return null;
186: }
187:
188: /**
189: * An array describing the functions that are defined in this tag library.
190: *
191: * @return the functions defined in this tag library, or a zero
192: * length array if the tag library defines no functions.
193: * @since 2.0
194: */
195: public FunctionInfo[] getFunctions() {
196: return functions;
197: }
198:
199: /**
200: * Get the FunctionInfo for a given function name, looking through all the
201: * functions in this tag library.
202: *
203: * @param name The name (no prefix) of the function
204: * @return the FunctionInfo for the function with the given name, or null
205: * if no such function exists
206: * @since 2.0
207: */
208: public FunctionInfo getFunction(String name) {
209:
210: if (functions == null || functions.length == 0) {
211: System.err.println("No functions");
212: return null;
213: }
214:
215: for (int i = 0; i < functions.length; i++) {
216: if (functions[i].getName().equals(name)) {
217: return functions[i];
218: }
219: }
220: return null;
221: }
222:
223: /**
224: * Returns an array of TagLibraryInfo objects representing the entire set
225: * of tag libraries (including this TagLibraryInfo) imported by taglib
226: * directives in the translation unit that references this TagLibraryInfo.
227: * If a tag library is imported more than once and bound to different prefices,
228: * only the TagLibraryInfo bound to the first prefix must be included
229: * in the returned array.
230: *
231: * @return Array of TagLibraryInfo objects representing the entire set
232: * of tag libraries (including this TagLibraryInfo) imported by taglib
233: * directives in the translation unit that references this TagLibraryInfo.
234: * @since 2.1
235: */
236: public abstract javax.servlet.jsp.tagext.TagLibraryInfo[] getTagLibraryInfos();
237:
238: // Protected fields
239:
240: /**
241: * The prefix assigned to this taglib from the taglib directive.
242: */
243: protected String prefix;
244:
245: /**
246: * The value of the uri attribute from the taglib directive for
247: * this library.
248: */
249: protected String uri;
250:
251: /**
252: * An array describing the tags that are defined in this tag library.
253: */
254: protected TagInfo[] tags;
255:
256: /**
257: * An array describing the tag files that are defined in this tag library.
258: *
259: * @since 2.0
260: */
261: protected TagFileInfo[] tagFiles;
262:
263: /**
264: * An array describing the functions that are defined in this tag library.
265: *
266: * @since 2.0
267: */
268: protected FunctionInfo[] functions;
269:
270: // Tag Library Data
271:
272: /**
273: * The version of the tag library.
274: */
275: protected String tlibversion; // required
276:
277: /**
278: * The version of the JSP specification this tag library is written to.
279: */
280: protected String jspversion; // required
281:
282: /**
283: * The preferred short name (prefix) as indicated in the TLD.
284: */
285: protected String shortname; // required
286:
287: /**
288: * The "reliable" URN indicated in the TLD.
289: */
290: protected String urn; // required
291:
292: /**
293: * Information (documentation) for this TLD.
294: */
295: protected String info; // optional
296: }
|