2.17.2: 2011-06-17

net.sf.basedb.clients.web.extensions
Class XJspCompiler

java.lang.Object
  extended by org.apache.jasper.compiler.Compiler
      extended by org.apache.jasper.compiler.JDTCompiler
          extended by net.sf.basedb.clients.web.extensions.XJspCompiler

public class XJspCompiler
extends JDTCompiler

Class that enabled compilation of custom JSP pages that are part of an extension that uses classes from the extension JAR file (eg. a JAR file in the /WEB-INF/extensions directory).

To make this compiler work the following is required:

Note! This feature is still experimental. It has only been tested with some versions of Tomcat 6.0.x. This class depends on internal implementation details of Tomcat, and may or may not work with future or older versions of Tomcat.

Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $

Field Summary
static String EXTENSIONS_URL
          The location where the extension system is looking for extensions.
private  File extensionsJar
           
private  boolean isXJsp
           
private  long lastModified
           
private static Pattern PATH_MATCH
          Path to JSP must match: /extensions/[jar-file-name]/[jsp-path].xjsp group(1) = JAR name, group(2) = JSP path
static String RESOURCES_URL
          The location where the extensions resources are extracted.
 
Fields inherited from class org.apache.jasper.compiler.Compiler
ctxt, errDispatcher, jsw, log, options, pageInfo, pageNodes, tfp
 
Constructor Summary
XJspCompiler()
           
 
Method Summary
protected  void generateClass(String[] smap)
          Called when a JSP page needs recompiling.
protected  URLClassLoader getExtensionClassLoader()
          Get a class loader that can load classes from the current web application as well as the extensions JAR file.
protected  ClassLoader getWebAppClassLoader()
          Get the class loader for the web application this JSP is located in.
 void init(JspCompilationContext ctxt, JspServletWrapper jsw)
          Initialises the compiler.
 boolean isOutDated(boolean checkClass)
          Checks if the extensions JAR file has been modified.
protected  void setContextClassLoader()
          Sets the context class loader if this JSP page is an extension JSP page and if the extensions JAR file has been modified since the last time the class loader was set.
 
Methods inherited from class org.apache.jasper.compiler.Compiler
compile, compile, compile, generateJava, getCompilationContext, getErrorDispatcher, getPageInfo, getPageNodes, isOutDated, removeGeneratedClassFiles, removeGeneratedFiles
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTENSIONS_URL

public static final String EXTENSIONS_URL
The location where the extension system is looking for extensions.

See Also:
Constant Field Values

RESOURCES_URL

public static final String RESOURCES_URL
The location where the extensions resources are extracted.

See Also:
Constant Field Values

PATH_MATCH

private static final Pattern PATH_MATCH
Path to JSP must match: /extensions/[jar-file-name]/[jsp-path].xjsp group(1) = JAR name, group(2) = JSP path


isXJsp

private boolean isXJsp

extensionsJar

private File extensionsJar

lastModified

private long lastModified
Constructor Detail

XJspCompiler

public XJspCompiler()
Method Detail

init

public void init(JspCompilationContext ctxt,
                 JspServletWrapper jsw)
Initialises the compiler. The JSP name is matched against the required pattern and the name of the extensions JAR file is extracted from the request path.

Overrides:
init in class Compiler

generateClass

protected void generateClass(String[] smap)
                      throws FileNotFoundException,
                             JasperException,
                             Exception
Called when a JSP page needs recompiling. We check if the extension JAR file has been modified and update the class loader if it has.

Overrides:
generateClass in class JDTCompiler
Throws:
FileNotFoundException
JasperException
Exception

isOutDated

public boolean isOutDated(boolean checkClass)
Checks if the extensions JAR file has been modified. If not, calls super.isOutDated(checkClass)

Overrides:
isOutDated in class Compiler

setContextClassLoader

protected void setContextClassLoader()
                              throws Exception
Sets the context class loader if this JSP page is an extension JSP page and if the extensions JAR file has been modified since the last time the class loader was set. This method does nothing if the JSP file is not an extensions JSP file, or if the JAR file hasn't changed since the last use.

Throws:
Exception

getExtensionClassLoader

protected URLClassLoader getExtensionClassLoader()
                                          throws Exception
Get a class loader that can load classes from the current web application as well as the extensions JAR file. The class loader for the current web application can be found in JspRuntimeContext.getParentClassLoader(). The extensions class loader is loaded from JarClassLoader in BASE.

Throws:
Exception

getWebAppClassLoader

protected ClassLoader getWebAppClassLoader()
Get the class loader for the web application this JSP is located in. Default implementation returns JspRuntimeContext.getParentClassLoader()


2.17.2: 2011-06-17