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 /** 098 * Information (documentation) for this TLD. 099 * 100 * @return the info string for this tag lib 101 */ 102 103 public String 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 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[] 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[] 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 getTag(String shortname) { 154 TagInfo 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 getTagFile(String shortname) { 178 TagFileInfo 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[] 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 getFunction(String 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[] getTagLibraryInfos(); 243 244 245 // Protected fields 246 247 /** 248 * The prefix assigned to this taglib from the taglib directive. 249 */ 250 protected String prefix; 251 252 /** 253 * The value of the uri attribute from the taglib directive for 254 * this library. 255 */ 256 protected String uri; 257 258 /** 259 * An array describing the tags that are defined in this tag library. 260 */ 261 protected TagInfo[] 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[] 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[] functions; 276 277 // Tag Library Data 278 279 /** 280 * The version of the tag library. 281 */ 282 protected String tlibversion; // required 283 284 /** 285 * The version of the JSP specification this tag library is written to. 286 */ 287 protected String jspversion; // required 288 289 /** 290 * The preferred short name (prefix) as indicated in the TLD. 291 */ 292 protected String shortname; // required 293 294 /** 295 * The "reliable" URN indicated in the TLD. 296 */ 297 protected String urn; // required 298 299 /** 300 * Information (documentation) for this TLD. 301 */ 302 protected String info; // optional 303 }