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

📄 a_cmslauncher.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/launcher/Attic/A_CmsLauncher.java,v $
* Date   : $Date: 2003/02/26 10:30:36 $
* Version: $Revision: 1.41 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* 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 OpenCms, please see the
* OpenCms 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 com.opencms.launcher;

import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsResponse;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsRequestContext;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsRootTemplate;
import com.opencms.template.CmsTemplateClassManager;
import com.opencms.template.I_CmsTemplate;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;

/**
 * Abstract OpenCms launcher class.
 * <P>
 * This class implements basic functionality for all OpenCms launchers.
 * For each relevant file type (e.g. XML control files, plain text files,
 * JavaScript files,...) a customized launcher has to be implemented.
 * <P>
 * Every extending class has to implement the abstract methods
 * <UL>
 * <LI>getLauncherId() to indicate the type of the launcher</LI>
 * <LI>launch() to be called by initlaunch</LI>
 * </UL>
 * <P>
 * The functionality of this class is
 * <UL>
 * <LI>provide a global cache for template class results</LI>
 * <LI>receive the system's launcher call, do some relevant initial
 * things and call the launch() method</LI>
 * <LI>provide some utility methods</LI>
 * </UL>
 *
 * @author Alexander Lucas
 * @version $Revision: 1.41 $ $Date: 2003/02/26 10:30:36 $
 */
abstract class A_CmsLauncher implements I_CmsLauncher,I_CmsLogChannels,I_CmsConstants {

    /** Boolean for additional debug output control */
    private static final boolean C_DEBUG = false;

    /** Value of the filesystem counter, when the last template clear cache was done. */
    private static long m_lastFsCounterTemplate = 0;

    /** Value of the filesystem counter, when the last XML file clear cache was done. */
    private static long m_lastFsCounterFile = 0;

    /** The template cache that holds all cached templates */
    protected static I_CmsTemplateCache m_templateCache = new CmsTemplateCache();

    /**
     * Utility method used by the launcher implementation to give control
     * to the CanonicalRoot.
     * The CanonicalRoot will call the master template and return a byte array of the
     * generated output.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param templateClass Class that should generate the output of the master template.
     * @param masterTemplate CmsFile Object with masterTemplate for the output.
     * @param parameters Hashtable with all parameters for the template class.
     * @return byte array with the generated output or null if there were errors.
     * @throws CmsException
     *
     */
    protected byte[] callCanonicalRoot(CmsObject cms, I_CmsTemplate templateClass, CmsFile masterTemplate, Hashtable parameters) throws CmsException {
        try {
            com.opencms.template.CmsRootTemplate root = (CmsRootTemplate)CmsTemplateClassManager.getClassInstance(cms, "com.opencms.template.CmsRootTemplate");
            return root.getMasterTemplate(cms, templateClass, masterTemplate, m_templateCache, parameters);
        }
        catch(Exception e) {

            // There is no document we could show.
            handleException(cms, e, "Received error while calling canonical root for requested file " + masterTemplate.getName() + ". ");
        }
        return null;
    }

    /**
     * Method for clearing this launchers template cache.
     */
    public void clearCache() {
        m_templateCache.clearCache();
        System.gc();
    }

    /**
     * Gets the name of the class in the form "[ClassName] "
     * This can be used for error logging purposes.
     * @return name of this class
     */
    protected String getClassName() {
        String name = getClass().getName();
        return "[" + name.substring(name.lastIndexOf(".") + 1) + "] ";
    }

    /** Default constructor to create a new launcher */

    /*public A_CmsLauncher() {
    if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
        A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "Initialized successfully.");
    }
    }*/

    /**
     * Gets the ID that indicates the type of the launcher.
     * @return launcher ID
     */
    public abstract int getLauncherId();

    /**
     * Gets a reference to the global template cache
     * @return Template cache
     */
    public static I_CmsTemplateCache getTemplateCache() {
        return m_templateCache;
    }

    /**
     * Calls the CmsClassManager to get an instance of the given template class.
     * The returned object is checked to be an implementing class of the interface
     * I_CmsTemplate.
     * If the template cache of the template class is not yet setted, this will
     * be done, too.
     * @param cms CmsObject object for accessing system resources.
     * @param classname Name of the requested template class.
     * @return Instance of the template class.
     * @throws CmsException.
     */
    protected I_CmsTemplate getTemplateClass(CmsObject cms, String classname) throws CmsException {
        if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
            A_OpenCms.log(C_OPENCMS_DEBUG, getClassName() + "Getting start template class " + classname + ". ");
        }
        Object o = CmsTemplateClassManager.getClassInstance(cms, classname);

        // Check, if the loaded class really is a OpenCms template class.

        // This is done be checking the implemented interface.
        if(!(o instanceof I_CmsTemplate)) {
            String errorMessage = "Class " + classname + " is no OpenCms template class.";
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(C_OPENCMS_CRITICAL, "[CmsTemplateClassManager] " + errorMessage);
            }
            throw new CmsException(errorMessage, CmsException.C_XML_NO_TEMPLATE_CLASS);
        }
        I_CmsTemplate cmsTemplate = (I_CmsTemplate)o;
        if(!cmsTemplate.isTemplateCacheSet()) {
            cmsTemplate.setTemplateCache(m_templateCache);

⌨️ 快捷键说明

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