Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.opencms.flex
Class CmsJspLoader  view CmsJspLoader download CmsJspLoader.java

java.lang.Object
  extended bycom.opencms.flex.CmsJspLoader
All Implemented Interfaces:
com.opencms.launcher.I_CmsLauncher, I_CmsResourceLoader

public class CmsJspLoader
extends java.lang.Object
implements com.opencms.launcher.I_CmsLauncher, I_CmsResourceLoader

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

It does NOT extend com.opencms.launcher.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.2.1 $

Field Summary
static java.lang.String C_DEFAULT_JSP_ENCODING
          Encoding to write JSP files to disk (ISO-8859-1)
static java.lang.String C_DIRECTIVE_END
          Special JSP directive tag start (%>)
static java.lang.String C_DIRECTIVE_START
          Special JSP directive tag start (<%@)
private static java.lang.String C_EXPORT_BODY
          Parameter constant to indicate a body previously discovered in an XMLTemplate
private static java.lang.String C_EXPORT_ENCODING
          Parameter constant to indicate encoding used in calling template
private static java.lang.String C_EXPORT_HEADER
          Header constant to indicate the found links in the response return headers
private static java.lang.String C_EXPORT_HEADER_SEP
          Separator constant to separate return headers
private static java.lang.String C_EXPORT_PARAM
          Parameter constant to indicate that the export is requested
static java.lang.String C_JSP_EXTENSION
          Extension for JSP managed by OpenCms (.jsp)
static java.lang.String C_LOADER_ERRORPAGECOMMIT
          Name of "error pages are commited or not" runtime property
static java.lang.String C_LOADER_JSPEXPORTURL
          Name of export URL runtime property
private static int DEBUG
          Flag for debugging output.
private static com.opencms.flex.cache.CmsFlexCache m_cache
          The CmsFlexCache used to store generated cache entries in
private static boolean m_errorPagesAreNotCommited
          Flag to indicate if error pages are mared a "commited"
private static java.lang.String m_jspExportUrl
          Export URL for JSP pages
private static java.lang.String m_jspRepository
          The directory to store the generated JSP pages in (absolute path)
