com.opencms.flex
Class CmsJspLoader

java.lang.Object
  |
  +--com.opencms.flex.CmsJspLoader
All Implemented Interfaces:
I_CmsLauncher, I_CmsResourceLoader

public class CmsJspLoader
extends Object
implements I_CmsLauncher, I_CmsResourceLoader

The JSP loader which enables the execution of JSP in OpenCms.

It does NOT extend A_CmsLauncher, since JSP are not related to the OpenCms Template mechanism. However, it implements the launcher interface so that JSP can be sub-elements in XMLTemplace pages.

Since:
FLEX alpha 1
Version:
$Revision: 1.24 $
Author:
Alexander Kandzior (a.kandzior@alkacon.com)
See Also:
I_CmsResourceLoader, I_CmsLauncher

Field Summary
static String C_DEFAULT_JSP_ENCODING
          Encoding to write JSP files to disk (ISO-8859-1)
static String C_DIRECTIVE_END
          Special JSP directive tag start (%>)
static String C_DIRECTIVE_START
          Special JSP directive tag start (<%@)
static String C_JSP_EXTENSION
          Extension for JSP managed by OpenCms (.jsp)
static String C_LOADER_ERRORPAGECOMMIT
          Name of "error pages are commited or not" runtime property
static String C_LOADER_JSPEXPORTURL
          Name of export URL runtime property
 
Fields inherited from interface com.opencms.launcher.I_CmsLauncher
C_TYPE_DUMP, C_TYPE_JAVASCRIPT, C_TYPE_JSP, C_TYPE_LINK, C_TYPE_PDF, C_TYPE_VELOCITY, C_TYPE_XML
 
Fields inherited from interface com.opencms.flex.I_CmsResourceLoader
C_LOADER_CACHENAME, C_LOADER_CACHEPROPERTY, C_LOADER_EXCEPTION_PREFIX, C_LOADER_STREAMPROPERTY
 
Constructor Summary
CmsJspLoader()
          The constructor of the class is empty, the initial instance will be created by the launcher manager upon startup of OpenCms.
 
Method Summary
 void clearCache()
          This is part of the I_CmsLauncher interface, but for JSP so far this is a NOOP.
 void destroy()
          Destroy this ResourceLoder, this is a NOOP so far.
static String getJspName(String name)
          Translates the JSP file name for a OpenCms VFS resourcn to the name used in the "real" file system.
static String getJspPath(String name, boolean online)
          Returns the absolute path in the "real" file system for a given JSP.
static String getJspRepository()
          Returns the absolute path in the "real" file system for the JSP repository toplevel directory.
