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

📄 cmsxmltemplateloader.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/legacy/CmsXmlTemplateLoader.java,v $
 * Date   : $Date: 2006/09/15 10:38:14 $
 * Version: $Revision: 1.16 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2002  Alkacon Software (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, 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 com.opencms.legacy;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsResource;
import org.opencms.flex.CmsFlexController;
import org.opencms.importexport.CmsCompatibleCheck;
import org.opencms.jsp.CmsJspTagInclude;
import org.opencms.loader.I_CmsLoaderIncludeExtension;
import org.opencms.loader.I_CmsResourceLoader;
import org.opencms.main.CmsEvent;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.I_CmsEventListener;
import org.opencms.main.OpenCms;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.editors.CmsDefaultPageEditor;

import com.opencms.core.*;
import com.opencms.template.*;
import com.opencms.template.cache.*;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.collections.ExtendedProperties;

/**
 * Implementation of the {@link I_CmsResourceLoader} for XMLTemplates.<p>
 * 
 * Parameters supported by this loader:<dl>
 * 
 * <dt>elementcache.enabled</dt>
 * <dd>(Optional) Controls if the legacy XMLTemplate element cache is disabled 
 * (the default) or enabled. Enable the element cache only to support old
 * XMLTemplate based code that depend on specific element cache behaviour.</dd>
 * 
 * <dt>elementcache.uri</dt>
 * <dd>(Optional) Element cache URI size. The default is 10000.</dd>
 * 
 * <dt>elementcache.elements</dt>
 * <dd>(Optional) Element cache element size. The default is 50000.</dd>
 * 
 * <dt>elementcache.variants</dt>
 * <dd>(Optional) Element cache variant size. The default is 100.</dd></dl>
 * 
 * @author  Alexander Kandzior (a.kandzior@alkacon.com)
 *
 * @version $Revision: 1.16 $
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public class CmsXmlTemplateLoader implements I_CmsResourceLoader, I_CmsLoaderIncludeExtension, I_CmsEventListener {

    /** URI of the bodyloader XML file in the OpenCms VFS. */
    public static final String C_BODYLOADER_URI = CmsWorkplace.VFS_PATH_SYSTEM + "shared/bodyloader.html";

    /** Magic element replace name. */
    public static final String C_ELEMENT_REPLACE = "_CMS_ELEMENTREPLACE";

    /** The id of this loader. */
    public static final int C_RESOURCE_LOADER_ID = 3;

    /** Flag for debugging output. Set to 9 for maximum verbosity. */
    private static final int DEBUG = 0;

    /** The element cache used for the online project. */
    private static CmsElementCache m_elementCache;

    /** The template cache that holds all cached templates. */
    private static I_CmsTemplateCache m_templateCache;

    /** The variant dependencies for the element cache. */
    private static Hashtable m_variantDeps;

    /** The resource loader configuration. */
    private Map m_configuration;

    /**
     * The constructor of the class is empty and does nothing.
     */
    public CmsXmlTemplateLoader() {

        OpenCms.addCmsEventListener(this);
        m_templateCache = new CmsTemplateCache();
        m_configuration = new TreeMap();
    }

    /**
     * Returns the element cache,
     * or null if the element cache is not initialized.<p>
     * 
     * @return the element cache that belongs to the given cms context
     */
    public static final CmsElementCache getElementCache() {

        return m_elementCache;
    }

    /**
     * Returns the variant dependencies of the online element cache.<p>
     * 
     * @return the variant dependencies of the online element cache
     */
    public static final CmsElementCache getOnlineElementCache() {

        return m_elementCache;
    }

    /**
     * Provides access to the current request through a CmsRequestContext, 
     * required for legacy backward compatibility.<p>
     * 
     * @param context the current request context
     * @return the request, of null if no request is available
     */
    public static I_CmsRequest getRequest(CmsRequestContext context) {

        return (I_CmsRequest)context.getAttribute(I_CmsRequest.C_CMS_REQUEST);
    }

    /**
     * Provides access to the current response through a CmsRequestContext, 
     * required for legacy backward compatibility.<p>
     * 
     * @param context the current request context
     * @return the response, of null if no request is available
     */
    public static I_CmsResponse getResponse(CmsRequestContext context) {

        return (I_CmsResponse)context.getAttribute(I_CmsResponse.C_CMS_RESPONSE);
    }

    /**
     * Provides access to the current session through a CmsRequestContext, 
     * required for legacy backward compatibility.<p>
     * 
     * @param context the current request context
     * @param value if true, try to create a session if none exist, if false, do not create a session
     * @return the response, of null if no request is available
     */
    public static I_CmsSession getSession(CmsRequestContext context, boolean value) {

        I_CmsRequest req = (I_CmsRequest)context.getAttribute(I_CmsRequest.C_CMS_REQUEST);
        HttpSession session = req.getOriginalRequest().getSession(value);
        if (session != null) {
            return new CmsSession(session);
        } else {
            return null;
        }
    }

    /**
     * Returns the hashtable with the variant dependencies used for the elementcache.<p>
     * 
     * @return the hashtable with the variant dependencies used for the elementcache
     */
    public static final Hashtable getVariantDependencies() {

        return m_variantDeps;
    }

    /**
     * Initializes the current request with the legacy Cms request and response wrappers.<p>
     * 
     * @param cms the current cms context
     * @param req the request to wrap
     * @param res the response to wrap
     * @throws CmsException if something goes wrong
     */
    public static void initLegacyRequest(CmsObject cms, HttpServletRequest req, HttpServletResponse res)
    throws CmsException {

        if (cms.getRequestContext().getAttribute(I_CmsRequest.C_CMS_REQUEST) != null) {
            return;
        }
        try {
            CmsRequestHttpServlet cmsReq = new CmsRequestHttpServlet(req, cms.getRequestContext().getFileTranslator());
            CmsResponseHttpServlet cmsRes = new CmsResponseHttpServlet(req, res);
            cms.getRequestContext().setAttribute(I_CmsRequest.C_CMS_REQUEST, cmsReq);
            cms.getRequestContext().setAttribute(I_CmsResponse.C_CMS_RESPONSE, cmsRes);
        } catch (IOException e) {
            throw new CmsLegacyException("Trouble setting up legacy request / response", e);
        }
    }

    /**
     * Returns true if the element cache is enabled.<p>
     * 
     * @return true if the element cache is enabled
     */
    public static final boolean isElementCacheEnabled() {

        return m_elementCache != null;
    }

    /**
     * Compatibility method to ensure the legacy cache command line parameters
     * are still supported.<p>
     * 
     * @param clearFiles if true, A_CmsXmlContent cache is cleared
     * @param clearTemplates if true, internal template cache is cleared
     */
    private static void clearLoaderCache(boolean clearFiles, boolean clearTemplates) {

        if (clearFiles) {
            A_CmsXmlContent.clearFileCache();
        }
        if (clearTemplates) {
            m_templateCache.clearCache();
        }
    }

    /**
     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String, java.lang.String)
     */
    public void addConfigurationParameter(String paramName, String paramValue) {

        m_configuration.put(paramName, paramValue);
    }

    /**
     * Implements the CmsEvent interface,
     * the static export properties uses the events to clear 
     * the list of cached keys in case a project is published.<p>
     *
     * @param event CmsEvent that has occurred
     */

⌨️ 快捷键说明

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