luehe       2002/07/25 15:28:46

  Modified:    jasper2/src/share/org/apache/jasper
                        JspCompilationContext.java
               jasper2/src/share/org/apache/jasper/compiler Parser.java
                        TagFileProcessor.java TagLibraryInfoImpl.java
               jasper2/src/share/org/apache/jasper/resources
                        messages.properties
  Added:       jasper2/src/share/org/apache/jasper/compiler
                        ImplicitTagLibraryInfo.java
  Log:
  Added support for implicit tag libraries containing the tag handlers of tag files 
stored in a directory without a TLD file
  
  Revision  Changes    Path
  1.10      +12 -11    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspCompilationContext.java
  
  Index: JspCompilationContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspCompilationContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JspCompilationContext.java        24 Jul 2002 09:09:47 -0000      1.9
  +++ JspCompilationContext.java        25 Jul 2002 22:28:45 -0000      1.10
  @@ -61,19 +61,16 @@
   
   package org.apache.jasper;
   
  +import java.io.*;
  +import java.net.*;
  +import java.util.Set;
  +import javax.servlet.ServletContext;
  +import org.apache.jasper.compiler.JspRuntimeContext;
   import org.apache.jasper.compiler.JspReader;
   import org.apache.jasper.compiler.ServletWriter;
  -import java.io.IOException;
  -import java.io.File;
  -import java.io.FileNotFoundException;
  -import java.net.URL;
  -import java.net.URLClassLoader;
  -import java.net.MalformedURLException;
   import org.apache.jasper.compiler.Compiler;
   import org.apache.jasper.servlet.JspServletWrapper;
   import org.apache.jasper.servlet.JasperLoader;
  -import javax.servlet.ServletContext;
  -import org.apache.jasper.compiler.JspRuntimeContext;
   
   /**
    * A place holder for various things that are used through out the JSP
  @@ -233,6 +230,10 @@
   
       public URL getResource(String res) throws MalformedURLException {
           return context.getResource(canonicalURI(res));
  +    }
  +
  +    public Set getResourcePaths(String path) {
  +        return context.getResourcePaths(canonicalURI(path));
       }
   
       /** 
  
  
  
  1.13      +25 -10    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Parser.java       25 Jul 2002 19:02:16 -0000      1.12
  +++ Parser.java       25 Jul 2002 22:28:45 -0000      1.13
  @@ -368,13 +368,28 @@
        Attributes attrs = parseAttributes();
        String uri = attrs.getValue("uri");
        String prefix = attrs.getValue("prefix");
  -     if (uri != null && prefix != null) {
  -         // Errors to be checked in Validator
  -         String[] location = ctxt.getTldLocation(uri);
  -         TagLibraryInfo tl = new TagLibraryInfoImpl(ctxt, parserController,
  -                                                    prefix, uri, location,
  -                                                    err);
  -         taglibs.put(prefix, tl);
  +     if (prefix != null) {
  +         TagLibraryInfo tagLibInfo = null;
  +         if (uri != null) {
  +             // Errors to be checked in Validator
  +             String[] location = ctxt.getTldLocation(uri);
  +             tagLibInfo = new TagLibraryInfoImpl(ctxt, parserController,
  +                                                 prefix, uri, location,
  +                                                 err);
  +         } else {
  +             String tagdir = attrs.getValue("tagdir");
  +             if (tagdir != null) {
  +                 tagLibInfo = ImplicitTagLibraryInfo.getTabLibraryInfo(
  +                                                    ctxt,
  +                                                 parserController,
  +                                                 prefix, 
  +                                                 tagdir,
  +                                                 err);
  +             }
  +         }
  +         if (tagLibInfo != null) {
  +             taglibs.put(prefix, tagLibInfo);
  +         }
        }
   
        new Node.TaglibDirective(attrs, start, parent);
  
  
  
  1.3       +12 -5     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java
  
  Index: TagFileProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagFileProcessor.java     25 Jul 2002 19:08:46 -0000      1.2
  +++ TagFileProcessor.java     25 Jul 2002 22:28:45 -0000      1.3
  @@ -274,15 +274,22 @@
                                  fragmentAttributes,
                                  dynamicAttributes);
           }
  -
       }
   
       public static TagInfo parseTagFile(ParserController pc, String tagfile)
  -                throws FileNotFoundException, JasperException {
  +                throws JasperException {
  +
  +        Node.Nodes page = null;
  +     try {
  +         page = pc.parse(tagfile);
  +     } catch (FileNotFoundException e) {
  +         pc.getCompiler().getErrorDispatcher().jspError(
  +                                        "jsp.error.file.not.found", tagfile);
  +     }
   
  -        Node.Nodes page = pc.parse(tagfile);
           TagFileVisitor tagFileVisitor = new TagFileVisitor(pc.getCompiler());
           page.visit(tagFileVisitor);
  +
           return tagFileVisitor.getTagInfo();
       }
   }
  
  
  
  1.6       +5 -9      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java
  
  Index: TagLibraryInfoImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TagLibraryInfoImpl.java   25 Jul 2002 19:02:16 -0000      1.5
  +++ TagLibraryInfoImpl.java   25 Jul 2002 22:28:45 -0000      1.6
  @@ -442,12 +442,8 @@
               String tname = child.getName();
               if ("path".equals(tname)) {
                String tagFilePath = child.getBody();
  -             try {
  -                 tagInfo = TagFileProcessor.parseTagFile(parserController,
  -                                                         tagFilePath);
  -             } catch (FileNotFoundException e) {
  -                 err.jspError("jsp.error.file.not.found", tagFilePath);
  -             }
  +             tagInfo = TagFileProcessor.parseTagFile(parserController,
  +                                                     tagFilePath);
                break;
            }
        }
  
  
  
  1.1                  
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java
  
  Index: ImplicitTagLibraryInfo.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  package org.apache.jasper.compiler;
  
  import java.util.*;
  import javax.servlet.jsp.tagext.TagLibraryInfo;
  import javax.servlet.jsp.tagext.TagInfo;
  import org.apache.jasper.JspCompilationContext;
  import org.apache.jasper.JasperException;
  
  /**
   * 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.
   */
  public class ImplicitTagLibraryInfo extends TagLibraryInfo {
  
      private static final String WEB_INF_TAGS = "/WEB-INF/tags/";
      private static final String TLD_SUFFIX = ".tld";
      private static final String TAG_FILE_SUFFIX = ".tag";
      private static final String TAGS_SHORTNAME = "tags";
      private static final String TLIB_VERSION = "1.0";
      private static final String JSP_VERSION = "2.0";
  
      private String tldFile;
  
      /**
       * Constructor.
       */
      public ImplicitTagLibraryInfo(JspCompilationContext ctxt,
                                  ParserController pc,
                                  String prefix,
                                  String tagdir,
                                  ErrorDispatcher err) throws JasperException {
          super(prefix, tagdir);
        
        tlibversion = TLIB_VERSION;
        jspversion = JSP_VERSION;
  
        if (!tagdir.startsWith(WEB_INF_TAGS)) {
            err.jspError("jsp.error.invalid.tagdir", tagdir);
        }
        
        // Determine the value of the <short-name> element
        if (tagdir.equals(WEB_INF_TAGS)) {
            shortname = TAGS_SHORTNAME;
        } else {
            shortname = tagdir.substring(WEB_INF_TAGS.length());
            shortname = shortname.replace('/', '-');
        }
  
        Set dirList = ctxt.getResourcePaths(tagdir);
        if (dirList != null) {
            Vector tagVector = new Vector();
            Iterator it = dirList.iterator();
            while (it.hasNext()) {
                String path = (String) it.next();
                if (path.endsWith(".tld")) {
                    tldFile = path;
                    break;
                } else if (path.endsWith(".tag")) {
                    tagVector.addElement(TagFileProcessor.parseTagFile(pc,
                                                                       path)); 
                }
            }
  
            tags = new TagInfo[tagVector.size()];
            tagVector.copyInto (this.tags);
        }
      }
  
      public static TagLibraryInfo getTabLibraryInfo(JspCompilationContext ctxt,
                                                   ParserController pc,
                                                   String prefix, 
                                                   String tagdir,
                                                   ErrorDispatcher err)
            throws JasperException {
  
        TagLibraryInfo tagLibInfo = new ImplicitTagLibraryInfo(ctxt, pc,
                                                               prefix, tagdir,
                                                               err);
        if (((ImplicitTagLibraryInfo) tagLibInfo).tldFile != null) {
            // tagdir contains TLD file
            String[] location = new String[2];
            location[0] = ((ImplicitTagLibraryInfo) tagLibInfo).tldFile;
            tagLibInfo = new TagLibraryInfoImpl(ctxt, pc, prefix, tagdir,
                                                location, err);
        }
        
        return tagLibInfo;
      }
  }
  
  
  
  1.16      +2 -1      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- messages.properties       24 Jul 2002 23:57:12 -0000      1.15
  +++ messages.properties       25 Jul 2002 22:28:46 -0000      1.16
  @@ -243,6 +243,7 @@
   tld.error.variableNotAllowed=It is an error for a tag that has one or more variable 
subelements to have a TagExtraInfo class that returns a non-null object.
   jsp.error.tldInWebDotXmlNotFound=Could not locate TLD {1} for URI {0} specified in 
web.xml
   jsp.error.taglibDirective.absUriCannotBeResolved=This absolute uri ({0}) cannot be 
resolved in either web.xml or the jar files deployed with this application
  +jsp.error.invalid.tagdir=Tag file directory {0} does not start with 
\"/WEB-INF/tags\"
   jsp.error.unterminated.user.tag=Unterminated user-defined tag: ending tag {0} not 
found or incorrectly nested
   #jspx.error.templateDataNotInJspCdata=Validation Error: Element &lt;{0}&gt; cannot 
have template data. Template data must be encapsulated within a &lt;jsp:cdata&gt; 
element. [JSP1.2 PFD section 5.1.9]\nTemplate data in error: {1}
   jspx.error.templateDataNotInJspCdata=Validation Error: Element &lt;{0}&gt; cannot 
have template data. Template data must be encapsulated within a &lt;jsp:text&gt; 
element. [JSP1.2 PFD section 5.1.9]\nTemplate data in error: {1}
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to