📄 cmsresourcemanager.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/loader/CmsResourceManager.java,v $
* Date : $Date: 2006/03/27 14:52:37 $
* Version: $Revision: 1.36 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 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.CmsResourceTypePlain;
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.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.36 $
*
* @since 6.0.0
*/
public class CmsResourceManager {
/**
* Contains the resource manager data that can be initialized during runtime by a module.<p>
*/
final class CmsResourceManagerConfiguration {
/** Array with all configured resource types. */
protected I_CmsResourceType[] m_resourceTypes;
/** The mappings of file extensions to resource types. */
private Map m_mappings;
/** A list that contains all initialized resource types. */
private List m_resourceTypeList;
/** A map that contains all initialized resource types mapped to their type name. */
private Map m_resourceTypeMap;
/**
* Creates a new resource manager data storage.<p>
*/
protected CmsResourceManagerConfiguration() {
m_resourceTypes = new I_CmsResourceType[100];
m_resourceTypeMap = new HashMap();
m_mappings = new HashMap();
m_resourceTypeList = new ArrayList();
}
/**
* Freezes the current configuration by making all configured data sructures unmodifiable.<p> *
*/
protected void freeze() {
// freeze the current configuration
m_resourceTypeList = Collections.unmodifiableList(m_resourceTypeList);
m_resourceTypeMap = Collections.unmodifiableMap(m_resourceTypeMap);
m_mappings = Collections.unmodifiableMap(m_mappings);
}
/**
* Returns the mappings of file extensions to resource types.<p>
*
* @return the mappings of file extensions to resource types
*/
protected Map getMappings() {
return m_mappings;
}
/**
* Returns the list that contains all initialized resource types.<p>
*
* @return the list that contains all initialized resource types
*/
protected List getResourceTypeList() {
return m_resourceTypeList;
}
/**
* Returns the map that contains all initialized resource types mapped to their type name.<p>
*
* @return the map that contains all initialized resource types mapped to their type name
*/
protected Map getResourceTypeMap() {
return m_resourceTypeMap;
}
}
/** The mimetype <code>"text/html"</code>. */
public static final String MIMETYPE_HTML = "text/html";
/** The mimetype <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;
/** 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;
/**
* 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();
Properties mimeTypes = new Properties();
try {
// first try: read mime types from default package
mimeTypes.load(getClass().getClassLoader().getResourceAsStream("mimetypes.properties"));
} catch (Throwable t) {
try {
// second try: read mime types from loader package
mimeTypes.load(getClass().getClassLoader().getResourceAsStream(
"org/opencms/loader/mimetypes.properties"));
} catch (Throwable t2) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_READ_MIMETYPES_FAILED_0), t);
}
}
// initalize the Map with all available mimetypes
m_mimeTypes = new HashMap(mimeTypes.size());
Iterator i = mimeTypes.keySet().iterator();
while (i.hasNext()) {
// ensure all mime type entries are lower case
String key = (String)i.next();
String value = (String)mimeTypes.get(key);
value = value.toLowerCase(Locale.ENGLISH);
m_mimeTypes.put(key, value);
}
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_NUM_MIMETYPES_1,
new Integer(m_mimeTypes.size())));
}
}
/**
* 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()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADD_COLLECTOR_CLASS_2, className, order));
}
// extend or init the current list of configured collectors
if (m_collectors != null) {
m_collectors = new ArrayList(m_collectors);
m_collectorNameMappings = new HashMap(m_collectorNameMappings);
} else {
m_collectors = new ArrayList();
m_collectorNameMappings = new HashMap();
}
if (!m_collectors.contains(collector)) {
// this is a collector not currently configured
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -