JSPTemplates

org.tp23.jasper
Class MyJasper

java.lang.Object
  |
  +--org.tp23.jasper.MyJasper
All Implemented Interfaces:
Engine

public class MyJasper
extends java.lang.Object
implements Engine

This is the object that serves the jsp responses, it is basically local java tomcat. (but really simple) Remember, when running this class you need to specify a path to put classes into; in order to run the generated classes the directory must be in the class path.
The package created for the jsps is the default package, this probably needs changing. In this implementatioin the Server itself maintains a single session object this will be passed to all jsps. If multi client mode is required it is possible to manage the Destination object out side of the MyJasper runtime and give them whatever session you like, as long as it is a org.tp23.jsp.Session. You can thus keep pools of sessions if you like N.B. I have done some budget hacks that assume all jsps end in .jsp I'm not sure if this is a requirement of Tomcat but is is a requirement of MyJapser. Also the file names of jsps should not include and non-letter or digit characters because I have not mangled the class calls properly. ;) The setJspClassLoader allows MyJasper to be used in an environment where more than one class loader is in operation, for example loading MyJapser classes from apache Jasper

Author:
Paul Hinds

Constructor Summary
MyJasper()
          Constructor for a default MyJasper that loads its parameters from a file called myjasper.properties that is in the same directory root as this classes class file or in the same jar file.
MyJasper(java.io.File jspDirectory, java.io.File classDirectory)
          Constructor for the MyJasper object
MyJasper(java.io.File jspDirectory, java.io.File classDirectory, boolean createSession)
          Constructor for the MyJasper object
MyJasper(java.util.Properties configuration, boolean createSession)
          Constructor for the MyJasper object
 
Method Summary
 void configure()
          performs all the operations of the no args constructor.
 void configure(java.util.Properties configuration, boolean createSession)
          performs all the operations of the MyJasper(Properties configuration, boolean createSession) constructor.
 java.util.Properties getConfiguration()
          Gets the config or creates a default if there is none.
 Destination getNewDestination(java.util.Map parameters)
           
 ObjectJspFactory getObjectJspFactory()
          Gets the objectJspFactory attribute of the MyJasper object
 java.lang.String getOutput(java.lang.String jspFile)
           
 java.lang.String getOutput(java.lang.String jspFile, Destination dest)
          Gets the output of a given JSP.
 java.lang.String getOutput(java.lang.String jspFile, java.util.Map props)
          Gets the output of a given JSP
 Session getSession()
          Gets the session of the MyJasper object
static void main(java.lang.String[] args)
          Run the test method.
 void setClassDirectory(java.io.File classDir)
           
 void setClassDirectory(java.lang.String classDir)
           
 void setClasspath(java.lang.String classpath)
          Sets the classpath attribute of the MyJasper object
 void setJspClassLoader(java.lang.ClassLoader jspClassLoader)
           
 void setJspDirectory(java.io.File jspDir)
           
 void setJspDirectory(java.lang.String jspDir)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyJasper

public MyJasper(java.io.File jspDirectory,
                java.io.File classDirectory)
Constructor for the MyJasper object
Parameters:
jspDirectory - The location of JSP files
classDirectory - The location of the classes

MyJasper

public MyJasper(java.io.File jspDirectory,
                java.io.File classDirectory,
                boolean createSession)
Constructor for the MyJasper object
Parameters:
jspDirectory - The location of JSP files
classDirectory - The location of the classes
createSession - if true create a session

MyJasper

public MyJasper(java.util.Properties configuration,
                boolean createSession)
Constructor for the MyJasper object
Parameters:
configuration - a populated Properties object. containing all the neccessary item for boot up e.g. myjasper.jsp.dir
createSession - if true create a session
See Also:
ObjectContainerContextImpl

MyJasper

public MyJasper()
         throws java.io.FileNotFoundException
Constructor for a default MyJasper that loads its parameters from a file called myjasper.properties that is in the same directory root as this classes class file or in the same jar file.
Method Detail

configure

public void configure(java.util.Properties configuration,
                      boolean createSession)
performs all the operations of the MyJasper(Properties configuration, boolean createSession) constructor. Eventually the constructor will do nothing allowing the server to be configured with out using the constructor so the class can be dynamically loaded and configured with this method (or others)
Specified by:
configure in interface Engine

configure

public void configure()
               throws java.io.FileNotFoundException
performs all the operations of the no args constructor. Eventually the no args constructor will do nothing allowing the server to be configured with out using the constructor so the class can be dynamically loaded and configured with this method (or others)

setJspDirectory

public void setJspDirectory(java.lang.String jspDir)
Specified by:
setJspDirectory in interface Engine

setJspDirectory

public void setJspDirectory(java.io.File jspDir)
Specified by:
setJspDirectory in interface Engine

setClassDirectory

public void setClassDirectory(java.lang.String classDir)
Specified by:
setClassDirectory in interface Engine

setClassDirectory

public void setClassDirectory(java.io.File classDir)
Specified by:
setClassDirectory in interface Engine

getConfiguration

public java.util.Properties getConfiguration()
Gets the config or creates a default if there is none. N.B. the default config dir for JSP configuration is the same directory as the JSP itself
Specified by:
getConfiguration in interface Engine

setClasspath

public void setClasspath(java.lang.String classpath)
Sets the classpath attribute of the MyJasper object
Specified by:
setClasspath in interface Engine
Parameters:
classpath - The new classpath value

getObjectJspFactory

public ObjectJspFactory getObjectJspFactory()
Gets the objectJspFactory attribute of the MyJasper object
Specified by:
getObjectJspFactory in interface Engine
Returns:
The objectJspFactory value

setJspClassLoader

public void setJspClassLoader(java.lang.ClassLoader jspClassLoader)

getOutput

public java.lang.String getOutput(java.lang.String jspFile,
                                  java.util.Map props)
                           throws JspEngineException
Gets the output of a given JSP
Specified by:
getOutput in interface Engine
Parameters:
jspFile - the name of the file (relative to the current JSP root
props - A set of porperties (consider this the request)
Returns:
The output as a java.lang.String
Throws:
JspEngineException -  

getOutput

public java.lang.String getOutput(java.lang.String jspFile)
                           throws JspEngineException
Specified by:
getOutput in interface Engine

getOutput

public java.lang.String getOutput(java.lang.String jspFile,
                                  Destination dest)
                           throws JspEngineException
Gets the output of a given JSP. If the JSP does not yet exist it is created and cached
Specified by:
getOutput in interface Engine
Parameters:
jspFile - the name of the file (relative to the current JSP root) e.g. mystuff.jsp
dest - a destination object, by maintaining a reference to this object it is possible to recall the result of the JSP without having to re-run the objects service method
Returns:
The output as a java.lang.String
Throws:
JspEngineException -  

getSession

public Session getSession()
Gets the session of the MyJasper object
Specified by:
getSession in interface Engine
Returns:
The session object

getNewDestination

public Destination getNewDestination(java.util.Map parameters)
Specified by:
getNewDestination in interface Engine
Returns:
a new Destination object of the correct runtime class;

main

public static void main(java.lang.String[] args)
Run the test method.
Parameters:
args - The command line arguments

JSPTemplates