📄 cmsdrivermanager.java
字号:
*
* @see CmsObject#chtype(String, int)
* @see I_CmsResourceType#chtype(CmsObject, CmsSecurityManager, CmsResource, int)
*/
public void chtype(CmsDbContext dbc, CmsResource resource, int type) throws CmsException {
// must operate on a clone to ensure resource is not modified in case permissions are not granted
CmsResource clone = (CmsResource)resource.clone();
I_CmsResourceType newType = OpenCms.getResourceManager().getResourceType(type);
clone.setType(newType.getTypeId());
writeResource(dbc, clone);
}
/**
* @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent)
*/
public void cmsEvent(CmsEvent event) {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_CMS_EVENT_1, new Integer(event.getType())));
}
I_CmsReport report;
CmsDbContext dbc;
switch (event.getType()) {
case I_CmsEventListener.EVENT_UPDATE_EXPORTS:
report = (I_CmsReport)event.getData().get(I_CmsEventListener.KEY_REPORT);
dbc = (CmsDbContext)event.getData().get(I_CmsEventListener.KEY_DBCONTEXT);
updateExportPoints(dbc, report);
break;
case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
CmsUUID publishHistoryId = new CmsUUID((String)event.getData().get(I_CmsEventListener.KEY_PUBLISHID));
report = (I_CmsReport)event.getData().get(I_CmsEventListener.KEY_REPORT);
dbc = (CmsDbContext)event.getData().get(I_CmsEventListener.KEY_DBCONTEXT);
int projectId = ((Integer)event.getData().get(I_CmsEventListener.KEY_PROJECTID)).intValue();
writeExportPoints(dbc, projectId, report, publishHistoryId);
break;
case I_CmsEventListener.EVENT_CLEAR_CACHES:
clearcache(false);
break;
case I_CmsEventListener.EVENT_CLEAR_PRINCIPAL_CACHES:
clearcache(true);
break;
default:
// noop
}
}
/**
* Copies the access control entries of a given resource to a destination resorce.<p>
*
* Already existing access control entries of the destination resource are removed.<p>
* @param dbc the current database context
* @param source the resource to copy the access control entries from
* @param destination the resource to which the access control entries are copied
* @param updateLastModifiedInfo if true, user and date "last modified" information on the target resource will be updated
*
* @throws CmsException if something goes wrong
*/
public void copyAccessControlEntries(
CmsDbContext dbc,
CmsResource source,
CmsResource destination,
boolean updateLastModifiedInfo) throws CmsException {
// get the entries to copy
ListIterator aceList = m_userDriver.readAccessControlEntries(
dbc,
dbc.currentProject(),
source.getResourceId(),
false).listIterator();
// remove the current entries from the destination
m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), destination.getResourceId());
// now write the new entries
while (aceList.hasNext()) {
CmsAccessControlEntry ace = (CmsAccessControlEntry)aceList.next();
m_userDriver.createAccessControlEntry(
dbc,
dbc.currentProject(),
destination.getResourceId(),
ace.getPrincipal(),
ace.getPermissions().getAllowedPermissions(),
ace.getPermissions().getDeniedPermissions(),
ace.getFlags());
}
// update the "last modified" information
if (updateLastModifiedInfo) {
setDateLastModified(dbc, destination, destination.getDateLastModified());
}
// clear the cache
clearAccessControlListCache();
// fire a resource modification event
OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap(
"resource",
destination)));
}
/**
* Copies a resource.<p>
*
* You must ensure that the destination path is anabsolute, vaild and
* existing VFS path. Relative paths from the source are currently not supported.<p>
*
* In case the target resource already exists, it is overwritten with the
* source resource.<p>
*
* The <code>siblingMode</code> parameter controls how to handle siblings
* during the copy operation.
* Possible values for this parameter are:
* <ul>
* <li><code>{@link org.opencms.file.CmsResource#COPY_AS_NEW}</code></li>
* <li><code>{@link org.opencms.file.CmsResource#COPY_AS_SIBLING}</code></li>
* <li><code>{@link org.opencms.file.CmsResource#COPY_PRESERVE_SIBLING}</code></li>
* </ul><p>
*
* @param dbc the current database context
* @param source the resource to copy
* @param destination the name of the copy destination with complete path
* @param siblingMode indicates how to handle siblings during copy
*
* @throws CmsException if something goes wrong
* @throws CmsIllegalArgumentException if the <code>source</code> argument is null or of length 0
*
* @see CmsObject#copyResource(String, String, int)
* @see I_CmsResourceType#copyResource(CmsObject, CmsSecurityManager, CmsResource, String, int)
*/
public void copyResource(CmsDbContext dbc, CmsResource source, String destination, int siblingMode)
throws CmsException, CmsIllegalArgumentException {
// check the sibling mode to see if this resource has to be copied as a sibling
boolean copyAsSibling = false;
// siblings of folders are not supported
if (!source.isFolder()) {
// if the "copy as sibling" mode is used, set the flag to true
if (siblingMode == CmsResource.COPY_AS_SIBLING) {
copyAsSibling = true;
}
// if the mode is "preserve siblings", we have to check the sibling counter
if (siblingMode == CmsResource.COPY_PRESERVE_SIBLING) {
if (source.getSiblingCount() > 1) {
copyAsSibling = true;
}
}
}
// read the source properties
List properties = readPropertyObjects(dbc, source, false);
if (copyAsSibling) {
// create a sibling of the source file at the destination
createSibling(dbc, source, destination, properties);
// after the sibling is created the copy operation is finished
return;
}
// prepare the content if required
byte[] content = null;
if (source.isFile()) {
CmsFile file;
if (source instanceof CmsFile) {
// resource already is a file
file = (CmsFile)source;
content = file.getContents();
}
if ((content == null) || (content.length < 1)) {
// no known content yet - read from database
file = m_vfsDriver.readFile(dbc, dbc.currentProject().getId(), false, source.getStructureId());
content = file.getContents();
}
}
// determine desitnation folder and resource name
String destinationFoldername = CmsResource.getParentFolder(destination);
String destinationResourceName = destination.substring(destinationFoldername.length());
if (CmsResource.isFolder(destinationResourceName)) {
// must cut of trailing '/' on destination folders
destinationResourceName = destinationResourceName.substring(0, destinationResourceName.length() - 1);
}
// read the destination folder (will also check read permissions)
CmsFolder destinationFolder = m_securityManager.readFolder(
dbc,
destinationFoldername,
CmsResourceFilter.IGNORE_EXPIRATION);
// no further permission check required here, will be done in createResource()
// set user and creation timestamps
long currentTime = System.currentTimeMillis();
long dateLastModified;
CmsUUID userLastModified;
if (source.isFolder()) {
// folders always get a new date and uswer when they are copied
dateLastModified = currentTime;
userLastModified = dbc.currentUser().getId();
} else {
// files keep the date and user last modified from the source
dateLastModified = source.getDateLastModified();
userLastModified = source.getUserLastModified();
}
// check the resource flags
int flags = source.getFlags();
if (source.isLabeled()) {
// reset "labeled" link flag for new resource
flags &= ~CmsResource.FLAG_LABELED;
}
// create the new resource
CmsResource newResource = new CmsResource(
new CmsUUID(),
new CmsUUID(),
destination,
source.getTypeId(),
source.isFolder(),
flags,
dbc.currentProject().getId(),
CmsResource.STATE_NEW,
currentTime,
dbc.currentUser().getId(),
dateLastModified,
userLastModified,
source.getDateReleased(),
source.getDateExpired(),
1,
source.getLength());
// trigger "is touched" state on resource (will ensure modification date is kept unchanged)
newResource.setDateLastModified(dateLastModified);
// create the resource
newResource = createResource(dbc, destination, newResource, content, properties, false);
// copy the access control entries to the created resource
copyAccessControlEntries(dbc, source, newResource, false);
// clear the cache
clearAccessControlListCache();
List modifiedResources = new ArrayList();
modifiedResources.add(source);
modifiedResources.add(newResource);
modifiedResources.add(destinationFolder);
OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_COPIED, Collections.singletonMap(
"resources",
modifiedResources)));
}
/**
* Copies a resource to the current project of the user.<p>
*
* @param dbc the current database context
* @param resource the resource to apply this operation to
*
* @throws CmsException if something goes wrong
*
* @see CmsObject#copyResourceToProject(String)
* @see I_CmsResourceType#copyResourceToProject(CmsObject, CmsSecurityManager, CmsResource)
*/
public void copyResourceToProject(CmsDbContext dbc, CmsResource resource) throws CmsException {
// copy the resource to the project only if the resource is not already in the project
if (!isInsideCurrentProject(dbc, resource.getRootPath())) {
// check if there are already any subfolders of this resource
if (resource.isFolder()) {
List projectResources = m_projectDriver.readProjectResources(dbc, dbc.currentProject());
for (int i = 0; i < projectResources.size(); i++) {
String resname = (String)projectResources.get(i);
if (resname.startsWith(resource.getRootPath())) {
// delete the existing project resource first
m_projectDriver.deleteProjectResource(dbc, dbc.currentProject().getId(), resname);
}
}
}
try {
m_projectDriver.createProjectResource(dbc, dbc.currentProject().getId(), resource.getRootPath(), null);
} catch (CmsException exc) {
// if the subfolder exists already - all is ok
} finally {
OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROJECT_MODIFIED, Collections.singletonMap(
"project",
dbc.currentProject())));
}
}
}
/**
* Counts the locked resources in a given folder.<p>
*
* @param dbc the current database context
* @param foldername the folder to search in
*
* @return the amount of locked resources in this project
*
* @throws CmsLockException if the current project is locked
*/
public int countLockedResources(CmsDbContext dbc, String foldername) throws CmsLockException {
// check the security
if (dbc.currentProject().getFlags() == CmsProject.PROJECT_STATE_UNLOCKED) {
// count locks
return m_lockManager.countExclusiveLocksInFolder(foldername);
} else {
throw new CmsLockException(org.opencms.lock.Messages.get().container(
org.opencms.lock.Messages.ERR_RESOURCE_LOCKED_1,
dbc.currentProject().getName()));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -