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

Quick Search    Search Deep

Source code: com/opencms/core/OpenCms.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/core/Attic/OpenCms.java,v $
3   * Date   : $Date: 2004/01/06 12:45:53 $
4   * Version: $Revision: 1.124.2.1 $
5   *
6   * This library is part of OpenCms -
7   * the Open Source Content Mananagement System
8   *
9   * Copyright (C) 2001  The OpenCms Group
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 OpenCms, please see the
22  * OpenCms Website: http://www.opencms.org
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  */
28  
29  package com.opencms.core;
30  
31  import com.opencms.boot.CmsBase;
32  import com.opencms.boot.I_CmsLogChannels;
33  import com.opencms.core.exceptions.CmsCheckResourceException;
34  import com.opencms.file.CmsFile;
35  import com.opencms.file.CmsFolder;
36  import com.opencms.file.CmsObject;
37  import com.opencms.file.CmsRbManager;
38  import com.opencms.file.CmsStaticExport;
39  import com.opencms.flex.CmsJspLoader;
40  import com.opencms.flex.util.CmsResourceTranslator;
41  import com.opencms.flex.util.CmsUUID;
42  import com.opencms.launcher.CmsLauncherManager;
43  import com.opencms.launcher.I_CmsLauncher;
44  import com.opencms.template.cache.CmsElementCache;
45  import com.opencms.util.Utils;
46  import com.opencms.workplace.I_CmsWpConstants;
47  
48  import java.util.ArrayList;
49  import java.util.Hashtable;
50  import java.util.Iterator;
51  import java.util.List;
52  import java.util.Vector;
53  
54  import javax.servlet.http.HttpServletRequest;
55  import javax.servlet.http.HttpServletResponse;
56  
57  import source.org.apache.java.util.Configurations;
58  
59  /**
60   * This class is the main class of the OpenCms system,
61   * think of it as the "operating system" of OpenCms.<p>
62   *  
63   * Any request to an OpenCms resource will be processed by this class first.
64   * The class will try to map the request to a VFS (Virtual File System) resource,
65   * i.e. an URI. If the resource is found, it will be read anf forwarded to
66   * to a launcher, which is performs the output of the requested resource.<p>
67   *
68   * The OpenCms class is independent of access module to the OpenCms 
69   * (e.g. Servlet, Command Shell), therefore this class is <b>not</b> responsible 
70   * for user authentification. This is done by the access module to the OpenCms.<p>
71   *
72   * There will be only one instance of the OpenCms object created for
73   * any accessing class. This means that in the default configuration, where 
74   * OpenCms is accessed through a servlet, there will be only one instance of 
75   * this class running at a time.
76   * 
77   * @see com.opencms.core.A_OpenCms
78   * @see com.opencms.core.OpenCmsHttpServlet
79   * @see com.opencms.file.CmsObject
80   * 
81   * @author Michael Emmerich
82   * @author Alexander Lucas
83   * @author Alexander Kandzior (a.kandzior@alkacon.com)
84   * 
85   * @version $Revision: 1.124.2.1 $ $Date: 2004/01/06 12:45:53 $
86   */
87  public class OpenCms extends A_OpenCms implements I_CmsConstants, I_CmsLogChannels {
88  
89      /**
90       * The default mimetype
91       */
92      private static final String C_DEFAULT_MIMETYPE = "text/html";
93  
94      /**
95       * The cron scheduler to schedule the cronjobs
96       */
97      private CmsCronScheduler m_scheduler;
98  
99      /**
100      * The cron table to use with the scheduler
101      */
102     private CmsCronTable m_table;
103 
104     /**
105      * Reference to the OpenCms launcer manager
106      */
107     private CmsLauncherManager m_launcherManager;
108 
109     /**
110      * Hashtable with all available Mimetypes.
111      */
112     private Hashtable m_mt = new Hashtable();
113 
114     /**
115      * Indicates, if the session-failover should be enabled or not
116      */
117     private boolean m_sessionFailover = false;
118 
119     /**
120      * Indicates, if the streaming should be enabled by the configurations.
121      */
122     private boolean m_streaming = true;
123 
124     /**
125      * The name of the class used to validate a new password
126      */
127     private static String c_passwordValidatingClass = "";
128 
129     /**
130      * Indicates, if the element cache should be enabled by the configurations
131      */
132     private boolean m_enableElementCache = true;
133 
134     /**
135      * Reference to the CmsElementCache object containing locators for all
136      * URIs and elements in cache
137      */
138     private static CmsElementCache c_elementCache = null;
139 
140     /**
141      * The object to store the  properties from the opencms.property file for the
142      * static export
143      */
144     private static CmsStaticExportProperties c_exportProperties = new CmsStaticExportProperties();
145 
146     /**
147      * In this hashtable the dependencies for all variants in the elementcache
148      * are stored. The keys are Strings with resourceNames like "/siteX/cos/ContentClass/news4"
149      * and the value is a Vector with strings (The elementvariants that depend on the keys)
150      * like "ElementClass|ElementTemplate|VariantCacheKey"
151      */
152     private static Hashtable c_variantDeps = null;
153     
154     /**
155      * Directory translator, used to translate all access to resources
156      */
157     private static CmsResourceTranslator m_directoryTranslator = null;
158 
159     /**
160      * Filename translator, used only for the creation of new files
161      */
162     private static CmsResourceTranslator m_fileTranslator = null;
163     
164     /**
165      * List of default file names (for directories, e.g, "index.html")
166      */
167     private static String[] m_defaultFilenames = null;
168 
169     /**
170      * Flag to indicate if the startup classes have already been initialized
171      */
172     private boolean m_isInitialized = false;
173     
174    /**
175     * Member variable to store instances to modify resources
176     */
177    private List m_checkFile = new ArrayList();
178     
179     /**
180      * Constructor to create a new OpenCms object.<p>
181      * 
182      * It reads the configurations from the <code>opencms.properties</code>
183      * file in the <code>config/</code> subdirectory. With the information 
184      * from this file is inits a ResourceBroker (Database access module),
185      * various caching systems and other options.<p>
186      * 
187      * This will only be done once per accessing class.
188      *
189      * @param conf The configurations from the <code>opencms.properties</code> file.
190      */
191     public OpenCms(Configurations conf) throws Exception {        
192         // Save the configuration
193         setConfiguration(conf);
194 
195         // this will initialize the encoding with some default from the A_OpenCms
196         String defaultEncoding = getDefaultEncoding();
197         // check the opencms.properties for a different setting
198         defaultEncoding = conf.getString("defaultContentEncoding", defaultEncoding);
199         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". OpenCms encoding     : " + defaultEncoding);
200         String systemEncoding = null;
201         try {
202             systemEncoding = System.getProperty("file.encoding");
203         } catch (SecurityException se) {
204             // security manager is active, but we will try other options before giving up
205         }
206         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". System file.encoding : " + systemEncoding);
207         if (! defaultEncoding.equals(systemEncoding)) { 
208             String msg = "OpenCms startup failure: System file.encoding '" + systemEncoding + 
209                 "' not equal to OpenCms encoding '" + defaultEncoding + "'";
210             if(C_LOGGING && isLogging(C_OPENCMS_CRITICAL)) log(C_OPENCMS_CRITICAL, ". Critical init error/1: " + msg);
211             throw new Exception(msg);                 
212         }
213         try {
214             // check if the found encoding is supported 
215             // this will work with Java 1.4+ only
216             if (!java.nio.charset.Charset.isSupported(defaultEncoding)) {
217                 defaultEncoding = getDefaultEncoding();
218             }
219         } catch (Throwable t) {
220             // will be thrown in Java < 1.4 (NoSuchMethodException etc.)
221             // in Java < 1.4 there is no easy way to check if encoding is supported,
222             // so you must make sure your setting in "opencms.properties" is correct.             
223         }        
224         setDefaultEncoding(defaultEncoding);
225         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Encoding set to      : " + defaultEncoding);
226         
227         // Read server ethernet address (MAC) and init UUID generator
228         String ethernetAddress = conf.getString("server.ethernet.address", CmsUUID.getDummyEthernetAddress());
229         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Ethernet address used: " + ethernetAddress);
230         CmsUUID.init(ethernetAddress);
231         
232         // invoke the ResourceBroker via the initalizer
233         try {
234             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) {
235                 String jdkinfo = System.getProperty("java.vm.name") + " ";
236                 jdkinfo += System.getProperty("java.vm.version") + " ";
237                 jdkinfo += System.getProperty("java.vm.info") + " ";
238                 jdkinfo += System.getProperty("java.vm.vendor") + " ";
239                 log(C_OPENCMS_INIT, ". Java VM in use       : " + jdkinfo);
240                 String osinfo = System.getProperty("os.name") + " ";
241                 osinfo += System.getProperty("os.version") + " ";
242                 osinfo += System.getProperty("os.arch") + " ";
243                 log(C_OPENCMS_INIT, ". Operating sytem      : " + osinfo);
244             }
245             m_sessionFailover = conf.getBoolean("sessionfailover.enabled", false);
246         } catch(Exception e) {
247             if(C_LOGGING && isLogging(C_OPENCMS_CRITICAL)) log(C_OPENCMS_CRITICAL, ". Critical init error/2: " + e.getMessage());
248             // any exception here is fatal and will cause a stop in processing
249             throw e;
250         }
251         
252         try {           
253             // init the rb via the manager with the configuration
254             // and init the cms-object with the rb.
255             m_resourceBroker = CmsRbManager.init(conf);
256         } catch(Exception e) {
257             if(C_LOGGING && isLogging(C_OPENCMS_CRITICAL)) log(C_OPENCMS_CRITICAL, ". Critical init error/3: " + e.getMessage());
258             // any exception here is fatal and will cause a stop in processing
259             throw new CmsException("Database init failed", CmsException.C_RB_INIT_ERROR, e);
260         }
261         
262         try {       
263             // initalize the Hashtable with all available mimetypes
264             m_mt = m_resourceBroker.readMimeTypes(null, null);
265             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Found mime types     : " + m_mt.size() + " entrys");
266 
267             // Check, if the HTTP streaming should be enabled
268             m_streaming = conf.getBoolean("httpstreaming.enabled", true);
269             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Legacy HTTP streaming: " + (m_streaming?"enabled":"disabled"));
270 
271             // if the System property opencms.disableScheduler is set to true, don't start scheduling
272             if(!new Boolean(System.getProperty("opencms.disableScheduler")).booleanValue()) {
273                 // now initialise the OpenCms scheduler to launch cronjobs
274                 m_table = new CmsCronTable(m_resourceBroker.readCronTable(null, null));
275                 m_scheduler = new CmsCronScheduler(this, m_table);
276                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". OpenCms scheduler    : enabled");
277             } else {
278                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". OpenCms scheduler    : disabled");
279             }
280         } catch(Exception e) {
281             if(C_LOGGING && isLogging(C_OPENCMS_CRITICAL)) log(C_OPENCMS_CRITICAL, ". Critical init error/5: " + e.getMessage());
282             // any exception here is fatal and will cause a stop in processing
283             throw e;
284         }
285         
286         // read flex jsp export url property and save in runtime configuration
287         String flexExportUrl = (String)conf.getString(CmsJspLoader.C_LOADER_JSPEXPORTURL, null);
288         if (null != flexExportUrl) {
289             // if JSP export URL is null it will be set in initStartupClasses()
290             if (flexExportUrl.endsWith(C_FOLDER_SEPARATOR)) {
291                 flexExportUrl = flexExportUrl.substring(0, flexExportUrl.length()-1);
292             }
293             setRuntimeProperty(CmsJspLoader.C_LOADER_JSPEXPORTURL, flexExportUrl);
294             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". JSP export URL       : using value from opencms.properties - " + flexExportUrl);
295         }
296         
297         // read flex jsp error page commit property and save in runtime configuration
298         Boolean flexErrorPageCommit = (Boolean)conf.getBoolean(CmsJspLoader.C_LOADER_ERRORPAGECOMMIT, new Boolean(true));
299         setRuntimeProperty(CmsJspLoader.C_LOADER_ERRORPAGECOMMIT, flexErrorPageCommit);
300         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". JSP errorPage commit : " + (flexErrorPageCommit.booleanValue()?"enabled":"disabled"));      
301 
302         // read old (proprietary XML-style) locale backward compatibily support flag
303         Boolean supportOldLocales = (Boolean)conf.getBoolean("compatibility.support.oldlocales", new Boolean(false));
304         setRuntimeProperty("compatibility.support.oldlocales", supportOldLocales);
305         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Old locale support   : " + (supportOldLocales.booleanValue()?"enabled":"disabled"));      
306 
307         // convert import files from 4.x versions old webapp URL
308         String webappUrl = (String)conf.getString("compatibility.support.import.old.webappurl", null);
309         if (webappUrl != null) {
310             setRuntimeProperty("compatibility.support.import.old.webappurl", webappUrl);
311         }
312         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Old webapp URL       : " + ((webappUrl == null)?"not set!":webappUrl));      
313 
314 
315         // Unwanted resource properties which are deleted during import
316         String[] propNames = conf.getStringArray("compatibility.support.import.remove.propertytags");
317         if (propNames == null) propNames = new String[0];  
318         List propertyNamesOri = java.util.Arrays.asList(propNames);
319         ArrayList propertyNames = new ArrayList();
320         for (int i=0; i<propertyNamesOri.size(); i++) {
321             // remove possible white space
322             String name = ((String)propertyNamesOri.get(i)).trim();
323             if (name != null && ! "".equals(name)) {
324                 propertyNames.add(name);
325                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Clear import property: " + (i+1) + " - " + name );
326             }               
327         }        
328         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Remove properties    : " + ((propertyNames.size() > 0)?"enabled":"disabled"));     
329         setRuntimeProperty("compatibility.support.import.remove.propertytags", propertyNames);
330 
331         // old web application names (for editor macro replacement) 
332         String[] appNames = conf.getStringArray("compatibility.support.webAppNames");
333         if (appNames == null) appNames = new String[0];  
334         List webAppNamesOri = java.util.Arrays.asList(appNames);
335         ArrayList webAppNames = new ArrayList();
336         for (int i=0; i<webAppNamesOri.size(); i++) {
337             // remove possible white space
338             String name = ((String)webAppNamesOri.get(i)).trim();
339             if (name != null && ! "".equals(name)) {
340                 webAppNames.add(name);
341                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Old context path     : " + (i+1) + " - " + name );
342             }               
343         }        
344         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Old context support  : " + ((webAppNames.size() > 0)?"enabled":"disabled"));     
345         setRuntimeProperty("compatibility.support.webAppNames", webAppNames);
346        
347         // Immutable import resources
348         String[] immuResources = conf.getStringArray("import.immutable.resources");
349         if (immuResources == null) immuResources = new String[0];  
350         List immutableResourcesOri = java.util.Arrays.asList(immuResources);
351         ArrayList immutableResources = new ArrayList();
352         for (int i=0; i<immutableResourcesOri.size(); i++) {
353             // remove possible white space
354             String path = ((String)immutableResourcesOri.get(i)).trim();
355             if (path != null && ! "".equals(path)) {
356                 immutableResources.add(path);
357                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Immutable resource   : " + (i+1) + " - " + path );
358             }               
359         }        
360         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Immutable resources  : " + ((immutableResources.size() > 0)?"enabled":"disabled"));     
361         setRuntimeProperty("import.immutable.resources", immutableResources);       
362        
363         // try to initialize directory translations
364         try {
365             boolean translationEnabled = conf.getBoolean("directory.translation.enabled", false);
366             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Directory translation: " + (translationEnabled?"enabled":"disabled"));
367             if (translationEnabled) {
368                 String[] translations = conf.getStringArray("directory.translation.rules");
369                 // Directory translation stops after fist match, hence the "false" parameter
370                 m_directoryTranslator = new CmsResourceTranslator(translations, false);        
371             }
372         } catch(Exception e) {
373             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Directory translation: non-critical error " + e.toString());
374         }   
375         // make sure we always have at least an empty array      
376         if (m_directoryTranslator == null) m_directoryTranslator = new CmsResourceTranslator(new String[0], false);
377         
378         // read the maximum file upload size limit
379         Integer fileMaxUploadSize = new Integer(conf.getInteger("workplace.file.maxuploadsize", -1));
380         setRuntimeProperty("workplace.file.maxuploadsize", fileMaxUploadSize);
381         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". File max. upload size: " + (fileMaxUploadSize.intValue()>0?(fileMaxUploadSize+" KB"):"unlimited"));
382         
383         // try to initialize filename translations
384         try {
385             boolean translationEnabled = conf.getBoolean("filename.translation.enabled", false);
386             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Filename translation : " + (translationEnabled?"enabled":"disabled"));
387             if (translationEnabled) {
388                 String[] translations = conf.getStringArray("filename.translation.rules");
389                 // Filename translations applies all rules, hence the true patameters
390                 m_fileTranslator = new CmsResourceTranslator(translations, true);        
391             }
392         } catch(Exception e) {
393             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Filename translation : non-critical error " + e.toString());
394         }           
395         // make sure we always have at last an emtpy array      
396         if (m_fileTranslator == null) m_fileTranslator = new CmsResourceTranslator(new String[0], false);
397                     
398         // try to initialize default file names
399         try {
400             m_defaultFilenames = conf.getStringArray("directory.default.files");
401             for (int i=0; i<m_defaultFilenames.length; i++) {
402                 // remove possible white space
403                 m_defaultFilenames[i] = m_defaultFilenames[i].trim();
404                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Default file         : " + (i+1) + " - " + m_defaultFilenames[i] );               
405             }
406         } catch(Exception e) {
407             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Default file         : non-critical error " + e.toString());
408         }    
409         // make sure we always have at last an emtpy array      
410         if (m_defaultFilenames == null) m_defaultFilenames = new String[0];                
411                 
412         // try to initialize the flex cache
413         try {
414             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Flex cache init      : starting");
415             // com.opencms.flex.cache.CmsFlexCache flexCache = new com.opencms.flex.cache.CmsFlexCache(this);
416             // the flexCache has static members that must be initialized with "this" object
417             new com.opencms.flex.cache.CmsFlexCache(this);
418             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Flex cache init      : finished");
419         } catch(Exception e) {
420             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Flex cache init      : non-critical error " + e.toString());
421         }        
422         
423         // try to initialize the launchers.
424         try {
425             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Launcher init        : starting");
426             m_launcherManager = new CmsLauncherManager(this);
427             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Launcher init        : finished");
428         } catch(Exception e) {
429             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Launcher init        : non-critical error " + e.toString());
430         }
431 
432         // get the password validating class
433         c_passwordValidatingClass = conf.getString("passwordvalidatingclass", "com.opencms.util.PasswordValidtation");
434         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Password validation  : " + c_passwordValidatingClass);
435         
436         // read the default user settings
437         try {
438             int userDefaultAccessFlags = conf.getInteger("workplace.user.default.flags", C_ACCESS_DEFAULT_FLAGS);
439             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". User permission init : Default access flags are " + userDefaultAccessFlags);
440             setUserDefaultAccessFlags(userDefaultAccessFlags);
441             String userDefaultLanguage = conf.getString("workplace.user.default.language", I_CmsWpConstants.C_DEFAULT_LANGUAGE);
442             setUserDefaultLanguage(userDefaultLanguage);
443             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". User permission init : Default language is '" + userDefaultLanguage + "'");
444         } catch(Exception e) {
445             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". User permission init : non-critical error " + e.toString());
446         }
447 
448         // Check, if the element cache should be enabled
449         m_enableElementCache = conf.getBoolean("elementcache.enabled", false);
450         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Element cache        : " + (m_enableElementCache?"enabled":"disabled"));
451         if(m_enableElementCache) {
452             try {
453                 c_elementCache = new CmsElementCache(conf.getInteger("elementcache.uri", 10000),
454                                                     conf.getInteger("elementcache.elements", 50000),
455                                                     conf.getInteger("elementcache.variants", 100));
456             }catch(Exception e) {
457                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Element cache        : non-critical error " + e.toString());
458             }
459             c_variantDeps = new Hashtable();
460             c_elementCache.getElementLocator().setExternDependencies(c_variantDeps);
461         }
462         // now for the link replacement rules there are up to three rulesets for export online and offline
463         try{
464             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Link rules init      : starting");
465             
466             String[] staticUrlPrefix = new String[4];
467             staticUrlPrefix[0]=Utils.replace(conf.getString(C_URL_PREFIX_EXPORT, ""), C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
468             staticUrlPrefix[1]=Utils.replace(conf.getString(C_URL_PREFIX_HTTP, ""), C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
469             staticUrlPrefix[2]=Utils.replace(conf.getString(C_URL_PREFIX_HTTPS, ""), C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
470             staticUrlPrefix[3]=Utils.replace(conf.getString(C_URL_PREFIX_SERVERNAME, ""), C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
471             c_exportProperties.setUrlPrefixArray(staticUrlPrefix);
472             // to get the right rulesets we need the default value for the export property
473             String exportDefault = conf.getString("staticexport.default.export", "true");
474             c_exportProperties.setExportDefaultValue(exportDefault);
475             String export = conf.getString("linkrules."+exportDefault+".export");
476             String[] linkRulesExport;
477             if(export != null && !"".equals(export)){
478                 linkRulesExport = conf.getStringArray("ruleset."+export);
479                 // now replace ${WEB_APP_NAME} with the correct name of the webapplication and replace the other variables
480                 for(int i = 0; i < linkRulesExport.length; i++) {
481                     linkRulesExport[i] = Utils.replace(linkRulesExport[i], C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
482                     linkRulesExport[i] = Utils.replace(linkRulesExport[i], "${"+C_URL_PREFIX_EXPORT+"}", staticUrlPrefix[0]);
483                     linkRulesExport[i] = Utils.replace(linkRulesExport[i], "${"+C_URL_PREFIX_HTTP+"}", staticUrlPrefix[1]);
484                     linkRulesExport[i] = Utils.replace(linkRulesExport[i], "${"+C_URL_PREFIX_HTTPS+"}", staticUrlPrefix[2]);
485                     linkRulesExport[i] = Utils.replace(linkRulesExport[i], "${"+C_URL_PREFIX_SERVERNAME+"}", staticUrlPrefix[3]);
486                 }
487                 c_exportProperties.setLinkRulesExport(linkRulesExport);
488             }
489             String online = conf.getString("linkrules."+exportDefault+".online");
490             String[] linkRulesOnline;
491             if(online != null && !"".equals(online)){
492                 linkRulesOnline = conf.getStringArray("ruleset."+online);
493                 // now replace ${WEB_APP_NAME} with the correct name of the webapplication and replace the other variables
494                 for(int i = 0; i < linkRulesOnline.length; i++) {
495                     linkRulesOnline[i] = Utils.replace(linkRulesOnline[i], C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
496                     linkRulesOnline[i] = Utils.replace(linkRulesOnline[i], "${"+C_URL_PREFIX_EXPORT+"}", staticUrlPrefix[0]);
497                     linkRulesOnline[i] = Utils.replace(linkRulesOnline[i], "${"+C_URL_PREFIX_HTTP+"}", staticUrlPrefix[1]);
498                     linkRulesOnline[i] = Utils.replace(linkRulesOnline[i], "${"+C_URL_PREFIX_HTTPS+"}", staticUrlPrefix[2]);
499                     linkRulesOnline[i] = Utils.replace(linkRulesOnline[i], "${"+C_URL_PREFIX_SERVERNAME+"}", staticUrlPrefix[3]);
500                 }
501                 c_exportProperties.setLinkRulesOnline(linkRulesOnline);
502             }
503             String offline = conf.getString("linkrules."+exportDefault+".offline");
504             String[] linkRulesOffline;
505             if(offline != null && !"".equals(offline)){
506                 linkRulesOffline = conf.getStringArray("ruleset."+offline);
507                 // now replace ${WEB_APP_NAME} with the correct name of the webapplication and replace the other variables
508                 for(int i = 0; i < linkRulesOffline.length; i++) {
509                     linkRulesOffline[i] = Utils.replace(linkRulesOffline[i], C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
510                     linkRulesOffline[i] = Utils.replace(linkRulesOffline[i], "${"+C_URL_PREFIX_EXPORT+"}", staticUrlPrefix[0]);
511                     linkRulesOffline[i] = Utils.replace(linkRulesOffline[i], "${"+C_URL_PREFIX_HTTP+"}", staticUrlPrefix[1]);
512                     linkRulesOffline[i] = Utils.replace(linkRulesOffline[i], "${"+C_URL_PREFIX_HTTPS+"}", staticUrlPrefix[2]);
513                     linkRulesOffline[i] = Utils.replace(linkRulesOffline[i], "${"+C_URL_PREFIX_SERVERNAME+"}", staticUrlPrefix[3]);
514                 }
515                 c_exportProperties.setLinkRulesOffline(linkRulesOffline);
516             }
517             String extern = conf.getString("linkrules."+exportDefault+".extern");
518             String[] linkRulesExtern;
519             if(extern != null && !"".equals(extern)){
520                 linkRulesExtern = conf.getStringArray("ruleset."+extern);
521                 // now replace ${WEB_APP_NAME} with the correct name of the webapplication and replace the other variables
522                 for(int i = 0; i < linkRulesExtern.length; i++) {
523                     linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
524                     linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_EXPORT+"}", staticUrlPrefix[0]);
525                     linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_HTTP+"}", staticUrlPrefix[1]);
526                     linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_HTTPS+"}", staticUrlPrefix[2]);
527                     linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_SERVERNAME+"}", staticUrlPrefix[3]);
528                 }
529                 c_exportProperties.setLinkRulesExtern(linkRulesExtern);
530             }
531             c_exportProperties.setStartRule(null); // temporary out of order: conf.getString("exportfirstrule");
532 
533             Vector staticExportStart=new Vector();
534             staticExportStart.add("/");
535             c_exportProperties.setStartPoints(staticExportStart);
536 
537             // at last the target for the export
538             c_exportProperties.setExportPath( com.opencms.boot.CmsBase.getAbsoluteWebPath(CmsBase.getAbsoluteWebPath(conf.getString(C_STATICEXPORT_PATH))));
539 
540             // should the links in static export be relative?
541             c_exportProperties.setExportRelativeLinks(conf.getBoolean("relativelinks_in_export", false));
542             // is the static export enabled?
543             String activCheck = conf.getString("staticexport.enabled", "false");
544             c_exportProperties.setStaticExportEnabledValue(activCheck);
545             if("true".equalsIgnoreCase(activCheck)){
546                 c_exportProperties.setStaticExportEnabled(true);
547             }else{
548                 c_exportProperties.setStaticExportEnabled(false);
549             }
550             if(c_exportProperties.isStaticExportEnabled()){
551                 // we have to generate the dynamic rulessets
552                 createDynamicLinkRules();
553             }else{
554                 if("false_ssl".equalsIgnoreCase(activCheck)){
555                     // no static esport, but we need the dynamic rules for setting the protokoll to https
556                     c_exportProperties.setLinkRulesOffline(new String[]{"s#^#" + staticUrlPrefix[1] + "#"});
557                     c_exportProperties.setLinkRulesOnline(new String[]{"*dynamicRules*", "s#^#" + staticUrlPrefix[1] + "#"});
558                     // and we have to change the standart export prefix to stay in opencms
559                     c_exportProperties.getUrlPrefixArray()[0] = staticUrlPrefix[1];
560                     // if we need them we should create them
561                     createDynamicLinkRules();
562                 }else{
563                     // no static export. We need online and offline rules to stay in OpenCms.
564                     // we generate them with the url_prefix_http so the user can still configure
565                     // the servletpath.
566                     c_exportProperties.setLinkRulesOffline(new String[]{"s#^#" + staticUrlPrefix[1] + "#"});
567                     c_exportProperties.setLinkRulesOnline(new String[]{"s#^#" + staticUrlPrefix[1] + "#"});
568                 }
569             }
570             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Link rules init      : finished");
571         }catch(Exception e){
572             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Link rules init      : non-critical error " + e.toString());
573         }
574         
575         // initialize 1 instance per class listed in the checkresource node
576         try{
577             Hashtable checkresourceNode = getRegistry().getSystemValues( "checkresource" );
578             if (checkresourceNode!=null) {
579                 for (int i=1;i<=checkresourceNode.size();i++) {
580                     String currentClass = (String)checkresourceNode.get( "class" + i );
581                     try {
582                         m_checkFile.add(Class.forName(currentClass).newInstance());
583                              if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Checkfile class init : " + currentClass + " instanciated");
584                     } catch (Exception e1){
585                         if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Checkfile class init : non-critical error " + e1.toString());
586                     }
587                 }
588             }
589         } catch (Exception e2){
590             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Checkfile class init : non-critical error " + e2.toString());
591         }
592     }
593 
594     /**
595      * Creates the dynamic linkrules.
596      * The CmsStaticExport class needs a CmsObject to create them.
597      */
598     private void createDynamicLinkRules(){
599         //create a valid cms-object
600         CmsObject cms = new CmsObject();
601         try{
602             initUser(cms, null, null, C_USER_ADMIN, C_GROUP_ADMIN, C_PROJECT_ONLINE_ID, null);
603             new CmsStaticExport(cms, null, false, null, null, null, null);
604         }catch(Exception e){
605             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Dynamic link rules   : non-critical error " + e.toString());
606         }
607     }
608     
609     /**
610      * Initialize the startup classes of this OpenCms object.<p>
611      * 
612      * A startup class has to be configured in the <code>registry.xml</code> 
613      * file of OpenCms. Startup classes are a way to create plug-in 
614      * functions that required to be initialized once at OpenCms load time 
615      * without the need to add initializing code to the constructor of this 
616      * class.<p>
617      * 
618      * This must be done only once per running OpenCms object instance.
619      * Usually this will be done by the OpenCms servlet.
620      * 
621      * @param req the current request
622      * @param res the current response 
623      */
624     void initStartupClasses(HttpServletRequest req, HttpServletResponse res) throws CmsException {
625         if (m_isInitialized) return;
626 
627         synchronized (this) {
628             // Set the initialized flag to true
629             m_isInitialized = true;
630             
631             if (res == null) {
632                 // currently no init action depends on res, this might change in the future
633             }
634     
635             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : starting");
636     
637             // set context once and for all
638             String context = req.getContextPath() + req.getServletPath();
639             if (! context.endsWith("/")) context += "/";
640             A_OpenCms.setOpenCmsContext(context);
641             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". OpenCms context      : " + context);
642             
643             // check for old webapp names and extend with context
644             ArrayList webAppNames = (ArrayList)A_OpenCms.getRuntimeProperty("compatibility.support.webAppNames");
645             if (webAppNames == null) {
646                 webAppNames = new ArrayList();
647             } 
648             if (! webAppNames.contains(context)) {
649                 webAppNames.add(context);
650                 setRuntimeProperty("compatibility.support.webAppNames", webAppNames);
651             }            
652     
653             // check for the JSP export URL runtime property
654             String jspExportUrl = (String)getRuntimeProperty(CmsJspLoader.C_LOADER_JSPEXPORTURL);
655             if (jspExportUrl == null) {
656                 StringBuffer url = new StringBuffer(256);
657                 url.append(req.getScheme());
658                 url.append("://");
659                 url.append(req.getServerName());
660                 url.append(":");
661                 url.append(req.getServerPort());
662                 url.append(context);        
663                 String flexExportUrl = new String(url);    
664                 // check if the URL ends with a "/", this is not allowed
665                 if (flexExportUrl.endsWith(C_FOLDER_SEPARATOR)) {
666                     flexExportUrl = flexExportUrl.substring(0, flexExportUrl.length()-1);
667                 }
668                 setRuntimeProperty(CmsJspLoader.C_LOADER_JSPEXPORTURL, flexExportUrl);
669                 CmsJspLoader.setJspExportUrl(flexExportUrl);
670                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". JSP export URL       : using value from first request - " + flexExportUrl);
671             }
672             
673     
674             // initialize 1 instance per class listed in the startup node
675             try{
676                 Hashtable startupNode = getRegistry().getSystemValues( "startup" );
677                 if (startupNode!=null) {
678                     for (int i=1;i<=startupNode.size();i++) {
679                         String currentClass = (String)startupNode.get( "class" + i );
680                         try {
681                             Class.forName(currentClass).newInstance();
682     
683                             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : " + currentClass + " instanciated");
684                         } catch (Exception e1){
685                             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : non-critical error " + e1.toString());
686                         }
687                     }
688                 }
689             } catch (Exception e2){
690                 if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : non-critical error " + e2.toString());
691             }
692             
693             if(C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_INIT)) {
694                 A_OpenCms.log(C_OPENCMS_INIT, ". Startup class init   : finished");
695                 A_OpenCms.log(C_OPENCMS_INIT, ".                      ...............................................................");        
696                 A_OpenCms.log(C_OPENCMS_INIT, ".");        
697             }    
698         }
699     }
700 
701     /**
702      * Destructor, called when the the servlet is shut down.
703      * 
704      * @throws CmsException If something goes wrong during shutdown.
705      */
706     public void destroy() throws CmsException {
707         if (m_scheduler!=null) {
708             m_scheduler.shutDown();
709         }
710         
711         if (m_resourceBroker!=null) {
712             CmsObject cms = new CmsObject();
713             cms.init(m_resourceBroker);
714             cms.destroy();
715         }
716     }
717 
718     /**
719      * Returns the launcher manager used.
720      * 
721      * @return The launcher manager used.
722      */
723     public CmsLauncherManager getLauncherManager() {
724         return m_launcherManager;
725     }
726 
727     /**
728      * Returns the ElementCache used for the online project.
729      * 
730      * @return The ElementCache used for the online project.
731      */
732     public static CmsElementCache getOnlineElementCache(){
733         return c_elementCache;
734     }
735 
736     /**
737      * Returns the Class that is used for the password validation.
738      * 
739      * @return The Class that is used for the password validation.
740      */
741     public static String getPasswordValidatingClass(){
742         return c_passwordValidatingClass;
743     }
744 
745     /**
746      * Returns the properties for the static export.
747      * 
748      * @return The properties for the static export.
749      */
750     public static CmsStaticExportProperties getStaticExportProperties(){
751         return c_exportProperties;
752     }
753 
754     /**
755      * Returns the hashtable with the variant dependencies used for the elementcache.
756      * 
757      * @return The hashtable with the variant dependencies used for the elementcache.
758      */
759     public static Hashtable getVariantDependencies(){
760         return c_variantDeps;
761     }
762     
763     /**
764      * Returns the file name translator this OpenCms has read from the opencms.properties.
765      * 
766      * @return The file name translator this OpenCms has read from the opencms.properties
767      */
768     public CmsResourceTranslator getFileTranslator() {
769         return m_fileTranslator;
770     } 
771     
772     /**
773      * This method reads the requested document from the OpenCms request context
774      * and returns it to the calling module, which will usually be 
775      * the running OpenCmsHttpServlet.<p>
776      * 
777      * In case a directory name is requested, the default files of the 
778      * directory will be looked up and the first match is returned.
779      *
780      * @param cms the current CmsObject
781      * @return CmsFile the requested file read from the VFS
782      * 
783      * @throws CmsException in case the file does not exist or the user has insufficient access permissions 
784      */
785   CmsFile initResource(CmsObject cms) throws CmsException {
786 
787     CmsFile file = null;
788     // Get the requested filename from the request context
789     String resourceName = cms.getRequestContext().getUri();
790 
791     try {
792       // Try to read the requested file
793       file = cms.readFile(resourceName);
794     } catch (CmsException e) {
795       if (e.getType() == CmsException.C_NOT_FOUND) {
796         // The requested file was not found
797         // Check if a folder name was requested, and if so, try
798         // to read the default pages in that folder
799 
800         try {
801           // Try to read the requested resource name as a folder
802           CmsFolder folder = cms.readFolder(resourceName);
803                     // If above call did not throw an exception the folder
804                     // was sucessfully read, so lets go on check for default 
805                     // pages in the folder now
806                     
807                     // Check if C_PROPERTY_DEFAULT_FILE is set on folder
808                     String defaultFileName = cms.readProperty(folder.getPath(), I_CmsConstants.C_PROPERTY_DEFAULT_FILE);
809                     if (defaultFileName != null) {
810                         // Property was set, so look up this file first
811                         String tmpResourceName = folder.getPath() + defaultFileName;
812                         try {
813                             file = cms.readFile(tmpResourceName);
814                             // No exception? So we have found the default file                         
815                             cms.getRequestContext().getRequest().setRequestedResource(tmpResourceName);                    
816                         } catch (CmsException exc) {                           
817                             if (exc.getType() == CmsException.C_NO_ACCESS) {
818                                 // Maybe no access to default file?
819                                 throw exc;
820                             }
821                         }                        
822                     }
823                     if (file == null) {
824                         // No luck with the property, so check default files specified in opencms.properties (if required)         
825                         for (int i=0; i<m_defaultFilenames.length; i++) {
826                             String tmpResourceName = folder.getPath() + m_defaultFilenames[i];
827                             try {
828                                 file = cms.readFile(tmpResourceName);
829                                 // No exception? So we have found the default file                         
830                                 cms.getRequestContext().getRequest().setRequestedResource(tmpResourceName);
831                                 // Stop looking for default files   
832                                 break;                     
833                             } catch (CmsException exc) {                           
834                                 if (exc.getType() == CmsException.C_NO_ACCESS) {
835                                     // Maybe no access to default file?
836                                     throw exc;
837                                 }
838                                 // Otherwise just continue looking for files
839                             }                                                
840                         }       
841                     }                    
842                     if (file == null) {
843                         // No default file was found, throw original exception
844                         throw e;
845                     }                                                     
846         } catch (CmsException ex) {
847                     // Exception trying to read the folder (or it's properties)
848           if (ex.getType() == CmsException.C_NOT_FOUND) {
849                         // Folder with the name does not exist, throw original exception
850                         throw e;
851                     }
852                     // If the folder was found there might have been a permission problem
853                     throw ex;
854         }
855 
856       } else {
857         // Throw the CmsException (possible cause e.g. no access permissions)
858         throw e;
859       }
860     }
861 
862     if (file != null) {
863       // test if this file is only available for internal access operations
864       if ((file.getAccessFlags() & C_ACCESS_INTERNAL_READ) > 0) {
865         throw new CmsException(
866           CmsException.C_EXTXT[CmsException.C_INTERNAL_FILE]
867             + cms.getRequestContext().getUri(),
868           CmsException.C_INTERNAL_FILE);
869       }
870             // test if this file has to be checked or modified
871             Iterator i = m_checkFile.iterator();
872             while (i.hasNext()) {
873                 try {
874                     file = ((I_CmsCheckResource) i.next()).checkResource(file, cms);
875                 // the loop has to be interrupted when the exception is thrown!
876                 } catch (CmsCheckResourceException e) {
877                     break;
878                 }
879             }
880     }
881         
882         // Return the file read from the VFS
883     return file;
884   }
885 
886     /**
887      * Inits a user and updates the given CmsObject withs this users information.<p>
888      * 
889      * @param cms The CmsObject to update
890      * @param cmsReq The current I_CmsRequest (usually initialized form the HttpServletRequest)
891      * @param cmsRes The current I_CmsResponse (usually initialized form the HttpServletResponse)
892      * @param user The name of the user to init
893      * @param group The name of the current group
894      * @param project The id of the current project
895      * @param sessionStorage The session storage for this OpenCms instance
896      */
897     public void initUser(CmsObject cms, I_CmsRequest cmsReq, I_CmsResponse cmsRes, String user,
898             String group, int project, CmsCoreSession sessionStorage) throws CmsException {
899 
900         if((!m_enableElementCache) || (project == C_PROJECT_ONLINE_ID)){
901             cms.init(m_resourceBroker, cmsReq, cmsRes, user, group, project, m_streaming, c_elementCache, sessionStorage, m_directoryTranslator, m_fileTranslator);
902         }else{
903             cms.init(m_resourceBroker, cmsReq, cmsRes, user, group, project, m_streaming, new CmsElementCache(10,200,10), sessionStorage, m_directoryTranslator, m_fileTranslator);
904         }
905     }
906 
907     /**
908      * Sets the mimetype of the response.<p>
909      * 
910      * The mimetype is selected by the file extension of the requested document.
911      * If no available mimetype is found, it is set to the default
912      * "application/octet-stream".
913      *
914      * @param cms The current initialized CmsObject
915      * @param file The requested document
916      */
917     void setResponse(CmsObject cms, CmsFile file) {
918         String mimetype = null;
919         int lastDot = file.getName().lastIndexOf(".");
920         // check if there was a file extension
921         if((lastDot > 0) && (lastDot < (file.getName().length()-1))) {
922             String ext = file.getName().substring(lastDot + 1, file.getName().length());
923             mimetype = (String)m_mt.get(ext);
924             // was there a mimetype fo this extension?
925             if(mimetype == null) {
926                 mimetype = C_DEFAULT_MIMETYPE;
927             }
928         } else {
929             mimetype = C_DEFAULT_MIMETYPE;
930         }
931         mimetype = mimetype.toLowerCase();
932         if (mimetype.startsWith("text")
933             && (mimetype.indexOf("charset") == -1)) {
934             mimetype += "; charset=" + cms.getRequestContext().getEncoding();
935         }
936         cms.getRequestContext().getResponse().setContentType(mimetype);
937     }
938 
939     /**
940      * Selects the appropriate launcher for a given file by analyzing the
941      * file's launcher id and calls the initlaunch() method to initiate the
942      * generating of the output.
943      *
944      * @param cms CmsObject containing all document and user information
945      * @param file CmsFile object representing the selected file.
946      * @throws CmsException In case of problems acessing the resource.
947      */
948     public void showResource(CmsObject cms, CmsFile file) throws CmsException {
949         int launcherId = file.getLauncherType();
950         String startTemplateClass = file.getLauncherClassname();
951         I_CmsLauncher launcher = m_launcherManager.getLauncher(launcherId);
952         if(launcher == null) {
953             String errorMessage = "Could not launch file " + file.getName() + ". Launcher for requested launcher ID "
954                     + launcherId + " could not be found.";
955             if(C_LOGGING && isLogging(C_OPENCMS_INFO)) {
956                 log(C_OPENCMS_INFO, "[OpenCms] " + errorMessage);
957             }
958             throw new CmsException(errorMessage, CmsException.C_UNKNOWN_EXCEPTION);
959         }
960         cms.setLauncherManager(m_launcherManager);
961         launcher.initlaunch(cms, file, startTemplateClass, this);
962     }
963 
964     /**
965      * This method loads old sessiondata from the database. It is used
966      * for session failover.
967      *
968      * @param oldSessionId the id of the old session.
969      * @return the old sessiondata.
970      */
971     Hashtable restoreSession(String oldSessionId) throws CmsException {
972         // is session-failopver enabled?
973         if(m_sessionFailover) {
974             // yes
975             return m_resourceBroker.restoreSession(oldSessionId);
976         }
977         else {
978             // no - do nothing
979             return null;
980         }
981     }
982     
983     /**
984      * This method stores sessiondata into the database. It is used
985      * for session failover.
986      *
987      * @param sessionId the id of the session.
988      * @param isNew determines, if the session is new or not.
989      * @return data the sessionData.
990      */
991     void storeSession(String sessionId, Hashtable sessionData) throws CmsException {
992         // is session failover enabled?
993         if(m_sessionFailover) {
994             // yes
995             m_resourceBroker.storeSession(sessionId, sessionData);
996         }
997     }
998 
999     /**
1000     * Starts a schedule job with a correct instantiated CmsObject.
1001     * 
1002     * @param entry the CmsCronEntry to start.
1003     */
1004    void startScheduleJob(CmsCronEntry entry) {
1005        // create a valid cms-object
1006        CmsObject cms = new CmsObject();
1007        try {
1008            initUser(cms, null, null, entry.getUserName(), entry.getGroupName(), C_PROJECT_ONLINE_ID, null);
1009            // create a new ScheduleJob and start it
1010            CmsCronScheduleJob job = new CmsCronScheduleJob(cms, entry);
1011            job.start();
1012        } catch(Exception exc) {
1013            if(C_LOGGING && isLogging(C_OPENCMS_CRONSCHEDULER)) {
1014                log(C_OPENCMS_CRONSCHEDULER, "Error initialising job for " + entry + " Error: " + Utils.getStackTrace(exc));
1015            }
1016        }
1017    }
1018
1019    /**
1020     * Reads the actual entries from the database and updates the Crontable
1021     */
1022    void updateCronTable() {
1023        try {
1024            m_table.update(m_resourceBroker.readCronTable(null, null));
1025        } catch(Exception exc) {
1026            if(C_LOGGING && isLogging(C_OPENCMS_CRITICAL)) {
1027                log(C_OPENCMS_CRITICAL, "[OpenCms] crontable corrupt. Scheduler is now disabled!");
1028            }
1029        }
1030    }
1031}