📄 cmsresourcemanager.java
字号:
/**
* Returns the initialized resource type instance for the given resource type name.<p>
*
* @param typeName the name of the resource type to get
* @return the initialized resource type instance for the given name
* @throws CmsLoaderException if no resource type is available for the given name
*/
public I_CmsResourceType getResourceType(String typeName) throws CmsLoaderException {
I_CmsResourceType result = (I_CmsResourceType)m_configuration.getResourceTypeMap().get(typeName);
if (result != null) {
return result;
}
throw new CmsLoaderException(Messages.get().container(Messages.ERR_UNKNOWN_RESTYPE_NAME_REQ_1, typeName));
}
/**
* Returns the (unmodifyable array) list with all initialized resource types.<p>
*
* @return the (unmodifyable array) list with all initialized resource types
*/
public List getResourceTypes() {
// return the list of resource types
return m_configuration.getResourceTypeList();
}
/**
* Returns a template loader facade for the given file.<p>
* @param cms the current cms context
* @param resource the requested file
* @param templateProperty the property to read for the template
*
* @return a resource loader facade for the given file
* @throws CmsException if something goes wrong
*/
public CmsTemplateLoaderFacade getTemplateLoaderFacade(CmsObject cms, CmsResource resource, String templateProperty)
throws CmsException {
String absolutePath = cms.getSitePath(resource);
String templateProp = cms.readPropertyObject(absolutePath, templateProperty, true).getValue();
if (templateProp == null) {
// no template property defined, this is a must for facade loaders
throw new CmsLoaderException(Messages.get().container(
Messages.ERR_NONDEF_PROP_2,
templateProperty,
absolutePath));
}
CmsResource template = cms.readFile(templateProp, CmsResourceFilter.IGNORE_EXPIRATION);
return new CmsTemplateLoaderFacade(getLoader(template), resource, template);
}
/**
* @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration()
*/
public void initConfiguration() {
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LOADER_CONFIG_FINISHED_0));
}
m_resourceTypesFromXml = Collections.unmodifiableList(m_resourceTypesFromXml);
m_loaderList = Collections.unmodifiableList(m_loaderList);
// initalize the resource types
initResourceTypes();
}
/**
* Initializes all additional resource types stored in the modules.<p>
*
* @param cms an initialized OpenCms user context with "module manager" role permissions
*
* @throws CmsRoleViolationException in case the provided OpenCms user context did not have "module manager" role permissions
*/
public synchronized void initialize(CmsObject cms) throws CmsRoleViolationException {
if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
// some simple test cases don't require this check
cms.checkRole(CmsRole.RESOURCE_TYPE_MANAGER);
}
// initalize the resource types
initResourceTypes();
// call initialize method on all resource types
Iterator i = m_configuration.getResourceTypeList().iterator();
while (i.hasNext()) {
I_CmsResourceType type = (I_CmsResourceType)i.next();
type.initialize(cms);
}
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LOADER_CONFIG_FINISHED_0));
}
}
/**
* Loads the requested resource and writes the contents to the response stream.<p>
*
* @param req the current http request
* @param res the current http response
* @param cms the curren cms context
* @param resource the requested resource
* @throws ServletException if something goes wrong
* @throws IOException if something goes wrong
* @throws CmsException if something goes wrong
*/
public void loadResource(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException, CmsException {
res.setContentType(getMimeType(resource.getName(), cms.getRequestContext().getEncoding()));
I_CmsResourceLoader loader = getLoader(resource);
loader.load(cms, resource, req, res);
}
/**
* Extension method for handling special, loader depended actions during the include process.<p>
*
* Note: If you have multiple loaders configured that require include extensions,
* all loaders are called in the order they are configured in.<p>
*
* @param target the target for the include, might be <code>null</code>
* @param element the element to select form the target might be <code>null</code>
* @param editable the flag to indicate if the target is editable
* @param paramMap a map of parameters for the include, can be modified, might be <code>null</code>
* @param req the current request
* @param res the current response
* @throws CmsException in case something goes wrong
* @return the modified target URI
*/
public String resolveIncludeExtensions(
String target,
String element,
boolean editable,
Map paramMap,
ServletRequest req,
ServletResponse res) throws CmsException {
if (m_includeExtensions == null) {
return target;
}
String result = target;
for (int i = 0; i < m_includeExtensions.size(); i++) {
// offer the element to every include extension
I_CmsLoaderIncludeExtension loader = (I_CmsLoaderIncludeExtension)m_includeExtensions.get(i);
result = loader.includeExtension(target, element, editable, paramMap, req, res);
}
return result;
}
/**
* Sets the folder and the file translator.<p>
*
* @param folderTranslator the folder translator to set
* @param fileTranslator the file translator to set
*/
public void setTranslators(CmsResourceTranslator folderTranslator, CmsResourceTranslator fileTranslator) {
m_folderTranslator = folderTranslator;
m_fileTranslator = fileTranslator;
}
/**
* Shuts down this resource manage instance.<p>
*
* @throws Exception in case of errors during shutdown
*/
public synchronized void shutDown() throws Exception {
Iterator it = m_loaderList.iterator();
while (it.hasNext()) {
// destroy all resource loaders
I_CmsResourceLoader loader = (I_CmsResourceLoader)it.next();
loader.destroy();
}
m_loaderList = null;
m_loaders = null;
m_collectorNameMappings = null;
m_includeExtensions = null;
m_mimeTypes = null;
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SHUTDOWN_1, this.getClass().getName()));
}
}
/**
* Adds a new resource type to the internal list of loaded resource types and initializes
* options for the resource type.<p>
*
* @param resourceType the resource type to add
* @param configuration the resource configuration
*/
private synchronized void initResourceType(
I_CmsResourceType resourceType,
CmsResourceManagerConfiguration configuration) {
// add the loader to the internal list of loaders
int pos = resourceType.getTypeId();
if (pos > configuration.m_resourceTypes.length) {
I_CmsResourceType[] types = new I_CmsResourceType[pos * 2];
System.arraycopy(configuration.m_resourceTypes, 0, types, 0, configuration.m_resourceTypes.length);
configuration.m_resourceTypes = types;
}
configuration.m_resourceTypes[pos] = resourceType;
configuration.getResourceTypeList().add(resourceType);
configuration.getResourceTypeMap().put(resourceType.getTypeName(), resourceType);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_ADD_RESTYPE_3,
resourceType.getTypeName(),
new Integer(resourceType.getTypeId()),
resourceType.getClass().getName()));
}
// add the mappings
List mappings = resourceType.getConfiguredMappings();
Iterator i = mappings.iterator();
while (i.hasNext()) {
String mapping = (String)i.next();
// only add this mapping if a mapping with this file extension does not
// exist already
if (!configuration.getMappings().containsKey(mapping)) {
configuration.getMappings().put(mapping, resourceType.getTypeName());
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_MAP_RESTYPE_2,
mapping,
resourceType.getTypeName()));
}
}
}
}
/**
* Initializes member variables required for storing the resource types.<p>
*/
private synchronized void initResourceTypes() {
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_STARTING_LOADER_CONFIG_0));
}
CmsResourceManagerConfiguration newConfiguration = new CmsResourceManagerConfiguration();
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_ADD_RESTYPE_FROM_FILE_2,
new Integer(m_resourceTypesFromXml.size()),
CmsVfsConfiguration.DEFAULT_XML_FILE_NAME));
}
// build a new resource type list from the resource types of the XML configuration
Iterator i;
i = m_resourceTypesFromXml.iterator();
while (i.hasNext()) {
I_CmsResourceType resourceType = (I_CmsResourceType)i.next();
initResourceType(resourceType, newConfiguration);
}
// add all resource types declared in the modules
CmsModuleManager moduleManager = OpenCms.getModuleManager();
if (moduleManager != null) {
i = moduleManager.getModuleNames().iterator();
while (i.hasNext()) {
CmsModule module = moduleManager.getModule((String)i.next());
if (module != null && module.getResourceTypes().size() > 0) {
// module contains resource types
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_ADD_NUM_RESTYPES_FROM_MOD_2,
new Integer(module.getResourceTypes().size()),
module.getName()));
}
Iterator j = module.getResourceTypes().iterator();
while (j.hasNext()) {
I_CmsResourceType resourceType = (I_CmsResourceType)j.next();
initResourceType(resourceType, newConfiguration);
}
}
}
}
// freeze the current configuration
newConfiguration.freeze();
m_configuration = newConfiguration;
m_frozen = true;
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_RESOURCE_TYPE_INITIALIZED_0));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -