📄 cmsresourcemanager.java
字号:
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
* provided 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
* ({@link I_CmsResourceCollector} objects).<p>
*
* @return an (unmodifiable) list of class names of all currently registered content collectors
* ({@link I_CmsResourceCollector} objects)
*/
public List getRegisteredContentCollectors() {
return m_collectors;
}
/**
* Returns an unmodifiable List of the configured {@link CmsRelationType} objects.<p>
*
* @return an unmodifiable List of the configured {@link CmsRelationType} objects
*/
public List getRelationTypes() {
return m_configuredRelationTypes;
}
/**
* Convenience method to get the initialized resource type instance for the given resource,
* with a fall back to special "unknown" resource types in case the resource type is not configured.<p>
*
* @param resource the resource to get the type for
*
* @return the initialized resource type instance for the given resource
*/
public I_CmsResourceType getResourceType(CmsResource resource) {
I_CmsResourceType result = m_configuration.getResourceTypeById(resource.getTypeId());
if (result == null) {
// this resource type is unknown, return the default files instead
if (resource.isFolder()) {
// resource is a folder
if (m_restypeUnknownFolder != null) {
result = m_restypeUnknownFolder;
} else {
result = m_configuration.getResourceTypeById(CmsResourceTypeFolder.getStaticTypeId());
}
} else {
// resource is a file
if (m_restypeUnknownFile != null) {
result = m_restypeUnknownFile;
} else {
result = m_configuration.getResourceTypeById(CmsResourceTypeBinary.getStaticTypeId());
}
}
}
return result;
}
/**
* 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 = m_configuration.getResourceTypeById(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 = m_configuration.getResourceTypeByName(typeName);
if (result != null) {
return result;
}
throw new CmsLoaderException(Messages.get().container(Messages.ERR_UNKNOWN_RESTYPE_NAME_REQ_1, typeName));
}
/**
* Returns the (unmodifiable) list with all initialized resource types.<p>
*
* @return the (unmodifiable) list with all initialized resource types
*/
public List getResourceTypes() {
return m_configuration.m_resourceTypeList;
}
/**
* Returns the (unmodifiable) list with all initialized resource types including unknown types.<p>
*
* @return the (unmodifiable) list with all initialized resource types including unknown types
*/
public List getResourceTypesWithUnknown() {
return m_configuration.m_resourceTypeListWithUnknown;
}
/**
* The configured default type for files when the resource type is missing.<p>
*
* @return the configured default type for files
*/
public I_CmsResourceType getResTypeUnknownFile() {
return m_restypeUnknownFile;
}
/**
* The configured default type for folders when the resource type is missing.<p>
*
* @return The configured default type for folders
*/
public I_CmsResourceType getResTypeUnknownFolder() {
return m_restypeUnknownFolder;
}
/**
* Returns a template loader facade for the given file.<p>
* @param cms the current OpenCms user 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 templateProp = cms.readPropertyObject(resource, 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,
cms.getSitePath(resource)));
}
CmsResource template = cms.readFile(templateProp, CmsResourceFilter.IGNORE_EXPIRATION);
return new CmsTemplateLoaderFacade(getLoader(template), resource, template);
}
/**
* Checks if an initialized resource type instance equal to the given resource type is available.<p>
*
* @param type the resource type to check
* @return <code>true</code> if such a resource type has been configured, <code>false</code> otherwise
*
* @see #getResourceType(String)
* @see #getResourceType(int)
*/
public boolean hasResourceType(I_CmsResourceType type) {
return hasResourceType(type.getTypeId());
}
/**
* Checks if an initialized resource type instance for the given resource type is is available.<p>
*
* @param typeId the id of the resource type to check
* @return <code>true</code> if such a resource type has been configured, <code>false</code> otherwise
*
* @see #getResourceType(int)
*/
public boolean hasResourceType(int typeId) {
return m_configuration.getResourceTypeById(typeId) != null;
}
/**
* Checks if an initialized resource type instance for the given resource type name is available.<p>
*
* @param typeName the name of the resource type to check
* @return <code>true</code> if such a resource type has been configured, <code>false</code> otherwise
*
* @see #getResourceType(String)
*/
public boolean hasResourceType(String typeName) {
return m_configuration.getResourceTypeByName(typeName) != null;
}
/**
* @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration()
*
* @throws CmsConfigurationException in case of duplicate resource types in the configuration
*/
public void initConfiguration() throws CmsConfigurationException {
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);
Collections.sort(m_configuredMimeTypes);
m_configuredMimeTypes = Collections.unmodifiableList(m_configuredMimeTypes);
m_configuredRelationTypes = Collections.unmodifiableList(m_configuredRelationTypes);
// initialize the resource types
initResourceTypes();
// initialize the MIME types
initMimeTypes();
}
/**
* 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
* @throws CmsConfigurationException in case of duplicate resource types in the configuration
*/
public synchronized void initialize(CmsObject cms) throws CmsRoleViolationException, CmsConfigurationException {
if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
// some simple test cases don't require this check
OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -