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

📄 cmsxmltemplate.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/CmsXmlTemplate.java,v $
 * Date   : $Date: 2005/06/27 23:22:20 $
 * Version: $Revision: 1.6 $
 *
 * 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.template;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsRequestContext;
import org.opencms.i18n.CmsEncoder;
import org.opencms.importexport.CmsCompatibleCheck;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.workplace.editors.CmsDefaultPageEditor;

import com.opencms.defaults.A_CmsContentDefinition;
import com.opencms.defaults.I_CmsTimedContentDefinition;
import com.opencms.legacy.CmsLegacyException;
import com.opencms.legacy.CmsXmlTemplateLoader;
import com.opencms.template.cache.A_CmsElement;
import com.opencms.template.cache.CmsElementCache;
import com.opencms.template.cache.CmsElementDefinition;
import com.opencms.template.cache.CmsElementDefinitionCollection;
import com.opencms.template.cache.CmsElementDescriptor;
import com.opencms.template.cache.CmsElementVariant;
import com.opencms.template.cache.CmsElementXml;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;

/**
 * Template class for displaying the processed contents of hierachical XML template files
 * that can include other subtemplates.
 *
 * @author Alexander Lucas
 * @version $Revision: 1.6 $ $Date: 2005/06/27 23:22:20 $
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public class CmsXmlTemplate extends A_CmsTemplate implements I_CmsXmlTemplate {

    /** Name of the special body element. */
    public static final String C_BODY_ELEMENT = CmsDefaultPageEditor.XML_BODY_ELEMENT;

    /** Boolean for additional debug output control. */
    public static final boolean C_DEBUG = true;

    /** Name of the frame selector parameter. */
    public static final String C_FRAME_SELECTOR = "cmsframe";

    /**
     * Template cache for storing cacheable results of the subtemplates.
     */
    protected static com.opencms.template.I_CmsTemplateCache m_cache;

    /** Element descriptor. */
    private static final String C_ELEMENT = "_ELEMENT_";

    /** Error string to be inserted for corrupt subtemplates for guest user requests. */
    private static final String C_ERRORTEXT = "ERROR!";

    /**
     * For debugging purposes only.
     * Counts the number of re-uses od the instance of this class.
     */
    private int m_counter;

    /**
     * Collect caching informations from the current template class.
     * <P>
     * Complex classes that are able to include other subtemplates
     * have to check the streaming ability of their subclasses here!
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public CmsCacheDirectives collectCacheDirectives(CmsObject cms, String templateFile,
        String elementName, Hashtable parameters, String templateSelector) {

        // Frist build our own cache directives.
        boolean isCacheable = isCacheable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isProxyPrivateCacheable = isProxyPrivateCacheable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isProxyPublicCacheable = isProxyPublicCacheable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isExportable = isExportable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isStreamable = isStreamable(cms, templateFile, elementName, parameters, templateSelector);
        CmsCacheDirectives result = new CmsCacheDirectives(isCacheable, isProxyPrivateCacheable,
            isProxyPublicCacheable, isExportable, isStreamable);

        // Collect all subelements of this page
        CmsXmlTemplateFile doc = null;
        Vector subtemplates = null;
        try {
            doc = this.getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
            doc.init(cms, templateFile);
            subtemplates = doc.getAllSubElements();

            // Loop through all subelements and get their cache directives
            int numSubtemplates = subtemplates.size();
            for (int i = 0; i < numSubtemplates; i++) {
                String elName = (String)subtemplates.elementAt(i);
                String className = null;
                String templateName = null;

                className = getTemplateClassName(elName, doc, parameters);
                templateName = getTemplateFileName(elName, doc, parameters);

                if (className != null) {
                    I_CmsTemplate templClass = (I_CmsTemplate)CmsTemplateClassManager.getClassInstance(className);
                    CmsCacheDirectives cd2 = templClass.collectCacheDirectives(cms, templateName, elName, parameters, null);
                    /*System.err.println("*                INT PUB PRV EXP STR");
                     debugPrint(elementName, result.m_cd);
                     System.err.println(" ");
                     debugPrint(elName, cd2.m_cd);
                     System.err.println(" " + templClass.getClass());
                     System.err.println("*                -------------------");*/

                    //result.merge(templClass.collectCacheDirectives(cms, templateName, elName, parameters, null));
                    result.merge(cd2);
                    /*debugPrint(elementName, result.m_cd);
                     System.err.println(" ");
                     System.err.println("* ");*/
                } else {
                    // This template file includes a subelement not exactly defined.
                    // The name of it's template class is missing at the moment, so
                    // we cannot say anything about the cacheablility.
                    // Set it to false.
                    return new CmsCacheDirectives(false);
                }
            }
        } catch (CmsException e) {
            if (CmsLog.getLog(this).isInfoEnabled()) {
                CmsLog.getLog(this).info("Can not determine cache directives for my template file "
                    + templateFile, e);
                return new CmsCacheDirectives(false);
            }
        }
        return result;

    }

    /**
     * For debugging purposes only.
     * Increments the class variable <code>counter</code> and
     * prints out its new value..
     * <P>
     * May be called from the template file using
     * <code>&lt;METHOD name="counter"&gt;</code>.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object the initiating XLM document.
     * @param userObject Hashtable with parameters.
     * @return Actual value of <code>counter</code>.
     */
    public Integer counter(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject)
    throws CmsException {

        m_counter++;
        return new Integer(m_counter);
    }

    /**
     * Create a new element for the element cache consisting of the current template
     * class and the given template file.
     * <P>
     * Complex template classes that are able to include other (sub-)templates
     * must generate a collection of element definitions for their possible
     * subtemplates. This collection is part of the new element.
     * @param cms CmsObject for accessing system resources.
     * @param templateFile Name of the template file for the new element
     * @param parameters All parameters of the current request
     * @return New element for the element cache
     */
    public A_CmsElement createElement(CmsObject cms, String templateFile, Hashtable parameters) {

        CmsElementDefinitionCollection subtemplateDefinitions = new CmsElementDefinitionCollection();
        int variantCachesize = 100;
        // if the templateFile is null someone didnt set the Templatefile in the elementdefinition
        // in this case we have to use the aktual body template when resolving the variant.
        // In a body element there are no subelements and we dont care about access rights.
        // So if if the Exception occurs becource of the template == null it is no error and
        // we set the readAccessGroup = null (this will happen by getReadingpermittedGroup)
        try {
            CmsElementCache elementCache = CmsXmlTemplateLoader.getElementCache();
            variantCachesize = elementCache.getVariantCachesize();

            CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, null, parameters, null);

            Vector subtemplates = xmlTemplateDocument.getAllSubElementDefinitions();

            int numSubtemplates = subtemplates.size();
            for (int i = 0; i < numSubtemplates; i++) {
                String elName = (String)subtemplates.elementAt(i);
                String className = null;
                String templateName = null;
                String templateSelector = null;

                if (xmlTemplateDocument.hasSubtemplateClass(elName)) {
                    className = xmlTemplateDocument.getSubtemplateClass(elName);
                }

                if (xmlTemplateDocument.hasSubtemplateFilename(elName)) {
                    templateName = xmlTemplateDocument.getSubtemplateFilename(elName);
                }

                if (xmlTemplateDocument.hasSubtemplateSelector(elName)) {
                    templateSelector = xmlTemplateDocument.getSubtemplateSelector(elName);
                }
                Hashtable templateParameters = xmlTemplateDocument.getParameters(elName);
                if (className != null || templateName != null || templateSelector != null
                    || templateParameters.size() > 0) {
                    if (className == null) {
                        className = CmsCompatibleCheck.XML_CONTROL_DEFAULT_CLASS;
                    }
                    if (templateName != null) {
                        templateName = CmsLinkManager.getAbsoluteUri(templateName, templateFile);
                    }
                    CmsElementDefinition elDef = new CmsElementDefinition(elName, className,
                        templateName, templateSelector, templateParameters);
                    subtemplateDefinitions.add(elDef);
                }
            }
        } catch (Exception e) {
            if (templateFile != null) {
                if (CmsLog.getLog(this).isWarnEnabled()) {
                    CmsLog.getLog(this).warn("Could not generate my template cache element", e);
                }
            }
        }
        CmsElementXml result = new CmsElementXml(getClass().getName(), templateFile,
            getCacheDirectives(cms, templateFile, null, parameters, null), subtemplateDefinitions,
            variantCachesize);
        return result;
    }

    /**
     * gets the caching information from the current template class.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile,
        String elementName, Hashtable parameters, String templateSelector) {

⌨️ 快捷键说明

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