luehe 2002/08/20 16:35:31 Modified: jasper2/src/share/org/apache/jasper JspCompilationContext.java jasper2/src/share/org/apache/jasper/servlet JspServletWrapper.java jasper2/src/share/org/apache/jasper/compiler Compiler.java ParserController.java TagFileProcessor.java TagLibraryInfoImpl.java Log: Added support for tag files packaged in JARs. Revision Changes Path 1.17 +27 -8 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- JspCompilationContext.java 20 Aug 2002 19:30:29 -0000 1.16 +++ JspCompilationContext.java 20 Aug 2002 23:35:30 -0000 1.17 @@ -63,7 +63,7 @@ import java.io.*; import java.net.*; -import java.util.Set; +import java.util.*; import javax.servlet.ServletContext; import javax.servlet.jsp.tagext.TagInfo; @@ -89,6 +89,9 @@ */ public class JspCompilationContext { + private Hashtable tagFileJars; + private boolean isPackagedTagFile; + protected String servletClassName; protected String jspUri; private boolean isErrPage; @@ -148,6 +151,8 @@ baseURI += '/'; } this.rctxt=rctxt; + + this.tagFileJars = new Hashtable(); } public JspCompilationContext(String tagfile, @@ -155,12 +160,16 @@ Options options, ServletContext context, JspServletWrapper jsw, - JspRuntimeContext rctxt) { + JspRuntimeContext rctxt, + Hashtable tagFileJars) { this(tagfile, false, options, context, jsw, rctxt); this.isTagFile = true; this.tagInfo = tagInfo; - return; + this.tagFileJars = tagFileJars; + if (tagFileJars != null && tagFileJars.get(tagfile) != null) { + isPackagedTagFile = true; + } } /* ==================== Methods to override ==================== */ @@ -268,7 +277,17 @@ } return path; } - + + /** + * Returns the tag-file-to-JAR-file mapping for tag files packaged in JARs. + * + * The mapping uses the tag file name as the key, and the JAR file + * containing the tag file as the value. + */ + public Hashtable getTagFileJars() { + return tagFileJars; + } + /* ==================== Common implementation ==================== */ /** @@ -521,7 +540,7 @@ public void compile() throws JasperException, FileNotFoundException { createCompiler(); - if (jspCompiler.isOutDated()) { + if (isPackagedTagFile || jspCompiler.isOutDated()) { try { jspCompiler.compile(); reload = true; 1.13 +7 -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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- JspServletWrapper.java 6 Aug 2002 00:11:36 -0000 1.12 +++ JspServletWrapper.java 20 Aug 2002 23:35:30 -0000 1.13 @@ -72,6 +72,7 @@ import java.io.IOException; import java.io.FileNotFoundException; +import java.util.Hashtable; import java.net.URL; import java.net.URLClassLoader; import java.net.MalformedURLException; @@ -134,14 +135,15 @@ */ public JspServletWrapper(ServletContext servletContext, Options options, String tagFilePath, TagInfo tagInfo, - JspRuntimeContext rctxt) + JspRuntimeContext rctxt, Hashtable tagFileJars) throws JasperException { this.config = null; // not used this.options = options; this.jspUri = tagFilePath; ctxt = new JspCompilationContext(jspUri, tagInfo, options, - servletContext, this, rctxt); + servletContext, this, rctxt, + tagFileJars); // Store tag file .java and .class files in standard location // (/tagfiles/org/apache/jsp/), regardless of the original tag file 1.30 +1 -1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java Index: Compiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- Compiler.java 20 Aug 2002 19:35:24 -0000 1.29 +++ Compiler.java 20 Aug 2002 23:35:30 -0000 1.30 @@ -193,7 +193,7 @@ * Compile the jsp file from the current engine context */ public void generateJava() - throws FileNotFoundException, JasperException, Exception + throws Exception { long t1=System.currentTimeMillis(); // Setup page info area 1.13 +25 -12 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ParserController.java 20 Aug 2002 15:50:22 -0000 1.12 +++ ParserController.java 20 Aug 2002 23:35:30 -0000 1.13 @@ -56,6 +56,8 @@ import java.io.*; import java.util.*; +import java.util.zip.*; +import java.util.jar.*; import javax.servlet.jsp.tagext.*; import org.xml.sax.InputSource; import org.xml.sax.Attributes; @@ -154,7 +156,7 @@ * @param inFileName The name of the JSP file to be parsed. */ public Node.Nodes parse(String inFileName) - throws FileNotFoundException, JasperException { + throws FileNotFoundException, JasperException, IOException { return parse(inFileName, null); } @@ -166,15 +168,18 @@ * @param parent The node for the 'include' directive. */ public Node.Nodes parse(String inFileName, Node parent) - throws FileNotFoundException, JasperException { + throws FileNotFoundException, JasperException, IOException { Node.Nodes parsedPage = null; - String absFileName = resolveFileName(inFileName); String encoding = topFileEncoding; InputStreamReader reader = null; + String absFileName = resolveFileName(inFileName); + + JarFile jarFile = (JarFile) ctxt.getTagFileJars().get(inFileName); + try { // Figure out what type of JSP document we are dealing with - reader = getReader(absFileName, encoding); + reader = getReader(absFileName, encoding, jarFile); figureOutJspDocument(absFileName, encoding, reader); if (newEncoding != null) encoding = newEncoding; @@ -193,7 +198,7 @@ // dispatch to the proper parser - reader = getReader(absFileName, encoding); + reader = getReader(absFileName, encoding, jarFile); if (isXml) { parsedPage = JspDocumentParser.parse(this, absFileName, reader, parent, @@ -332,17 +337,25 @@ return fileName; } - private InputStreamReader getReader(String file, String encoding) - throws FileNotFoundException, JasperException - { + private InputStreamReader getReader(String file, String encoding, + JarFile jarFile) + throws FileNotFoundException, JasperException, IOException { + InputStream in; InputStreamReader reader; + if (jarFile != null) { + ZipEntry jarEntry = + jarFile.getEntry(file.substring(1, file.length())); + in = jarFile.getInputStream(jarEntry); + } else { + in = ctxt.getResourceAsStream(file); + } + if (in == null) { + throw new FileNotFoundException(file); + } + try { - in = ctxt.getResourceAsStream(file); - if (in == null) { - throw new FileNotFoundException(file); - } return new InputStreamReader(in, encoding); } catch (UnsupportedEncodingException ex) { throw new JasperException( 1.15 +8 -4 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- TagFileProcessor.java 20 Aug 2002 15:50:22 -0000 1.14 +++ TagFileProcessor.java 20 Aug 2002 23:35:30 -0000 1.15 @@ -63,7 +63,7 @@ package org.apache.jasper.compiler; import java.util.*; -import java.io.FileNotFoundException; +import java.io.*; import javax.servlet.ServletException; import javax.servlet.jsp.tagext.*; @@ -317,6 +317,9 @@ } catch (FileNotFoundException e) { pc.getCompiler().getErrorDispatcher().jspError( "jsp.error.file.not.found", tagfile); + } catch (IOException e) { + pc.getCompiler().getErrorDispatcher().jspError( + "jsp.error.file.not.found", tagfile); } TagFileVisitor tagFileVisitor = new TagFileVisitor(pc.getCompiler(), @@ -344,7 +347,8 @@ ctxt.getOptions(), tagFilePath, tagInfo, - ctxt.getRuntimeContext()); + ctxt.getRuntimeContext(), + ctxt.getTagFileJars()); } } } 1.12 +13 -8 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.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TagLibraryInfoImpl.java 19 Aug 2002 16:54:16 -0000 1.11 +++ TagLibraryInfoImpl.java 20 Aug 2002 23:35:30 -0000 1.12 @@ -192,7 +192,7 @@ err.jspError("jsp.error.file.not.found", location[0]); } // Now parse the tld. - parseTLD(ctxt, location[0], in); + parseTLD(ctxt, location[0], in, null); } else { // Location points to a jar file // tag library in jar file @@ -214,7 +214,7 @@ jarFile = conn.getJarFile(); jarEntry = jarFile.getEntry(location[1]); stream = jarFile.getInputStream(jarEntry); - parseTLD(ctxt, location[0], stream); + parseTLD(ctxt, location[0], stream, jarFile); // FIXME @@@ // -- it seems that the JarURLConnection class caches JarFile // objects for particular URLs, and there is no way to get @@ -248,7 +248,7 @@ } private void parseTLD(JspCompilationContext ctxt, - String uri, InputStream in) + String uri, InputStream in, JarFile jarFile) throws JasperException { Vector tagVector = new Vector(); @@ -286,7 +286,8 @@ else if ("tag".equals(tname)) tagVector.addElement(createTagInfo(element)); else if ("tag-file".equals(tname)) - tagFileVector.addElement(createTagFileInfo(element, uri)); + tagFileVector.addElement(createTagFileInfo(element, uri, + jarFile)); else if ("function".equals(tname)) // JSP2.0 functionVector.addElement(createFunctionInfo(element)); else if ("display-name".equals(tname) || // Ignored elements @@ -429,7 +430,8 @@ * * @return TagInfo correspoding to tag file directives */ - private TagFileInfo createTagFileInfo(TreeNode elem, String uri) + private TagFileInfo createTagFileInfo(TreeNode elem, String uri, + JarFile jarFile) throws JasperException { String name = null; @@ -455,6 +457,9 @@ if (!path.startsWith("/")) { // relative to uri of TLD file path = uri.substring(0, uri.lastIndexOf("/") + 1) + path; + } else if (path.startsWith("/META-INF/tags")) { + // Tag file packaged in JAR + ctxt.getTagFileJars().put(path, jarFile); } TagInfo tagInfo = TagFileProcessor.parseTagFile(parserController, name, path,
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>