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

📄 cmsresourcemanager.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/loader/CmsResourceManager.java,v $
 * Date   : $Date: 2007-09-05 11:19:35 $
 * Version: $Revision: 1.45 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 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.loader;

import org.opencms.configuration.CmsConfigurationException;
import org.opencms.configuration.CmsVfsConfiguration;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.collectors.I_CmsResourceCollector;
import org.opencms.file.types.CmsResourceTypeBinary;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.file.types.CmsResourceTypeUnknownFile;
import org.opencms.file.types.CmsResourceTypeUnknownFolder;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.module.CmsModule;
import org.opencms.module.CmsModuleManager;
import org.opencms.relations.CmsRelationType;
import org.opencms.security.CmsRole;
import org.opencms.security.CmsRoleViolationException;
import org.opencms.util.CmsResourceTranslator;
import org.opencms.util.CmsStringUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;

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

import org.apache.commons.logging.Log;

/**
 * Collects all available resource loaders, resource types and resource collectors at startup and provides
 * methods to access them during OpenCms runtime.<p> 
 *
 * @author Alexander Kandzior 
 * 
 * @version $Revision: 1.45 $ 
 * 
 * @since 6.0.0 
 */
public class CmsResourceManager {

    /**
     * Contains the part of the resource manager configuration that can be changed 
     * during runtime by the import / deletion of a module.<p>
     * 
     * A module can add resource types and extension mappings to resource types.<p>
     */
    static final class CmsResourceManagerConfiguration {

        /** The mappings of file extensions to resource types. */
        protected Map m_extensionMappings;

        /** A list that contains all initialized resource types. */
        protected List m_resourceTypeList;

        /** A list that contains all initialized resource types, plus configured types for "unknown" resources. */
        protected List m_resourceTypeListWithUnknown;

        /** A map that contains all initialized resource types mapped to their type id. */
        private Map m_resourceTypeIdMap;

        /** A map that contains all initialized resource types mapped to their type name. */
        private Map m_resourceTypeNameMap;

        /**
         * Creates a new resource manager data storage.<p>
         */
        protected CmsResourceManagerConfiguration() {

            m_resourceTypeIdMap = new HashMap(128);
            m_resourceTypeNameMap = new HashMap(128);
            m_extensionMappings = new HashMap(128);
            m_resourceTypeList = new ArrayList(32);
        }

        /**
         * Adds a resource type to the list of configured resource types.<p>
         * 
         * @param type the resource type to add
         */
        protected void addResourceType(I_CmsResourceType type) {

            m_resourceTypeIdMap.put(new Integer(type.getTypeId()), type);
            m_resourceTypeNameMap.put(type.getTypeName(), type);
            m_resourceTypeList.add(type);
        }

        /**
         * Freezes the current configuration by making all data structures unmodifiable
         * that can be accessed form outside this class.<p> 
         * 
         * @param restypeUnknownFolder the configured default resource type for unknown folders
         * @param restypeUnknownFile the configured default resource type for unknown files
         */
        protected void freeze(I_CmsResourceType restypeUnknownFolder, I_CmsResourceType restypeUnknownFile) {

            // generate the resource type list with unknown resource types
            m_resourceTypeListWithUnknown = new ArrayList(m_resourceTypeList.size() + 2);
            if (restypeUnknownFolder != null) {
                m_resourceTypeListWithUnknown.add(restypeUnknownFolder);
            }
            if (restypeUnknownFile != null) {
                m_resourceTypeListWithUnknown.add(restypeUnknownFile);
            }
            m_resourceTypeListWithUnknown.addAll(m_resourceTypeList);

            // freeze the current configuration
            m_resourceTypeListWithUnknown = Collections.unmodifiableList(m_resourceTypeListWithUnknown);
            m_resourceTypeList = Collections.unmodifiableList(m_resourceTypeList);
            m_extensionMappings = Collections.unmodifiableMap(m_extensionMappings);
        }

        /**
         * Returns the configured resource type with the matching type id, or <code>null</code>
         * if a resource type with that id is not configured.<p> 
         * 
         * @param typeId the type id to get the resource type for
         * 
         * @return the configured resource type with the matching type id, or <code>null</code>
         */
        protected I_CmsResourceType getResourceTypeById(int typeId) {

            return (I_CmsResourceType)m_resourceTypeIdMap.get(new Integer(typeId));
        }

