luehe 2002/12/18 15:18:21 Modified: jasper2/src/share/org/apache/jasper JspCompilationContext.java jasper2/src/share/org/apache/jasper/compiler ImplicitTagLibraryInfo.java JspDocumentParser.java Parser.java ParserController.java TagFileProcessor.java TagLibraryInfoImpl.java jasper2/src/share/org/apache/jasper/servlet JspServletWrapper.java Log: If a tag file is packaged in a JAR, any of its include directives must be resolved against the JAR as opposed to the filesystem. Revision Changes Path 1.28 +24 -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.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- JspCompilationContext.java 8 Dec 2002 13:42:52 -0000 1.27 +++ JspCompilationContext.java 18 Dec 2002 23:18:20 -0000 1.28 @@ -64,6 +64,7 @@ import java.io.*; import java.net.*; import java.util.*; +import java.util.jar.JarFile; import javax.servlet.ServletContext; import javax.servlet.jsp.tagext.TagInfo; import javax.servlet.jsp.tagext.TagData; @@ -122,6 +123,7 @@ private boolean isTagFile; private boolean protoTypeMode; private TagInfo tagInfo; + private JarFile tagFileJar; // jspURI _must_ be relative to the context public JspCompilationContext(String jspUri, @@ -162,13 +164,12 @@ ServletContext context, JspServletWrapper jsw, JspRuntimeContext rctxt, - Hashtable tagFileJars) { - + JarFile tagFileJar) { this(tagfile, false, options, context, jsw, rctxt); this.isTagFile = true; this.tagInfo = tagInfo; - this.tagFileJars = tagFileJars; - if (tagFileJars != null && tagFileJars.get(tagfile) != null) { + this.tagFileJar = tagFileJar; + if (tagFileJar != null) { isPackagedTagFile = true; } } @@ -284,13 +285,25 @@ } /** - * Returns the tag-file-to-JAR-file mapping for tag files packaged in JARs. + * Returns the tag-file-name-to-JAR-file map of this compilation unit, + * which maps tag file names to the JAR files in which the tag files are + * packaged. * - * The mapping uses the tag file name as the key, and the JAR file - * containing the tag file as the value. + * The map is populated when parsing the tag-file elements of the TLDs + * of any imported taglibs. */ public Hashtable getTagFileJars() { - return tagFileJars; + return this.tagFileJars; + } + + /** + * Returns the JAR file in which the tag file for which this + * JspCompilationContext was created is packaged, or null if this + * 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; } /* ==================== Common implementation ==================== */ 1.18 +7 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java Index: ImplicitTagLibraryInfo.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ImplicitTagLibraryInfo.java 14 Dec 2002 14:16:07 -0000 1.17 +++ ImplicitTagLibraryInfo.java 18 Dec 2002 23:18:20 -0000 1.18 @@ -159,8 +159,10 @@ TagInfo tagInfo = null; try { - tagInfo = TagFileProcessor.parseTagFile(pc, shortName, path, - this); + tagInfo = TagFileProcessor.parseTagFileDirectives(pc, + shortName, + path, + this); } catch (JasperException je) { throw new RuntimeException(je.toString()); } 1.34 +4 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java Index: JspDocumentParser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- JspDocumentParser.java 12 Dec 2002 03:30:58 -0000 1.33 +++ JspDocumentParser.java 18 Dec 2002 23:18:20 -0000 1.34 @@ -759,7 +759,7 @@ } try { - parserController.parse(fname, includeDir); + parserController.parse(fname, includeDir, null); } catch (FileNotFoundException fnfe) { throw new SAXParseException(err.getString( "jsp.error.file.not.found", fname), 1.52 +14 -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.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- Parser.java 18 Dec 2002 17:37:50 -0000 1.51 +++ Parser.java 18 Dec 2002 23:18:21 -0000 1.52 @@ -65,6 +65,7 @@ import java.util.Hashtable; import java.util.List; import java.util.Iterator; +import java.util.jar.JarFile; import javax.servlet.jsp.tagext.TagLibraryInfo; import javax.servlet.jsp.tagext.TagInfo; import javax.servlet.jsp.tagext.TagFileInfo; @@ -98,7 +99,8 @@ private int scriptlessCount; private boolean isTagFile; private boolean directivesOnly; - + private JarFile jarFile; + // Virtual body content types, to make parsing a little easier. // These are not accessible from outside the parser. private static final String JAVAX_BODY_CONTENT_PARAM = @@ -112,7 +114,7 @@ * The constructor */ private Parser(ParserController pc, JspReader reader, boolean isTagFile, - boolean directivesOnly) { + boolean directivesOnly, JarFile jarFile) { this.parserController = pc; this.ctxt = pc.getJspCompilationContext(); this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries(); @@ -122,6 +124,7 @@ this.scriptlessCount = 0; this.isTagFile = isTagFile; this.directivesOnly = directivesOnly; + this.jarFile = jarFile; start = reader.mark(); } @@ -138,10 +141,12 @@ JspReader reader, Node parent, boolean isTagFile, - boolean directivesOnly) + boolean directivesOnly, + JarFile jarFile) throws JasperException { - Parser parser = new Parser(pc, reader, isTagFile, directivesOnly); + Parser parser = new Parser(pc, reader, isTagFile, directivesOnly, + jarFile); Node.Root root = new Node.Root(null, reader.mark(), parent); @@ -185,7 +190,7 @@ public static Attributes parseAttributes(ParserController pc, JspReader reader) throws JasperException { - Parser tmpParser = new Parser(pc, reader, false, false); + Parser tmpParser = new Parser(pc, reader, false, false, null); return tmpParser.parseAttributes(); } @@ -361,7 +366,7 @@ } try { - parserController.parse(file, parent); + parserController.parse(file, parent, jarFile); } catch (FileNotFoundException ex) { err.jspError(start, "jsp.error.file.not.found", file); } catch (Exception ex) { 1.28 +35 -24 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.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- ParserController.java 27 Nov 2002 16:42:26 -0000 1.27 +++ ParserController.java 18 Dec 2002 23:18:21 -0000 1.28 @@ -115,7 +115,7 @@ * Constructor */ public ParserController(JspCompilationContext ctxt, Compiler compiler) { - this.ctxt = ctxt; // @@@ can we assert that ctxt is not null? + this.ctxt = ctxt; this.compiler = compiler; this.pageInfo = compiler.getPageInfo(); this.err = compiler.getErrorDispatcher(); @@ -130,60 +130,71 @@ } /** - * Parses a jsp file. This is invoked by the compiler. + * Parses a JSP page or tag file. This is invoked by the compiler. * - * @param inFileName The name of the JSP file to be parsed. + * @param inFileName The path to the JSP page or tag file to be parsed. */ public Node.Nodes parse(String inFileName) throws FileNotFoundException, JasperException, IOException { - return parse(inFileName, null); + // If we're parsing a packaged tag file or a resource included by it + // (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()); } /** - * Parses a jsp file. This is invoked to process an include file. + * Processes an include directive with the given path. * - * @param inFileName The name of the JSP file to be parsed. - * @param parent The node for the 'include' directive. + * @param inFileName The path to the resource to be included. + * @param parent The parent node of the include directive. + * @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) + public Node.Nodes parse(String inFileName, Node parent, JarFile jarFile) throws FileNotFoundException, JasperException, IOException { - return parseFile(inFileName, parent, ctxt.isTagFile(), false); + return parse(inFileName, parent, ctxt.isTagFile(), false, jarFile); } /** - * Parses a tag file. This is invoked by the compiler to extract tag - * file directive information. + * Extracts tag file directive information from the tag file with the + * given name. + * + * This is invoked by the compiler * * @param inFileName The name of the tag file to be parsed. */ - public Node.Nodes parseTagFile(String inFileName) + public Node.Nodes parseTagFileDirectives(String inFileName) throws FileNotFoundException, JasperException, IOException { isTopFile = true; - return parseFile(inFileName, null, true, true); + return parse(inFileName, null, true, true, + (JarFile) ctxt.getTagFileJars().get(inFileName)); } /** - * Parse the JSP page provided as an argument. - * This is invoked recursively to handle 'include' directives. + * Parses the JSP page or tag file with the given path name. * - * @param inFileName The name of the jsp file to be parsed. - * @param parent The parent node for the parser, and is non-null when - * parsing an included file + * @param inFileName The name of the JSP page or tag file to be parsed. + * @param parent The parent node (non-null when processing an include + * directive) * @param isTagFile true if file to be parsed is tag file, and false if it - * is a regular jsp page + * is a regular JSP page * @param directivesOnly true if the file to be parsed is a tag file and * we are only interested in the directives needed for constructing a * TagFileInfo. + * @param jarFile The JAR file from which to read the JSP page or tag file, + * or null if the JSP page or tag file is to be read from the filesystem */ - private Node.Nodes parseFile(String inFileName, Node parent, - boolean isTagFile, boolean directivesOnly) + private Node.Nodes parse(String inFileName, + Node parent, + boolean isTagFile, + boolean directivesOnly, + JarFile jarFile) throws FileNotFoundException, JasperException, IOException { Node.Nodes parsedPage = null; String absFileName = resolveFileName(inFileName); - JarFile jarFile = (JarFile) ctxt.getTagFileJars().get(inFileName); - // Figure out what type of JSP document and encoding type we are // dealing with String encoding = figureOutJspDocument(absFileName, jarFile); @@ -222,7 +233,7 @@ encoding, inStreamReader, err); parsedPage = Parser.parse(this, jspReader, parent, isTagFile, - directivesOnly); + directivesOnly, jarFile); } finally { if (inStreamReader != null) { try { 1.37 +17 -16 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.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- TagFileProcessor.java 28 Nov 2002 04:18:08 -0000 1.36 +++ TagFileProcessor.java 18 Dec 2002 23:18:21 -0000 1.37 @@ -63,6 +63,7 @@ package org.apache.jasper.compiler; import java.util.*; +import java.util.jar.JarFile; import java.io.*; import javax.servlet.ServletException; @@ -299,17 +300,17 @@ * @param tagLibInfo the TagLibraryInfo object associated with this TagInfo * @return a TagInfo object assembled from the directives in the tag file. */ - public static TagInfo parseTagFile(ParserController pc, - String name, - String path, - TagLibraryInfo tagLibInfo) - throws JasperException { + public static TagInfo parseTagFileDirectives(ParserController pc, + String name, + String path, + TagLibraryInfo tagLibInfo) + throws JasperException { ErrorDispatcher err = pc.getCompiler().getErrorDispatcher(); Node.Nodes page = null; try { - page = pc.parseTagFile(path); + page = pc.parseTagFileDirectives(path); } catch (FileNotFoundException e) { err.jspError("jsp.error.file.not.found", path); } catch (IOException e) { @@ -361,7 +362,7 @@ tagFilePath, tagInfo, ctxt.getRuntimeContext(), - ctxt.getTagFileJars()); + (JarFile) ctxt.getTagFileJars().get(tagFilePath)); rctxt.addWrapper(tagFilePath,wrapper); } @@ -374,13 +375,13 @@ // file is compiled in prototype mode, to avoid infinite // recursion. - JspServletWrapper tempWrapper = new JspServletWrapper( - ctxt.getServletContext(), - ctxt.getOptions(), - tagFilePath, - tagInfo, - ctxt.getRuntimeContext(), - ctxt.getTagFileJars()); + JspServletWrapper tempWrapper + = new JspServletWrapper(ctxt.getServletContext(), + ctxt.getOptions(), + tagFilePath, + tagInfo, + ctxt.getRuntimeContext(), + (JarFile) ctxt.getTagFileJars().get(tagFilePath)); tagClazz = tempWrapper.loadTagFilePrototype(); tempVector.add( tempWrapper.getJspEngineContext().getCompiler()); 1.31 +6 -6 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.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- TagLibraryInfoImpl.java 16 Dec 2002 20:39:17 -0000 1.30 +++ TagLibraryInfoImpl.java 18 Dec 2002 23:18:21 -0000 1.31 @@ -452,9 +452,9 @@ err.jspError("jsp.error.tagfile.illegalPath", path); } - TagInfo tagInfo = TagFileProcessor.parseTagFile(parserController, - name, path, - this); + TagInfo tagInfo + = TagFileProcessor.parseTagFileDirectives(parserController, name, + path, this); return new TagFileInfo(name, path, tagInfo); } 1.24 +6 -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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- JspServletWrapper.java 8 Dec 2002 13:42:53 -0000 1.23 +++ JspServletWrapper.java 18 Dec 2002 23:18:21 -0000 1.24 @@ -63,6 +63,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Hashtable; +import java.util.jar.JarFile; import java.net.URL; import java.net.URLClassLoader; import java.net.MalformedURLException; @@ -144,7 +145,7 @@ String tagFilePath, TagInfo tagInfo, JspRuntimeContext rctxt, - Hashtable tagFileJars) + JarFile tagFileJar) throws JasperException { this.isTagFile = true; @@ -154,7 +155,7 @@ this.tripCount = 0; ctxt = new JspCompilationContext(jspUri, tagInfo, options, servletContext, this, rctxt, - tagFileJars); + tagFileJar); ctxt.createOutdir("/tags/" + tagInfo.getTagClassName().replace('.', '/')); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>