📄 a_cmsresourcetype.java
字号:
if (isNew) {
// if the source was new, destination must get a new lock
securityManager.lockResource(cms.getRequestContext(), destinationResource, CmsLock.COMMON);
} else {
// if source existed, destination must "steal" the lock
securityManager.changeLock(cms.getRequestContext(), destinationResource);
}
}
public void removeResourceFromProject(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource)
throws CmsException {
securityManager.removeResourceFromProject(cms.getRequestContext(), resource);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#replaceResource(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, int, byte[], List)
*/
public void replaceResource(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource resource,
int type,
byte[] content,
List properties) throws CmsException {
securityManager.replaceResource(cms.getRequestContext(), resource, type, content, properties);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#restoreResourceBackup(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, int)
*/
public void restoreResourceBackup(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource, int tag)
throws CmsException {
securityManager.restoreResource(cms.getRequestContext(), resource, tag);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#setAdditionalModuleResourceType(boolean)
*/
public void setAdditionalModuleResourceType(boolean additionalType) {
m_addititionalModuleResourceType = additionalType;
}
/**
* @see org.opencms.file.types.I_CmsResourceType#setDateExpired(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, long, boolean)
*/
public void setDateExpired(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource resource,
long dateExpired,
boolean recursive) throws CmsException {
securityManager.setDateExpired(cms.getRequestContext(), resource, dateExpired);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#setDateLastModified(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, long, boolean)
*/
public void setDateLastModified(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource resource,
long dateLastModified,
boolean recursive) throws CmsException {
securityManager.setDateLastModified(cms.getRequestContext(), resource, dateLastModified);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#setDateReleased(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, long, boolean)
*/
public void setDateReleased(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource resource,
long dateReleased,
boolean recursive) throws CmsException {
securityManager.setDateReleased(cms.getRequestContext(), resource, dateReleased);
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer output = new StringBuffer();
output.append("[ResourceType] class=");
output.append(getClass().getName());
output.append(" name=");
output.append(getTypeName());
output.append(" id=");
output.append(getTypeId());
output.append(" loaderId=");
output.append(getLoaderId());
return output.toString();
}
/**
* @see org.opencms.file.types.I_CmsResourceType#undoChanges(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, boolean)
*/
public void undoChanges(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource, boolean recursive)
throws CmsException {
securityManager.undoChanges(cms.getRequestContext(), resource);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#unlockResource(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource)
*/
public void unlockResource(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource)
throws CmsException {
securityManager.unlockResource(cms.getRequestContext(), resource);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#writeFile(org.opencms.file.CmsObject, CmsSecurityManager, CmsFile)
*/
public CmsFile writeFile(CmsObject cms, CmsSecurityManager securityManager, CmsFile resource)
throws CmsException, CmsVfsException, CmsSecurityException {
if (resource.isFile()) {
return securityManager.writeFile(cms.getRequestContext(), resource);
}
// folders can never be written like a file
throw new CmsVfsException(Messages.get().container(
Messages.ERR_WRITE_FILE_IS_FOLDER_1,
cms.getSitePath(resource)));
}
/**
* @see org.opencms.file.types.I_CmsResourceType#writePropertyObject(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, CmsResource, org.opencms.file.CmsProperty)
*/
public void writePropertyObject(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource resource,
CmsProperty property) throws CmsException {
securityManager.writePropertyObject(cms.getRequestContext(), resource, property);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#writePropertyObjects(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, CmsResource, java.util.List)
*/
public void writePropertyObjects(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource resource,
List properties) throws CmsException {
securityManager.writePropertyObjects(cms.getRequestContext(), resource, properties);
}
/**
* Creates a macro resolver based on the current users OpenCms context and the provided resource name.<p>
*
* @param cms the current OpenCms user context
* @param resourcename the resource name for macros like {@link A_CmsResourceType#MACRO_RESOURCE_FOLDER_PATH}
*
* @return a macro resolver based on the current users OpenCms context and the provided resource name
*/
protected CmsMacroResolver getMacroResolver(CmsObject cms, String resourcename) {
CmsMacroResolver result = CmsMacroResolver.newInstance().setCmsObject(cms);
if (isFolder() && (!CmsResource.isFolder(resourcename))) {
// ensure folder ends with "/" so
resourcename = resourcename.concat("/");
}
// add special mappings for macros in default properties
result.addMacro(MACRO_RESOURCE_ROOT_PATH, cms.getRequestContext().addSiteRoot(resourcename));
result.addMacro(MACRO_RESOURCE_SITE_PATH, resourcename);
result.addMacro(MACRO_RESOURCE_FOLDER_PATH, CmsResource.getFolderPath(resourcename));
result.addMacro(MACRO_RESOURCE_PARENT_PATH, CmsResource.getParentFolder(resourcename));
result.addMacro(MACRO_RESOURCE_NAME, CmsResource.getName(resourcename));
return result;
}
/**
* Convenience method to return the initialized resource type
* instance for the given id.<p>
*
* @param resourceType the id of the resource type to get
* @return the initialized resource type instance for the given id
* @throws CmsException if something goes wrong
*
* @see org.opencms.loader.CmsResourceManager#getResourceType(int)
*/
protected I_CmsResourceType getResourceType(int resourceType) throws CmsException {
return OpenCms.getResourceManager().getResourceType(resourceType);
}
/**
* Processes the copy resources of this resource type.<p>
*
* @param cms the current OpenCms user context
* @param resourcename the name of the base resource
* @param resolver the resolver used for resolving target macro names
*/
protected void processCopyResources(CmsObject cms, String resourcename, CmsMacroResolver resolver) {
Iterator i = m_copyResources.iterator();
while (i.hasNext()) {
CmsConfigurationCopyResource copyResource = (CmsConfigurationCopyResource)i.next();
String target = copyResource.getTarget();
if (copyResource.isTargetWasNull()
|| target.equals(CmsMacroResolver.formatMacro(MACRO_RESOURCE_FOLDER_PATH))) {
// target is just the resource folder, must add source file name to target
target = target.concat(CmsResource.getName(copyResource.getSource()));
}
// now resolve the macros in the target name
target = resolver.resolveMacros(target);
// now resolve possible releative paths in the target
target = CmsFileUtil.normalizePath(CmsLinkManager.getAbsoluteUri(target, resourcename), '/');
try {
cms.copyResource(copyResource.getSource(), target, copyResource.getType());
} catch (Exception e) {
// CmsIllegalArgumentException as well as CmsException
// log the error and continue with the other copy resources
if (LOG.isDebugEnabled()) {
// log stack trace in debug level only
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_PROCESS_COPY_RESOURCES_3,
resourcename,
copyResource,
target), e);
} else {
LOG.error(Messages.get().getBundle().key(
Messages.LOG_PROCESS_COPY_RESOURCES_3,
resourcename,
copyResource,
target));
}
}
}
}
/**
* Returns a list of property objects that are attached to the resource on creation.<p>
*
* It's possible to use OpenCms macros for the property values.
* Please see {@link CmsMacroResolver} for allowed macro values.<p>
*
* @param properties the (optional) properties provided by the user
* @param resolver the resolver used to resolve the macro values
*
* @return a list of property objects that are attached to the resource on creation
*/
protected List processDefaultProperties(List properties, CmsMacroResolver resolver) {
if ((m_defaultProperties == null) || (m_defaultProperties.size() == 0)) {
// no default properties are defined
return properties;
}
// the properties must be copied since the macros could contain macros that are
// resolved differently for every user / context
ArrayList result = new ArrayList();
Iterator i = m_defaultProperties.iterator();
while (i.hasNext()) {
// create a clone of the next property
CmsProperty property = (CmsProperty)((CmsProperty)i.next()).clone();
// resolve possible macros in the property values
if (property.getResourceValue() != null) {
property.setResourceValue(resolver.resolveMacros(property.getResourceValue()));
}
if (property.getStructureValue() != null) {
property.setStructureValue(resolver.resolveMacros(property.getStructureValue()));
}
// save the new property in the result list
result.add(property);
}
// add the original properties
if (properties != null) {
result.addAll(properties);
}
// return the result
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -