📄 cmsresourcemanager.java
字号:
throw new CmsConfigurationException(Messages.get().container(Messages.ERR_NO_CONFIG_AFTER_STARTUP_0));
}
// add the loader to the internal list of loaders
int pos = loader.getLoaderId();
if (pos > m_loaders.length) {
I_CmsResourceLoader[] buffer = new I_CmsResourceLoader[pos * 2];
System.arraycopy(m_loaders, 0, buffer, 0, m_loaders.length);
m_loaders = buffer;
}
m_loaders[pos] = loader;
if (loader instanceof I_CmsLoaderIncludeExtension) {
// this loader requires special processing during the include process
m_includeExtensions.add(loader);
}
m_loaderList.add(loader);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_ADD_LOADER_2,
loader.getClass().getName(),
new Integer(pos)));
}
}
/**
* Adds a new MIME type from the XML configuration to the internal list of MIME types.<p>
*
* @param extension the MIME type extension
* @param type the MIME type description
*
* @return the created content collector instance
*
* @throws CmsConfigurationException in case the resource manager configuration is already initialized
*/
public CmsMimeType addMimeType(String extension, String type) throws CmsConfigurationException {
// check if new resource types can still be added
if (m_frozen) {
throw new CmsConfigurationException(Messages.get().container(Messages.ERR_NO_CONFIG_AFTER_STARTUP_0));
}
CmsMimeType mimeType = new CmsMimeType(extension, type);
m_configuredMimeTypes.add(mimeType);
return mimeType;
}
/**
* Adds a new resource type from the XML configuration to the internal list of loaded resource types.<p>
*
* Resource types can also be added from a module.<p>
*
* @param resourceType the resource type to add
* @throws CmsConfigurationException in case the resource manager configuration is already initialized
*/
public synchronized void addResourceType(I_CmsResourceType resourceType) throws CmsConfigurationException {
// check if new resource types can still be added
if (m_frozen) {
throw new CmsConfigurationException(Messages.get().container(Messages.ERR_NO_CONFIG_AFTER_STARTUP_0));
}
m_resourceTypesFromXml.add(resourceType);
}
/**
* Returns the configured content collector with the given name, or <code>null</code> if
* no collector with this name is configured.<p>
*
* @param collectorName the name of the collector to get
* @return the configured content collector with the given name
*/
public I_CmsResourceCollector getContentCollector(String collectorName) {
return (I_CmsResourceCollector)m_collectorNameMappings.get(collectorName);
}
/**
* Returns the default resource type for the given resource name, using the
* configured resource type file extensions.<p>
*
* In case the given name does not map to a configured resource type,
* {@link CmsResourceTypePlain} is returned.<p>
*
* This is only required (and should <i>not</i> be used otherwise) when
* creating a new resource automatically during file upload or synchronization.
* Only in this case, the file type for the new resource is determined using this method.
* Otherwise the resource type is <i>always</i> stored as part of the resource,
* and is <i>not</i> related to the file name.<p>
*
* @param resourcename the resource name to look up the resource type for
*
* @return the default resource type for the given resource name
*
* @throws CmsException if something goes wrong
*/
public I_CmsResourceType getDefaultTypeForName(String resourcename) throws CmsException {
String typeName = null;
String suffix = null;
if (CmsStringUtil.isNotEmpty(resourcename)) {
int pos = resourcename.lastIndexOf('.');
if (pos >= 0) {
suffix = resourcename.substring(pos);
if (CmsStringUtil.isNotEmpty(suffix)) {
suffix = suffix.toLowerCase();
typeName = (String)m_configuration.getMappings().get(suffix);
}
}
}
if (typeName == null) {
// use default type "plain"
typeName = CmsResourceTypePlain.getStaticTypeName();
}
if (CmsLog.INIT.isDebugEnabled()) {
CmsLog.INIT.debug(Messages.get().getBundle().key(Messages.INIT_GET_RESTYPE_2, typeName, suffix));
}
// look up and return the resource type
return getResourceType(typeName);
}
/**
* Returns the file extensions (suffixes) mappings to resource types.<p>
*
* @return a Map with all known file extensions as keys and their resource types as values.
*/
public Map getExtensionMapping() {
return m_configuration.getMappings();
}
/**
* Returns the file translator.<p>
*
* @return the file translator
*/
public CmsResourceTranslator getFileTranslator() {
return m_fileTranslator;
}
/**
* Returns the folder translator.<p>
*
* @return the folder translator
*/
public CmsResourceTranslator getFolderTranslator() {
return m_folderTranslator;
}
/**
* Returns the loader class instance for a given resource.<p>
*
* @param resource the resource
* @return the appropriate loader class instance
* @throws CmsLoaderException if something goes wrong
*/
public I_CmsResourceLoader getLoader(CmsResource resource) throws CmsLoaderException {
return getLoader(getResourceType(resource.getTypeId()).getLoaderId());
}
/**
* Returns the loader class instance for the given loader id.<p>
*
* @param id the id of the loader to return
* @return the loader class instance for the given loader id
*/
public I_CmsResourceLoader getLoader(int id) {
return m_loaders[id];
}
/**
* Returns the (unmodifyable array) list with all initialized resource loaders.<p>
*
* @return the (unmodifyable array) list with all initialized resource loaders
*/
public List getLoaders() {
return m_loaderList;
}
/**
* Returns the mime type for a specified file name.<p>
*
* If an encoding parameter that is not <code>null</code> is provided,
* the returned mime type is extended with a <code>; charset={encoding}</code> setting.<p>
*
* If no mime type for the given filename can be determined, the
* default <code>{@link #MIMETYPE_HTML}</code> is used.<p>
*
* @param filename the file name to check the mime type for
* @param encoding the default encoding (charset) in case of mime types is of type "text"
*
* @return the mime type for a specified file
*/
public String getMimeType(String filename, String encoding) {
return getMimeType(filename, encoding, MIMETYPE_HTML);
}
/**
* Returns the mime type for a specified file name.<p>
*
* If an encoding parameter that is not <code>null</code> is provided,
* the returned mime type is extended with a <code>; charset={encoding}</code> setting.<p>
*
* If no mime type for the given filename can be determined, the
* privided default is used.<p>
*
* @param filename the file name to check the mime type for
* @param encoding the default encoding (charset) in case of mime types is of type "text"
* @param defaultMimeType the default mime type to use if no matching type for the filename is found
*
* @return the mime type for a specified file
*/
public String getMimeType(String filename, String encoding, String defaultMimeType) {
String mimeType = null;
int lastDot = filename.lastIndexOf('.');
// check the mime type for the file extension
if ((lastDot > 0) && (lastDot < (filename.length() - 1))) {
mimeType = (String)m_mimeTypes.get(filename.substring(lastDot).toLowerCase(Locale.ENGLISH));
}
if (mimeType == null) {
mimeType = defaultMimeType;
if (mimeType == null) {
// no default mime type was provided
return null;
}
}
StringBuffer result = new StringBuffer(mimeType);
if ((encoding != null) && mimeType.startsWith("text") && (mimeType.indexOf("charset") == -1)) {
result.append("; charset=");
result.append(encoding);
}
return result.toString();
}
/**
* Returns an unmodifiable List of the configured {@link CmsMimeType} objects.<p>
*
* @return an unmodifiable List of the configured {@link CmsMimeType} objects
*/
public List getMimeTypes() {
return m_configuredMimeTypes;
}
/**
* Returns an (unmodifiable) list of class names of all currently registered content collectors.<p>
*
* @return an (unmodifiable) list of class names of all currently registered content collectors
*/
public List getRegisteredContentCollectors() {
return m_collectors;
}
/**
* Returns the initialized resource type instance for the given id.<p>
*
* @param typeId the id of the resource type to get
* @return the initialized resource type instance for the given id
* @throws CmsLoaderException if no resource type is available for the given id
*/
public I_CmsResourceType getResourceType(int typeId) throws CmsLoaderException {
I_CmsResourceType result = null;
if (typeId < m_configuration.m_resourceTypes.length) {
result = m_configuration.m_resourceTypes[typeId];
}
if (result == null) {
throw new CmsLoaderException(Messages.get().container(
Messages.ERR_UNKNOWN_RESTYPE_ID_REQ_1,
new Integer(typeId)));
}
return result;
}
/**
* 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -