1 31 32 package org.opencms.main; 33 34 import org.opencms.i18n.CmsEncoder; 35 import org.opencms.mail.CmsMailSettings; 36 import org.opencms.util.CmsFileUtil; 37 38 import java.io.File ; 39 import java.util.Properties ; 40 41 58 public class CmsSystemInfo { 59 60 61 public static final String FILE_PROPERTIES = "opencms.properties"; 62 63 64 public static final String FOLDER_CONFIG = "config" + File.separatorChar; 65 66 67 public static final String FOLDER_MODULES = "modules" + File.separatorChar; 68 69 70 public static final String FOLDER_PACKAGES = "packages" + File.separatorChar; 71 72 73 private static final String DEFAULT_ENCODING = CmsEncoder.ENCODING_UTF_8; 74 75 76 private static final String DEFAULT_VERSION_NUMBER = "6.2.x"; 77 78 79 private String m_configurationFileRfsPath; 80 81 82 private String m_contextPath; 83 84 85 private String m_defaultEncoding; 86 87 88 private String m_defaultWebApplicationName; 89 90 91 private CmsHttpAuthenticationSettings m_httpAuthenticationSettings; 92 93 94 private CmsMailSettings m_mailSettings; 95 96 97 private String m_notificationProject; 98 99 100 private int m_notificationTime; 101 102 103 private String m_openCmsContext; 104 105 106 private String m_packagesRfsPath; 107 108 109 private String m_serverName; 110 111 112 private String m_servletPath; 113 114 115 private long m_startupTime; 116 117 118 private String m_version; 119 120 121 private boolean m_versionHistoryEnabled; 122 123 124 private int m_versionHistoryMaxCount; 125 126 127 private String m_versionNumber; 128 129 130 private String m_webApplicationName; 131 132 133 private String m_webApplicationRfsPath; 134 135 136 private String m_webInfRfsPath; 137 138 141 public CmsSystemInfo() { 142 143 m_startupTime = System.currentTimeMillis(); 145 initVersion(); 147 m_defaultEncoding = DEFAULT_ENCODING.intern(); 149 } 150 151 161 public String getAbsoluteRfsPathRelativeToWebApplication(String path) { 162 163 if ((path == null) || (getWebApplicationRfsPath() == null)) { 164 return null; 165 } 166 File f = new File (path); 168 if (f.isAbsolute()) { 169 path = f.getAbsolutePath(); 171 if (f.isDirectory() && !path.endsWith(File.separator)) { 172 path = path.concat(File.separator); 174 } 175 return path; 176 } 177 return CmsFileUtil.normalizePath(getWebApplicationRfsPath() + path); 178 } 179 180 189 public String getAbsoluteRfsPathRelativeToWebInf(String path) { 190 191 if (path == null) { 192 return null; 193 } 194 File f = new File (path); 196 if (f.isAbsolute()) { 197 return f.getAbsolutePath(); 199 } 200 return CmsFileUtil.normalizePath(getWebInfRfsPath() + path); 201 } 202 203 208 public String getConfigurationFileRfsPath() { 209 210 if (m_configurationFileRfsPath == null) { 211 m_configurationFileRfsPath = getAbsoluteRfsPathRelativeToWebInf(FOLDER_CONFIG + FILE_PROPERTIES); 212 } 213 return m_configurationFileRfsPath; 214 } 215 216 233 public String getContextPath() { 234 235 return m_contextPath; 236 } 237 238 247 public String getDefaultEncoding() { 248 249 return m_defaultEncoding; 250 } 251 252 257 public String getDefaultWebApplicationName() { 258 259 return m_defaultWebApplicationName; 260 } 261 262 267 public CmsHttpAuthenticationSettings getHttpAuthenticationSettings() { 268 269 return m_httpAuthenticationSettings; 270 } 271 272 280 public String getLogFileRfsPath() { 281 282 return CmsLog.getLogFileRfsPath(); 283 } 284 285 290 public CmsMailSettings getMailSettings() { 291 292 return m_mailSettings; 293 } 294 295 300 public String getNotificationProject() { 301 302 return m_notificationProject; 303 } 304 305 310 public int getNotificationTime() { 311 312 return m_notificationTime; 313 } 314 315 325 public String getOpenCmsContext() { 326 327 return m_openCmsContext; 328 } 329 330 335 public String getPackagesRfsPath() { 336 337 if (m_packagesRfsPath == null) { 338 m_packagesRfsPath = getAbsoluteRfsPathRelativeToWebInf(CmsSystemInfo.FOLDER_PACKAGES); 339 } 340 return m_packagesRfsPath; 341 } 342 343 348 public long getRuntime() { 349 350 return System.currentTimeMillis() - m_startupTime; 351 } 352 353 363 public String getServerName() { 364 365 return m_serverName; 366 } 367 368 382 public String getServletPath() { 383 384 return m_servletPath; 385 } 386 387 392 public long getStartupTime() { 393 394 return m_startupTime; 395 } 396 397 404 public String getVersion() { 405 406 return m_version; 407 } 408 409 417 public int getVersionHistoryMaxCount() { 418 419 return m_versionHistoryMaxCount; 420 } 421 422 427 public String getVersionName() { 428 429 return m_versionNumber; 430 } 431 432 444 public String getWebApplicationName() { 445 446 return m_webApplicationName; 447 } 448 449 454 public String getWebApplicationRfsPath() { 455 456 return m_webApplicationRfsPath; 457 } 458 459 464 public String getWebInfRfsPath() { 465 466 return m_webInfRfsPath; 467 } 468 469 474 public boolean isVersionHistoryEnabled() { 475 476 return m_versionHistoryEnabled; 477 } 478 479 485 public boolean keepVersionHistory() { 486 487 return true; 489 } 490 491 496 public void setNotificationProject(String notificationProject) { 497 498 m_notificationProject = notificationProject; 499 } 500 501 506 public void setNotificationTime(int notificationTime) { 507 508 m_notificationTime = notificationTime; 509 } 510 511 517 public void setVersionHistorySettings(boolean historyEnabled, int historyMaxCount) { 518 519 m_versionHistoryEnabled = historyEnabled; 520 m_versionHistoryMaxCount = historyMaxCount; 521 } 522 523 531 protected void init( 532 String webInfRfsPath, 533 String servletMapping, 534 String webApplicationContext, 535 String defaultWebApplication) { 536 537 webInfRfsPath = webInfRfsPath.replace('\\', '/'); 539 if (!webInfRfsPath.endsWith("/")) { 540 webInfRfsPath = webInfRfsPath + "/"; 541 } 542 m_webInfRfsPath = CmsFileUtil.normalizePath(webInfRfsPath); 543 544 if (!servletMapping.startsWith("/")) { 546 servletMapping = "/" + servletMapping; 547 } 548 if (servletMapping.endsWith("/*")) { 549 servletMapping = servletMapping.substring(0, servletMapping.length() - 2); 551 } 552 m_servletPath = servletMapping; 553 554 if (defaultWebApplication.endsWith("/")) { 556 defaultWebApplication = defaultWebApplication.substring(0, defaultWebApplication.length() - 1); 557 } 558 if (defaultWebApplication.startsWith("/")) { 559 defaultWebApplication = defaultWebApplication.substring(1); 560 } 561 m_defaultWebApplicationName = defaultWebApplication; 562 563 File path = new File (m_webInfRfsPath); 565 m_webApplicationName = path.getParentFile().getName(); 566 567 String contextPath; 568 if (webApplicationContext == null) { 569 contextPath = m_webApplicationName; 571 } else { 572 contextPath = webApplicationContext; 575 } 576 577 if (contextPath.equals(getDefaultWebApplicationName())) { 579 m_contextPath = ""; 580 } else { 581 m_contextPath = "/" + contextPath; 582 } 583 584 if (m_contextPath.endsWith(".war")) { 586 m_contextPath = m_contextPath.substring(0, m_contextPath.length() - 4); 587 } 588 589 m_openCmsContext = m_contextPath + m_servletPath; 591 592 m_webApplicationRfsPath = path.getParentFile().getAbsolutePath(); 594 if (!m_webApplicationRfsPath.endsWith(File.separator)) { 595 m_webApplicationRfsPath += File.separator; 596 } 597 } 598 599 604 protected void setDefaultEncoding(String encoding) { 605 606 m_defaultEncoding = encoding.intern(); 607 if (CmsLog.INIT.isInfoEnabled()) { 608 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_SET_DEFAULT_ENCODING_1, m_defaultEncoding)); 609 } 610 } 611 612 617 protected void setHttpAuthenticationSettings(CmsHttpAuthenticationSettings httpAuthenticationSettings) { 618 619 m_httpAuthenticationSettings = httpAuthenticationSettings; 620 } 621 622 627 protected void setMailSettings(CmsMailSettings mailSettings) { 628 629 m_mailSettings = mailSettings; 630 } 631 632 642 protected void setServerName(String serverName) { 643 644 m_serverName = serverName; 645 if (CmsLog.INIT.isInfoEnabled()) { 646 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_SET_SERVERNAME_1, m_serverName)); 647 } 648 } 649 650 654 private void initVersion() { 655 656 m_versionNumber = DEFAULT_VERSION_NUMBER; 658 m_version = "OpenCms/" + m_versionNumber; 660 Properties props = new Properties (); 662 try { 663 props.load(this.getClass().getClassLoader().getResourceAsStream("org/opencms/main/version.properties")); 664 } catch (Throwable t) { 665 return; 667 } 668 m_versionNumber = props.getProperty("version.number", DEFAULT_VERSION_NUMBER); 669 m_version = "OpenCms/" + m_versionNumber; 671 } 672 } | Popular Tags |