Author: remm Date: Fri Sep 8 07:14:35 2006 New Revision: 441504 URL: http://svn.apache.org/viewvc?view=rev&rev=441504 Log: - 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 ?
Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/AntCompiler.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/BeanRepository.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Compiler.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ELNode.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ErrorDispatcher.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java Fri Sep 8 07:14:35 2006 @@ -21,7 +21,8 @@ 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 @@ protected org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(JspCompilationContext.class); - private Hashtable tagFileJarUrls; - private boolean isPackagedTagFile; + protected Map<String, URL> tagFileJarUrls; + protected 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 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 @@ } this.rctxt = rctxt; - this.tagFileJarUrls = new Hashtable(); + this.tagFileJarUrls = new HashMap<String, URL>(); this.basePackageName = Constants.JSP_PACKAGE_NAME; } @@ -230,7 +231,7 @@ 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 @@ * 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 @@ } } - private String getDerivedPackageName() { + protected String getDerivedPackageName() { if (derivedPackageName == null) { int iSep = jspUri.lastIndexOf('/'); derivedPackageName = (iSep > 0) ? @@ -597,18 +602,18 @@ 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 @@ } } - 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(); Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/AntCompiler.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/AntCompiler.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/AntCompiler.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/AntCompiler.java Fri Sep 8 07:14:35 2006 @@ -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 @@ */ 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 @@ // 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 @@ return project; } - class JasperAntLogger extends DefaultLogger { + public class JasperAntLogger extends DefaultLogger { protected StringBuffer reportBuf = new StringBuffer(); @@ -221,8 +224,8 @@ } } 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 @@ 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 @@ } if( log.isDebugEnabled() ) { - long t2=System.currentTimeMillis(); + long t2 = System.currentTimeMillis(); log.debug("Compiled " + ctxt.getServletJavaFileName() + " " + (t2-t1) + "ms"); } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/BeanRepository.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/BeanRepository.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/BeanRepository.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/BeanRepository.java Fri Sep 8 07:14:35 2006 @@ -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 @@ * 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<String, String> 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<String, String>(); } - + 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); } } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Compiler.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Compiler.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Compiler.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Compiler.java Fri Sep 8 07:14:35 2006 @@ -43,13 +43,9 @@ * @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 Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ELNode.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ELNode.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ELNode.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ELNode.java Fri Sep 8 07:14:35 2006 @@ -172,10 +172,10 @@ EL expression, for communication to Generator. */ String mapName = null; // The function map associated this EL - private List list; + private List<ELNode> list; public Nodes() { - list = new ArrayList(); + list = new ArrayList<ELNode>(); } public void add(ELNode en) { @@ -187,10 +187,10 @@ * @param v The visitor used */ public void visit(Visitor v) throws JasperException { - Iterator iter = list.iterator(); + Iterator<ELNode> 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 @@ * @return true if the expression contains a ${...} */ public boolean containsEL() { - Iterator iter = list.iterator(); + Iterator<ELNode> 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; } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ErrorDispatcher.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ErrorDispatcher.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ErrorDispatcher.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ErrorDispatcher.java Fri Sep 8 07:14:35 2006 @@ -18,8 +18,8 @@ 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 @@ String errMsg, String fname, Node.Nodes page) throws IOException, JasperException { - Vector errVec = new Vector(); + ArrayList<JavacErrorDetail> errors = new ArrayList<JavacErrorDetail>(); StringBuffer errMsgBuf = null; int lineNum = -1; JavacErrorDetail javacError = null; @@ -453,14 +453,14 @@ 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 @@ // 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; Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/Generator.java Fri Sep 8 07:14:35 2006 @@ -70,8 +70,10 @@ 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; Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java Fri Sep 8 07:14:35 2006 @@ -131,7 +131,7 @@ isTagFile = true; directiveOnly = true; Node.Nodes page = doParse(inFileName, null, - (URL) ctxt.getTagFileJarUrls().get(inFileName)); + ctxt.getTagFileJarUrl(inFileName)); directiveOnly = directiveOnlySave; isTagFile = isTagFileSave; return page; Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java Fri Sep 8 07:14:35 2006 @@ -517,8 +517,7 @@ 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 @@ 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 @@ 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); } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java Fri Sep 8 07:14:35 2006 @@ -65,8 +65,6 @@ // Logger private Log log = LogFactory.getLog(TagLibraryInfoImpl.class); - private Hashtable jarEntries; - private JspCompilationContext ctxt; private PageInfo pi; @@ -478,7 +476,7 @@ 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); } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties?view=diff&rev=441504&r1=441503&r2=441504 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/resources/LocalStrings.properties Fri Sep 8 07:14:35 2006 @@ -131,6 +131,9 @@ 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=* --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]