KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > legacy > CmsJspTemplate


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/legacy/CmsJspTemplate.java,v $
3  * Date : $Date: 2005/06/27 23:27:46 $
4  * Version: $Revision: 1.10 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 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.legacy;
33
34 import org.opencms.file.CmsFile;
35 import org.opencms.file.CmsObject;
36 import org.opencms.loader.CmsJspLoader;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.OpenCms;
40
41 import com.opencms.template.*;
42
43 import java.util.Hashtable JavaDoc;
44
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46 import javax.servlet.http.HttpServletResponse JavaDoc;
47
48 /**
49  * A simple dump class which enables
50  * the use of JSP as sub-elements in the legacy OpenCms XMLTemplate
51  * mechanism.<p>
52  *
53  * @author Alexander Kandzior (a.kandzior@alkacon.com)
54  *
55  * @version $Revision: 1.10 $
56  * @since 5.0 beta 1
57  *
58  * @deprecated Will not be supported past the OpenCms 6 release.
59  */

60 public class CmsJspTemplate extends CmsDumpTemplate {
61     
62     /**
63      * The constructor of the class is empty and does nothing.<p>
64      */

65     public CmsJspTemplate() {
66         // NOOP
67
}
68
69     /**
70      * Gets the content of the given JSP file to include them
71      * in the XMLTemplate.<p>
72      *
73      * @param cms for accessing system resources
74      * @param jspFile filename of the JSP in the VFS
75      * @param elementName <em>not used</em>
76      * @param parameters <em>not used</em>
77      *
78      * @return Content of the requested JSP page.
79      *
80      * @throws CmsException in case something goes wrong
81      */

82     public byte[] getContent(CmsObject cms, String JavaDoc jspFile, String JavaDoc elementName, Hashtable JavaDoc parameters) throws CmsException {
83         if (CmsLog.getLog(this).isDebugEnabled()) {
84             CmsLog.getLog(this).debug("Loading contents of file " + jspFile);
85         }
86
87         byte[] s = null;
88         try {
89             CmsFile file = cms.readFile(jspFile);
90             CmsJspLoader loader = (CmsJspLoader)OpenCms.getResourceManager().getLoader(CmsJspLoader.RESOURCE_LOADER_ID);
91
92             HttpServletRequest JavaDoc req = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest();
93             HttpServletResponse JavaDoc res = CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).getOriginalResponse();
94
95             s = loader.dump(cms, file, null, null, req, res);
96         } catch (java.lang.ClassCastException JavaDoc e) {
97             s = null;
98             throw new CmsLegacyException("[CmsJspTemplate] " + jspFile + " is not a JSP");
99         } catch (org.opencms.main.CmsException e) {
100             s = null;
101             // File might not exist or no read permissions
102
throw new CmsLegacyException("[CmsJspTemplate] Error while reading JSP " + jspFile + "\n" + e, e);
103         } catch (Exception JavaDoc e) {
104             s = null;
105             String JavaDoc errorMessage = "[CmsJspTemplate] Error while loading jsp file " + jspFile + ": " + e;
106             if (CmsLog.getLog(this).isErrorEnabled()) {
107                 CmsLog.getLog(this).error(errorMessage, e);
108             }
109             if (e instanceof CmsException) {
110                 throw (CmsException)e;
111             } else {
112                 throw new CmsLegacyException(errorMessage, CmsLegacyException.C_UNKNOWN_EXCEPTION);
113             }
114         }
115         return s;
116     }
117     
118     /**
119      * Cache method required by the ElementCache to indicate if the
120      * results of the page should be cached in the ElementCache.<p>
121      *
122      * JSPs will be cached in the FlexCache and so
123      * we always return <code>false</code> here.
124      *
125      * @return <code>false</code>
126      */

127     public boolean isTemplateCacheSet() {
128         return false;
129     }
130     
131     /**
132      * Method used by the ElementCache to check if the page
133      * should reload or not.<p>
134      *
135      * JSPs will be cached in the FlexCache and so
136      * we always return <code>true</code> here.
137      *
138      * @param cms default argument for element cache method
139      * @param templateFile default argument for element cache method
140      * @param elementName default argument for element cache method
141      * @param parameters default argument for element cache method
142      * @param templateSelector default argument for element cache method
143      * @return <code>true</code>
144      */

145     public boolean shouldReload(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
146         return true;
147     }
148     
149     /**
150      * Returns the caching information from the current template class for the
151      * ElementCache.<p>
152      *
153      * JSPs will be cached in the FlexCache and so
154      * we always return directives that prevent caching here,
155      * i.e. <code>new CmsCacheDirectives(false)</code>
156      *
157      * @param cms CmsObject Object for accessing system resources
158      * @param templateFile filename of the template file
159      * @param elementName element name of this template in our parent template
160      * @param parameters Hashtable with all template class parameters
161      * @param templateSelector template section that should be processed
162      * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
163      */

164     public CmsCacheDirectives getCacheDirectives(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
165         // Just set caching to false
166
return new CmsCacheDirectives(false);
167     }
168 }
169
Popular Tags