From 85c4a689e0e2cc6962de10e60212ea61e69bae66 Mon Sep 17 00:00:00 2001 From: remm Date: Fri, 8 Sep 2006 14:14:35 +0000 Subject: [PATCH] - More cleanup (incl small API tweaks, parametrization, etc). - Slash away most of BeanRepository. Most of it wasn't being used or did anything of value (other than doing tons of lookups in Vectors). Weird. Did I miss something ? git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@441504 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/JspCompilationContext.java | 97 +++++++++++---------- java/org/apache/jasper/compiler/AntCompiler.java | 20 +++-- .../org/apache/jasper/compiler/BeanRepository.java | 98 +++++++--------------- java/org/apache/jasper/compiler/Compiler.java | 6 +- java/org/apache/jasper/compiler/ELNode.java | 20 ++--- .../apache/jasper/compiler/ErrorDispatcher.java | 16 ++-- java/org/apache/jasper/compiler/Generator.java | 6 +- .../apache/jasper/compiler/ParserController.java | 2 +- .../apache/jasper/compiler/TagFileProcessor.java | 7 +- .../apache/jasper/compiler/TagLibraryInfoImpl.java | 4 +- .../jasper/resources/LocalStrings.properties | 3 + 11 files changed, 122 insertions(+), 157 deletions(-) diff --git a/java/org/apache/jasper/JspCompilationContext.java b/java/org/apache/jasper/JspCompilationContext.java index c68ef013a..4e4e76ed7 100644 --- a/java/org/apache/jasper/JspCompilationContext.java +++ b/java/org/apache/jasper/JspCompilationContext.java @@ -21,7 +21,8 @@ import java.io.FileNotFoundException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import javax.servlet.ServletContext; @@ -54,41 +55,41 @@ public class JspCompilationContext { protected org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(JspCompilationContext.class); - private Hashtable tagFileJarUrls; - private boolean isPackagedTagFile; - - private String className; - private String jspUri; - private boolean isErrPage; - private String basePackageName; - private String derivedPackageName; - private String servletJavaFileName; - private String javaPath; - private String classFileName; - private String contentType; - private ServletWriter writer; - private Options options; - private JspServletWrapper jsw; - private Compiler jspCompiler; - private String classPath; - - private String baseURI; - private String outputDir; - private ServletContext context; - private URLClassLoader loader; - - private JspRuntimeContext rctxt; - - private int removed = 0; - - private URLClassLoader jspLoader; - private URL baseUrl; - private Class servletClass; - - private boolean isTagFile; - private boolean protoTypeMode; - private TagInfo tagInfo; - private URL tagFileJarUrl; + protected Map tagFileJarUrls; + protected boolean isPackagedTagFile; + + protected String className; + protected String jspUri; + protected boolean isErrPage; + protected String basePackageName; + protected String derivedPackageName; + protected String servletJavaFileName; + protected String javaPath; + protected String classFileName; + protected String contentType; + protected ServletWriter writer; + protected Options options; + protected JspServletWrapper jsw; + protected Compiler jspCompiler; + protected String classPath; + + protected String baseURI; + protected String outputDir; + protected ServletContext context; + protected URLClassLoader loader; + + protected JspRuntimeContext rctxt; + + protected int removed = 0; + + protected URLClassLoader jspLoader; + protected URL baseUrl; + protected Class servletClass; + + protected boolean isTagFile; + protected boolean protoTypeMode; + protected TagInfo tagInfo; + protected URL tagFileJarUrl; // jspURI _must_ be relative to the context public JspCompilationContext(String jspUri, @@ -118,7 +119,7 @@ public class JspCompilationContext { } this.rctxt = rctxt; - this.tagFileJarUrls = new Hashtable(); + this.tagFileJarUrls = new HashMap(); this.basePackageName = Constants.JSP_PACKAGE_NAME; } @@ -230,7 +231,7 @@ public class JspCompilationContext { return jspCompiler; } - private Compiler createCompiler(String className) { + protected Compiler createCompiler(String className) { Compiler compiler = null; try { compiler = (Compiler) Class.forName(className).newInstance(); @@ -304,8 +305,12 @@ public class JspCompilationContext { * The map is populated when parsing the tag-file elements of the TLDs * of any imported taglibs. */ - public Hashtable getTagFileJarUrls() { - return this.tagFileJarUrls; + public URL getTagFileJarUrl(String tagFile) { + return this.tagFileJarUrls.get(tagFile); + } + + public void setTagFileJarUrl(String tagFile, URL tagFileURL) { + this.tagFileJarUrls.put(tagFile, tagFileURL); } /** @@ -415,7 +420,7 @@ public class JspCompilationContext { } } - private String getDerivedPackageName() { + protected String getDerivedPackageName() { if (derivedPackageName == null) { int iSep = jspUri.lastIndexOf('/'); derivedPackageName = (iSep > 0) ? @@ -597,18 +602,18 @@ public class JspCompilationContext { return servletClass; } - // ==================== Private methods ==================== + // ==================== protected methods ==================== static Object outputDirLock = new Object(); - private boolean makeOutputDir() { + protected boolean makeOutputDir() { synchronized(outputDirLock) { File outDirFile = new File(outputDir); return outDirFile.mkdirs(); } } - private void createOutputDir() { + protected void createOutputDir() { String path = null; if (isTagFile()) { String tagName = tagInfo.getTagClassName(); @@ -632,11 +637,11 @@ public class JspCompilationContext { } } - private static final boolean isPathSeparator(char c) { + protected static final boolean isPathSeparator(char c) { return (c == '/' || c == '\\'); } - private static final String canonicalURI(String s) { + protected static final String canonicalURI(String s) { if (s == null) return null; StringBuffer result = new StringBuffer(); final int len = s.length(); diff --git a/java/org/apache/jasper/compiler/AntCompiler.java b/java/org/apache/jasper/compiler/AntCompiler.java index 50136ab61..4d60fcce7 100644 --- a/java/org/apache/jasper/compiler/AntCompiler.java +++ b/java/org/apache/jasper/compiler/AntCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999,2004 The Apache Software Foundation. + * Copyright 1999,2004-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,13 +42,15 @@ import org.apache.tools.ant.types.PatternSet; */ public class AntCompiler extends Compiler { + protected static Object javacLock = new Object(); + static { System.setErr(new SystemLogHandler(System.err)); } // ----------------------------------------------------- Instance Variables - protected Project project=null; + protected Project project = null; protected JasperAntLogger logger; // ------------------------------------------------------------ Constructor @@ -56,7 +58,8 @@ public class AntCompiler extends Compiler { // Lazy eval - if we don't need to compile we probably don't need the project protected Project getProject() { - if( project!=null ) return project; + if (project != null) + return project; // Initializing project project = new Project(); @@ -78,7 +81,7 @@ public class AntCompiler extends Compiler { return project; } - class JasperAntLogger extends DefaultLogger { + public class JasperAntLogger extends DefaultLogger { protected StringBuffer reportBuf = new StringBuffer(); @@ -221,8 +224,8 @@ public class AntCompiler extends Compiler { } } catch (BuildException e) { be = e; - log.error( "Javac exception ", e); - log.error( "Env: " + info.toString()); + log.error(Localizer.getMessage("jsp.error.javac"), e); + log.error(Localizer.getMessage("jsp.error.javac.env") + info.toString()); } errorReport.append(logger.getReport()); @@ -241,8 +244,7 @@ public class AntCompiler extends Compiler { if (be != null) { String errorReportString = errorReport.toString(); - log.error("Error compiling file: " + javaFileName + " " - + errorReportString); + log.error(Localizer.getMessage("jsp.error.compilation", javaFileName, errorReportString)); JavacErrorDetail[] javacErrors = ErrorDispatcher.parseJavacErrors( errorReportString, javaFileName, pageNodes); if (javacErrors != null) { @@ -253,7 +255,7 @@ public class AntCompiler extends Compiler { } if( log.isDebugEnabled() ) { - long t2=System.currentTimeMillis(); + long t2 = System.currentTimeMillis(); log.debug("Compiled " + ctxt.getServletJavaFileName() + " " + (t2-t1) + "ms"); } diff --git a/java/org/apache/jasper/compiler/BeanRepository.java b/java/org/apache/jasper/compiler/BeanRepository.java index f31cadb5d..8fcc21d1d 100644 --- a/java/org/apache/jasper/compiler/BeanRepository.java +++ b/java/org/apache/jasper/compiler/BeanRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 1999,2004 The Apache Software Foundation. + * Copyright 1999,2004-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,7 @@ package org.apache.jasper.compiler; -import java.util.Vector; -import java.util.Hashtable; +import java.util.HashMap; import org.apache.jasper.JasperException; @@ -25,86 +24,47 @@ import org.apache.jasper.JasperException; * Repository of {page, request, session, application}-scoped beans * * @author Mandar Raje + * @author Remy Maucherat */ -class BeanRepository { +public class BeanRepository { - private Vector sessionBeans; - private Vector pageBeans; - private Vector appBeans; - private Vector requestBeans; - private Hashtable beanTypes; - private ClassLoader loader; - private ErrorDispatcher errDispatcher; + protected HashMap beanTypes; + protected ClassLoader loader; + protected ErrorDispatcher errDispatcher; - /* + /** * Constructor. */ public BeanRepository(ClassLoader loader, ErrorDispatcher err) { - this.loader = loader; - this.errDispatcher = err; - - sessionBeans = new Vector(11); - pageBeans = new Vector(11); - appBeans = new Vector(11); - requestBeans = new Vector(11); - beanTypes = new Hashtable(); + this.errDispatcher = err; + beanTypes = new HashMap(); } - + public void addBean(Node.UseBean n, String s, String type, String scope) - throws JasperException { + throws JasperException { + + if (!(scope == null || scope.equals("page") || scope.equals("request") + || scope.equals("session") || scope.equals("application"))) { + errDispatcher.jspError(n, "jsp.error.usebean.badScope"); + } - if (scope == null || scope.equals("page")) { - pageBeans.addElement(s); - } else if (scope.equals("request")) { - requestBeans.addElement(s); - } else if (scope.equals("session")) { - sessionBeans.addElement(s); - } else if (scope.equals("application")) { - appBeans.addElement(s); - } else { - errDispatcher.jspError(n, "jsp.error.usebean.badScope"); - } - - putBeanType(s, type); + beanTypes.put(s, type); } - public Class getBeanType(String bean) throws JasperException { - Class clazz = null; - try { - clazz = loader.loadClass ((String)beanTypes.get(bean)); - } catch (ClassNotFoundException ex) { - throw new JasperException (ex); - } - return clazz; + public Class getBeanType(String bean) + throws JasperException { + Class clazz = null; + try { + clazz = loader.loadClass(beanTypes.get(bean)); + } catch (ClassNotFoundException ex) { + throw new JasperException (ex); + } + return clazz; } - public boolean checkVariable (String bean) { - // XXX Not sure if this is the correct way. - // After pageContext is finalised this will change. - return (checkPageBean(bean) || checkSessionBean(bean) || - checkRequestBean(bean) || checkApplicationBean(bean)); - } - - - private void putBeanType(String bean, String type) { - beanTypes.put (bean, type); - } - - private boolean checkPageBean (String s) { - return pageBeans.contains (s); - } - - private boolean checkRequestBean (String s) { - return requestBeans.contains (s); - } - - private boolean checkSessionBean (String s) { - return sessionBeans.contains (s); - } - - private boolean checkApplicationBean (String s) { - return appBeans.contains (s); + public boolean checkVariable(String bean) { + return beanTypes.containsKey(bean); } } diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 5e697d28e..048916fd4 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -43,14 +43,10 @@ import org.apache.jasper.servlet.JspServletWrapper; * @author Mark Roth */ public abstract class Compiler { + protected org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory .getLog(Compiler.class); - // ----------------------------------------------------------------- Static - - // Some javac are not thread safe; use a lock to serialize compilation, - static Object javacLock = new Object(); - // ----------------------------------------------------- Instance Variables protected JspCompilationContext ctxt; diff --git a/java/org/apache/jasper/compiler/ELNode.java b/java/org/apache/jasper/compiler/ELNode.java index 06f6d6db9..97fdc106e 100644 --- a/java/org/apache/jasper/compiler/ELNode.java +++ b/java/org/apache/jasper/compiler/ELNode.java @@ -172,10 +172,10 @@ abstract class ELNode { EL expression, for communication to Generator. */ String mapName = null; // The function map associated this EL - private List list; + private List list; public Nodes() { - list = new ArrayList(); + list = new ArrayList(); } public void add(ELNode en) { @@ -187,10 +187,10 @@ abstract class ELNode { * @param v The visitor used */ public void visit(Visitor v) throws JasperException { - Iterator iter = list.iterator(); + Iterator iter = list.iterator(); while (iter.hasNext()) { - ELNode n = (ELNode) iter.next(); - n.accept(v); + ELNode n = iter.next(); + n.accept(v); } } @@ -206,12 +206,12 @@ abstract class ELNode { * @return true if the expression contains a ${...} */ public boolean containsEL() { - Iterator iter = list.iterator(); + Iterator iter = list.iterator(); while (iter.hasNext()) { - ELNode n = (ELNode) iter.next(); - if (n instanceof Root) { - return true; - } + ELNode n = iter.next(); + if (n instanceof Root) { + return true; + } } return false; } diff --git a/java/org/apache/jasper/compiler/ErrorDispatcher.java b/java/org/apache/jasper/compiler/ErrorDispatcher.java index 5eecf5284..6a1015b9b 100644 --- a/java/org/apache/jasper/compiler/ErrorDispatcher.java +++ b/java/org/apache/jasper/compiler/ErrorDispatcher.java @@ -18,8 +18,8 @@ package org.apache.jasper.compiler; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; -import java.util.Vector; import java.net.MalformedURLException; +import java.util.ArrayList; import org.apache.jasper.JasperException; import org.xml.sax.SAXException; @@ -428,7 +428,7 @@ public class ErrorDispatcher { String errMsg, String fname, Node.Nodes page) throws IOException, JasperException { - Vector errVec = new Vector(); + ArrayList errors = new ArrayList(); StringBuffer errMsgBuf = null; int lineNum = -1; JavacErrorDetail javacError = null; @@ -453,14 +453,14 @@ public class ErrorDispatcher { if ((beginColon >= 0) && (endColon >= 0)) { if (javacError != null) { // add previous error to error vector - errVec.add(javacError); + errors.add(javacError); } String lineNumStr = line.substring(beginColon + 1, endColon); try { lineNum = Integer.parseInt(lineNumStr); } catch (NumberFormatException e) { - // XXX + lineNum = -1; } errMsgBuf = new StringBuffer(); @@ -477,15 +477,15 @@ public class ErrorDispatcher { // Add last error to error vector if (javacError != null) { - errVec.add(javacError); + errors.add(javacError); } reader.close(); JavacErrorDetail[] errDetails = null; - if (errVec.size() > 0) { - errDetails = new JavacErrorDetail[errVec.size()]; - errVec.copyInto(errDetails); + if (errors.size() > 0) { + errDetails = new JavacErrorDetail[errors.size()]; + errors.toArray(errDetails); } return errDetails; diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index d744d1bd6..c3b719c98 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -70,8 +70,10 @@ class Generator { private static final Class[] OBJECT_CLASS = { Object.class }; - private static final String VAR_EXPRESSIONFACTORY = "_el_expressionfactory"; - private static final String VAR_ANNOTATIONPROCESSOR = "_jsp_annotationprocessor"; + private static final String VAR_EXPRESSIONFACTORY = + System.getProperty("org.apache.jasper.compiler.Generator.VAR_EXPRESSIONFACTORY", "_el_expressionfactory"); + private static final String VAR_ANNOTATIONPROCESSOR = + System.getProperty("org.apache.jasper.compiler.Generator.VAR_ANNOTATIONPROCESSOR", "_jsp_annotationprocessor"); private ServletWriter out; diff --git a/java/org/apache/jasper/compiler/ParserController.java b/java/org/apache/jasper/compiler/ParserController.java index d84e8ccdb..1795225d5 100644 --- a/java/org/apache/jasper/compiler/ParserController.java +++ b/java/org/apache/jasper/compiler/ParserController.java @@ -131,7 +131,7 @@ class ParserController implements TagConstants { isTagFile = true; directiveOnly = true; Node.Nodes page = doParse(inFileName, null, - (URL) ctxt.getTagFileJarUrls().get(inFileName)); + ctxt.getTagFileJarUrl(inFileName)); directiveOnly = directiveOnlySave; isTagFile = isTagFileSave; return page; diff --git a/java/org/apache/jasper/compiler/TagFileProcessor.java b/java/org/apache/jasper/compiler/TagFileProcessor.java index bec57c2d2..8d06640ff 100644 --- a/java/org/apache/jasper/compiler/TagFileProcessor.java +++ b/java/org/apache/jasper/compiler/TagFileProcessor.java @@ -517,8 +517,7 @@ class TagFileProcessor { if (wrapper == null) { wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt .getOptions(), tagFilePath, tagInfo, ctxt - .getRuntimeContext(), (URL) ctxt.getTagFileJarUrls() - .get(tagFilePath)); + .getRuntimeContext(), ctxt.getTagFileJarUrl(tagFilePath)); rctxt.addWrapper(tagFilePath, wrapper); // Use same classloader and classpath for compiling tag files @@ -545,7 +544,7 @@ class TagFileProcessor { JspServletWrapper tempWrapper = new JspServletWrapper(ctxt .getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), - (URL) ctxt.getTagFileJarUrls().get(tagFilePath)); + ctxt.getTagFileJarUrl(tagFilePath)); tagClazz = tempWrapper.loadTagFilePrototype(); tempVector.add(tempWrapper.getJspEngineContext() .getCompiler()); @@ -597,7 +596,7 @@ class TagFileProcessor { if (tagFileInfo != null) { String tagFilePath = tagFileInfo.getPath(); JspCompilationContext ctxt = compiler.getCompilationContext(); - if (ctxt.getTagFileJarUrls().get(tagFilePath) == null) { + if (ctxt.getTagFileJarUrl(tagFilePath) == null) { // Omit tag file dependency info on jar files for now. pageInfo.addDependant(tagFilePath); } diff --git a/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java b/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java index fe6c4b988..3726e3716 100644 --- a/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java +++ b/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java @@ -65,8 +65,6 @@ class TagLibraryInfoImpl extends TagLibraryInfo implements TagConstants { // Logger private Log log = LogFactory.getLog(TagLibraryInfoImpl.class); - private Hashtable jarEntries; - private JspCompilationContext ctxt; private PageInfo pi; @@ -478,7 +476,7 @@ class TagLibraryInfoImpl extends TagLibraryInfo implements TagConstants { if (path.startsWith("/META-INF/tags")) { // Tag file packaged in JAR - ctxt.getTagFileJarUrls().put(path, jarFileUrl); + ctxt.setTagFileJarUrl(path, jarFileUrl); } else if (!path.startsWith("/WEB-INF/tags")) { err.jspError("jsp.error.tagfile.illegalPath", path); } diff --git a/java/org/apache/jasper/resources/LocalStrings.properties b/java/org/apache/jasper/resources/LocalStrings.properties index 42d2d5cb7..3c5ef3856 100644 --- a/java/org/apache/jasper/resources/LocalStrings.properties +++ b/java/org/apache/jasper/resources/LocalStrings.properties @@ -131,6 +131,9 @@ jsp.error.ise_on_clear=Illegal to clear() when buffer size == 0 jsp.error.setproperty.beanNotFound=setProperty: Bean {0} not found jsp.error.getproperty.beanNotFound=getProperty: Bean {0} not found jsp.error.setproperty.ClassNotFound=setProperty: Class {0} not found +jsp.error.javac=Javac exception +jsp.error.javac.env=Environment: +jsp.error.compilation=Error compiling file: {0} {1} # typo ? #jsp.error.setproperty.invalidSayntax=setProperty: can't have non-null value when property=* jsp.error.setproperty.invalidSyntax=setProperty: can't have non-null value when property=* -- 2.11.0