private static java.lang.String m_jspWebAppRepository
          The directory to store the generated JSP pages in (relative path in web application
 
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.
private  int exportCheckMode(com.opencms.file.CmsObject cms, javax.servlet.http.HttpServletRequest req)
          Checks if the request parameter C_EXPORT_PARAM is set, if so sets the CmsObject working mode to C_MODUS_EXPORT.
private  byte[] exportJsp(com.opencms.file.CmsObject cms, com.opencms.file.CmsFile file)
          Perform an export of the requested JSP page.
private  void exportResetMode(com.opencms.file.CmsObject cms, int oldMode)
          Restores the mode stored in the oldMode paameter to the CmsObject.
private  void exportSetLinkHeader(com.opencms.file.CmsObject cms, javax.servlet.http.HttpServletResponse res)
          Returns the links found in the currently processed page as response headers, so that the static export can pick them up later.
static java.lang.String getJspName(java.lang.String name)
          Translates the JSP file name for a OpenCms VFS resourcn to the name used in the "real" file system.
static java.lang.String getJspPath(java.lang.String name, boolean online)
          Returns the absolute path in the "real" file system for a given JSP.
static java.lang.String getJspRepository()
          Returns the absolute path in the "real" file system for the JSP repository toplevel directory.
static java.lang.String getJspUri(java.lang.String name, boolean online)
          Returns the uri for a given JSP in the "real" file system, i.e.
 int getLauncherId()
          Returns the ID that indicates the type of the launcher.
 java.lang.String getResourceLoaderInfo()
          Return a String describing the ResourceLoader, which is "The OpenCms default resource loader for JSP"
 void init(com.opencms.core.A_OpenCms openCms)
          Initialize the ResourceLoader, here the configuration for the JSP repository (directories used) is set.
 void initlaunch(com.opencms.file.CmsObject cms, com.opencms.file.CmsFile file, java.lang.String startTemplateClass, com.opencms.core.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(com.opencms.file.CmsObject cms, com.opencms.file.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(com.opencms.file.CmsObject cms, com.opencms.file.CmsFile file)
          Method to enable JSPs to be used as sub-elements in XMLTemplates.
 void service(com.opencms.file.CmsObject cms, com.opencms.file.CmsResource file, javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
          Does the job of including the JSP, this method should usually be called from a CmsFlexRequestDispatcher only.
static void setJspExportUrl(java.lang.String value)
          Set's the JSP export URL.
 void setOpenCms(com.opencms.core.A_OpenCms openCms)
          This is part of the I_CmsLauncher interface, used here to call the init() method.
private  java.lang.String updateJsp(com.opencms.file.CmsObject cms, com.opencms.file.CmsResource file, javax.servlet.ServletRequest req, com.opencms.flex.cache.CmsFlexController controller, java.util.Set updates)
          Updates a JSP page in the "real" file system in case the VFS resource has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_jspRepository

private static java.lang.String m_jspRepository
The directory to store the generated JSP pages in (absolute path)


m_jspWebAppRepository

private static java.lang.String m_jspWebAppRepository
The directory to store the generated JSP pages in (relative path in web application


m_cache

private static com.opencms.flex.cache.CmsFlexCache m_cache
The CmsFlexCache used to store generated cache entries in


m_jspExportUrl

private static java.lang.String m_jspExportUrl
Export URL for JSP pages


m_errorPagesAreNotCommited

private static boolean m_errorPagesAreNotCommited
Flag to indicate if error pages are mared a "commited"


C_DIRECTIVE_START

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

See Also:
Constant Field Values

C_DIRECTIVE_END

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

See Also:
Constant Field Values

C_DEFAULT_JSP_ENCODING

public static final java.lang.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 java.lang.String C_JSP_EXTENSION
Extension for JSP managed by OpenCms (.jsp)

See Also:
Constant Field Values

C_EXPORT_PARAM

private static final java.lang.String C_EXPORT_PARAM
Parameter constant to indicate that the export is requested

See Also:
Constant Field Values

C_EXPORT_BODY

private static final java.lang.String C_EXPORT_BODY
Parameter constant to indicate a body previously discovered in an XMLTemplate

See Also:
Constant Field Values

C_EXPORT_ENCODING

private static final java.lang.String C_EXPORT_ENCODING
Parameter constant to indicate encoding used in calling template

See Also:
Constant Field Values

C_EXPORT_HEADER

private static final java.lang.String C_EXPORT_HEADER
Header constant to indicate the found links in the response return headers

See Also:
Constant Field Values

C_EXPORT_HEADER_SEP

private static final java.lang.String C_EXPORT_HEADER_SEP
Separator constant to separate return headers

See Also:
Constant Field Values

C_LOADER_JSPEXPORTURL

public static final java.lang.String C_LOADER_JSPEXPORTURL
Name of export URL runtime property

See Also:
Constant Field Values

C_LOADER_ERRORPAGECOMMIT

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

See Also:
Constant Field Values

DEBUG

private static final int DEBUG
Flag for debugging output. Set to 9 for maximum verbosity.

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.

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 com.opencms.launcher.I_CmsLauncher

setOpenCms

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

Specified by:
setOpenCms in interface com.opencms.launcher.I_CmsLauncher

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 com.opencms.launcher.I_CmsLauncher

initlaunch

public void initlaunch(com.opencms.file.CmsObject cms,
                       com.opencms.file.CmsFile file,
                       java.lang.String startTemplateClass,
                       com.opencms.core.A_OpenCms openCms)
                throws com.opencms.core.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 com.opencms.launcher.I_CmsLauncher

exportCheckMode

private int exportCheckMode(com.opencms.file.CmsObject cms,
                            javax.servlet.http.HttpServletRequest req)
Checks if the request parameter C_EXPORT_PARAM is set, if so sets the CmsObject working mode to C_MODUS_EXPORT.


exportResetMode

private void exportResetMode(com.opencms.file.CmsObject cms,
                             int oldMode)
Restores the mode stored in the oldMode paameter to the CmsObject.


exportSetLinkHeader

private void exportSetLinkHeader(com.opencms.file.CmsObject cms,
                                 javax.servlet.http.HttpServletResponse res)
Returns the links found in the currently processed page as response headers, so that the static export can pick them up later.


exportJsp

private byte[] exportJsp(com.opencms.file.CmsObject cms,
                         com.opencms.file.CmsFile file)
                  throws com.opencms.core.CmsException
Perform an export of the requested JSP page.

The export of a JSP is done in the following way:

  • A HttpURLConnection is openend to the address configured in the runtime property with the name C_LOADER_JSPEXPORTURL 55 , which usually should be the current OpenCms server.
  • The URI of the file is appended to the connection as path information, so this will be the page requested and exported.
  • All current request parameters are encoded and also added to the request as parameters.
  • The currently requested URI is also appended as value of the special parameter C_EXPORT_PARAM 55 .
  • When processing this special request, the mode of the CmsObject will be set to C_MODUS_EXPORT, which is the required mode if you want to generate the result for an export.
  • All links found while processing the exported JSP will be written in a special header of the response, called C_EXPORT_HEADER 55 .
  • The response result will be checked for the headers and all links found will be added to the link vector of the currently processed page.
  • The content of the resonse will be read into a byte array and returned as result of this call.


destroy

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

Specified by:
destroy in interface I_CmsResourceLoader

getResourceLoaderInfo

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

Specified by:
getResourceLoaderInfo in interface I_CmsResourceLoader

init

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

Specified by:
init in interface I_CmsResourceLoader

setJspExportUrl

public static void setJspExportUrl(java.lang.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(com.opencms.file.CmsObject cms,
                 com.opencms.file.CmsFile file,
                 javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
          throws javax.servlet.ServletException,
                 java.io.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

loadTemplate

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


getJspName

public static java.lang.String getJspName(java.lang.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()


getJspUri

public static java.lang.String getJspUri(java.lang.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.


getJspPath

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


getJspRepository

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


updateJsp

private java.lang.String updateJsp(com.opencms.file.CmsObject cms,
                                   com.opencms.file.CmsResource file,
                                   javax.servlet.ServletRequest req,
                                   com.opencms.flex.cache.CmsFlexController controller,
                                   java.util.Set updates)
                            throws java.io.IOException,
                                   javax.servlet.ServletException
Updates a JSP page in the "real" file system in case the VFS resource has changed.

Also processes the <%@ cms %> tags before the JSP is written to the real FS. Also recursivly updates all files that are referenced by a <%@ cms %> tag on this page to make sure the file actually exists in the real FS. All <%@ include %> tags are parsed and the name in the tag is translated from the OpenCms VFS path to the path in the real FS. The same is done for filenames in <%@ page errorPage=... %> tags.


service

public void service(com.opencms.file.CmsObject cms,
                    com.opencms.file.CmsResource file,
                    javax.servlet.ServletRequest req,
                    javax.servlet.ServletResponse res)
             throws javax.servlet.ServletException,
                    java.io.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