View Javadoc

    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  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  //
    19  // This source code implements specifications defined by the Java
    20  // Community Process. In order to remain compliant with the specification
    21  // DO NOT add / change / or delete method signatures!
    22  //
    23
    24  package javax.servlet.jsp.tagext;
    25
    26
    27  /**
    28   * Translation-time information associated with a taglib directive, and its
    29   * underlying TLD file.
    30   *
    31   * Most of the information is directly from the TLD, except for
    32   * the prefix and the uri values used in the taglib directive
    33   *
    34   *
    35   */
    36
    37  abstract public class TagLibraryInfo {
    38
    39      /**
    40       * Constructor.
    41       *
    42       * This will invoke the constructors for TagInfo, and TagAttributeInfo
    43       * after parsing the TLD file.
    44       *
    45       * @param prefix the prefix actually used by the taglib directive
    46       * @param uri the URI actually used by the taglib directive
    47       */
    48      protected TagLibraryInfo(String prefix, String uri) {
    49  	this.prefix = prefix;
    50  	this.uri    = uri;
    51      }
    52
    53      // ==== methods accessing taglib information =======
    54
    55      /**
    56       * The value of the uri attribute from the taglib directive for
    57       * this library.
    58       *
    59       * @return the value of the uri attribute
    60       */
    61
    62      public String getURI() {
    63          return uri;
    64      }
    65
    66      /**
    67       * The prefix assigned to this taglib from the taglib directive
    68       *
    69       * @return the prefix assigned to this taglib from the taglib directive
    70       */
    71
    72      public String getPrefixString() {
    73  	return prefix;
    74      }
    75
    76      // ==== methods using the TLD data =======
    77
    78      /**
    79       * The preferred short name (prefix) as indicated in the TLD.
    80       * This may be used by authoring tools as the preferred prefix
    81       * to use when creating an taglib directive for this library.
    82       *
    83       * @return the preferred short name for the library
    84       */
    85      public String getShortName() {
    86          return shortname;
    87      }
    88
    89      /**
    90       * The "reliable" URN indicated in the TLD (the uri element).
    91       * This may be used by authoring tools as a global identifier
    92       * to use when creating a taglib directive for this library.
    93       *
    94       * @return a reliable URN to a TLD like this
    95       */
    96      public String getReliableURN() {
    97          return urn;
    98      }
    99
    100
    101     /**
    102      * Information (documentation) for this TLD.
    103      *
    104      * @return the info string for this tag lib
    105      */
    106
    107     public String getInfoString() {
    108         return info;
    109     }
    110
    111
    112     /**
    113      * A string describing the required version of the JSP container.
    114      *
    115      * @return the (minimal) required version of the JSP container.
    116      * @see javax.servlet.jsp.JspEngineInfo
    117      */
    118
    119     public String getRequiredVersion() {
    120         return jspversion;
    121     }
    122
    123
    124     /**
    125      * An array describing the tags that are defined in this tag library.
    126      *
    127      * @return the TagInfo objects corresponding to the tags defined by this
    128      *         tag library, or a zero length array if this tag library
    129      *         defines no tags
    130      */
    131     public TagInfo[] getTags() {
    132         return tags;
    133     }
    134
    135     /**
    136      * An array describing the tag files that are defined in this tag library.
    137      *
    138      * @return the TagFileInfo objects corresponding to the tag files defined
    139      *         by this tag library, or a zero length array if this
    140      *         tag library defines no tags files
    141      * @since 2.0
    142      */
    143     public TagFileInfo[] getTagFiles() {
    144         return tagFiles;
    145     }
    146
    147
    148     /**
    149      * Get the TagInfo for a given tag name, looking through all the
    150      * tags in this tag library.
    151      *
    152      * @param shortname The short name (no prefix) of the tag
    153      * @return the TagInfo for the tag with the specified short name, or
    154      *         null if no such tag is found
    155      */
    156
    157     public TagInfo getTag(String shortname) {
    158         TagInfo tags[] = getTags();
    159
    160         if (tags == null || tags.length == 0) {
    161             return null;
    162         }
    163
    164         for (int i=0; i < tags.length; i++) {
    165             if (tags[i].getTagName().equals(shortname)) {
    166                 return tags[i];
    167             }
    168         }
    169         return null;
    170     }
    171
    172     /**
    173      * Get the TagFileInfo for a given tag name, looking through all the
    174      * tag files in this tag library.
    175      *
    176      * @param shortname The short name (no prefix) of the tag
    177      * @return the TagFileInfo for the specified Tag file, or null
    178      *         if no Tag file is found
    179      * @since 2.0
    180      */
    181     public TagFileInfo getTagFile(String shortname) {
    182         TagFileInfo tagFiles[] = getTagFiles();
    183
    184         if (tagFiles == null || tagFiles.length == 0) {
    185             return null;
    186         }
    187
    188         for (int i=0; i < tagFiles.length; i++) {
    189             if (tagFiles[i].getName().equals(shortname)) {
    190                 return tagFiles[i];
    191             }
    192         }
    193         return null;
    194     }
    195
    196     /**
    197      * An array describing the functions that are defined in this tag library.
    198      *
    199      * @return the functions defined in this tag library, or a zero
    200      *         length array if the tag library defines no functions.
    201      * @since 2.0
    202      */
    203     public FunctionInfo[] getFunctions() {
    204         return functions;
    205     }
    206
    207
    208     /**
    209      * Get the FunctionInfo for a given function name, looking through all the
    210      * functions in this tag library.
    211      *
    212      * @param name The name (no prefix) of the function
    213      * @return the FunctionInfo for the function with the given name, or null
    214      *         if no such function exists
    215      * @since 2.0
    216      */
    217     public FunctionInfo getFunction(String name) {
    218
    219         if (functions == null || functions.length == 0) {
    220             return null;
    221         }
    222
    223         for (int i=0; i < functions.length; i++) {
    224             if (functions[i].getName().equals(name)) {
    225                 return functions[i];
    226             }
    227         }
    228         return null;
    229     }
    230
    231
    232     // Protected fields
    233
    234     /**
    235      * The prefix assigned to this taglib from the taglib directive.
    236      */
    237     protected String        prefix;
    238
    239     /**
    240      * The value of the uri attribute from the taglib directive for
    241      * this library.
    242      */
    243     protected String        uri;
    244
    245     /**
    246      * An array describing the tags that are defined in this tag library.
    247      */
    248     protected TagInfo[]     tags;
    249
    250     /**
    251      * An array describing the tag files that are defined in this tag library.
    252      *
    253      * @since 2.0
    254      */
    255     protected TagFileInfo[] tagFiles;
    256
    257     /**
    258      * An array describing the functions that are defined in this tag library.
    259      *
    260      * @since 2.0
    261      */
    262     protected FunctionInfo[] functions;
    263
    264     // Tag Library Data
    265
    266     /**
    267      * The version of the tag library.
    268      */
    269     protected String tlibversion; // required
    270
    271     /**
    272      * The version of the JSP specification this tag library is written to.
    273      */
    274     protected String jspversion;  // required
    275
    276     /**
    277      * The preferred short name (prefix) as indicated in the TLD.
    278      */
    279     protected String shortname;   // required
    280
    281     /**
    282      * The "reliable" URN indicated in the TLD.
    283      */
    284     protected String urn;         // required
    285
    286     /**
    287      * Information (documentation) for this TLD.
    288      */
    289     protected String info;        // optional
    290 }