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