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 * @return the number versions in the VFS version history for deleted resources 433 */ 434 public int getHistoryVersionsAfterDeletion() { 435 436 return m_historyVersionsAfterDeletion; 437 } 438 439 /** 440 * Returns the HTTP authentication settings.<p> 441 * 442 * @return the HTTP authentication settings 443 */ 444 public CmsHttpAuthenticationSettings getHttpAuthenticationSettings() { 445 446 return m_httpAuthenticationSettings; 447 } 448 449 /** 450 * Returns the filename of the log file (in the "real" file system).<p> 451 * 452 * If the method returns <code>null</code>, this means that the log 453 * file is not managed by OpenCms.<p> 454 * 455 * @return the filename of the log file (in the "real" file system) 456 */ 457 public String getLogFileRfsPath() { 458 459 return CmsLog.getLogFileRfsPath(); 460 } 461 462 /** 463 * Returns the settings for the internal OpenCms email service.<p> 464 * 465 * @return the settings for the internal OpenCms email service 466 */ 467 public CmsMailSettings getMailSettings() { 468 469 return m_mailSettings; 470 } 471 472 /** 473 * Returns the project in which time stamps for the content notification are read.<p> 474 * 475 * @return the project in which time stamps for the content notification are read 476 */ 477 public String getNotificationProject() { 478 479 return m_notificationProject; 480 } 481 482 /** 483 * Returns the duration after which responsible resource owners will be notified about out-dated content (in days).<p> 484 * 485 * @return the duration after which responsible resource owners will be notified about out-dated content 486 */ 487 public int getNotificationTime() { 488 489 return m_notificationTime; 490 } 491 492 /** 493 * Returns the OpenCms request context, e.g. "/opencms/opencms".<p> 494 * 495 * The OpenCms context will always start with a "/" and never have a trailing "/". 496 * The OpenCms context is identical to <code>getContexPath() + getServletPath()</code>.<p> 497 * 498 * @return the OpenCms request context, e.g. "/opencms/opencms" 499 * @see #getContextPath() 500 * @see #getServletPath() 501 */ 502 public String getOpenCmsContext() { 503 504 return m_servletContainerSettings.getOpenCmsContext(); 505 } 506 507 /** 508 * Returns the absolute path to the "packages" folder (in the "real" file system).<p> 509 * 510 * @return the absolute path to the "packages" folder 511 */ 512 public String getPackagesRfsPath() { 513 514 if (m_packagesRfsPath == null) { 515 m_packagesRfsPath = getAbsoluteRfsPathRelativeToWebInf(CmsSystemInfo.FOLDER_PACKAGES); 516 } 517 return m_packagesRfsPath; 518 } 519 520 /** 521 * Returns the absolute path to the "persistence.xml" file (in the "real" file system).<p> 522 * 523 * @return the absolute path to the "persistence.xml" configuration file 524 */ 525 public String getPersistenceFileRfsPath() { 526 527 if (m_persistenceFileRfsPath == null) { 528 m_persistenceFileRfsPath = getAbsoluteRfsPathRelativeToWebInf(FILE_PERSISTENCE); 529 } 530 return m_persistenceFileRfsPath; 531 } 532 533 /** 534 * Returns the time this OpenCms instance is running in milliseconds.<p> 535 * 536 * @return the time this OpenCms instance is running in milliseconds 537 */ 538 public long getRuntime() { 539 540 return System.currentTimeMillis() - m_startupTime; 541 } 542 543 /** 544 * Returns the OpenCms server name, e.g. "OpenCmsServer".<p> 545 * 546 * The server name is set in <code>opencms.properties</code>. 547 * It is not related to any DNS name the server might also have. 548 * The server name is useful e.g. in a cluster to distinguish different servers, 549 * or if you compare log files from multiple servers.<p> 550 * 551 * @return the OpenCms server name 552 */ 553 public String getServerName() { 554 555 return m_serverName; 556 } 557 558 /** 559 * Returns the servlet container specific settings.<p> 560 * 561 * @return the servlet container specific settings 562 */ 563 public CmsServletContainerSettings getServletContainerSettings() { 564 565 return m_servletContainerSettings; 566 } 567 568 /** 569 * Returns the OpenCms servlet path, e.g. "/opencms".<p> 570 * 571 * <i>From the Java Servlet Specification v2.4:</i><br> 572 * <b>Servlet Path:</b> The path section that directly corresponds to the mapping 573 * which activated this request. This path starts with a?/? character except in the 574 * case where the request is matched with the ?/*? pattern, in which case it is the 575 * empty string.<p> 576 * 577 * @return the OpenCms servlet path 578 * @see #getContextPath() 579 * @see #getWebApplicationName() 580 * @see #getOpenCmsContext() 581 */ 582 public String getServletPath() { 583 584 return m_servletContainerSettings.getServletPath(); 585 } 586 587 /** 588 * Returns the time this OpenCms instance was started in milliseconds.<p> 589 * 590 * @return the time this OpenCms instance was started in milliseconds 591 */ 592 public long getStartupTime() { 593 594 return m_startupTime; 595 } 596 597 /** 598 * Returns the context for static resources served from the class path, e.g. "/opencms/opencms/handleStatic".<p> 599 * 600 * @return the static resource context 601 */ 602 public String getStaticResourceContext() { 603 604 if (m_staticResourcePathFragment == null) { 605 m_staticResourcePathFragment = CmsStaticResourceHandler.getStaticResourceContext( 606 OpenCms.getStaticExportManager().getVfsPrefix(), 607 getVersionNumber()); 608 } 609 return m_staticResourcePathFragment; 610 } 611 612 /** 613 * Returns the identifier "OpenCms/" plus the OpenCms version number.<p> 614 * 615 * This information is used for example to identify OpenCms in HTTP response headers.<p> 616 * 617 * @return the identifier "OpenCms/" plus the OpenCms version number 618 */ 619 public String getVersion() { 620 621 return m_version; 622 } 623 624 /** 625 * Returns the version ID of this OpenCms system.<p> 626 * 627 * The version ID is usually set dynamically by the build system. 628 * It can be used to identify intermediate builds when the main 629 * version number has not changed.<p> 630 * 631 * @return the version ID of this OpenCms system 632 * 633 * @since 9.5.0 634 */ 635 public String getVersionId() { 636 637 return m_versionId; 638 } 639 640 /** 641 * Returns the version number of this OpenCms system, for example <code>9.5.0</code>.<p> 642 * 643 * @return the version number of this OpenCms system 644 * 645 * @since 7.0.2 646 */ 647 public String getVersionNumber() { 648 649 return m_versionNumber; 650 } 651 652 /** 653 * Returns the OpenCms web application name, e.g. "opencms" or "ROOT" (no leading or trailing "/").<p> 654 * 655 * The web application name is stored for informational purposes only. 656 * If you want to construct an URI, use either {@link #getContextPath()} and 657 * {@link #getServletPath()}, or for links to the OpenCms VFS use {@link #getOpenCmsContext()}.<p> 658 * 659 * @return the OpenCms web application name 660 * @see #getContextPath() 661 * @see #getServletPath() 662 * @see #getOpenCmsContext() 663 */ 664 public String getWebApplicationName() { 665 666 return m_servletContainerSettings.getWebApplicationName(); 667 } 668 669 /** 670 * Returns the OpenCms web application folder in the servlet container.<p> 671 * 672 * @return the OpenCms web application folder in the servlet container 673 */ 674 public String getWebApplicationRfsPath() { 675 676 return m_servletContainerSettings.getWebApplicationRfsPath(); 677 } 678 679 /** 680 * Returns the OpenCms web application "WEB-INF" directory path.<p> 681 * 682 * @return the OpenCms web application "WEB-INF" directory path 683 */ 684 public String getWebInfRfsPath() { 685 686 return m_servletContainerSettings.getWebInfRfsPath(); 687 } 688 689 /** 690 * Returns the OpenCms workplace request context, e.g. "/opencms/workplace".<p> 691 * 692 * The OpenCms workplace context will always start with a "/" and never have a trailing "/". 693 * The OpenCms context is identical to <code>getContexPath() + WORKPLACE_PATH</code>.<p> 694 * 695 * @return the OpenCms request context, e.g. "/opencms/workplace" 696 * @see #getContextPath() 697 * @see #WORKPLACE_PATH 698 */ 699 public String getWorkplaceContext() { 700 701 return getContextPath() + WORKPLACE_PATH; 702 } 703 704 /** 705 * Returns if the VFS version history is enabled.<p> 706 * 707 * @return if the VFS version history is enabled 708 */ 709 public boolean isHistoryEnabled() { 710 711 return m_historyEnabled; 712 } 713 714 /** 715 * Return true if detail contents are restricted to detail pages from the same site.<p> 716 * 717 * @return true if detail contents are restricted to detail pages from the same site 718 */ 719 public boolean isRestrictDetailContents() { 720 721 return m_restrictDetailContents; 722 } 723 724 /** 725 * Sets the project in which time stamps for the content notification are read.<p> 726 * 727 * @param notificationProject the project in which time stamps for the content notification are read 728 */ 729 public void setNotificationProject(String notificationProject) { 730 731 m_notificationProject = notificationProject; 732 } 733 734 /** 735 * Sets the duration after which responsible resource owners will be notified about out-dated content (in days).<p> 736 * 737 * @param notificationTime the duration after which responsible resource owners will be notified about out-dated content 738 */ 739 public void setNotificationTime(int notificationTime) { 740 741 m_notificationTime = notificationTime; 742 } 743 744 /** 745 * VFS version history settings are set here.<p> 746 * 747 * @param historyEnabled if true the history is enabled 748 * @param historyVersions the maximum number of versions that are kept per VFS resource 749 * @param historyVersionsAfterDeletion the maximum number of versions that are kept for deleted resources 750 */ 751 public void setVersionHistorySettings( 752 boolean historyEnabled, 753 int historyVersions, 754 int historyVersionsAfterDeletion) { 755 756 m_historyEnabled = historyEnabled; 757 m_historyVersions = historyVersions; 758 if (historyVersionsAfterDeletion < 0) { 759 m_historyVersionsAfterDeletion = historyVersions; 760 } else { 761 m_historyVersionsAfterDeletion = historyVersionsAfterDeletion; 762 } 763 } 764 765 /** 766 * Sets the OpenCms web application "WEB-INF" directory path (in the "real" file system).<p> 767 * 768 * @param settings container specific information needed for this system info 769 */ 770 protected void init(CmsServletContainerSettings settings) { 771 772 m_servletContainerSettings = settings; 773 } 774 775 /** 776 * Sets the default encoding, called after the configuration files have been read.<p> 777 * 778 * @param encoding the default encoding to set 779 */ 780 protected void setDefaultEncoding(String encoding) { 781 782 m_defaultEncoding = encoding.intern(); 783 if (CmsLog.INIT.isInfoEnabled()) { 784 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_SET_DEFAULT_ENCODING_1, m_defaultEncoding)); 785 } 786 } 787 788 /** 789 * Sets the device selector.<p> 790 * 791 * @param selector the device selector to set 792 */ 793 protected void setDeviceSelector(I_CmsJspDeviceSelector selector) { 794 795 m_deviceSelector = selector; 796 } 797 798 /** 799 * Sets the HTTP authentication settings.<p> 800 * 801 * @param httpAuthenticationSettings the HTTP authentication settings to set 802 */ 803 protected void setHttpAuthenticationSettings(CmsHttpAuthenticationSettings httpAuthenticationSettings) { 804 805 m_httpAuthenticationSettings = httpAuthenticationSettings; 806 } 807 808 /** 809 * Sets the settings for the internal OpenCms email service.<p> 810 * 811 * @param mailSettings the settings for the internal OpenCms email service to set 812 */ 813 protected void setMailSettings(CmsMailSettings mailSettings) { 814 815 m_mailSettings = mailSettings; 816 } 817 818 /** 819 * Sets the value of the 'restrict detail contents' option.<p> 820 * 821 * @param restrictDetailContents the new value for the option 822 */ 823 protected void setRestrictDetailContents(boolean restrictDetailContents) { 824 825 m_restrictDetailContents = restrictDetailContents; 826 } 827 828 /** 829 * Sets the server name.<p> 830 * 831 * The server name is set in <code>opencms.properties</code>. 832 * It is not related to any DNS name the server might also have. 833 * The server name is useful e.g. in a cluster to distinguish different servers, 834 * or if you compare log files from multiple servers.<p> 835 * 836 * @param serverName the server name to set 837 */ 838 protected void setServerName(String serverName) { 839 840 m_serverName = serverName; 841 if (CmsLog.INIT.isInfoEnabled()) { 842 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_SET_SERVERNAME_1, m_serverName)); 843 } 844 } 845 846 /** 847 * Initializes the version for this OpenCms, will be called by 848 * {@link OpenCmsServlet} or {@link CmsShell} upon system startup.<p> 849 */ 850 private void initVersion() { 851 852 // initialize version information with static defaults 853 m_versionNumber = DEFAULT_VERSION_NUMBER; 854 m_versionId = DEFAULT_VERSION_ID; 855 m_version = "OpenCms/" + m_versionNumber; 856 m_buildInfo = Collections.emptyMap(); 857 // read the version-informations from properties 858 Properties props = new Properties(); 859 try { 860 props.load(this.getClass().getClassLoader().getResourceAsStream("org/opencms/main/version.properties")); 861 } catch (Throwable t) { 862 // no properties found - we just use the defaults 863 return; 864 } 865 // initialize OpenCms version information from the property values 866 m_versionNumber = props.getProperty("version.number", DEFAULT_VERSION_NUMBER); 867 m_versionId = props.getProperty("version.id", DEFAULT_VERSION_ID); 868 m_version = "OpenCms/" + m_versionNumber; 869 m_buildInfo = new TreeMap<String, BuildInfoItem>(); 870 871 // iterate the properties and generate the build information from the entries 872 for (String key : props.stringPropertyNames()) { 873 if (!"version.number".equals(key) && !"version.id".equals(key) && !key.startsWith("nicename")) { 874 String value = props.getProperty(key); 875 String nicename = props.getProperty("nicename." + key, key); 876 m_buildInfo.put(key, new BuildInfoItem(value, nicename, key)); 877 } 878 } 879 // make the map unmodifiable 880 m_buildInfo = Collections.unmodifiableMap(m_buildInfo); 881 } 882}