Class CmsJspLoader

  • All Implemented Interfaces:
    I_CmsConfigurationParameterHandler, I_CmsFlexCacheEnabledLoader, I_CmsResourceLoader, I_CmsEventListener

    public class CmsJspLoader
    extends java.lang.Object
    implements I_CmsResourceLoader, I_CmsFlexCacheEnabledLoader, I_CmsEventListener
    The JSP loader which enables the execution of JSP in OpenCms.

    Parameters supported by this loader:

    jsp.repository
    (Optional) This is the root directory in the "real" file system where generated JSPs are stored. The default is the web application path, e.g. in Tomcat if your web application is names "opencms" it would be ${TOMCAT_HOME}/webapps/opencms/. The jsp.folder (see below) is added to this path. Usually the jsp.repository is not changed.
    jsp.folder
    (Optional) A path relative to the jsp.repository path where the JSPs generated by OpenCms are stored. The default is to store the generated JSP in /WEB-INF/jsp/. This works well in Tomcat 4, and the JSPs are not accessible directly from the outside this way, only through the OpenCms servlet. Please note: Some servlet environments (e.g. BEA Weblogic) do not permit JSPs to be stored under /WEB-INF. For environments like these, set the path to some place where JSPs can be accessed, e.g. /jsp/ only.
    jsp.errorpage.committed
    (Optional) This parameter controls behavior of JSP error pages i.e. <% page errorPage="..." %>. If you find that these don't work in your servlet environment, you should try to change the value here. The default true has been tested with Tomcat 4.1 and 5.0. Older versions of Tomcat like 4.0 require a setting of false.
    Since:
    6.0.0
    See Also:
    I_CmsResourceLoader
    • Constructor Detail

      • CmsJspLoader

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

        See Also:
        CmsResourceManager
    • Method Detail

      • dump

        public byte[] dump​(CmsObject cms,
                           CmsResource file,
                           java.lang.String element,
                           java.util.Locale locale,
                           javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res)
                    throws javax.servlet.ServletException,
                           java.io.IOException
        Description copied from interface: I_CmsResourceLoader
        Dumps the processed content of the the requested file (and it's sub-elements) to a byte array.

        Dumping the content is like calling "load" where the result is not written to the response stream, but to the returned byte array. Dumping is different from an export because the export might actually require that the content is handled or modified in a special way, or set special http headers.

        Moreover, if the page type is template based, calling "dump" will not trigger the template but directly deliver the contents from the selected element.

        Specified by:
        dump in interface I_CmsResourceLoader
        Parameters:
        cms - used to access the OpenCms VFS
        file - the requested resource in the VFS
        element - the element in the file to display
        locale - the locale to display
        req - the servlet request
        res - the servlet response
        Returns:
        the content of the processed file
        Throws:
        javax.servlet.ServletException - might be thrown by the servlet environment
        java.io.IOException - might be thrown by the servlet environment
        See Also:
        I_CmsResourceLoader.dump(org.opencms.file.CmsObject, org.opencms.file.CmsResource, java.lang.String, java.util.Locale, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      • export

        public byte[] export​(CmsObject cms,
                             CmsResource resource,
                             javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse res)
                      throws javax.servlet.ServletException,
                             java.io.IOException
        Description copied from interface: I_CmsResourceLoader
        Static exports the contents of the requested file and it's sub-elements.

        During static export, the resource content may be written to 2 streams: The export stream, and the http response output stream. Which stream is actually used depends whether the export is in "on demand" or "after publish" mode. In "on demand" mode, the resource needs to be written both to the response stream and to the file stream. In "after publish" mode, it's usually only written to the file stream, but sometimes it's required to write to the response stream as well.

        Specified by:
        export in interface I_CmsResourceLoader
        Parameters:
        cms - the initialized CmsObject which provides user permissions
        resource - the requested OpenCms VFS resource
        req - the servlet request
        res - the servlet response
        Returns:
        the contents to export, or null if no export is required
        Throws:
        javax.servlet.ServletException - might be thrown in the process of including the sub element
        java.io.IOException - might be thrown in the process of including the sub element
        See Also:
        I_CmsResourceLoader.export(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      • getJspRepository

        public java.lang.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
      • getReferencingStrongLinks

        public void getReferencingStrongLinks​(CmsObject cms,
                                              CmsResource resource,
                                              java.util.Set<java.lang.String> referencingPaths)
                                       throws CmsException
        Returns a set of root paths of files that are including the given resource using the 'link.strong' macro.

        Parameters:
        cms - the current cms context
        resource - the resource to check
        referencingPaths - the set of already referencing paths, also return parameter
        Throws:
        CmsException - if something goes wrong
      • getResourceLoaderInfo

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

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

        @Deprecated
        public java.lang.String processTaglibAttributes​(java.lang.String content)
        Deprecated.
        Replaces taglib attributes in page directives with taglib directives.

        Parameters:
        content - the JSP source text
        Returns:
        the transformed JSP text
      • removeFromCache

        public void removeFromCache​(java.util.Set<java.lang.String> rootPaths,
                                    boolean online)
        Removes the given resources from the cache.

        Parameters:
        rootPaths - the set of root paths to remove
        online - if online or offline
      • triggerPurge

        public void triggerPurge​(java.lang.Runnable afterPurgeAction)
        Triggers an asynchronous purge of the JSP repository.

        Parameters:
        afterPurgeAction - the action to execute after purging
      • updateJsp

        public java.lang.String updateJsp​(CmsResource resource,
                                          CmsFlexController controller,
                                          java.util.Set<java.lang.String> updatedFiles)
                                   throws java.io.IOException,
                                          javax.servlet.ServletException,
                                          CmsLoaderException
        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 recursively 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.

        Parameters:
        resource - the requested JSP file resource in the VFS
        controller - the controller for the JSP integration
        updatedFiles - a Set containing all JSP pages that have been already updated
        Returns:
        the file name of the updated JSP in the "real" FS
        Throws:
        javax.servlet.ServletException - might be thrown in the process of including the JSP
        java.io.IOException - might be thrown in the process of including the JSP
        CmsLoaderException - if the resource type can not be read
      • updateJspFromRequest

        public void updateJspFromRequest​(java.lang.String servletPath,
                                         CmsFlexRequest request)
        Updates the internal jsp repository when the servlet container tries to compile a jsp file that may not exist.

        Parameters:
        servletPath - the servlet path, just to avoid unneeded recursive calls
        request - the current request
      • dispatchJsp

        protected byte[] dispatchJsp​(CmsFlexController controller)
                              throws javax.servlet.ServletException,
                                     java.io.IOException
        Dispatches the current request to the OpenCms internal JSP.

        Parameters:
        controller - the current controller
        Returns:
        the content of the processed JSP
        Throws:
        javax.servlet.ServletException - if inclusion does not work
        java.io.IOException - if inclusion does not work
      • doPurge

        protected void doPurge​(java.lang.Runnable afterPurgeAction)
        Purges the JSP repository.
        Parameters:
        afterPurgeAction - the action to execute after purging
      • generateTaglibInclusions

        protected java.lang.String generateTaglibInclusions​(java.util.Collection<java.lang.String> taglibs)
        Generates the taglib directives for a collection of taglib identifiers.

        Parameters:
        taglibs - the taglib identifiers
        Returns:
        a string containing taglib directives
      • getController

        protected CmsFlexController getController​(CmsObject cms,
                                                  CmsResource resource,
                                                  javax.servlet.http.HttpServletRequest req,
                                                  javax.servlet.http.HttpServletResponse res,
                                                  boolean streaming,
                                                  boolean top)
        Delivers a Flex controller, either by creating a new one, or by re-using an existing one.

        Parameters:
        cms - the initial CmsObject to wrap in the controller
        resource - the resource requested
        req - the current request
        res - the current response
        streaming - indicates if the response is streaming
        top - indicates if the response is the top response
        Returns:
        a Flex controller
      • initCaches

        protected void initCaches​(int cacheSize)
        Initializes the caches.

        Parameters:
        cacheSize - the cache size
      • parseJsp

        protected byte[] parseJsp​(byte[] byteContent,
                                  java.lang.String encoding,
                                  CmsFlexController controller,
                                  java.util.Set<java.lang.String> updatedFiles,
                                  boolean isHardInclude)
        Parses the JSP and modifies OpenCms critical directive information.

        Parameters:
        byteContent - the original JSP content
        encoding - the encoding to use for the JSP
        controller - the controller for the JSP integration
        updatedFiles - a Set containing all JSP pages that have been already updated
        isHardInclude - indicated if this page is actually a "hard" include with <%@ include file="..." >
        Returns:
        the modified JSP content
      • parseJspCmsTag

        protected java.lang.String parseJspCmsTag​(java.lang.String content,
                                                  CmsFlexController controller,
                                                  java.util.Set<java.lang.String> updatedFiles)
        Parses the JSP content for the special <%cms file="..." %> tag.

        Parameters:
        content - the JSP content to parse
        controller - the current JSP controller
        updatedFiles - a set of already updated jsp files
        Returns:
        the parsed JSP content
      • parseJspEncoding

        protected java.lang.String parseJspEncoding​(java.lang.String content,
                                                    java.lang.String encoding,
                                                    boolean isHardInclude)
        Parses the JSP content for the <%page pageEncoding="..." %> tag and ensures that the JSP page encoding is set according to the OpenCms "content-encoding" property value of the JSP.

        Parameters:
        content - the JSP content to parse
        encoding - the encoding to use for the JSP
        isHardInclude - indicated if this page is actually a "hard" include with <%@ include file="..." >
        Returns:
        the parsed JSP content
      • parseJspIncludes

        protected java.lang.String parseJspIncludes​(java.lang.String content,
                                                    CmsFlexController controller,
                                                    java.util.Set<java.lang.String> updatedFiles)
        Parses the JSP content for includes and replaces all OpenCms VFS path information with information for the real FS.

        Parameters:
        content - the JSP content to parse
        controller - the current JSP controller
        updatedFiles - a set of already updated files
        Returns:
        the parsed JSP content
      • parseJspLinkMacros

        protected java.lang.String parseJspLinkMacros​(java.lang.String content,
                                                      CmsFlexController controller)
        Parses all jsp link macros, and replace them by the right target path.

        Parameters:
        content - the content to parse
        controller - the request controller
        Returns:
        the parsed content
      • readJspResource

        protected CmsResource readJspResource​(CmsFlexController controller,
                                              java.lang.String jspName)
                                       throws CmsException
        Returns the jsp resource identified by the given name, using the controllers cms context.

        Parameters:
        controller - the flex controller
        jspName - the name of the jsp
        Returns:
        an OpenCms resource
        Throws:
        CmsException - if something goes wrong
      • showSource

        protected void showSource​(CmsObject cms,
                                  CmsResource file,
                                  javax.servlet.http.HttpServletRequest req,
                                  javax.servlet.http.HttpServletResponse res)
                           throws CmsException,
                                  java.io.IOException
        Delivers the plain uninterpreted resource with escaped XML.

        This is intended for viewing historical versions.

        Parameters:
        cms - the initialized CmsObject which provides user permissions
        file - the requested OpenCms VFS resource
        req - the servlet request
        res - the servlet response
        Throws:
        java.io.IOException - might be thrown by the servlet environment
        CmsException - in case of errors accessing OpenCms functions
      • updateJsp

        protected java.lang.String updateJsp​(java.lang.String vfsName,
                                             CmsFlexController controller,
                                             java.util.Set<java.lang.String> updatedFiles)
        Updates a JSP page in the "real" file system in case the VFS resource has changed based on the resource name.

        Generates a resource based on the provided name and calls updateJsp(CmsResource, CmsFlexController, Set).

        Parameters:
        vfsName - the name of the JSP file resource in the VFS
        controller - the controller for the JSP integration
        updatedFiles - a Set containing all JSP pages that have been already updated
        Returns:
        the file name of the updated JSP in the "real" FS
      • updateStrongLinks

        protected boolean updateStrongLinks​(CmsResource resource,
                                            CmsFlexController controller,
                                            java.util.Set<java.lang.String> updatedFiles)
                                     throws CmsLoaderException,
                                            java.io.IOException,
                                            javax.servlet.ServletException
        Updates all jsp files that include the given jsp file using the 'link.strong' macro.

        Parameters:
        resource - the current updated jsp file
        controller - the controller for the jsp integration
        updatedFiles - the already updated files
        Returns:
        true if the given JSP file should be updated due to dirty included files
        Throws:
        javax.servlet.ServletException - might be thrown in the process of including the JSP
        java.io.IOException - might be thrown in the process of including the JSP
        CmsLoaderException - if the resource type can not be read