KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/legacy/CmsXmlPageTemplate.java,v $
3  * Date : $Date: 2005/06/27 23:27:46 $
4  * Version: $Revision: 1.9 $
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.CmsXmlPageLoader;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.OpenCms;
40 import org.opencms.xml.page.CmsXmlPage;
41 import org.opencms.xml.page.CmsXmlPageFactory;
42
43 import com.opencms.template.*;
44
45 import java.util.Hashtable JavaDoc;
46 import java.util.Locale JavaDoc;
47
48 /**
49  * A simple dump class which enables
50  * the use of XmlPage as sub-elements in the legacy OpenCms XMLTemplate
51  * mechanism.<p>
52  *
53  * @author Carsten Weinholz
54  *
55  * @version $Revision: 1.9 $
56  * @since 5.1
57  *
58  * @deprecated Will not be supported past the OpenCms 6 release.
59  */

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

65     public CmsXmlPageTemplate() {
66         // NOOP
67
}
68
69     /**
70      * Gets the content of the given XmlPage file to include them
71      * in the XMLTemplate.<p>
72      *
73      * @param cms for accessing system resources
74      * @param filename name of the xml page file 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 filename, String JavaDoc elementName, Hashtable JavaDoc parameters) throws CmsException {
83         if (CmsLog.getLog(this).isDebugEnabled()) {
84             CmsLog.getLog(this).debug("Loading contents of file " + filename);
85         }
86
87         byte[] s = null;
88         try {
89             CmsFile file = cms.readFile(filename);
90             CmsXmlPageLoader loader = (CmsXmlPageLoader)OpenCms.getResourceManager().getLoader(CmsXmlPageLoader.RESOURCE_LOADER_ID);
91             // check the current locales
92
CmsXmlPage page = CmsXmlPageFactory.unmarshal(cms, file);
93             String JavaDoc absolutePath = cms.getSitePath(file);
94             Locale JavaDoc locale = OpenCms.getLocaleManager().getBestMatchingLocale(cms.getRequestContext().getLocale(), OpenCms.getLocaleManager().getDefaultLocales(cms, absolutePath), page.getLocales());
95             s = loader.dump(cms, file, elementName, locale, null, null);
96         } catch (java.lang.ClassCastException JavaDoc e) {
97             s = null;
98             throw new CmsLegacyException("[CmsXmlPageTemplate] " + filename + " is not a xml page");
99         } catch (org.opencms.main.CmsException e) {
100             s = null;
101             // File might not exist or no read permissions
102
throw new CmsLegacyException("[CmsXmlPageTemplate] Error while reading xml page " + filename + "\n" + e, e);
103         } catch (Exception JavaDoc e) {
104             s = null;
105             String JavaDoc errorMessage = "[CmsXmlPageTemplate] Error while loading xml page file " + filename + ": " + 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      * @return <code>false</code>
123      */

124     public boolean isTemplateCacheSet() {
125         return false;
126     }
127     
128     /**
129      * Method used by the ElementCache to check if the page
130      * should reload or not.<p>
131      *
132      * @param cms default argument for element cache method
133      * @param templateFile default argument for element cache method
134      * @param elementName default argument for element cache method
135      * @param parameters default argument for element cache method
136      * @param templateSelector default argument for element cache method
137      * @return <code>true</code>
138      */

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

158     public CmsCacheDirectives getCacheDirectives(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
159         // Just set caching to false
160
return new CmsCacheDirectives(false);
161     }
162 }
163
Popular Tags