        /**
         * Returns the configured resource type with the matching type name, or <code>null</code>
         * if a resource type with that name is not configured.<p> 
         * 
         * @param typeName the type name to get the resource type for
         * 
         * @return the configured resource type with the matching type name, or <code>null</code>
         */
        protected I_CmsResourceType getResourceTypeByName(String typeName) {

            return (I_CmsResourceType)m_resourceTypeNameMap.get(typeName);
        }
    }

    /** The MIME type <code>"text/html"</code>. */
    public static final String MIMETYPE_HTML = "text/html";

    /** The MIME type <code>"text/plain"</code>. */
    public static final String MIMETYPE_TEXT = "text/plain";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsResourceManager.class);

    /** The map for all configured collector names, mapped to their collector class. */
    private Map m_collectorNameMappings;

    /** The list of all currently configured content collector instances. */
    private List m_collectors;

    /** The current resource manager configuration. */
    private CmsResourceManagerConfiguration m_configuration;

    /** The list of all configured MIME types. */
    private List m_configuredMimeTypes;

    /** The list of all configured relation types. */
    private List m_configuredRelationTypes;

    /** Filename translator, used only for the creation of new files. */
    private CmsResourceTranslator m_fileTranslator;

    /** Folder translator, used to translate all accesses to resources. */
    private CmsResourceTranslator m_folderTranslator;

    /** Indicates if the configuration is finalized (frozen). */
    private boolean m_frozen;

    /** Contains all loader extensions to the include process. */
    private List m_includeExtensions;

    /** A list that contains all initialized resource loaders. */
    private List m_loaderList;

    /** All initialized resource loaders, mapped to their id. */
    private I_CmsResourceLoader[] m_loaders;

    /** The OpenCms map of configured MIME types. */
    private Map m_mimeTypes;

    /** A list that contains all resource types added from the XML configuration. */
    private List m_resourceTypesFromXml;

    /** The configured default type for files when the resource type is missing. */
    private I_CmsResourceType m_restypeUnknownFile;

    /** The configured default type for folders when the resource type is missing. */
    private I_CmsResourceType m_restypeUnknownFolder;

    /**
     * Creates a new instance for the resource manager, 
     * will be called by the VFS configuration manager.<p>
     */
    public CmsResourceManager() {

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_STARTING_LOADER_CONFIG_0));
        }

        m_resourceTypesFromXml = new ArrayList();
        m_loaders = new I_CmsResourceLoader[16];
        m_loaderList = new ArrayList();
        m_includeExtensions = new ArrayList();
        m_configuredMimeTypes = new ArrayList();
        m_configuredRelationTypes = new ArrayList();
    }

    /**
     * Adds a given content collector class to the type manager.<p> 
     * 
     * @param className the name of the class to add
     * @param order the order number for this collector
     * 
     * @return the created content collector instance
     * 
     * @throws CmsConfigurationException in case the collector could not be properly initialized
     */
    public synchronized I_CmsResourceCollector addContentCollector(String className, String order)
    throws CmsConfigurationException {

        Class classClazz;
        // init class for content collector
        try {
            classClazz = Class.forName(className);
        } catch (ClassNotFoundException e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_CONTENT_COLLECTOR_CLASS_NOT_FOUND_1, className), e);
            return null;
        }

        I_CmsResourceCollector collector;
        try {
            collector = (I_CmsResourceCollector)classClazz.newInstance();
        } catch (InstantiationException e) {
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_INVALID_COLLECTOR_NAME_1,
                className));
        } catch (IllegalAccessException e) {
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_INVALID_COLLECTOR_NAME_1,
                className));
        } catch (ClassCastException e) {
            throw new CmsConfigurationException(Messages.get().container(
                Messages.ERR_INVALID_COLLECTOR_NAME_1,
                className));
        }

        // set the configured order for the collector
        int ord = 0;
        try {
            ord = Integer.valueOf(order).intValue();
        } catch (NumberFormatException e) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_COLLECTOR_BAD_ORDER_NUMBER_1, className), e);
        }
        collector.setOrder(ord);

        if (CmsLog.INIT.isInfoEnabled()) {

⌨️ 快捷键说明

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