static String getJspUri(String name, boolean online)
          Returns the uri for a given JSP in the "real" file system, i.e. the path in the file system relative to the web application directory.
 int getLauncherId()
          Returns the ID that indicates the type of the launcher.
 String getResourceLoaderInfo()
          Return a String describing the ResourceLoader, which is "The OpenCms default resource loader for JSP"
 void init(A_OpenCms openCms)
          Initialize the ResourceLoader, here the configuration for the JSP repository (directories used) is set.
 void initlaunch(CmsObject cms, CmsFile file, String startTemplateClass, A_OpenCms openCms)
          Start launch method called by the OpenCms system to show a resource, this basically processes the resource and returns the output.
 void load(CmsObject cms, CmsFile file, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Basic top-page processing method for this I_CmsResourceLoader, this method is called by initlaunch() if a JSP is requested and the original request was from the launcher manager.
 byte[] loadTemplate(CmsObject cms, CmsFile file)
          Method to enable JSPs to be used as sub-elements in XMLTemplates.
 void service(CmsObject cms, CmsResource file, CmsFlexRequest req, CmsFlexResponse res)
          Does the job of including the JSP, this method should usually be called from a CmsFlexRequestDispatcher only.
static void setJspExportUrl(String value)
          Set's the JSP export URL.
 void setOpenCms(A_OpenCms openCms)
          This is part of the I_CmsLauncher interface, used here to call the init() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C_DIRECTIVE_START

public static final String C_DIRECTIVE_START
Special JSP directive tag start (<%@)

See Also:
Constant Field Values

C_DIRECTIVE_END

public static final String C_DIRECTIVE_END
Special JSP directive tag start (%>)

See Also:
Constant Field Values

C_DEFAULT_JSP_ENCODING

public static final String C_DEFAULT_JSP_ENCODING
Encoding to write JSP files to disk (ISO-8859-1)

See Also:
Constant Field Values

C_JSP_EXTENSION

public static final String C_JSP_EXTENSION
Extension for JSP managed by OpenCms (.jsp)

See Also:
Constant Field Values

C_LOADER_JSPEXPORTURL

public static final String C_LOADER_JSPEXPORTURL
Name of export URL runtime property

See Also:
Constant Field Values

C_LOADER_ERRORPAGECOMMIT

public static final String C_LOADER_ERRORPAGECOMMIT
Name of "error pages are commited or not" runtime property

See Also:
Constant Field Values
Constructor Detail

CmsJspLoader

public CmsJspLoader()
The constructor of the class is empty, the initial instance will be created by the launcher manager upon startup of OpenCms.

To initilize the fields in this class, the setOpenCms() method will be called by the launcher.

See Also:
CmsLauncherManager, setOpenCms(A_OpenCms openCms)
Method Detail

clearCache

public void clearCache()
This is part of the I_CmsLauncher interface, but for JSP so far this is a NOOP.

Specified by:
clearCache in interface I_CmsLauncher

setOpenCms

public void setOpenCms(A_OpenCms openCms)
This is part of the I_CmsLauncher interface, used here to call the init() method.

Specified by:
setOpenCms in interface I_CmsLauncher
See Also:
init(A_OpenCms openCms)

getLauncherId

public int getLauncherId()
Returns the ID that indicates the type of the launcher. The IDs for all launchers of the core distributions are constants in the I_CmsLauncher interface. The value returned is com.opencms.launcher.I_CmsLauncher.C_TYPE_JSP.

Specified by:
getLauncherId in interface I_CmsLauncher
Returns:
launcher ID
See Also:
I_CmsLauncher

initlaunch

public void initlaunch(CmsObject cms,
                       CmsFile file,
                       String startTemplateClass,
                       A_OpenCms openCms)
                throws CmsException
Start launch method called by the OpenCms system to show a resource, this basically processes the resource and returns the output.

This is part of the Launcher interface. All requests will be forwarded to the load() method of this class. That forms the link between the Launcher and Loader interfaces.

Exceptions thrown in the load() method of this loader will be handled here, usually by wrapping them in a CmsException that will then be shown in the OpenCms error dialog.

Specified by:
initlaunch in interface I_CmsLauncher
Parameters:
cms - CmsObject Object for accessing system resources.
file - CmsFile Object with the selected resource to be shown.
startTemplateClass - Name of the template class to start with.
openCms - a instance of A_OpenCms for redirect-needs
Throws:
CmsException - all exeptions in the load process of a JSP will be caught here and wrapped to a CmsException
See Also:
I_CmsLauncher, load(CmsObject cms, CmsFile file, HttpServletRequest req, HttpServletResponse res)

destroy

public void destroy()
Destroy this ResourceLoder, this is a NOOP so far.

Specified by:
destroy in interface I_CmsResourceLoader

getResourceLoaderInfo

public String getResourceLoaderInfo()
Return a String describing the ResourceLoader, which is "The OpenCms default resource loader for JSP"

Specified by:
getResourceLoaderInfo in interface I_CmsResourceLoader
Returns:
a describing String for the ResourceLoader

init

public void init(A_OpenCms openCms)
Initialize the ResourceLoader, here the configuration for the JSP repository (directories used) is set.

Specified by:
init in interface I_CmsResourceLoader
Parameters:
openCms - An OpenCms object to use for initalizing.

setJspExportUrl

public static void setJspExportUrl(String value)
Set's the JSP export URL.

This is required after init() called if the URL was not set in opencms. properties.


load

public void load(CmsObject cms,
                 CmsFile file,
                 javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
          throws javax.servlet.ServletException,
                 IOException
Basic top-page processing method for this I_CmsResourceLoader, this method is called by initlaunch() if a JSP is requested and the original request was from the launcher manager.

Specified by:
load in interface I_CmsResourceLoader
Parameters:
cms - The initialized CmsObject which provides user permissions
file - The requested OpenCms VFS resource
req - The original servlet request
res - The original servlet response
Throws:
javax.servlet.ServletException - might be thrown in the process of including the JSP
IOException - might be thrown in the process of including the JSP
See Also:
I_CmsResourceLoader, initlaunch(CmsObject cms, CmsFile file, String startTemplateClass, A_OpenCms openCms)

loadTemplate

public byte[] loadTemplate(CmsObject cms,
                           CmsFile file)
                    throws CmsException
Method to enable JSPs to be used as sub-elements in XMLTemplates.

Parameters:
cms - The initialized CmsObject which provides user permissions
file - The requested OpenCms VFS resource
Throws:
CmsException - In case the Loader can not process the requested resource
See Also:
CmsJspTemplate

getJspName

public static String getJspName(String name)
Translates the JSP file name for a OpenCms VFS resourcn to the name used in the "real" file system.

The name given must be a absolute URI in the OpenCms VFS, e.g. CmsFile.getAbsolutePath()

Parameters:
name - The file to calculate the JSP name for
Returns:
The JSP name for the file

getJspUri

public static String getJspUri(String name,
                               boolean online)
Returns the uri for a given JSP in the "real" file system, i.e. the path in the file system relative to the web application directory.

Parameters:
name - The name of the JSP file
online - Flag to check if this is request is online or not
Returns:
The full uri to the JSP

getJspPath

public static String getJspPath(String name,
                                boolean online)
Returns the absolute path in the "real" file system for a given JSP.

Parameters:
name - The name of the JSP file
online - Flag to check if this is request is online or not
Returns:
The full path to the JSP

getJspRepository

public static String getJspRepository()
Returns the absolute path in the "real" file system for the JSP repository toplevel directory.

Returns:
The full path to the JSP repository

service

public void service(CmsObject cms,
                    CmsResource file,
                    CmsFlexRequest req,
                    CmsFlexResponse res)
             throws javax.servlet.ServletException,
                    IOException
Does the job of including the JSP, this method should usually be called from a CmsFlexRequestDispatcher only.

This method is called directly if the element is called as a sub-element from another I_CmsResourceLoader.

One of the tricky issues is the correct cascading of the Exceptions, so that you are able to identify the true origin of the problem. This ia achived by imprinting a String C_EXCEPTION_PREFIX to the exception message.

Specified by:
service in interface I_CmsResourceLoader
Parameters:
cms - Used to access the OpenCms VFS
file - The reqested JSP file resource in the VFS
req - The current request
res - The current response
Throws:
javax.servlet.ServletException - might be thrown in the process of including the JSP
IOException - might be thrown in the process of including the JSP
See Also:
CmsFlexRequestDispatcher