⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmssysteminfo.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/main/CmsSystemInfo.java,v $
 * Date   : $Date: 2006/04/28 15:20:52 $
 * Version: $Revision: 1.49 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.main;

import org.opencms.i18n.CmsEncoder;
import org.opencms.mail.CmsMailSettings;
import org.opencms.util.CmsFileUtil;

import java.io.File;
import java.util.Properties;

/**
 * Provides access to system wide "read only" information.<p>
 * 
 * Regarding the naming conventions used, this comes straight from the Servlet Sepc v2.4:<p>
 *   
 * <i>SRV.3.1 Introduction to the ServletContext Interface<br>
 * [...] A ServletContext is rooted at a known path within a web server. For example
 * a servlet context could be located at http://www.mycorp.com/catalog. All
 * requests that begin with the /catalog request path, known as the <b>context path</b>, are
 * routed to the <b>web application</b> associated with the ServletContext.</i><p>   
 * 
 * @author  Alexander Kandzior 
 * 
 * @version $Revision: 1.49 $ 
 * 
 * @since 6.0.0 
 */
public class CmsSystemInfo {

    /** The name of the opencms.properties file. */
    public static final String FILE_PROPERTIES = "opencms.properties";

    /** Path to the "config" folder relative to the "WEB-INF" directory of the application. */
    public static final String FOLDER_CONFIG = "config" + File.separatorChar;

    /** The name of the module folder in the package path. */
    public static final String FOLDER_MODULES = "modules" + File.separatorChar;

    /** Path to the "packages" folder relative to the "WEB-INF" directory of the application. */
    public static final String FOLDER_PACKAGES = "packages" + File.separatorChar;

    /** Default encoding. */
    private static final String DEFAULT_ENCODING = CmsEncoder.ENCODING_UTF_8;

    /** Static version number to use if version.properties can not be read. */
    private static final String DEFAULT_VERSION_NUMBER = "6.2.x";

    /** The abolute path to the "opencms.properties" configuration file (in the "real" file system). */
    private String m_configurationFileRfsPath;

    /** The web application context path. */
    private String m_contextPath;

    /** Default encoding, can be overwritten in "opencms.properties". */
    private String m_defaultEncoding;

    /** The default web application (usually "ROOT"). */
    private String m_defaultWebApplicationName;

    /** The HTTP basic authentication settings. */
    private CmsHttpAuthenticationSettings m_httpAuthenticationSettings;

    /** The settings for the internal OpenCms email service. */
    private CmsMailSettings m_mailSettings;

    /** The project in which timestamps for the content notification are read. */
    private String m_notificationProject;

    /** The duration after which responsibles will be notified about out-dated content (in days). */
    private int m_notificationTime;

    /** The OpenCms context and servlet path, e.g. <code>/opencms/opencms</code>. */
    private String m_openCmsContext;

    /** The abolute path to the "packages" folder (in the "real" file system). */
    private String m_packagesRfsPath;

    /** The name of the OpenCms server. */
    private String m_serverName;

    /** The servlet path for the OpenCms servlet. */
    private String m_servletPath;

    /** The startup time of this OpenCms instance. */
    private long m_startupTime;

    /** The version identifier of this OpenCms installation, contains "OpenCms/" and the version number. */
    private String m_version;

    /** Indicates if the version history is enabled. */
    private boolean m_versionHistoryEnabled;

    /** The maximum number of entries in the version history (per resource). */
    private int m_versionHistoryMaxCount;

    /** The version number of this OpenCms installation. */
    private String m_versionNumber;

    /** The web application name. */
    private String m_webApplicationName;

    /** The OpenCms web application servlet container folder path (in the "real" file system). */
    private String m_webApplicationRfsPath;

    /** The OpenCms web application "WEB-INF" path (in the "real" file system). */
    private String m_webInfRfsPath;

    /**
     * Creates a new system info container.<p>
     */
    public CmsSystemInfo() {

        // set startup time
        m_startupTime = System.currentTimeMillis();
        // init version onformation
        initVersion();
        // set default encoding (will be changed again later when properties have been read)
        m_defaultEncoding = DEFAULT_ENCODING.intern();
    }

    /**
     * Returns an absolute path (to a directory or a file in the "real" file system) from a path relative to 
     * the web application folder of OpenCms.<p> 
     * 
     * If the provided path is already absolute, then it is returned unchanged.
     * If the provided path is a folder, the result will always end with a folder separator.<p>
     * 
     * @param path the path (relative) to generate an absolute path from
     * @return an absolute path (to a directory or a file) from a path relative to the web application folder of OpenCms
     */
    public String getAbsoluteRfsPathRelativeToWebApplication(String path) {

        if ((path == null) || (getWebApplicationRfsPath() == null)) {
            return null;
        }
        // check for absolute path is system depended, let's just use the standard check  
        File f = new File(path);
        if (f.isAbsolute()) {
            // apparently this is an absolute path already
            path = f.getAbsolutePath();
            if (f.isDirectory() && !path.endsWith(File.separator)) {
                // make sure all folder paths end with a separator
                path = path.concat(File.separator);
            }
            return path;
        }
        return CmsFileUtil.normalizePath(getWebApplicationRfsPath() + path);
    }

