001: /*
002: * Copyright (c) 1998-2008 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: * Information about the entire tag library.
033: *
034: * Tag libraries are declared in a JSP file like:
035: * <code><pre>
036: * <%@ taglib prefix='foo' uri='WEB-INF/tags.tld' %>
037: * </pre></code>
038: *
039: * <p>The tags.tld will look something like:
040: *
041: * <code><pre>
042: * <taglib>
043: * <uri>http://www.caucho.com/taglibs/2000-03-04/mytaglib.tld</uri>
044: * <info>A sample tag library</info>
045: * <shortname>mytaglib</shortname>
046: * <jspversion>1.1</jspversion>
047: *
048: * ...
049: *
050: * <tag>
051: * ...
052: * </tag>
053: * </taglib>
054: * </pre></code>
055: */
056: abstract public class TagLibraryInfo {
057: protected FunctionInfo[] functions;
058: protected String info;
059: protected String jspversion;
060: protected String prefix;
061: protected String shortname;
062: protected TagFileInfo[] tagFiles;
063: protected TagInfo[] tags;
064: protected String tlibversion;
065: protected String uri;
066: protected String urn;
067:
068: /**
069: * Called by the JSP engine to collect tag library information.
070: */
071: protected TagLibraryInfo(String prefix, String uri) {
072: this .prefix = prefix;
073: this .uri = uri;
074: }
075:
076: /**
077: * Returns a descriptive string for the library. Taken from the
078: * <code>info</code> attribute in the TLD.
079: *
080: * <code><pre>
081: * <taglib>
082: * <info>A sample tag library</info>
083: * </pre></code>
084: */
085: public String getInfoString() {
086: return this .info;
087: }
088:
089: /**
090: * Returns the library's prefix string from the taglib declaration:
091: *
092: * <code><pre>
093: * <%@ taglib prefix='foo' uri='WEB-INF/tags.tld' %>
094: * </pre></code>
095: */
096: public String getPrefixString() {
097: return this .prefix;
098: }
099:
100: /**
101: * Returns the library's uri from the taglib declaration:
102: *
103: * <code><pre>
104: * <%@ taglib prefix='foo' uri='WEB-INF/tags.tld' %>
105: * </pre></code>
106: */
107: public String getURI() {
108: return this .uri;
109: }
110:
111: /**
112: * The preferred short name for the library.
113: */
114: public String getShortName() {
115: return this .shortname;
116: }
117:
118: /**
119: * Returns a canonical name representing this tag library. Taken
120: * from the <code>uri</code> attribute in the taglib.
121: *
122: * <code><pre>
123: * <taglib>
124: * <uri>http://www.caucho.com/taglibs/2000-03-04/mytaglib.tld</uri>
125: * </pre></code>
126: */
127: public String getReliableURN() {
128: return this .urn;
129: }
130:
131: /**
132: * Returns the minimum required JSP version for the tag library.
133: */
134: public String getRequiredVersion() {
135: return this .jspversion;
136: }
137:
138: /**
139: * Returns an array of all the tags in the library
140: */
141: public TagInfo[] getTags() {
142: return this .tags;
143: }
144:
145: /**
146: * Returns the information for a specific tag.
147: */
148: public TagInfo getTag(String name) {
149: if (this .tags == null)
150: return null;
151:
152: for (int i = 0; i < this .tags.length; i++) {
153: if (this .tags[i].getTagName().equals(name))
154: return this .tags[i];
155: }
156:
157: return null;
158: }
159:
160: /**
161: * Returns the named function.
162: *
163: * @since JSP 2.0
164: */
165: public FunctionInfo getFunction(String name) {
166: if (this .functions == null)
167: return null;
168:
169: for (int i = 0; i < this .functions.length; i++)
170: if (this .functions[i].getName().equals(name))
171: return this .functions[i];
172:
173: return null;
174: }
175:
176: /**
177: * Returns the functions for the tag.
178: *
179: * @since JSP 2.0
180: */
181: public FunctionInfo[] getFunctions() {
182: return this .functions;
183: }
184:
185: /**
186: * Returns the tag from the tag file.
187: */
188: public TagFileInfo[] getTagFiles() {
189: return this .tagFiles;
190: }
191:
192: /**
193: * Returns the information from the tag file.
194: */
195: public abstract TagLibraryInfo[] getTagLibraryInfos();
196:
197: /**
198: * Returns the tag from the tag file.
199: */
200: public TagFileInfo getTagFile(String shortname) {
201: if (this .tagFiles == null)
202: return null;
203:
204: for (int i = 0; i < this.tagFiles.length; i++)
205: if (this.tagFiles[i].getName().equals(shortname))
206: return this.tagFiles[i];
207:
208: return null;
209: }
210: }
|