costin 01/06/12 08:39:27
Modified: jasper34/liaison/org/apache/jasper34/servlet
JasperLoader.java JspEngineContext.java
JspServlet.java
Log:
Implement the changes in core and toolbox.
Few changes in JasperLoader to make it independent of jasper ( try to make
it an independent tool, might be usefull )
Prepare to remove the deps on JasperLoader from JspServlet and start using
URLClassLoader ( or SimpleClassLoader ) via jdkcompat.
Revision Changes Path
1.2 +42 -15
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/servlet/JasperLoader.java
Index: JasperLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/servlet/JasperLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JasperLoader.java 2001/05/28 02:17:58 1.1
+++ JasperLoader.java 2001/06/12 15:39:24 1.2
@@ -95,9 +95,10 @@
* @author Anil K. Vijendran
* @author Harish Prabandham
*/
-public class JasperLoader extends JspLoader {
-// ClassLoader parent;
-// Options options;
+public class JasperLoader extends ClassLoader {
+ ClassLoader parent;
+ String scratchDir;
+ //Options options;
Object pd;
/*
@@ -107,19 +108,45 @@
super();
}
-// public void setParentClassLoader( ClassLoader cl)
-// {
-// this.parent = cl;
-// }
-
-// public void setOptions( Options options) {
-// this.options = options;
-// }
+ public void setParentClassLoader( ClassLoader cl)
+ {
+ this.parent = cl;
+ }
+
+ // public void setOptions( Options options) {
+ // this.options = options;
+ // }
+ public void setScratchDir( String s ) {
+ scratchDir=s;
+ }
public void setProtectionDomain( Object pd ) {
this.pd=pd;
}
+
+ protected Vector jars = new Vector();
+ public void addJar(String jarFileName) throws IOException {
+ if (!jars.contains(jarFileName)) {
+ ContainerLiaison.message("jsp.message.adding_jar",
+ new Object[] { jarFileName },
+ Log.INFORMATION);
+
+ jars.addElement(jarFileName);
+ }
+ }
+
+ public String getClassPath() {
+ StringBuffer cpath = new StringBuffer();
+ String sep = System.getProperty("path.separator");
+
+ for(int i = 0; i < jars.size(); i++) {
+ cpath.append((String)jars.elementAt(i)+sep);
+ }
+
+ return cpath.toString();
+ }
+
protected synchronized Class loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
@@ -190,7 +217,7 @@
return defClass(className, classBytes);
} else {
String fileName = null;
- String outputDir = options.getScratchDir().toString();
+ String outputDir = scratchDir;
if (className.indexOf('$', end) != -1) {
// this means we're loading an inner class
@@ -210,14 +237,14 @@
*/
classBytes = loadClassDataFromFile(fileName);
if( classBytes == null ) {
- throw new ClassNotFoundException(Constants.getString(
+ throw new ClassNotFoundException(ContainerLiaison.getString(
"jsp.error.unable.loadclass",
new Object[] {className}));
}
return defClass(className, classBytes);
}
} catch (Exception ex) {
- throw new ClassNotFoundException(Constants.getString(
+ throw new ClassNotFoundException(ContainerLiaison.getString(
"jsp.error.unable.loadclass",
new Object[] {className}));
}
@@ -318,7 +345,7 @@
}
public String toString() {
- Object obj = (options==null)?null: options.getScratchDir();
+ Object obj = scratchDir;
String s = (obj==null)?"null":obj.toString();
return "JspLoader@"+hashCode()+"( " + s + " ) / " + parent;
}
1.5 +15 -32
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/servlet/JspEngineContext.java
Index: JspEngineContext.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/servlet/JspEngineContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JspEngineContext.java 2001/06/07 06:56:14 1.4
+++ JspEngineContext.java 2001/06/12 15:39:25 1.5
@@ -78,17 +78,15 @@
* engine. This is a per-request/per-context data structure. Some of
* the instance variables are set at different points.
*
- * JspLoader creates this object and passes this off to the "compiler"
- * subsystem, which then initializes the rest of the variables.
- *
* @author Anil K. Vijendran
* @author Harish Prabandham
*/
-public class JspEngineContext implements JspCompilationContext {
+public class JspEngineContext extends ContainerLiaison
+{
JspReader reader;
ServletWriter writer;
ServletContext context;
- JasperLoader loader;
+ ClassLoader loader;
String classpath; // for compiling JSPs.
boolean isErrPage;
String jspFile;
@@ -101,7 +99,7 @@
HttpServletResponse res;
- public JspEngineContext(JasperLoader loader, String classpath,
+ public JspEngineContext(ClassLoader loader, String classpath,
ServletContext context, String jspFile,
boolean isErrPage, Options options,
HttpServletRequest req, HttpServletResponse res)
@@ -135,7 +133,7 @@
* The classpath that is passed off to the Java compiler.
*/
public String getClassPath() {
- return loader.getClassPath() + classpath;
+ return ((JasperLoader)loader).getClassPath() + classpath;
}
/**
@@ -167,9 +165,9 @@
return loader;
}
- public void addJar( String jar ) throws IOException {
- loader.addJar( jar );
- }
+// public void addJar( String jar ) throws IOException {
+// loader.addJar( jar );
+// }
/**
* Are we processing something that has been declared as an
@@ -284,33 +282,18 @@
* jspCompilerPlugin is not specified or is not available, the
* SunJavaCompiler is used.
*/
- public Compiler createCompiler() throws JasperException {
+ public JavaCompiler getJavaCompiler() throws JasperException {
String compilerPath = options.getJspCompilerPath();
- Class jspCompilerPlugin = options.getJspCompilerPlugin();
- JavaCompiler javac;
-
- if (jspCompilerPlugin != null) {
- try {
- javac = (JavaCompiler) jspCompilerPlugin.newInstance();
- } catch (Exception ex) {
- Constants.message("jsp.warning.compiler.class.cantcreate",
- new Object[] { jspCompilerPlugin, ex },
- Log.FATAL);
- javac = new SunJavaCompiler();
- }
- } else {
- javac = new SunJavaCompiler();
- }
+ String jspCompilerPlugin = options.getJspCompilerPlugin();
+ JavaCompiler javac=JavaCompiler.createJavaCompiler( this,
+ jspCompilerPlugin);
if (compilerPath != null)
javac.setCompilerPath(compilerPath);
- Compiler jspCompiler = new JspCompiler(this);
- jspCompiler.setJavaCompiler(javac);
-
- return jspCompiler;
+ return javac;
}
-
+
/**
* Get the full value of a URI relative to this compilations context
*/
@@ -372,6 +355,6 @@
TagLibReader reader=new TagLibReader( this, libs );
reader.readTagLib( tl, prefix, uri );
}
-
+
}
1.4 +91 -62
jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/servlet/JspServlet.java
Index: JspServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper34/liaison/org/apache/jasper34/servlet/JspServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JspServlet.java 2001/06/09 21:26:20 1.3
+++ JspServlet.java 2001/06/12 15:39:25 1.4
@@ -76,6 +76,8 @@
import org.apache.jasper34.runtime.*;
import org.apache.jasper34.core.*;
import org.apache.jasper34.generator.*;
+import org.apache.jasper34.jsptree.*;
+import org.apache.jasper34.liaison.*;
import org.apache.jasper34.core.Compiler;
import org.apache.tomcat.util.log.Log;
@@ -89,7 +91,7 @@
public class JspServlet extends HttpServlet {
Log loghelper = Log.getLog("JASPER_LOG", "JspServlet");
-
+
class JspServletWrapper {
Servlet theServlet;
String jspUri;
@@ -138,15 +140,15 @@
} else
accordingto = "according to the Servlet Engine";
- Constants.message("jsp.message.cp_is",
+ ContainerLiaison.message("jsp.message.cp_is",
new Object[] {
accordingto,
cp == null ? "" : cp
},
Log.INFORMATION);
- if (loadJSP(jspUri, cp, isErrorPage, req, res)
- || theServlet == null) {
+ if ( loadJSP(jspUri, cp, isErrorPage, req, res)
+ || theServlet == null) {
load();
}
}
@@ -177,14 +179,14 @@
try {
if (insecure_TMI) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
- Constants.getString
+ ContainerLiaison.getString
("jsp.error.file.not.found.TMI",
new Object[] {
ex.getMessage()
}));
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND,
- Constants.getString
+ ContainerLiaison.getString
("jsp.error.file.not.found",
new Object[] {
// Too Much Information --
ex.getMessage()
@@ -192,17 +194,17 @@
}
} catch (IllegalStateException ise) {
// logs are presumed to be secure, thus the TMI info can be
logged
- Constants.jasperLog.log(Constants.getString
- ("jsp.error.file.not.found.TMI",
+ ContainerLiaison.message(ContainerLiaison.getString
+ ("jsp.error.file.not.found.TMI",
new Object[] {
ex.getMessage()
- }), ex,
+ }),
Log.ERROR);
// rethrow FileNotFoundException so someone higher up can handle
if (insecure_TMI)
throw ex;
else
- throw new FileNotFoundException(Constants.getString
+ throw new FileNotFoundException(ContainerLiaison.getString
("jsp.error.file.not.found",
new Object[] {
// Too Much Information --
ex.getMessage()
@@ -223,10 +225,10 @@
protected Hashtable jsps = new Hashtable();
// protected Hashtable loadedJSPs = new Hashtable();
protected ServletConfig config;
- protected JasperLoader loader;
+ protected ClassLoader loader;
protected Options options;
protected ClassLoader parentClassLoader;
- protected ServletEngine engine;
+ // protected ServletEngine engine;
protected String serverInfo;
/** Set to true to provide Too Much Information on errors */
@@ -250,7 +252,7 @@
this.context = config.getServletContext();
this.serverInfo = context.getServerInfo();
- options = new EmbededServletOptions(config, context);
+ options = new OptionsServletConfig(config, context);
parentClassLoader = (ClassLoader)
context.getAttribute(Constants.SERVLET_CLASS_LOADER);
if (parentClassLoader == null)
@@ -258,13 +260,13 @@
// getClass().getClassLoader() returns null in JDK 1.1.6/1.1.8
if (parentClassLoader != null) {
- Constants.message("jsp.message.parent_class_loader_is",
+ ContainerLiaison.message("jsp.message.parent_class_loader_is",
new Object[] {
parentClassLoader.toString()
}, Log.DEBUG);
}
else {
- Constants.message("jsp.message.parent_class_loader_is",
+ ContainerLiaison.message("jsp.message.parent_class_loader_is",
new Object[] {
"<none>"
}, Log.DEBUG);
@@ -282,18 +284,18 @@
if( loader==null )
loader = new JasperLoader();
- loader.setParentClassLoader(parentClassLoader);
- loader.setOptions(options);
+ ((JasperLoader)loader).setParentClassLoader(parentClassLoader);
+ ((JasperLoader)loader).setScratchDir(options.getScratchDir().toString());
Object pd=context.getAttribute("org.apache.tomcat.protection_domain");
- loader.setProtectionDomain( pd );
+ ((JasperLoader)loader).setProtectionDomain( pd );
}
if (firstTime) {
firstTime = false;
- Constants.message("jsp.message.scratch.dir.is",
+ ContainerLiaison.message("jsp.message.scratch.dir.is",
new Object[] {
options.getScratchDir().toString()
}, Log.INFORMATION );
- Constants.message("jsp.message.dont.modify.servlets", Log.INFORMATION);
+ ContainerLiaison.message("jsp.message.dont.modify.servlets",
Log.INFORMATION);
JspFactory.setDefaultFactory(new JspFactoryImpl());
}
}
@@ -365,25 +367,25 @@
boolean precompile = preCompile(request);
- Log jasperLog = Constants.jasperLog;
+// Log jasperLog = Constants.jasperLog;
- if (jasperLog != null &&
- jasperLog.getLevel() >= Log.INFORMATION)
- {
- jasperLog.log("JspEngine --> "+jspUri);
- jasperLog.log("\t ServletPath: "+request.getServletPath());
- jasperLog.log("\t PathInfo: "+request.getPathInfo());
- jasperLog.log("\t RealPath: "
-
+getServletConfig().getServletContext().getRealPath(jspUri));
- jasperLog.log("\t RequestURI: "+request.getRequestURI());
- jasperLog.log("\t QueryString: "+request.getQueryString());
- jasperLog.log("\t Request Params: ");
- Enumeration e = request.getParameterNames();
- while (e.hasMoreElements()) {
- String name = (String) e.nextElement();
- jasperLog.log("\t\t "+name+" = "+request.getParameter(name));
- }
- }
+// if (jasperLog != null &&
+// jasperLog.getLevel() >= Log.INFORMATION)
+// {
+// jasperLog.log("JspEngine --> "+jspUri);
+// jasperLog.log("\t ServletPath: "+request.getServletPath());
+// jasperLog.log("\t PathInfo: "+request.getPathInfo());
+// jasperLog.log("\t RealPath: "
+//
+getServletConfig().getServletContext().getRealPath(jspUri));
+// jasperLog.log("\t RequestURI: "+request.getRequestURI());
+// jasperLog.log("\t QueryString: "+request.getQueryString());
+// jasperLog.log("\t Request Params: ");
+// Enumeration e = request.getParameterNames();
+// while (e.hasMoreElements()) {
+// String name = (String) e.nextElement();
+// jasperLog.log("\t\t "+name+" = "+request.getParameter(name));
+// }
+// }
serviceJspFile(request, response, jspUri, null, precompile);
} catch (RuntimeException e) {
throw e;
@@ -404,15 +406,14 @@
}
public void destroy() {
- if (Constants.jasperLog != null)
- Constants.jasperLog.log("JspServlet.destroy()", Log.INFORMATION);
+ // if (Constants.jasperLog != null)
+ ContainerLiaison.message("JspServlet.destroy()", Log.INFORMATION);
Enumeration servlets = jsps.elements();
while (servlets.hasMoreElements())
((JspServletWrapper) servlets.nextElement()).destroy();
}
-
/* Check if we need to reload a JSP page.
*
* Side-effect: re-compile the JSP page.
@@ -426,9 +427,11 @@
{
// Loader knows how to set the right priviledges, and call
// doLoadeJsp
- return loader.loadJSP( this,jspUri, classpath, isErrorPage, req, res );
+ return ((JasperLoader)loader).loadJSP( this,jspUri, classpath, isErrorPage,
req, res );
}
+
+
/* Check if we need to reload a JSP page.
*
* Side-effect: re-compile the JSP page.
@@ -446,44 +449,61 @@
}
// Class jspClass = (Class) loadedJSPs.get(jspUri);
boolean firstTime = jsw.servletClass == null;
- JspCompilationContext ctxt = new JspEngineContext(loader, classpath,
+ JspEngineContext ctxt = new JspEngineContext(loader, classpath,
context, jspUri,
isErrorPage, options,
req, res);
+
boolean outDated = false;
+ ContainerLiaison containerL=ctxt;
+
+ Compiler compiler = new Compiler(ctxt);
+ //compiler.setJavaCompiler(ctxt.getJavaCompiler());
- Compiler compiler = ctxt.createCompiler();
+ ManglerOld mangler=new ManglerOld();
+ JspPageInfo pageInfo=new JspPageInfo( ctxt, options,
+ mangler );
+
+ pageInfo.setJspFile( jspUri );
+ pageInfo.setErrorPage( isErrorPage );
+
+ mangler.init(pageInfo.getJspFile(), containerL.getOutputDir());
+ // compiler.setMangler( mangler );
+
try {
- outDated = compiler.isOutDated();
+ outDated = isOutDated( containerL, pageInfo.getJspFile(), mangler);
if ( (jsw.servletClass == null) || outDated ) {
synchronized ( this ) {
if ((jsw.servletClass == null) ||
- (compiler.isOutDated() )) {
- outDated = compiler.compile();
+ ( isOutDated(containerL, pageInfo.getJspFile(),
+ mangler) )) {
+ outDated = compiler.compile(pageInfo,
+ ctxt.getJavaCompiler());
}
}
}
} catch (FileNotFoundException ex) {
- compiler.removeGeneratedFiles();
+ compiler.removeGeneratedFiles(pageInfo);
throw ex;
} catch (JasperException ex) {
throw ex;
} catch (Exception ex) {
- throw new JasperException(Constants.getString("jsp.error.unable.compile"),
+ throw new
JasperException(ContainerLiaison.getString("jsp.error.unable.compile"),
ex);
}
// Reload only if it's outdated
if((jsw.servletClass == null) || outDated) {
try {
- if( null ==ctxt.getServletClassName() ) {
- compiler.computeServletClassName();
- }
- jsw.servletClass = loader.loadClass(ctxt.getFullClassName());
+// if( null ==ctxt.getServletClassName() ) {
+// compiler.computeServletClassName();
+// }
+ jsw.servletClass =
+ loader.loadClass(pageInfo.getFullClassName());
//loadClass(ctxt.getFullClassName(), true);
} catch (ClassNotFoundException cex) {
- throw new
JasperException(Constants.getString("jsp.error.unable.load"),
+ throw new
JasperException(ContainerLiaison.getString("jsp.error.unable.load"),
cex);
}
@@ -493,18 +513,28 @@
return outDated;
}
- /**
+ /**
* Determines whether the current JSP class is older than the JSP file
* from whence it came
*/
- public boolean isOutDated(File jsp, JspCompilationContext ctxt,
- Mangler mangler ) {
+ public boolean isOutDated(ContainerLiaison containerL, String jspS,
+ Mangler mangler)
+ {
+ boolean outDated=false;
+ File jsp=new File( jspS );
File jspReal = null;
- boolean outDated;
-
- jspReal = new File(ctxt.getRealPath(jsp.getPath()));
+
+ String realPath = containerL.getRealPath(jsp.getPath());
+ if (realPath == null)
+ return true;
- File classFile = new File(mangler.getClassFileName());
+ jspReal = new File(realPath);
+
+ if(!jspReal.exists()){
+ return true;
+ }
+
+ File classFile = new File(mangler.getClassFileName());
if (classFile.exists()) {
outDated = classFile.lastModified() < jspReal.lastModified();
} else {
@@ -513,5 +543,4 @@
return outDated;
}
-
}