Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.jasper.compiler;
 
 import static org.jboss.web.JasperMessages.MESSAGES;
 
 import java.util.Set;
 
 
Class responsible for generating an implicit tag library containing tag handlers corresponding to the tag files in "/WEB-INF/tags/" or a subdirectory of it.

Author(s):
Jan Luehe
 
 
     private static final String WEB_INF_TAGS = "/WEB-INF/tags";
     private static final String TAG_FILE_SUFFIX = ".tag";
     private static final String TAGX_FILE_SUFFIX = ".tagx";
     private static final String TAGS_SHORTNAME = "tags";
     private static final String TLIB_VERSION = "1.0";
     private static final String JSP_VERSION = "2.0";
     private static final String IMPLICIT_TLD = "implicit.tld";
 
     // Maps tag names to tag file paths
     private Hashtable tagFileMap;
 
     private ParserController pc;
     private PageInfo pi;
     private Vector vec;

    
Constructor.
 
             ParserController pc,
             PageInfo pi,
             String prefix,
             String tagdir,
             ErrorDispatcher errthrows JasperException {
         super(prefixnull);
         this. = pc;
         this. = pi;
         this. = new Hashtable();
         this. = new Vector();
 
         // Implicit tag libraries have no functions:
         this. = new FunctionInfo[0];
 
          = ;
          = ;
 
         if (!tagdir.startsWith()) {
             err.jspError(.invalidTagFileDirectory(tagdir));
         }
 
         // Determine the value of the <short-name> subelement of the
         // "imaginary" <taglib> element
         if (tagdir.equals()
                 || tagdir.equals + "/")) {
              = ;
         } else {
              = tagdir.substring(.length());
              = .replace('/''-');
         }
 
        // Populate mapping of tag names to tag file paths
        Set dirList = ctxt.getResourcePaths(tagdir);
        if (dirList != null) {
            Iterator it = dirList.iterator();
            while (it.hasNext()) {
                String path = (Stringit.next();
                if (path.endsWith()
                        || path.endsWith()) {
                    /*
                     * Use the filename of the tag file, without the .tag or
                     * .tagx extension, respectively, as the <name> subelement
                     * of the "imaginary" <tag-file> element
                     */
                    String suffix = path.endsWith() ?
                             : 
                    String tagName = path.substring(path.lastIndexOf("/") + 1);
                    tagName = tagName.substring(0,
                            tagName.lastIndexOf(suffix));
                    .put(tagNamepath);
                } else if (path.endsWith()) {
                    InputStream is = null;
                    try {
                        is = ctxt.getResourceAsStream(path);
                        if (is != null) {
                            
                            // Add implicit TLD to dependency list
                            if (pi != null) {
                                pi.addDependant(path);
                            }
                            
                            XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(is);
                            
                            reader.require(.nullnull);
                            while (reader.hasNext() && reader.next() != .) {
                                // Skip until first element
                            }
                            
                            final int count = reader.getAttributeCount();
                            for (int i = 0; i < counti ++) {
                                if ("version".equals(reader.getAttributeLocalName(i))) {
                                    this. = reader.getAttributeValue(i);
                                }
                            }
                            while (reader.hasNext() && reader.nextTag() != .) {
                                String elementName = reader.getLocalName();
                                if ("tlibversion".equals(elementName// JSP 1.1
                                        || "tlib-version".equals(elementName)) { // JSP 1.2
                                    this. = reader.getElementText().trim();
                                } else if ("jspversion".equals(elementName)
                                        || "jsp-version".equals(elementName)) {
                                    this. = reader.getElementText().trim();
                                } else if ("shortname".equals(elementName) || "short-name".equals(elementName)) {
                                    reader.getElementText();
                                } else {
                                    // All other elements are invalid
                                    err.jspError(.invalidImplicitTld(path));
                                }
                            }
                            try {
                                double version = Double.parseDouble(this.);
                                if (version < 2.0) {
                                    err.jspError(.invalidImplicitTldVersion(path));
                                }
                            } catch (NumberFormatException e) {
                                err.jspError(.invalidImplicitTldVersion(path));
                            }
                        }
                    } catch (XMLStreamException e) {
                        err.jspError(.invalidImplicitTld(path), e);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (Throwable t) {
                            }
                        }
                    }
                }
            }
        }        
        
    }

    
Checks to see if the given tag name maps to a tag file path, and if so, parses the corresponding tag file.

Returns:
The TagFileInfo corresponding to the given tag name, or null if the given tag name is not implemented as a tag file
    public TagFileInfo getTagFile(String shortName) {
        TagFileInfo tagFile = super.getTagFile(shortName);
        if (tagFile == null) {
            String path = (String.get(shortName);
            if (path == null) {
                return null;
            }
            TagInfo tagInfo = null;
            try {
                tagInfo = TagFileProcessor.parseTagFileDirectives(,
                        shortName,
                        path,
                        .getJspCompilationContext().getTagFileJarUrl(path),
                        this);
            } catch (JasperException je) {
                throw new RuntimeException(je.toString(), je);
            }
            tagFile = new TagFileInfo(shortNamepathtagInfo);
            .addElement(tagFile);
            this. = new TagFileInfo[.size()];
            .copyInto(this.);
        }
        return tagFile;
    }
    public TagLibraryInfo[] getTagLibraryInfos() {
        Collection coll = .getTaglibs();
        return (TagLibraryInfo[]) coll.toArray(new TagLibraryInfo[0]);
    }
New to GrepCode? Check out our FAQ X