001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.main;
029
030import org.opencms.file.CmsObject;
031import org.opencms.i18n.CmsEncoder;
032import org.opencms.jsp.util.I_CmsJspDeviceSelector;
033import org.opencms.mail.CmsMailSettings;
034import org.opencms.util.CmsFileUtil;
035import org.opencms.util.CmsStringUtil;
036
037import java.io.File;
038import java.util.Collections;
039import java.util.Map;
040import java.util.Properties;
041import java.util.TreeMap;
042
043/**
044 * Provides access to system wide "read only" information about the running OpenCms instance.<p>
045 *
046 * Contains information about:
047 * <ul>
048 * <li>version and build number</li>
049 * <li>server name</li>
050 * <li>mail settings</li>
051 * <li>configuration paths</li>
052 * <li>default character encoding</li>
053 * <li>...and more.</li>
054 * </ul>
055 *
056 * @since 6.0.0
057 */
058public class CmsSystemInfo {
059
060    /**
061     * Wrapper class used to access build information.<p>
062     */
063    public class BuildInfoItem {
064
065        /** The key name. */
066        private String m_keyName;
067
068        /** The nice name for display. */
069        private String m_niceName;
070
071        /** The build information value. */
072        private String m_value;
073
074        /**
075         * Creates a new instance wrapping a build info string array.<p>
076         *
077         * @param value the value
078         * @param niceName the nice name
079         * @param keyName the key name
080         */
081        public BuildInfoItem(String value, String niceName, String keyName) {
082
083            m_value = value;
084            m_niceName = niceName;
085            m_keyName = keyName;
086        }
087
088        /**
089         * Gets the key name for this build info item.<p>
090         *
091         * @return the value
092         */
093        public String getKeyName() {
094
095            return m_keyName;
096        }
097
098        /**
099         * Gets the nice name for this build info item.<p>
100         *
101         * @return the nice name
102         */
103        public String getNiceName() {
104
105            return m_niceName;
106        }
107
108        /**
109         * Gets the value for this build info item.<p>
110         *
111         * @return the value
112         */
113        public String getValue() {
114
115            return m_value;
116        }
117    }
118
119    /** Name of the config folder property provides as Java VM parameter -Dopencms.config=.*/
120    public static final String CONFIG_FOLDER_PROPERTY = "opencms.config";
121
122    /** Relative path to persistence.xml file. */
123    public static final String FILE_PERSISTENCE = "classes"
124        + File.separatorChar
125        + "META-INF"
126        + File.separatorChar
127        + "persistence.xml";
128
129    /** The name of the opencms.properties file. */
130    public static final String FILE_PROPERTIES = "opencms.properties";
131
132    /** The name of the opencms.tld file. */
133    public static final String FILE_TLD = "opencms.tld";
134
135    /** Path to the default "config" folder relative to the "WEB-INF" directory of the application. */
136    public static final String FOLDER_CONFIG_DEFAULT = "config" + File.separatorChar;
137
138    /** The name of the module folder in the package path. */
139    public static final String FOLDER_MODULES = "modules" + File.separatorChar;
140
141    /** Path to the "packages" folder relative to the "WEB-INF" directory of the application. */
142    public static final String FOLDER_PACKAGES = "packages" + File.separatorChar;
143
144    /** Path to the "WEB-INF" folder relative to the directory of the application. */
145    public static final String FOLDER_WEBINF = "WEB-INF" + File.separatorChar;
146
147    /** The workplace UI servlet name. */
148    public static final String WORKPLACE_PATH = "/workplace";
149
150    /** Default encoding. */
151    private static final String DEFAULT_ENCODING = CmsEncoder.ENCODING_UTF_8;
152
153    /** Static version id to use if version.properties can not be read. */
154    private static final String DEFAULT_VERSION_ID = "Static";
155
156    /** Static version number to use if version.properties can not be read. */
157    private static final String DEFAULT_VERSION_NUMBER = "9.x.y";
158
159    /** The VFS config files folder. */
160    public static final String VFS_CONFIG_FOLDER = "/system/config/";
161
162    /** The folder to contain configuration file overrides. */
163    public static final String VFS_CONFIG_OVERRIDE_FOLDER = VFS_CONFIG_FOLDER + "overrides/";
164
165    /** The list of additional version information that was contained in the version.properties file. */
166    private Map<String, BuildInfoItem> m_buildInfo;
167
168    /** The absolute path to the "opencms.properties" configuration file (in the "real" file system). */
169    private String m_configurationFileRfsPath;
170
171    /** Default encoding, can be set in opencms-system.xml. */
172    private String m_defaultEncoding;
173
174    /** The device selector instance. */
175    private I_CmsJspDeviceSelector m_deviceSelector;
176
177    /** Indicates if the version history is enabled. */
178    private boolean m_historyEnabled;
179
180    /** The maximum number of entries in the version history (per resource). */
181    private int m_historyVersions;
182
183    /** The maximum number of versions in the VFS version history for deleted resources. */
184    private int m_historyVersionsAfterDeletion;
185
186    /** The HTTP basic authentication settings. */
187    private CmsHttpAuthenticationSettings m_httpAuthenticationSettings;
188
189    /** The settings for the internal OpenCms email service. */
190    private CmsMailSettings m_mailSettings;
191
192    /** The project in which time stamps for the content notification are read. */
193    private String m_notificationProject;
194
195    /** The duration after which responsible resource owners will be notified about out-dated content (in days). */
196    private int m_notificationTime;
197
198    /** The absolute path to the "packages" folder (in the "real" file system). */
199    private String m_packagesRfsPath;
200
201    /** The absolute path to the persistence.xml file (in the "real" file system). */
202    private String m_persistenceFileRfsPath;
203
204    /** True if detail contents are restricted to detail pages from the same site. */
205    private boolean m_restrictDetailContents;
206
207    /** The name of the OpenCms server. */
208    private String m_serverName;
209
210    /** The servlet container specific settings. */
211    private CmsServletContainerSettings m_servletContainerSettings;
212
213    /** The startup time of this OpenCms instance. */
214    private long m_startupTime;
215
216    /** The static resource version parameter. */
217    private String m_staticResourcePathFragment;
218
219    /** The version identifier of this OpenCms installation, contains "OpenCms/" and the version number. */
220    private String m_version;
221
222    /** The version ID of this OpenCms installation, usually set by the build system. */
223    private String m_versionId;
224
225    /** The version number of this OpenCms installation. */
226    private String m_versionNumber;
227
228    /**
229     * Creates a new system info container.<p>
230     */
231    public CmsSystemInfo() {
232
233        // set startup time
234        m_startupTime = System.currentTimeMillis();
235        // init version information
236        initVersion();
237        // set default encoding (will be changed again later when properties have been read)
238        m_defaultEncoding = DEFAULT_ENCODING.intern();
239        // this may look odd, but initMembers in OpenCms core has to initialize this (e.g. for setup to avoid NPE)
240        m_servletContainerSettings = new CmsServletContainerSettings(null);
241    }
242
243    /**
244     * Returns an absolute path (to a directory or a file in the "real" file system) from a path relative to
245     * the web application folder of OpenCms.<p>
246     *
247     * If the provided path is already absolute, then it is returned unchanged.
248     * If the provided path is a folder, the result will always end with a folder separator.<p>
249     *
250     * @param path the path (relative) to generate an absolute path from
251     * @return an absolute path (to a directory or a file) from a path relative to the web application folder of OpenCms
252     */
253    public String getAbsoluteRfsPathRelativeToWebApplication(String path) {
254
255        if ((path == null) || (getWebApplicationRfsPath() == null)) {
256            return null;
257        }
258        // check for absolute path is system depended, let's just use the standard check
259        File f = new File(path);
260        if (f.isAbsolute()) {
261            // apparently this is an absolute path already
262            path = f.getAbsolutePath();
263            if (f.isDirectory() && !path.endsWith(File.separator)) {
264                // make sure all folder paths end with a separator
265                path = path.concat(File.separator);
266            }
267            return path;
268        }
269        return CmsFileUtil.normalizePath(getWebApplicationRfsPath() + path);
270    }
271
272    /**
273     * Returns an absolute path (to a directory or a file in the "real" file system) from a path relative to
274     * the "WEB-INF" folder of the OpenCms web application.<p>
275     *
276     * If the provided path is already absolute, then it is returned unchanged.<p>
277     *
278     * @param path the path (relative) to generate an absolute path from
279     * @return an absolute path (to a directory or a file) from a path relative to the "WEB-INF" folder
280     */
281    public String getAbsoluteRfsPathRelativeToWebInf(String path) {
282
283        if (path == null) {
284            return null;
285        }
286        // check for absolute path is system depended, let's just use the standard check
287        File f = new File(path);
288        if (f.isAbsolute()) {
289            // apparently this is an absolute path already
290            return f.getAbsolutePath();
291        }
292        return CmsFileUtil.normalizePath(getWebInfRfsPath() + path);
293    }
294
295    /**
296     * Returns the map of additional build information that was contained in the version.properties file.<p>
297     *
298     * The values are String arrays of length 2. First in this array is the actual value,
299     * and second the "nice name" for the value that can be used to display the value somewhere.
300     * In case no nice name was provided, the second value will repeat the key name.<p>
301     *
302     * @return the map of additional build information that was contained in the version.properties file
303     *
304     * @since 9.5.0
305     */
306    public Map<String, BuildInfoItem> getBuildInfo() {
307
308        return m_buildInfo;
309    }
310
311    /**
312     * Returns the path to a configuration file.<p>
313     * This will either be a file below /system/config/ or in case an override file exists below /system/config/overrides/.<p>
314     *
315     * @param cms the cms ontext
316     * @param configFile the config file path within /system/config/
317     *
318     * @return the file path
319     */
320    public String getConfigFilePath(CmsObject cms, String configFile) {
321
322        String path = CmsStringUtil.joinPaths(VFS_CONFIG_OVERRIDE_FOLDER, configFile);
323        if (!cms.existsResource(path)) {
324            path = CmsStringUtil.joinPaths(VFS_CONFIG_FOLDER, configFile);
325        }
326        return path;
327    }
328
329    /**
330     * Gets the path of the opencms config folder.<p>
331     * Per default this is the "/WEB-INF/config/ folder.
332     * If configured with the "-Dopencms.config=..." java startup parameter, OpenCms can access an external config
333     * folder outside its webapplication.
334     * @return complete rfs path to the config folder.
335     */
336    public String getConfigFolder() {
337
338        // check if the system property is set and return its value
339        if (CmsStringUtil.isNotEmpty(System.getProperty(CONFIG_FOLDER_PROPERTY))) {
340            return System.getProperty(CONFIG_FOLDER_PROPERTY);
341        } else {
342            return getAbsoluteRfsPathRelativeToWebInf(FOLDER_CONFIG_DEFAULT);
343        }
344    }
345
346    /**
347     * Returns the absolute path to the "opencms.properties" configuration file (in the "real" file system).<p>
348     *
349     * @return the absolute path to the "opencms.properties" configuration file
350     */
351    public String getConfigurationFileRfsPath() {
352
353        if (m_configurationFileRfsPath == null) {
354            m_configurationFileRfsPath = getConfigFolder() + FILE_PROPERTIES;
355        }
356        return m_configurationFileRfsPath;
357    }
358
359    /**
360     * Returns the web application context path, e.g. "" (empty String) if the web application
361     * is the default web application (usually "ROOT"), or "/opencms" if the web application
362     * is called "opencms".<p>
363     *
364     * <i>From the Java Servlet Specification v2.4:</i><br>
365     * <b>Context Path:</b> The path prefix associated with the ServletContext that this
366     * servlet is a part of. If this context is the "default" context rooted at the base of
367     * the web server's URL name space, this path will be an empty string. Otherwise,
368     * if the context is not rooted at the root of the server's name space, the path starts
369     * with a "/" character but does not end with a "/" character.<p>
370     *
371     * @return the web application context path
372     * @see #getWebApplicationName()
373     * @see #getServletPath()
374     * @see #getOpenCmsContext()
375     */
376    public String getContextPath() {
377
378        return m_servletContainerSettings.getContextPath();
379    }
380
381    /**
382     * Return the OpenCms default character encoding.<p>
383     *
384     * The default is set in the opencms-system.xml file.
385     * If this is not set in opencms-system.xml the default
386     * is "UTF-8".<p>
387     *
388     * @return the default encoding, e.g. "UTF-8" or "ISO-8859-1"
389     */
390    public String getDefaultEncoding() {
391
392        return m_defaultEncoding;
393    }
394
395    /**
396     * Returns the default web application name (usually "ROOT").<p>
397     *
398     * @return the default web application name
399     */
400    public String getDefaultWebApplicationName() {
401
402        return m_servletContainerSettings.getDefaultWebApplicationName();
403    }
404
405    /**
406     * Gets the device selector.<p>
407     *
408     * @return the device selector
409     */
410    public I_CmsJspDeviceSelector getDeviceSelector() {
411
412        return m_deviceSelector;
413    }
414
415    /**
416     * Returns the maximum number of versions that are kept per file in the VFS version history.<p>
417     *
418     * If the version history is disabled, this setting has no effect.<p>
419     *
420     * @return the maximum number of versions that are kept per file
421     * @see #isHistoryEnabled()
422     */
423    public int getHistoryVersions() {
424
425        return m_historyVersions;
426    }
427
428    /**
429     * Returns the number of versions in the VFS version history that should be
430     * kept after a resource is deleted.<p>
431     *
432     * For resources in folders where the history.removedeleted property is set to "true", this setting is ignored.
433     *
434     * @return the number versions in the VFS version history for deleted resources
435     */
436    public int getHistoryVersionsAfterDeletion() {
437
438        return m_historyVersionsAfterDeletion;
439    }
440
441    /**
442     * Returns the HTTP authentication settings.<p>
443     *
444     * @return the HTTP authentication settings
445     */
446    public CmsHttpAuthenticationSettings getHttpAuthenticationSettings() {
447
448        return m_httpAuthenticationSettings;
449    }
450
451    /**
452     * Returns the filename of the log file (in the "real" file system).<p>
453     *
454     * If the method returns <code>null</code>, this means that the log
455     * file is not managed by OpenCms.<p>
456     *
457     * @return the filename of the log file (in the "real" file system)
458     */
459    public String getLogFileRfsPath() {
460
461        return CmsLog.getLogFileRfsPath();
462    }
463
464    /**
465     * Returns the absolute path to the folder of the main OpenCms log file
466     * (in the "real" file system).<p>
467     *
468     * If the method returns <code>null</code>, this means that the log
469     * file is not managed by OpenCms.<p>
470     *
471     * @return the absolute path to the folder of the main OpenCms log file (in
472     * the "real" file system)
473     */
474    public String getLogFileRfsFolder() {
475
476        return CmsLog.getLogFileRfsFolder();
477    }
478
479    /**
480     * Returns the settings for the internal OpenCms email service.<p>
481     *
482     * @return the settings for the internal OpenCms email service
483     */
484    public CmsMailSettings getMailSettings() {
485
486        return m_mailSettings;
487    }
488
489    /**
490     * Returns the project in which time stamps for the content notification are read.<p>
491     *
492     * @return the project in which time stamps for the content notification are read
493     */
494    public String getNotificationProject() {
495
496        return m_notificationProject;
497    }
498
499    /**
500     * Returns the duration after which responsible resource owners will be notified about out-dated content (in days).<p>
501     *
502     * @return the duration after which responsible resource owners will be notified about out-dated content
503     */
504    public int getNotificationTime() {
505
506        return m_notificationTime;
507    }
508
509    /**
510     * Returns the OpenCms request context, e.g. "/opencms/opencms".<p>
511     *
512     * The OpenCms context will always start with a "/" and never have a trailing "/".
513     * The OpenCms context is identical to <code>getContexPath() + getServletPath()</code>.<p>
514     *
515     * @return the OpenCms request context, e.g. "/opencms/opencms"
516     * @see #getContextPath()
517     * @see #getServletPath()
518     */
519    public String getOpenCmsContext() {
520
521        return m_servletContainerSettings.getOpenCmsContext();
522    }
523
524    /**
525     * Returns the absolute path to the "packages" folder (in the "real" file system).<p>
526     *
527     * @return the absolute path to the "packages" folder
528     */
529    public String getPackagesRfsPath() {
530
531        if (m_packagesRfsPath == null) {
532            m_packagesRfsPath = getAbsoluteRfsPathRelativeToWebInf(CmsSystemInfo.FOLDER_PACKAGES);
533        }
534        return m_packagesRfsPath;
535    }
536
537    /**
538     * Returns the absolute path to the "persistence.xml" file (in the "real" file system).<p>
539     *
540     * @return the absolute path to the "persistence.xml" configuration file
541     */
542    public String getPersistenceFileRfsPath() {
543
544        if (m_persistenceFileRfsPath == null) {
545            m_persistenceFileRfsPath = getAbsoluteRfsPathRelativeToWebInf(FILE_PERSISTENCE);
546        }
547        return m_persistenceFileRfsPath;
548    }
549
550    /**
551     * Returns the time this OpenCms instance is running in milliseconds.<p>
552     *
553     * @return the time this OpenCms instance is running in milliseconds
554     */
555    public long getRuntime() {
556
557        return System.currentTimeMillis() - m_startupTime;
558    }
559
560    /**
561     * Returns the OpenCms server name, e.g. "OpenCmsServer".<p>
562     *
563     * The server name is set in <code>opencms.properties</code>.
564     * It is not related to any DNS name the server might also have.
565     * The server name is useful e.g. in a cluster to distinguish different servers,
566     * or if you compare log files from multiple servers.<p>
567     *
568     * @return the OpenCms server name
569     */
570    public String getServerName() {
571
572        return m_serverName;
573    }
574
575    /**
576     * Returns the servlet container specific settings.<p>
577     *
578     * @return the servlet container specific settings
579     */
580    public CmsServletContainerSettings getServletContainerSettings() {
581
582        return m_servletContainerSettings;
583    }
584
585    /**
586     * Returns the OpenCms servlet path, e.g. "/opencms".<p>
587     *
588     * <i>From the Java Servlet Specification v2.4:</i><br>
589     * <b>Servlet Path:</b> The path section that directly corresponds to the mapping
590     * which activated this request. This path starts with a?/? character except in the
591     * case where the request is matched with the ?/*? pattern, in which case it is the
592     * empty string.<p>
593     *
594     * @return the OpenCms servlet path
595     * @see #getContextPath()
596     * @see #getWebApplicationName()
597     * @see #getOpenCmsContext()
598     */
599    public String getServletPath() {
600
601        return m_servletContainerSettings.getServletPath();
602    }
603
604    /**
605     * Returns the time this OpenCms instance was started in milliseconds.<p>
606     *
607     * @return the time this OpenCms instance was started in milliseconds
608     */
609    public long getStartupTime() {
610
611        return m_startupTime;
612    }
613
614    /**
615     * Returns the context for static resources served from the class path, e.g. "/opencms/opencms/handleStatic".<p>
616     *
617     * @return the static resource context
618     */
619    public String getStaticResourceContext() {
620
621        if (m_staticResourcePathFragment == null) {
622            m_staticResourcePathFragment = CmsStaticResourceHandler.getStaticResourceContext(
623                OpenCms.getStaticExportManager().getVfsPrefix(),
624                getVersionNumber());
625        }
626        return m_staticResourcePathFragment;
627    }
628
629    /**
630     * Returns the identifier "OpenCms/" plus the OpenCms version number.<p>
631     *
632     * This information is used for example to identify OpenCms in HTTP response headers.<p>
633     *
634     * @return the identifier "OpenCms/" plus the OpenCms version number
635     */
636    public String getVersion() {
637
638        return m_version;
639    }
640
641    /**
642     * Returns the version ID of this OpenCms system.<p>
643     *
644     * The version ID is usually set dynamically by the build system.
645     * It can be used to identify intermediate builds when the main
646     * version number has not changed.<p>
647     *
648     * @return the version ID of this OpenCms system
649     *
650     * @since 9.5.0
651     */
652    public String getVersionId() {
653
654        return m_versionId;
655    }
656
657    /**
658     * Returns the version number of this OpenCms system, for example <code>9.5.0</code>.<p>
659     *
660     * @return the version number of this OpenCms system
661     *
662     * @since 7.0.2
663     */
664    public String getVersionNumber() {
665
666        return m_versionNumber;
667    }
668
669    /**
670     * Returns the OpenCms web application name, e.g. "opencms" or "ROOT" (no leading or trailing "/").<p>
671     *
672     * The web application name is stored for informational purposes only.
673     * If you want to construct an URI, use either {@link #getContextPath()} and
674     * {@link #getServletPath()}, or for links to the OpenCms VFS use {@link  #getOpenCmsContext()}.<p>
675     *
676     * @return the OpenCms web application name
677     * @see #getContextPath()
678     * @see #getServletPath()
679     * @see #getOpenCmsContext()
680     */
681    public String getWebApplicationName() {
682
683        return m_servletContainerSettings.getWebApplicationName();
684    }
685
686    /**
687     * Returns the OpenCms web application folder in the servlet container.<p>
688     *
689     * @return the OpenCms web application folder in the servlet container
690     */
691    public String getWebApplicationRfsPath() {
692
693        return m_servletContainerSettings.getWebApplicationRfsPath();
694    }
695
696    /**
697     * Returns the OpenCms web application "WEB-INF" directory path.<p>
698     *
699     * @return the OpenCms web application "WEB-INF" directory path
700     */
701    public String getWebInfRfsPath() {
702
703        return m_servletContainerSettings.getWebInfRfsPath();
704    }
705
706    /**
707     * Returns the OpenCms workplace request context, e.g. "/opencms/workplace".<p>
708     *
709     * The OpenCms workplace context will always start with a "/" and never have a trailing "/".
710     * The OpenCms context is identical to <code>getContexPath() + WORKPLACE_PATH</code>.<p>
711     *
712     * @return the OpenCms request context, e.g. "/opencms/workplace"
713     * @see #getContextPath()
714     * @see #WORKPLACE_PATH
715     */
716    public String getWorkplaceContext() {
717
718        return getContextPath() + WORKPLACE_PATH;
719    }
720
721    /**
722     * Returns if the VFS version history is enabled.<p>
723     *
724     * @return if the VFS version history is enabled
725     */
726    public boolean isHistoryEnabled() {
727
728        return m_historyEnabled;
729    }
730
731    /**
732     * Return true if detail contents are restricted to detail pages from the same site.<p>
733     *
734     * @return true if detail contents are restricted to detail pages from the same site
735     */
736    public boolean isRestrictDetailContents() {
737
738        return m_restrictDetailContents;
739    }
740
741    /**
742     * Sets the project in which time stamps for the content notification are read.<p>
743     *
744     * @param notificationProject the project in which time stamps for the content notification are read
745     */
746    public void setNotificationProject(String notificationProject) {
747
748        m_notificationProject = notificationProject;
749    }
750
751    /**
752     * Sets the duration after which responsible resource owners will be notified about out-dated content (in days).<p>
753     *
754     * @param notificationTime the duration after which responsible resource owners will be notified about out-dated content
755     */
756    public void setNotificationTime(int notificationTime) {
757
758        m_notificationTime = notificationTime;
759    }
760
761    /**
762     * VFS version history settings are set here.<p>
763     *
764     * @param historyEnabled if true the history is enabled
765     * @param historyVersions the maximum number of versions that are kept per VFS resource
766     * @param historyVersionsAfterDeletion the maximum number of versions that are kept for deleted resources
767     */
768    public void setVersionHistorySettings(
769        boolean historyEnabled,
770        int historyVersions,
771        int historyVersionsAfterDeletion) {
772
773        m_historyEnabled = historyEnabled;
774        m_historyVersions = historyVersions;
775        if (historyVersionsAfterDeletion < 0) {
776            m_historyVersionsAfterDeletion = historyVersions;
777        } else {
778            m_historyVersionsAfterDeletion = historyVersionsAfterDeletion;
779        }
780    }
781
782    /**
783     * Sets the OpenCms web application "WEB-INF" directory path (in the "real" file system).<p>
784     *
785     * @param settings container specific information needed for this system info
786     */
787    protected void init(CmsServletContainerSettings settings) {
788
789        m_servletContainerSettings = settings;
790    }
791
792    /**
793     * Sets the default encoding, called after the configuration files have been read.<p>
794     *
795     * @param encoding the default encoding to set
796     */
797    protected void setDefaultEncoding(String encoding) {
798
799        m_defaultEncoding = encoding.intern();
800        if (CmsLog.INIT.isInfoEnabled()) {
801            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_SET_DEFAULT_ENCODING_1, m_defaultEncoding));
802        }
803    }
804
805    /**
806     * Sets the device selector.<p>
807     *
808     * @param selector the device selector to set
809     */
810    protected void setDeviceSelector(I_CmsJspDeviceSelector selector) {
811
812        m_deviceSelector = selector;
813    }
814
815    /**
816     * Sets the HTTP authentication settings.<p>
817     *
818     * @param httpAuthenticationSettings the HTTP authentication settings to set
819     */
820    protected void setHttpAuthenticationSettings(CmsHttpAuthenticationSettings httpAuthenticationSettings) {
821
822        m_httpAuthenticationSettings = httpAuthenticationSettings;
823    }
824
825    /**
826     * Sets the settings for the internal OpenCms email service.<p>
827     *
828     * @param mailSettings the settings for the internal OpenCms email service to set
829     */
830    protected void setMailSettings(CmsMailSettings mailSettings) {
831
832        m_mailSettings = mailSettings;
833    }
834
835    /**
836     * Sets the value of the 'restrict detail contents' option.<p>
837     *
838     * @param restrictDetailContents the new value for the option
839     */
840    protected void setRestrictDetailContents(boolean restrictDetailContents) {
841
842        m_restrictDetailContents = restrictDetailContents;
843    }
844
845    /**
846     * Sets the server name.<p>
847     *
848     * The server name is set in <code>opencms.properties</code>.
849     * It is not related to any DNS name the server might also have.
850     * The server name is useful e.g. in a cluster to distinguish different servers,
851     * or if you compare log files from multiple servers.<p>
852     *
853     * @param serverName the server name to set
854     */
855    protected void setServerName(String serverName) {
856
857        m_serverName = serverName;
858        if (CmsLog.INIT.isInfoEnabled()) {
859            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_SET_SERVERNAME_1, m_serverName));
860        }
861    }
862
863    /**
864     * Initializes the version for this OpenCms, will be called by
865     * {@link OpenCmsServlet} or {@link CmsShell} upon system startup.<p>
866     */
867    private void initVersion() {
868
869        // initialize version information with static defaults
870        m_versionNumber = DEFAULT_VERSION_NUMBER;
871        m_versionId = DEFAULT_VERSION_ID;
872        m_version = "OpenCms/" + m_versionNumber;
873        m_buildInfo = Collections.emptyMap();
874        // read the version-informations from properties
875        Properties props = new Properties();
876        try {
877            props.load(this.getClass().getClassLoader().getResourceAsStream("org/opencms/main/version.properties"));
878        } catch (Throwable t) {
879            // no properties found - we just use the defaults
880            return;
881        }
882        // initialize OpenCms version information from the property values
883        m_versionNumber = props.getProperty("version.number", DEFAULT_VERSION_NUMBER);
884        m_versionId = props.getProperty("version.id", DEFAULT_VERSION_ID);
885        m_version = "OpenCms/" + m_versionNumber;
886        m_buildInfo = new TreeMap<String, BuildInfoItem>();
887
888        // iterate the properties and generate the build information from the entries
889        for (String key : props.stringPropertyNames()) {
890            if (!"version.number".equals(key) && !"version.id".equals(key) && !key.startsWith("nicename")) {
891                String value = props.getProperty(key);
892                String nicename = props.getProperty("nicename." + key, key);
893                m_buildInfo.put(key, new BuildInfoItem(value, nicename, key));
894            }
895        }
896        // make the map unmodifiable
897        m_buildInfo = Collections.unmodifiableMap(m_buildInfo);
898    }
899}