luehe 2002/11/27 20:18:08 Modified: jasper2/src/share/org/apache/jasper Constants.java EmbededServletOptions.java JspCompilationContext.java jasper2/src/share/org/apache/jasper/compiler Compiler.java Generator.java ImplicitTagLibraryInfo.java JspRuntimeContext.java JspUtil.java Node.java TagFileProcessor.java TagLibraryInfoImpl.java jasper2/src/share/org/apache/jasper/servlet JasperLoader.java JspServletWrapper.java Log: Avoid conflicts between tag files that are located in different directories and therefore are considered to belong to different implicit tag libraries. The path of a tag file is now reflected in the directory in which the corresponding tag handler is stored, and in the name of the package to which the tag handler is assigned. This change also avoids conflicts between tag files with the same name and path under /META-INF/tags/ and /WEB-INF/tags/, by adding "meta" or "web", respectively, to the directory and package names of the respective tag handlers. Revision Changes Path 1.10 +1 -2 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Constants.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Constants.java 16 Nov 2002 04:20:09 -0000 1.9 +++ Constants.java 28 Nov 2002 04:18:07 -0000 1.10 @@ -158,8 +158,7 @@ /** * The default package name for tag handlers generated from tag files */ - public static final String TAG_FILE_PACKAGE_NAME - = "org.apache.jsp.tagfile"; + public static final String TAG_FILE_PACKAGE_NAME = "org.apache.jsp.tag"; /** * Servlet context and request attributes that the JSP engine 1.13 +10 -9 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbededServletOptions.java Index: EmbededServletOptions.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbededServletOptions.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- EmbededServletOptions.java 16 Nov 2002 04:20:09 -0000 1.12 +++ EmbededServletOptions.java 28 Nov 2002 04:18:07 -0000 1.13 @@ -435,12 +435,14 @@ if (classpath != null) this.classpath = classpath; + /* + * scratchdir + */ String dir = config.getInitParameter("scratchdir"); - - if (dir != null) + if (dir != null) { scratchDir = new File(dir); - else { - // First we try the Servlet 2.2 javax.servlet.context.tempdir property + } else { + // First try the Servlet 2.2 javax.servlet.context.tempdir property scratchDir = (File) context.getAttribute(Constants.TMP_DIR); if (scratchDir == null) { // Not running in a Servlet 2.2 container. @@ -449,8 +451,7 @@ if (dir != null) scratchDir = new File(dir); } - } - + } if (this.scratchDir == null) { Constants.message("jsp.error.no.scratch.dir", Logger.FATAL); return; 1.25 +68 -54 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.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- JspCompilationContext.java 28 Oct 2002 18:16:19 -0000 1.24 +++ JspCompilationContext.java 28 Nov 2002 04:18:07 -0000 1.25 @@ -91,7 +91,7 @@ private Hashtable tagFileJars; private boolean isPackagedTagFile; - private String servletClassName; + private String className; private String jspUri; private boolean isErrPage; private String servletPackageName; @@ -301,40 +301,45 @@ */ public String getServletClassName() { - if (isTagFile) { - return tagInfo.getTagName(); - } - - if (servletClassName != null) { - return servletClassName; + if (className != null) { + return className; } - int iSep = jspUri.lastIndexOf('/') + 1; - int iEnd = jspUri.length(); - StringBuffer modifiedClassName = - new StringBuffer(jspUri.length() - iSep); - if (!Character.isJavaIdentifierStart(jspUri.charAt(iSep)) || - jspUri.charAt(iSep) == '_' ) { - // If the first char is not a start of Java identifier or is _ - // prepend a '_'. - modifiedClassName.append('_'); + if (isTagFile) { + className = tagInfo.getTagClassName(); + int lastIndex = className.lastIndexOf('.'); + if (lastIndex != -1) { + className = className.substring(lastIndex + 1); + } + } else { + int iSep = jspUri.lastIndexOf('/') + 1; + int iEnd = jspUri.length(); + StringBuffer modifiedClassName = + new StringBuffer(jspUri.length() - iSep); + if (!Character.isJavaIdentifierStart(jspUri.charAt(iSep)) || + jspUri.charAt(iSep) == '_' ) { + // If the first char is not a start of Java identifier or is _ + // prepend a '_'. + modifiedClassName.append('_'); + } + for (int i = iSep; i < iEnd; i++) { + char ch = jspUri.charAt(i); + if (Character.isJavaIdentifierPart(ch)) { + modifiedClassName.append(ch); + } else if (ch == '.') { + modifiedClassName.append('_'); + } else { + modifiedClassName.append(mangleChar(ch)); + } + } + className = modifiedClassName.toString(); } - for (int i = iSep; i < iEnd; i++) { - char ch = jspUri.charAt(i); - if (Character.isJavaIdentifierPart(ch)) { - modifiedClassName.append(ch); - } else if (ch == '.') { - modifiedClassName.append('_'); - } else { - modifiedClassName.append(mangleChar(ch)); - } - } - servletClassName = modifiedClassName.toString(); - return servletClassName; + + return className; } - public void setServletClassName(String servletClassName) { - this.servletClassName = servletClassName; + public void setServletClassName(String className) { + this.className = className; } /** @@ -441,8 +446,9 @@ } if (isTagFile) { - jspPath = "tagfiles/org/apache/jsp/tagfile/" - + tagInfo.getTagName() + ".java"; + jspPath = "tags/" + + tagInfo.getTagClassName().replace('.', File.separatorChar) + + ".java"; } else { String dirName = getJspFile(); int pos = dirName.lastIndexOf('/'); @@ -583,14 +589,14 @@ rctxt.getPermissionCollection(), rctxt.getCodeSource()); - String className; + String name; if (isTagFile()) { - className = tagInfo.getTagClassName(); + name = tagInfo.getTagClassName(); } else { - className = getServletPackageName() + "." + + name = getServletPackageName() + "." + getServletClassName(); } - servletClass = jspLoader.loadClass(className); + servletClass = jspLoader.loadClass(name); } catch (FileNotFoundException ex) { jspCompiler.removeGeneratedFiles(); throw ex; @@ -609,26 +615,34 @@ } public void createOutdir(String dirPath) { - File outDirF = null; + try { - URL outURL = options.getScratchDir().toURL(); - String outUri = outURL.toString(); - if (outUri.endsWith("/")) { - outUri = outUri - + dirPath.substring(1, dirPath.lastIndexOf("/") + 1); + // Append servlet or tag handler path to scratch dir + URL outUrl = options.getScratchDir().toURL(); + String outUrlString = outUrl.toString(); + if (outUrlString.endsWith("/")) { + outUrlString += dirPath.substring(1, + dirPath.lastIndexOf("/")+1); } else { - outUri = outUri - + dirPath.substring(0, dirPath.lastIndexOf("/") + 1); + outUrlString += dirPath.substring(0, + dirPath.lastIndexOf("/")+1); } - outURL = new URL(outUri); - outDirF = new File(outURL.getFile()); - if (!outDirF.exists()) { - outDirF.mkdirs(); + outUrl = new URL(outUrlString); + File outDirFile = new File(outUrl.getFile()); + if (!outDirFile.exists()) { + outDirFile.mkdirs(); } - this.outputDir = outDirF.toString() + File.separator; + this.outputDir = outDirFile.toString() + File.separator; - outUrls[0] = new URL(outDirF.toURL().toString() + File.separator); - outUrls[1] = new URL("file:" + options.getScratchDir() + File.separator + "tagfiles" + File.separator); + // Populate the URL array with the URLs from which to load the + // generated servlet and tag handler classes. The URL array is + // passed to our org.apache.jasper.servlet.JasperLoader, which + // extends URLClassLoader + outUrls[0] = new URL(outDirFile.toURL().toString() + + File.separator); + outUrls[1] = new URL("file:" + options.getScratchDir() + + File.separator + "tags" + + File.separator); } catch (Exception e) { throw new IllegalStateException("No output directory: " + e.getMessage()); 1.38 +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.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- Compiler.java 21 Oct 2002 20:13:32 -0000 1.37 +++ Compiler.java 28 Nov 2002 04:18:08 -0000 1.38 @@ -373,7 +373,7 @@ javac.execute(); } } catch (BuildException e) { - log.error( "Javac execption ", e); + log.error( "Javac exception ", e); success = false; } 1.133 +9 -8 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java Index: Generator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v retrieving revision 1.132 retrieving revision 1.133 diff -u -r1.132 -r1.133 --- Generator.java 27 Nov 2002 02:31:29 -0000 1.132 +++ Generator.java 28 Nov 2002 04:18:08 -0000 1.133 @@ -2830,10 +2830,11 @@ // Generate package declaration String className = tagInfo.getTagClassName(); - if (className.indexOf('.') != -1) { - String pkgName - = className.substring(0, className.lastIndexOf(".")); - genPreamblePackage( pkgName ); + int lastIndex = className.lastIndexOf('.'); + if (lastIndex != -1) { + String pkgName = className.substring(0, lastIndex); + genPreamblePackage(pkgName); + className = className.substring(lastIndex + 1); } // Generate imports @@ -2841,7 +2842,7 @@ // Generate class declaration out.printin("public final class "); - out.println(tagInfo.getTagName()); + out.println(className); out.printil(" extends javax.servlet.jsp.tagext.SimpleTagSupport"); /* Supress until we also implement resolveFunction() out.printil(" implements "javax.servlet.jsp.el.FunctionMapper, "); 1.15 +5 -6 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- ImplicitTagLibraryInfo.java 30 Oct 2002 18:06:09 -0000 1.14 +++ ImplicitTagLibraryInfo.java 28 Nov 2002 04:18:08 -0000 1.15 @@ -110,9 +110,8 @@ // Determine the value of the <short-name> subelement of the // "imaginary" <taglib> element - if (tagdir.equals(WEB_INF_TAGS) || - tagdir.equals( WEB_INF_TAGS + "/" ) ) - { + if (tagdir.equals(WEB_INF_TAGS) + || tagdir.equals( WEB_INF_TAGS + "/")) { shortname = TAGS_SHORTNAME; } else { shortname = tagdir.substring(WEB_INF_TAGS.length()); 1.7 +5 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspRuntimeContext.java Index: JspRuntimeContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspRuntimeContext.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JspRuntimeContext.java 7 Nov 2002 21:14:53 -0000 1.6 +++ JspRuntimeContext.java 28 Nov 2002 04:18:08 -0000 1.7 @@ -366,7 +366,7 @@ } } - cpath.append(options.getScratchDir() + "/tagfiles" + sep); + cpath.append(options.getScratchDir() + "/tags" + sep); String cp = (String) context.getAttribute(Constants.SERVLET_CLASSPATH); if (cp == null || cp.equals("")) { 1.24 +44 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java Index: JspUtil.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- JspUtil.java 27 Nov 2002 02:48:10 -0000 1.23 +++ JspUtil.java 28 Nov 2002 04:18:08 -0000 1.24 @@ -99,6 +99,9 @@ */ public class JspUtil { + private static final String WEB_INF_TAGS = "/WEB-INF/tags/"; + private static final String META_INF_TAGS = "/META-INF/tags/"; + // Delimiters for request-time expressions (JSP and XML syntax) private static final String OPEN_EXPR = "<%="; private static final String CLOSE_EXPR = "%>"; @@ -750,6 +753,44 @@ return in; } + /** + * Gets the fully-qualified class name of the tag handler corresponding to + * the given tag file path. + */ + public static String getTagHandlerClassName(String path, + ErrorDispatcher err) + throws JasperException { + + String className = null; + int begin = 0; + int index; + + // Remove ".tag" suffix + index = path.lastIndexOf(".tag"); + if (index != -1) { + path = path.substring(0, index); + } else { + err.jspError("XXX", path); + } + + index = path.indexOf(WEB_INF_TAGS); + if (index != -1) { + className = "org.apache.jsp.tag.web."; + begin = index + WEB_INF_TAGS.length(); + } else { + index = path.indexOf(META_INF_TAGS); + if (index != -1) { + className = "org.apache.jsp.tag.meta."; + begin = index + META_INF_TAGS.length(); + } else { + err.jspError("jsp.error.tagfile.wrong.path", path); + } + } + + className += path.substring(begin).replace(File.separatorChar, '.'); + + return className; + } static InputStreamReader getReader(String fname, String encoding, JarFile jarFile, 1.42 +4 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java Index: Node.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- Node.java 26 Nov 2002 01:25:29 -0000 1.41 +++ Node.java 28 Nov 2002 04:18:08 -0000 1.42 @@ -141,7 +141,7 @@ } /** - * Get the attribute that is non requrest time expression, either + * Get the attribute that is non request time expression, either * from the attribute of the node, or from a jsp:attrbute */ public String getTextAttribute(String name) { 1.36 +20 -17 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.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- TagFileProcessor.java 30 Oct 2002 20:53:11 -0000 1.35 +++ TagFileProcessor.java 28 Nov 2002 04:18:08 -0000 1.36 @@ -123,7 +123,7 @@ private TagLibraryInfo tagLibInfo; private String name = null; - private String tagclass = null; + private String path = null; private TagExtraInfo tei = null; private String bodycontent = null; private String description = null; @@ -137,10 +137,12 @@ public TagFileDirectiveVisitor(Compiler compiler, TagLibraryInfo tagLibInfo, - String name) { + String name, + String path) { err = compiler.getErrorDispatcher(); this.tagLibInfo = tagLibInfo; this.name = name; + this.path = path; attributeVector = new Vector(); variableVector = new Vector(); } @@ -251,7 +253,7 @@ return variableVector; } - public TagInfo getTagInfo() { + public TagInfo getTagInfo() throws JasperException { if (name == null) { // XXX Get it from tag file name @@ -261,7 +263,7 @@ bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS; } - tagclass = Constants.TAG_FILE_PACKAGE_NAME + "." + name; + String tagClassName = JspUtil.getTagHandlerClassName(path, err); TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()]; @@ -272,7 +274,7 @@ attributeVector.copyInto(tagAttributeInfo); return new TagInfo(name, - tagclass, + tagClassName, bodycontent, description, tagLibInfo, @@ -299,7 +301,7 @@ */ public static TagInfo parseTagFile(ParserController pc, String name, - String tagfile, + String path, TagLibraryInfo tagLibInfo) throws JasperException { @@ -307,15 +309,16 @@ Node.Nodes page = null; try { - page = pc.parseTagFile(tagfile); + page = pc.parseTagFile(path); } catch (FileNotFoundException e) { - err.jspError("jsp.error.file.not.found", tagfile); + err.jspError("jsp.error.file.not.found", path); } catch (IOException e) { - err.jspError("jsp.error.file.not.found", tagfile); + err.jspError("jsp.error.file.not.found", path); } TagFileDirectiveVisitor tagFileVisitor - = new TagFileDirectiveVisitor(pc.getCompiler(), tagLibInfo, name); + = new TagFileDirectiveVisitor(pc.getCompiler(), tagLibInfo, name, + path); page.visit(tagFileVisitor); /* @@ -330,7 +333,7 @@ TagVariableInfo varInfo = (TagVariableInfo) varsIter.next(); if (attrInfo.getName().equals(varInfo.getNameGiven())) { err.jspError("jsp.error.tagfile.var_name_given_equals_attr_name", - tagfile, attrInfo.getName()); + path, attrInfo.getName()); } } } @@ -362,7 +365,7 @@ rctxt.addWrapper(tagFilePath,wrapper); } - Class tagClass; + Class tagClazz; int tripCount = wrapper.incTripCount(); try { if (tripCount > 0) { @@ -378,11 +381,11 @@ tagInfo, ctxt.getRuntimeContext(), ctxt.getTagFileJars()); - tagClass = tempWrapper.loadTagFilePrototype(); + tagClazz = tempWrapper.loadTagFilePrototype(); tempVector.add( tempWrapper.getJspEngineContext().getCompiler()); } else { - tagClass = wrapper.loadTagFile(); + tagClazz = wrapper.loadTagFile(); } } finally { wrapper.decTripCount(); @@ -399,7 +402,7 @@ } } - return tagClass; + return tagClazz; } } 1.27 +11 -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.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- TagLibraryInfoImpl.java 27 Nov 2002 16:00:14 -0000 1.26 +++ TagLibraryInfoImpl.java 28 Nov 2002 04:18:08 -0000 1.27 @@ -196,8 +196,7 @@ pageInfo.addDependant(location[0]); } } else { - // Location points to a jar file - // tag library in jar file + // Tag library is packaged in JAR file JarFile jarFile = null; ZipEntry jarEntry = null; InputStream stream = null; @@ -439,12 +438,18 @@ path = path.replace('\\', '/'); if (!path.startsWith("/")) { - // relative to uri of TLD file + // Tag file path is relative to uri of TLD file path = uri.substring(0, uri.lastIndexOf("/") + 1) + path; + try { + path = new File(path).getCanonicalPath(); + } catch (IOException ioe) { + throw new JasperException(ioe); + } } else if (path.startsWith("/META-INF/tags")) { // Tag file packaged in JAR ctxt.getTagFileJars().put(path, jarFile); } + TagInfo tagInfo = TagFileProcessor.parseTagFile(parserController, name, path, this); 1.7 +2 -2 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JasperLoader.java Index: JasperLoader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JasperLoader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JasperLoader.java 7 Nov 2002 21:13:05 -0000 1.6 +++ JasperLoader.java 28 Nov 2002 04:18:08 -0000 1.7 @@ -92,10 +92,10 @@ private SecurityManager securityManager; private PrivilegedLoadClass privLoadClass; - public JasperLoader(URL [] urls, String className, ClassLoader parent, + public JasperLoader(URL[] urls, String className, ClassLoader parent, PermissionCollection permissionCollection, CodeSource codeSource) { - super(urls,parent); + super(urls, parent); this.permissionCollection = permissionCollection; this.codeSource = codeSource; this.className = className; 1.21 +7 -15 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.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- JspServletWrapper.java 27 Nov 2002 16:00:41 -0000 1.20 +++ JspServletWrapper.java 28 Nov 2002 04:18:08 -0000 1.21 @@ -60,6 +60,7 @@ package org.apache.jasper.servlet; import java.io.IOException; +import java.io.File; import java.io.FileNotFoundException; import java.util.Hashtable; import java.net.URL; @@ -83,6 +84,7 @@ import org.apache.jasper.Options; import org.apache.jasper.JspCompilationContext; import org.apache.jasper.compiler.JspRuntimeContext; +import org.apache.jasper.compiler.JspUtil; import org.apache.jasper.runtime.JspSourceDependent; import org.apache.jasper.logging.Logger; @@ -152,18 +154,8 @@ ctxt = new JspCompilationContext(jspUri, tagInfo, options, servletContext, this, rctxt, tagFileJars); - - // Store tag handler .java and .class files in standard location - // (/tagfiles/org/apache/jsp/), regardless of the original tag file - // path - String standard = null; - if (tagFilePath.indexOf('/') != -1) { - standard = "/tagfiles/org/apache/jsp/tagfile/" - + tagFilePath.substring(tagFilePath.lastIndexOf("/") + 1); - } else { - standard = "/tagfiles/org/apache/jsp/tagfile/" + tagFilePath; - } - ctxt.createOutdir(standard); + ctxt.createOutdir("/tags/" + + tagInfo.getTagClassName().replace('.', File.separatorChar)); } public JspCompilationContext getJspEngineContext() {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>