    /**
     * Returns an absolute path (to a directory or a file in the "real" file system) from a path relative to 
     * the "WEB-INF" folder of the OpenCms web application.<p> 
     * 
     * If the provided path is already absolute, then it is returned unchanged.<p>
     * 
     * @param path the path (relative) to generate an absolute path from
     * @return an absolute path (to a directory or a file) from a path relative to the "WEB-INF" folder
     */
    public String getAbsoluteRfsPathRelativeToWebInf(String path) {

        if (path == null) {
            return null;
        }
        // check for absolute path is system depended, let's just use the standard check  
        File f = new File(path);
        if (f.isAbsolute()) {
            // apparently this is an absolute path already
            return f.getAbsolutePath();
        }
        return CmsFileUtil.normalizePath(getWebInfRfsPath() + path);
    }

    /**
     * Returns the abolute path to the "opencms.properties" configuration file (in the "real" file system).<p>
     * 
     * @return the abolute path to the "opencms.properties" configuration file
     */
    public String getConfigurationFileRfsPath() {

        if (m_configurationFileRfsPath == null) {
            m_configurationFileRfsPath = getAbsoluteRfsPathRelativeToWebInf(FOLDER_CONFIG + FILE_PROPERTIES);
        }
        return m_configurationFileRfsPath;
    }

    /**
     * Returns the web application context path, e.g. "" (empty String) if the web application 
     * is the default web application (usually "ROOT"), or "/opencms" if the web application 
     * is called "opencms".<p>
     * 
     * <i>From the Java Servlet Sepcecification v2.4:</i><br>
     * <b>Context Path:</b> The path prefix associated with the ServletContext that this
     * servlet is a part of. If this context is the "default" context rooted at the base of
     * the web server's URL namespace, this path will be an empty string. Otherwise,
     * if the context is not rooted at the root of the server's namespace, the path starts
     * with a "/" character but does not end with a "/" character.<p>
     *  
     * @return the web application context path
     * @see #getWebApplicationName()
     * @see #getServletPath()
     * @see #getOpenCmsContext()
     */
    public String getContextPath() {

        return m_contextPath;
    }

    /**
     * Return the OpenCms default character encoding.<p>
     * 
     * The default is set in the "opencms.properties" file.
     * If this is not set in "opencms.properties" the default 
     * is "UTF-8".<p>
     * 
     * @return the default encoding, e.g. "UTF-8" or "ISO-8859-1"
     */
    public String getDefaultEncoding() {

        return m_defaultEncoding;
    }

    /**
     * Returns the default web application name (usually "ROOT").<p>
     * 
     * @return the default web application name
     */
    public String getDefaultWebApplicationName() {

        return m_defaultWebApplicationName;
    }

    /**
     * Returns the HTTP authentication settings.<p>
     *
     * @return the HTTP authentication settings
     */
    public CmsHttpAuthenticationSettings getHttpAuthenticationSettings() {

        return m_httpAuthenticationSettings;
    }

    /**
     * Returns the filename of the logfile (in the "real" file system).<p>
     * 
     * If the method returns <code>null</code>, this means that the log
     * file is not managed by OpenCms.<p>
     * 
     * @return the filename of the logfile (in the "real" file system)
     */
    public String getLogFileRfsPath() {

        return CmsLog.getLogFileRfsPath();
    }

    /**
     * Returns the settings for the internal OpenCms email service.<p>
     * 
     * @return the settings for the internal OpenCms email service
     */
    public CmsMailSettings getMailSettings() {

        return m_mailSettings;
    }

    /**
     * Returns the project in which timestamps for the content notification are read.<p>
     * 
     * @return the project in which timestamps for the content notification are read
     */
    public String getNotificationProject() {

        return m_notificationProject;
    }

    /**
     * Returns the duration after which responsibles will be notified about out-dated content (in days).<p>
     * 
     * @return the duration after which responsibles will be notified about out-dated content
     */
    public int getNotificationTime() {

        return m_notificationTime;
    }

    /**
     * Returns the OpenCms request context, e.g. "/opencms/opencms".<p>
     * 
     * The OpenCms context will always start with a "/" and never have a trailing "/".
     * The OpenCms context is identical to <code>getContexPath() + getServletPath()</code>.<p>
     * 
     * @return the OpenCms request context, e.g. "/opencms/opencms"
     * @see #getContextPath()
     * @see #getServletPath()
     */
    public String getOpenCmsContext() {

        return m_openCmsContext;
    }

    /**
     * Returns the abolute path to the "packages" folder (in the "real" file system).<p>
     * 
     * @return the abolute path to the "packages" folder
     */
    public String getPackagesRfsPath() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -