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

📄 a_cmselement.java

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

import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsSecurityException;

import com.opencms.legacy.CmsLegacyException;
import com.opencms.legacy.CmsXmlTemplateLoader;
import com.opencms.template.A_CmsCacheDirectives;
import com.opencms.template.CmsCacheDirectives;
import com.opencms.template.CmsTemplateClassManager;
import com.opencms.template.I_CmsTemplate;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 * An instance of A_CmsElement represents an requestable Element in the OpenCms
 * element cache area. It contains all informations to generate the content of this
 * element. It also stores the variants of once generated content to speed up
 * performance.
 *
 * It may point to other depending elements. Theses elements are called to generate
 * their content on generation-time.
 *
 * @author Andreas Schouten
 * @author Alexander Lucas
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */
public abstract class A_CmsElement {

    /** The class-name of this element definition. */
    protected String m_className;

    /** The template-name of this element definition. */
    protected String m_templateName;

    /** Cache directives of this element. */
    protected A_CmsCacheDirectives m_cacheDirectives;

    /** Last time this element was generated.(used for CacheDirectives timeout) */
    protected long m_timestamp = 0;

    /** All definitions declared in this element. */
    protected CmsElementDefinitionCollection m_elementDefinitions;

    /** LruCache for element variant cache */
    private CmsLruCache m_variants;

    /** indicates if this element may have a variant that has dependencies
     *  if such a element is deletet from elementcache the extern dependencies
     *  hashtable must be updated.
     */
    protected boolean m_hasDepVariants = false;

    /**
     * Initializer for an element with the given class and template name.
     */
    protected void init(String className, String templateName, A_CmsCacheDirectives cd,
        int variantCachesize) {

        m_className = className;
        m_templateName = templateName;
        m_cacheDirectives = cd;
        m_elementDefinitions = new CmsElementDefinitionCollection();
        m_variants = new CmsLruCache(variantCachesize);
    }

    /**
     * Initializer for building an element with the given element definitions.
     * @param name the name of this element-definition.
     * @param className the classname of this element-definition.
     * @param cd Cache directives for this element
     * @param defs Vector with ElementDefinitions for this element.
     * @param variantCachesize The size of the variant cache.
     */
    protected void init(String className, String templateName, A_CmsCacheDirectives cd,
        CmsElementDefinitionCollection defs, int variantCachesize) {

        m_className = className;
        m_templateName = templateName;
        m_cacheDirectives = cd;
        m_elementDefinitions = defs;
        m_variants = new CmsLruCache(variantCachesize);
    }

    /**
     * Adds a single definition to this element.
     * @param def - the ElementDefinition to add.
     */
    public void addDefinition(CmsElementDefinition def) {

        m_elementDefinitions.add(def);
    }

    /**
     * Adds a single variant to this element.
     * @param def - the ElementVariant to add.
     * @return a CmsElementVariant of dependencies that must be deleted from extern store for this element
     */
    public Vector addVariant(Object key, CmsElementVariant variant) {

        if (CmsLog.getLog(this).isInfoEnabled()) {
            CmsLog.getLog(this).info("Adding variant \"" + key + "\" to xml template cache");
        }
        if (key != null) {
            CmsElementVariant old = (CmsElementVariant)m_variants.get(key);
            if ((old != null) && (old.size() == 0)) {
                variant.addDependencies(old.getDependencies());
                variant.mergeNextTimeout(old.getNextTimeout());
            }
            return m_variants.put(key, variant);
        }
        return null;
    }

    public void removeVariant(Object key) {

        if (CmsLog.getLog(this).isInfoEnabled()) {
            CmsLog.getLog(this).info(toString() + " removing variant \"" + key
                + "\" from xml template cache");
        }
        if (key != null) {
            m_variants.remove(key);
        }
    }

    /**
     * checks the read access.
     * @param cms The cms Object for reading groups.
     * @throws CmsException if no read access.
     */
    public void checkReadAccess(CmsObject cms) throws CmsException {

        return;
    }

    /**
     * Clears all variants. Used for TimeCritical elements.
     */
    public void clearVariantCache() {

        m_variants.clearCache();
        m_timestamp = System.currentTimeMillis();
    }

    /**
     *
     */
    public Vector getAllVariantKeys() {

        return m_variants.getAllKeys();
    }

    /**
     * Get a variant from the vatiant cache
     * @param key Key of the ElementVariant.
     * @return Cached CmsElementVariant object
     */
    public CmsElementVariant getVariant(Object key) {

        if (key == null) {
            return null;
        }
        CmsElementVariant result = (CmsElementVariant)m_variants.get(key);
        if (result != null && result.size() == 0) {
            result = null;
        }
        if (CmsLog.getLog(this).isInfoEnabled()) {
            if (result != null) {
                CmsLog.getLog(this).info(toString() + " getting variant \"" + key
                    + "\" from cache. ");
            } else {
                CmsLog.getLog(this).info(toString() + " Variant \"" + key
                    + "\" is not in element cache. ");
            }
        }
        return result;
    }

    /**
     * says if the extern dependenciescache has to be updated when this element
     * is deleted.
     */
    public boolean hasDependenciesVariants() {

        return m_hasDepVariants;
    }

    /**
     * indicates this element critical for delete.
     */
    public void thisElementHasDepVariants() {

        m_hasDepVariants = true;
    }

    /**
     * Returns a Vector with all ElementDefinitions
     * @return a Vector with all ElementDefinitions.
     */
    public CmsElementDefinitionCollection getAllDefinitions() {

        return m_elementDefinitions;
    }

    /**
     * Get the element definition for the sub-element with the given name
     * @param name Name of the sub-element that should be looked up
     * @return Element definition of <em>name</em>
     */
    public CmsElementDefinition getElementDefinition(String name) {

        return m_elementDefinitions.get(name);
    }

    /** Get cache directives for this element.
     *  @return cache directives.
     */
    public A_CmsCacheDirectives getCacheDirectives() {

        return m_cacheDirectives;
    }

    /**
     * checks the proxy public and the proxy private cache settings
     *  of this element and all subelements.
     *  @param cms the cms object.
     *  @param proxySettings The CacheDirectives to merge the own CacheDriectives with.
     *  @param parameters A Hashtable with the parameters.
     */
    public void checkProxySettings(CmsObject cms, CmsCacheDirectives proxySettings,
        Hashtable parameters) throws CmsException {

        // first our own cachedirectives are they set or not?
        if (!(m_cacheDirectives.userSetProxyPrivate() && m_cacheDirectives.userSetProxyPublic())) {
            // we have to find out manually
            boolean proxyPublic = false;
            boolean proxyPrivate = false;
            boolean export = false;
            if (m_templateName == null) {
                // no template given set everything to true
                proxyPublic = true;
                proxyPrivate = true;
                export = true;
            } else {
                try {
                    if (m_cacheDirectives.isInternalCacheable()
                        && (!m_cacheDirectives.isUserPartOfKey())) {
                        CmsResource templ = cms.readResource(m_templateName);
                        int accessflags = templ.getFlags();
                        if (!((accessflags & CmsResource.FLAG_INTERNAL) > 0)) {
                            // internal flag not set
                            proxyPrivate = true;
                            if ((!m_cacheDirectives.isParameterPartOfKey())
                                && (!m_cacheDirectives.isTimeCritical())) {

⌨️ 快捷键说明

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