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