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

Quick Search    Search Deep

Source code: com/opencms/flex/CmsJspTemplate.java


1   /*
2    * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/Attic/CmsJspTemplate.java,v $
3    * Date   : $Date: 2003/02/26 15:19:24 $
4    * Version: $Revision: 1.7 $
5    *
6    * This library is part of OpenCms -
7    * the Open Source Content Mananagement System
8    *
9    * Copyright (C) 2002 - 2003 Alkacon Software (http://www.alkacon.com)
10   *
11   * This library is free software; you can redistribute it and/or
12   * modify it under the terms of the GNU Lesser General Public
13   * License as published by the Free Software Foundation; either
14   * version 2.1 of the License, or (at your option) any later version.
15   *
16   * This library is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   * Lesser General Public License for more details.
20   *
21   * For further information about Alkacon Software, please see the
22   * company website: http://www.alkacon.com
23   *
24   * For further information about OpenCms, please see the
25   * project website: http://www.opencms.org
26   * 
27   * You should have received a copy of the GNU Lesser General Public
28   * License along with this library; if not, write to the Free Software
29   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30   */
31   
32  package com.opencms.flex;
33  
34  import com.opencms.boot.I_CmsLogChannels;
35  import com.opencms.core.A_OpenCms;
36  import com.opencms.core.CmsException;
37  import com.opencms.file.CmsFile;
38  import com.opencms.file.CmsObject;
39  import com.opencms.template.CmsCacheDirectives;
40  
41  import java.util.Hashtable;
42  
43  /**
44   * A simple dump class for JSPs which enables
45   * the use of JSP as sub-elements in the legacy OpenCms XMLTemplate 
46   * mechanism.<p>
47   *
48   * @author  Alexander Kandzior (a.kandzior@alkacon.com)
49   * 
50   * @version $Revision: 1.7 $
51   * @since 5.0 beta 1
52   */
53  public class CmsJspTemplate extends com.opencms.template.CmsDumpTemplate {
54      
55      /**
56       * The constructor of the class is empty and does nothing.<p>
57       */
58      public CmsJspTemplate() {
59          // NOOP
60      }
61  
62      /**
63       * Gets the content of the given JSP file to include them
64       * in the XMLTemplate.<p>
65       *
66       * @param cms for accessing system resources
67       * @param jspFile filename of the JSP in the VFS
68       * @param elementName <em>not used</em>
69       * @param parameters <em>not used</em>
70       * 
71       * @return Content of the requested JSP page.
72       * 
73       * @throws CmsException
74       */
75      public byte[] getContent(CmsObject cms, String jspFile, String elementName, Hashtable parameters) throws CmsException {
76          if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(C_FLEX_LOADER)) {
77              A_OpenCms.log(C_FLEX_LOADER, "[CmsJspTemplate] Now loading contents of file " + jspFile);
78          }
79  
80          byte[] s = null;
81          try {
82              CmsFile file = cms.readFile(jspFile);
83              int type = file.getLauncherType();
84              com.opencms.flex.CmsJspLoader loader = (com.opencms.flex.CmsJspLoader)cms.getLauncherManager().getLauncher(type);
85              s = loader.loadTemplate(cms, file);
86          } catch (java.lang.ClassCastException e) {
87              throw new CmsException("[CmsJspTemplate] " + jspFile + " is not a JSP");
88          } catch (com.opencms.core.CmsException e) {
89              // File might not exist or no read permissions
90              throw new CmsException("[CmsJspTemplate] Error while reading JSP " + jspFile + "\n" + e, e);
91          }        
92  
93          catch(Exception e) {
94              String errorMessage = "[CmsJspTemplate] Error while loading jsp file " + jspFile + ": " + e;
95              if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_CRITICAL) ) {
96                  A_OpenCms.log(C_OPENCMS_CRITICAL, "[CmsJspTemplate] " + errorMessage);
97              }
98              if(e instanceof CmsException) {
99                  throw (CmsException)e;
100             }
101             else {
102                 throw new CmsException(errorMessage, CmsException.C_UNKNOWN_EXCEPTION);
103             }
104         }
105         return s;
106     }
107     
108     /**
109      * Cache method required by the ElementCache to indicate if the
110      * results of the page should be cached in the ElementCache.<p>
111      * 
112      * JSPs will be cached in the FlexCache and so 
113      * we always return <code>false</code> here.
114      * 
115      * @return <code>false</code>
116      */
117     public boolean isTemplateCacheSet() {
118         return false;
119     }    
120     
121     /**
122      * Method used by the ElementCache to check if the page 
123      * should reload or not.<p>
124      * 
125      * JSPs will be cached in the FlexCache and so 
126      * we always return <code>true</code> here.
127      * 
128      * @return <code>true</code>
129      */
130     public boolean shouldReload(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
131         return true;
132     } 
133     
134     /**
135      * Returns the caching information from the current template class for the
136      * ElementCache.<p>
137      * 
138      * JSPs will be cached in the FlexCache and so 
139      * we always return directives that prevent caching here,
140      * i.e. <code>new CmsCacheDirectives(false)</code>
141      *
142      * @param cms CmsObject Object for accessing system resources
143      * @param templateFile filename of the template file
144      * @param elementName element name of this template in our parent template
145      * @param parameters Hashtable with all template class parameters
146      * @param templateSelector template section that should be processed
147      * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
148      */
149     public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
150         // Just set caching to false
151         return new CmsCacheDirectives(false);
152     }    
153 }