tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet JspServletWrapper.java
Date Wed, 21 May 2003 18:09:33 GMT
luehe       2003/05/21 11:09:33

  Modified:    jasper2/src/share/org/apache/jasper
                        JspCompilationContext.java
               jasper2/src/share/org/apache/jasper/compiler Parser.java
                        ParserController.java TagFileProcessor.java
                        TagLibraryInfoImpl.java
               jasper2/src/share/org/apache/jasper/servlet
                        JspServletWrapper.java
  Log:
  Close JARs after parsing their TLDs, regardless of whether the JAR
  contains any packaged tag files (in order to parse those, the JAR will
  need to be reopened)
  
  Revision  Changes    Path
  1.40      +13 -13    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.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- JspCompilationContext.java	13 May 2003 03:02:20 -0000	1.39
  +++ JspCompilationContext.java	21 May 2003 18:09:33 -0000	1.40
  @@ -91,7 +91,7 @@
    */
   public class JspCompilationContext {
   
  -    private Hashtable tagFileJars;
  +    private Hashtable tagFileJarUrls;
       private boolean isPackagedTagFile;
   
       private String className;
  @@ -126,7 +126,7 @@
       private boolean isTagFile;
       private boolean protoTypeMode;
       private TagInfo tagInfo;
  -    private JarFile tagFileJar;
  +    private URL tagFileJarUrl;
   
       private static final String javaKeywords[] = {
           "abstract", "boolean", "break", "byte", "case",
  @@ -169,7 +169,7 @@
           }
   
           this.rctxt = rctxt;
  -        this.tagFileJars = new Hashtable();
  +        this.tagFileJarUrls = new Hashtable();
           this.basePackageName = Constants.JSP_PACKAGE_NAME;
       }
   
  @@ -179,12 +179,12 @@
                                    ServletContext context,
                                    JspServletWrapper jsw,
                                    JspRuntimeContext rctxt,
  -                                 JarFile tagFileJar) {
  +                                 URL tagFileJarUrl) {
           this(tagfile, false, options, context, jsw, rctxt);
           this.isTagFile = true;
           this.tagInfo = tagInfo;
  -        this.tagFileJar = tagFileJar;
  -        if (tagFileJar != null) {
  +        this.tagFileJarUrl = tagFileJarUrl;
  +        if (tagFileJarUrl != null) {
               isPackagedTagFile = true;
           }
       }
  @@ -309,8 +309,8 @@
        * The map is populated when parsing the tag-file elements of the TLDs
        * of any imported taglibs. 
        */
  -    public Hashtable getTagFileJars() {
  -        return this.tagFileJars;
  +    public Hashtable getTagFileJarUrls() {
  +        return this.tagFileJarUrls;
       }
   
       /**
  @@ -319,8 +319,8 @@
        * JspCompilationContext does not correspond to a tag file, or if the
        * corresponding tag file is not packaged in a JAR.
        */
  -    public JarFile getTagFileJar() {
  -        return this.tagFileJar;
  +    public URL getTagFileJarUrl() {
  +        return this.tagFileJarUrl;
       }
   
       /* ==================== Common implementation ==================== */
  
  
  
  1.74      +10 -9     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.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- Parser.java	7 May 2003 23:05:25 -0000	1.73
  +++ Parser.java	21 May 2003 18:09:33 -0000	1.74
  @@ -67,6 +67,7 @@
   import java.util.List;
   import java.util.Iterator;
   import java.util.jar.JarFile;
  +import java.net.URL;
   import javax.servlet.jsp.tagext.TagLibraryInfo;
   import javax.servlet.jsp.tagext.TagInfo;
   import javax.servlet.jsp.tagext.TagFileInfo;
  @@ -101,7 +102,7 @@
       private int scriptlessCount;
       private boolean isTagFile;
       private boolean directivesOnly;
  -    private JarFile jarFile;
  +    private URL jarFileUrl;
   
       // Virtual body content types, to make parsing a little easier.
       // These are not accessible from outside the parser.
  @@ -116,7 +117,7 @@
        * The constructor
        */
       private Parser(ParserController pc, JspReader reader, boolean isTagFile,
  -		   boolean directivesOnly, JarFile jarFile) {
  +		   boolean directivesOnly, URL jarFileUrl) {
   	this.parserController = pc;
   	this.ctxt = pc.getJspCompilationContext();
   	this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries();
  @@ -127,7 +128,7 @@
           this.scriptlessCount = 0;
   	this.isTagFile = isTagFile;
   	this.directivesOnly = directivesOnly;
  -	this.jarFile = jarFile;
  +	this.jarFileUrl = jarFileUrl;
           start = reader.mark();
       }
   
  @@ -145,14 +146,14 @@
   				   Node parent,
   				   boolean isTagFile,
   				   boolean directivesOnly,
  -				   JarFile jarFile,
  +				   URL jarFileUrl,
   				   String pageEnc,
   				   String jspConfigPageEnc,
   				   boolean isDefaultPageEncoding)
   		throws JasperException {
   
   	Parser parser = new Parser(pc, reader, isTagFile, directivesOnly,
  -				   jarFile);
  +				   jarFileUrl);
   
   	Node.Root root = new Node.Root(reader.mark(), parent, false);
   	root.setPageEncoding(pageEnc);
  @@ -379,7 +380,7 @@
   	}
   
   	try {
  -	    parserController.parse(file, parent, jarFile);
  +	    parserController.parse(file, parent, jarFileUrl);
   	} catch (FileNotFoundException ex) {
   	    err.jspError(start, "jsp.error.file.not.found", file);
   	} catch (Exception ex) {
  
  
  
  1.42      +30 -7     jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java
  
  Index: ParserController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- ParserController.java	7 May 2003 23:05:25 -0000	1.41
  +++ ParserController.java	21 May 2003 18:09:33 -0000	1.42
  @@ -58,6 +58,7 @@
   import java.util.*;
   import java.util.zip.*;
   import java.util.jar.*;
  +import java.net.*;
   import javax.servlet.jsp.tagext.*;
   import org.xml.sax.InputSource;
   import org.xml.sax.Attributes;
  @@ -136,7 +137,7 @@
   	// (using an include directive), ctxt.getTagFileJar() returns the 
   	// JAR file from which to read the tag file or included resource,
   	// respectively.
  -	return parse(inFileName, null, ctxt.getTagFileJar());
  +	return parse(inFileName, null, ctxt.getTagFileJarUrl());
       }
   
       /**
  @@ -147,9 +148,10 @@
        * @param jarFile The JAR file from which to read the included resource,
        * or null of the included resource is to be read from the filesystem
        */
  -    public Node.Nodes parse(String inFileName, Node parent, JarFile jarFile)
  +    public Node.Nodes parse(String inFileName, Node parent,
  +			    URL jarFileUrl)
   	        throws FileNotFoundException, JasperException, IOException {
  -	return parse(inFileName, parent, ctxt.isTagFile(), false, jarFile);
  +	return parse(inFileName, parent, ctxt.isTagFile(), false, jarFileUrl);
       }
   
       /**
  @@ -163,7 +165,7 @@
       public Node.Nodes parseTagFileDirectives(String inFileName)
   	        throws FileNotFoundException, JasperException, IOException {
   	return parse(inFileName, null, true, true,
  -		     (JarFile) ctxt.getTagFileJars().get(inFileName));
  +		     (URL) ctxt.getTagFileJarUrls().get(inFileName));
       }
   
       /**
  @@ -184,13 +186,14 @@
   			     Node parent,
   			     boolean isTagFile,
   			     boolean directivesOnly,
  -			     JarFile jarFile)
  +			     URL jarFileUrl)
   	        throws FileNotFoundException, JasperException, IOException {
   
   	Node.Nodes parsedPage = null;
   	isEncodingSpecifiedInProlog = false;
   	isDefaultPageEncoding = false;
   
  +	JarFile jarFile = getJarFile(jarFileUrl);
   	String absFileName = resolveFileName(inFileName);
   	String jspConfigPageEnc = getJspConfigPageEncoding(absFileName);
   
  @@ -249,8 +252,8 @@
   						    sourceEnc, inStreamReader,
   						    err);
                   parsedPage = Parser.parse(this, jspReader, parent, isTagFile,
  -					  directivesOnly, jarFile, sourceEnc,
  -					  jspConfigPageEnc,
  +					  directivesOnly, jarFileUrl,
  +					  sourceEnc, jspConfigPageEnc,
   					  isDefaultPageEncoding);
               } finally {
   		if (inStreamReader != null) {
  @@ -262,6 +265,12 @@
   	    }
   	}
   
  +	if (jarFile != null) {
  +	    try {
  +		jarFile.close();
  +	    } catch (Throwable t) {}
  +	}
  +
   	baseDirStack.pop();
   
   	return parsedPage;
  @@ -572,4 +581,18 @@
   
   	return false;
       }
  +
  +    private JarFile getJarFile(URL jarFileUrl) throws IOException {
  +	JarFile jarFile = null;
  +
  +	if (jarFileUrl != null) {
  +	    JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
  +	    conn.setUseCaches(false);
  +	    conn.connect();
  +	    jarFile = conn.getJarFile();
  +	}
  +
  +	return jarFile;
  +    }
  +
   }
  
  
  
  1.51      +6 -6      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.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- TagFileProcessor.java	24 Apr 2003 20:45:42 -0000	1.50
  +++ TagFileProcessor.java	21 May 2003 18:09:33 -0000	1.51
  @@ -65,7 +65,7 @@
   import java.util.*;
   import java.util.jar.JarFile;
   import java.io.*;
  -import java.net.URLClassLoader;
  +import java.net.*;
   
   import javax.servlet.ServletException;
   import javax.servlet.jsp.tagext.*;
  @@ -474,7 +474,7 @@
                                                   tagFilePath,
                                                   tagInfo,
                                                   ctxt.getRuntimeContext(),
  -                                                (JarFile) ctxt.getTagFileJars().get(tagFilePath));
  +                                                (URL) ctxt.getTagFileJarUrls().get(tagFilePath));
                       rctxt.addWrapper(tagFilePath,wrapper);
   
   		// Use same classloader and classpath for compiling tag files
  @@ -498,7 +498,7 @@
                                                   tagFilePath,
                                                   tagInfo,
                                                   ctxt.getRuntimeContext(),
  -                                                (JarFile) ctxt.getTagFileJars().get(tagFilePath));
  +                                                (URL) ctxt.getTagFileJarUrls().get(tagFilePath));
                       tagClazz = tempWrapper.loadTagFilePrototype();
                       tempVector.add(
                                  tempWrapper.getJspEngineContext().getCompiler());
  @@ -545,7 +545,7 @@
               if (tagFileInfo != null) {
                   String tagFilePath = tagFileInfo.getPath();
   		JspCompilationContext ctxt = compiler.getCompilationContext();
  -		if (ctxt.getTagFileJars().get(tagFilePath) == null) {
  +		if (ctxt.getTagFileJarUrls().get(tagFilePath) == null) {
   		    // Omit tag file dependency info on jar files for now.
                       pageInfo.addDependant(tagFilePath);
   		}
  
  
  
  1.42      +13 -21    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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- TagLibraryInfoImpl.java	16 Apr 2003 16:12:27 -0000	1.41
  +++ TagLibraryInfoImpl.java	21 May 2003 18:09:33 -0000	1.42
  @@ -162,7 +162,6 @@
   	this.parserController = pc;
   	this.err = err;
           InputStream in = null;
  -	boolean hasPackagedTagFiles = false;
           JarFile jarFile = null;
   
   	if (location == null) {
  @@ -191,15 +190,15 @@
               } else {
                   // Tag library is packaged in JAR file
                   try {
  -                    URL url = new URL("jar:" + location[0] + "!/");
  -                    JarURLConnection conn = (JarURLConnection) url.openConnection();
  +                    URL jarFileUrl = new URL("jar:" + location[0] + "!/");
  +                    JarURLConnection conn =
  +			(JarURLConnection) jarFileUrl.openConnection();
   		    conn.setUseCaches(false);
                       conn.connect();
                       jarFile = conn.getJarFile();
                       ZipEntry jarEntry = jarFile.getEntry(location[1]);
                       in = jarFile.getInputStream(jarEntry);
  -                    hasPackagedTagFiles = parseTLD(ctxt, location[0], in,
  -						   jarFile);
  +                    parseTLD(ctxt, location[0], in, jarFileUrl);
                   } catch (Exception ex) {
                       err.jspError("jsp.error.tld.unable_to_read", location[0],
                                    location[1], ex.toString());
  @@ -211,7 +210,7 @@
                       in.close();
                   } catch (Throwable t) {}
               }
  -            if (jarFile != null && !hasPackagedTagFiles) {
  +            if (jarFile != null) {
                   try {
                       jarFile.close();
                   } catch (Throwable t) {}
  @@ -232,14 +231,13 @@
        * given JAR (that is, one or more tag files whose path element starts
        * with /META-INF/tags), and false otherwise
        */
  -    private boolean parseTLD(JspCompilationContext ctxt,
  -			     String uri, InputStream in, JarFile jarFile) 
  +    private void parseTLD(JspCompilationContext ctxt,
  +			  String uri, InputStream in, URL jarFileUrl) 
           throws JasperException
       {
           Vector tagVector = new Vector();
           Vector tagFileVector = new Vector();
           Hashtable functionTable = new Hashtable();
  -	boolean hasPackagedTagFiles = false;
   
           // Create an iterator over the child elements of our <taglib> element
           ParserUtils pu = new ParserUtils();
  @@ -277,12 +275,8 @@
                   tagVector.addElement(createTagInfo(element));
               else if ("tag-file".equals(tname)) {
   		TagFileInfo tagFileInfo = createTagFileInfo(element, uri,
  -							    jarFile);
  +							    jarFileUrl);
                   tagFileVector.addElement(tagFileInfo);
  -		if (tagFileInfo.getPath().startsWith("/META-INF/tags")) {
  -		    // Tag file is packaged in JAR
  -		    hasPackagedTagFiles = true;
  -		}
   	    } else if ("function".equals(tname)) {         // JSP2.0
   		FunctionInfo funcInfo = createFunctionInfo(element);
   		String funcName = funcInfo.getName();
  @@ -329,8 +323,6 @@
   	while (enum.hasMoreElements()) {
   	    this.functions[i++] = (FunctionInfo) enum.nextElement();
   	}
  -
  -	return hasPackagedTagFiles;
       }
       
       /*
  @@ -472,7 +464,7 @@
        * @return TagInfo correspoding to tag file directives
        */
       private TagFileInfo createTagFileInfo(TreeNode elem, String uri,
  -					  JarFile jarFile)
  +					  URL jarFileUrl)
   	        throws JasperException {
   
   	String name = null;
  @@ -496,7 +488,7 @@
   
   	if (path.startsWith("/META-INF/tags")) {
   	    // Tag file packaged in JAR
  -	    ctxt.getTagFileJars().put(path, jarFile);
  +	    ctxt.getTagFileJarUrls().put(path, jarFileUrl);
   	} else if (!path.startsWith("/WEB-INF/tags")) {
   	    err.jspError("jsp.error.tagfile.illegalPath", path);
   	}
  
  
  
  1.30      +5 -5      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java
  
  Index: JspServletWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- JspServletWrapper.java	11 Apr 2003 22:41:58 -0000	1.29
  +++ JspServletWrapper.java	21 May 2003 18:09:33 -0000	1.30
  @@ -150,7 +150,7 @@
   			     String tagFilePath,
   			     TagInfo tagInfo,
   			     JspRuntimeContext rctxt,
  -			     JarFile tagFileJar)
  +			     URL tagFileJarUrl)
   	    throws JasperException {
   
   	this.isTagFile = true;
  @@ -160,7 +160,7 @@
   	this.tripCount = 0;
           ctxt = new JspCompilationContext(jspUri, tagInfo, options,
   					 servletContext, this, rctxt,
  -					 tagFileJar);
  +					 tagFileJarUrl);
       }
   
       public JspCompilationContext getJspEngineContext() {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message