📄 cmsdrivermanager.java
字号:
/**
* Counts the locked resources in this project.<p>
*
* @param project the project to count the locked resources in
*
* @return the amount of locked resources in this project
*
* @throws CmsLockException if the given project itself is locked
*/
public int countLockedResources(CmsProject project) throws CmsLockException {
// check the security
if (project.getFlags() == CmsProject.PROJECT_STATE_UNLOCKED) {
// count locks
return m_lockManager.countExclusiveLocksInProject(project);
} else {
throw new CmsLockException(org.opencms.lock.Messages.get().container(
org.opencms.lock.Messages.ERR_RESOURCE_LOCKED_1,
project.getName()));
}
}
/**
* Add a new group to the Cms.<p>
*
* Only the admin can do this.
* Only users, which are in the group "administrators" are granted.<p>
*
* @param dbc the current database context
* @param id the id of the new group
* @param name the name of the new group
* @param description the description for the new group
* @param flags the flags for the new group
* @param parent the name of the parent group (or null)
*
* @return new created group
*
* @throws CmsDataAccessException if the creation of the group failed
* @throws CmsIllegalArgumentException if the length of the given name was below 1
*/
public CmsGroup createGroup(CmsDbContext dbc, CmsUUID id, String name, String description, int flags, String parent)
throws CmsIllegalArgumentException, CmsDataAccessException {
// check the groupname
OpenCms.getValidationHandler().checkGroupName(name);
// trim the name
name = name.trim();
// create the group
return m_userDriver.createGroup(dbc, id, name, description, flags, parent, null);
}
/**
* Creates a new task for project creation.<p>
*
* @param dbc the current database context
* @param projectName name of the project
* @param roleName usergroup for the project
* @param timeout time when the Project must finished
* @param priority priority for the Project
*
* @return the new task project
*
* @throws CmsDataAccessException if something goes wrong
*/
public CmsTask createProject(CmsDbContext dbc, String projectName, String roleName, long timeout, int priority)
throws CmsDataAccessException {
CmsGroup role = null;
// read the role
if (CmsStringUtil.isNotEmpty(roleName)) {
role = readGroup(dbc, roleName);
}
// create the timestamp
java.sql.Timestamp timestamp = new java.sql.Timestamp(timeout);
java.sql.Timestamp now = new java.sql.Timestamp(System.currentTimeMillis());
return m_workflowDriver.createTask(dbc, 0, 0, 1, // standard project type,
dbc.currentUser().getId(),
dbc.currentUser().getId(),
role.getId(),
projectName,
now,
timestamp,
priority);
}
/**
* Creates a project.<p>
*
* @param dbc the current database context
* @param name the name of the project to create
* @param description the description of the project
* @param groupname the project user group to be set
* @param managergroupname the project manager group to be set
* @param projecttype the type of the project
*
* @return the created project
*
* @throws CmsIllegalArgumentException if the chosen <code>name</code> is already used
* by the online project
* @throws CmsDataAccessException if something goes wrong
*/
public CmsProject createProject(
CmsDbContext dbc,
String name,
String description,
String groupname,
String managergroupname,
int projecttype) throws CmsIllegalArgumentException, CmsDataAccessException {
if (CmsProject.ONLINE_PROJECT_NAME.equals(name)) {
throw new CmsIllegalArgumentException(Messages.get().container(
Messages.ERR_CREATE_PROJECT_ONLINE_PROJECT_NAME_1,
CmsProject.ONLINE_PROJECT_NAME));
}
// read the needed groups from the cms
CmsGroup group = readGroup(dbc, groupname);
CmsGroup managergroup = readGroup(dbc, managergroupname);
// create a new task for the project
CmsTask task = createProject(
dbc,
name,
group.getName(),
System.currentTimeMillis(),
CmsTaskService.TASK_PRIORITY_NORMAL);
return m_projectDriver.createProject(
dbc,
dbc.currentUser(),
group,
managergroup,
task,
name,
description,
CmsProject.PROJECT_STATE_UNLOCKED,
projecttype,
null);
}
/**
* Creates a property definition.<p>
*
* Property definitions are valid for all resource types.<p>
*
* @param dbc the current database context
* @param name the name of the property definition to create
*
* @return the created property definition
*
* @throws CmsException if something goes wrong
*/
public CmsPropertyDefinition createPropertyDefinition(CmsDbContext dbc, String name) throws CmsException {
CmsPropertyDefinition propertyDefinition = null;
name = name.trim();
// validate the property name
CmsPropertyDefinition.checkPropertyName(name);
try {
try {
propertyDefinition = m_vfsDriver.readPropertyDefinition(dbc, name, dbc.currentProject().getId());
} catch (CmsException e) {
propertyDefinition = m_vfsDriver.createPropertyDefinition(dbc, dbc.currentProject().getId(), name);
}
try {
m_vfsDriver.readPropertyDefinition(dbc, name, CmsProject.ONLINE_PROJECT_ID);
} catch (CmsException e) {
m_vfsDriver.createPropertyDefinition(dbc, CmsProject.ONLINE_PROJECT_ID, name);
}
try {
m_backupDriver.readBackupPropertyDefinition(dbc, name);
} catch (CmsException e) {
m_backupDriver.createBackupPropertyDefinition(dbc, name);
}
} finally {
// fire an event that a property of a resource has been deleted
OpenCms.fireCmsEvent(new CmsEvent(
I_CmsEventListener.EVENT_PROPERTY_DEFINITION_CREATED,
Collections.singletonMap("propertyDefinition", propertyDefinition)));
}
return propertyDefinition;
}
/**
* Creates a new resource with the provided content and properties.<p>
*
* The <code>content</code> parameter may be null if the resource id already exists.
* If so, the created resource will be made a sibling of the existing resource,
* the existing content will remain unchanged.
* This is used during file import for import of siblings as the
* <code>manifest.xml</code> only contains one binary copy per file.
* If the resource id exists but the <code>content</code> is not null,
* the created resource will be made a sibling of the existing resource,
* and both will share the new content.<p>
*
* Note: the id used to identify the content record (pk of the record) is generated
* on each call of this method (with valid content) !
*
* @param dbc the current database context
* @param resourcePath the name of the resource to create (full path)
* @param resource the new resource to create
* @param content the content for the new resource
* @param properties the properties for the new resource
* @param importCase if true, signals that this operation is done while importing resource,
* causing different lock behaviour and potential "lost and found" usage
*
* @return the created resource
*
* @throws CmsException if something goes wrong
*/
public CmsResource createResource(
CmsDbContext dbc,
String resourcePath,
CmsResource resource,
byte[] content,
List properties,
boolean importCase) throws CmsException {
CmsResource newResource = null;
if (m_concurrentCreateResourceLocks.contains(resourcePath)) {
// since this method is a long-runner, we must make sure to avoid concurrent creation of the same resource
throw new CmsVfsResourceAlreadyExistsException(org.opencms.db.generic.Messages.get().container(
org.opencms.db.generic.Messages.ERR_RESOURCE_WITH_NAME_CURRENTLY_CREATED_1,
dbc.removeSiteRoot(resourcePath)));
// potential issue with this solution:
// in theory, someone _without_ write permissions could "block" the concurrent creation of a resource
// for someone _with_ permissions this way since the permissions have not been checked yet
}
try {
// avoid concurrent creation issues
m_concurrentCreateResourceLocks.add(resourcePath);
// check import configuration of "lost and found" folder
boolean useLostAndFound = importCase && !OpenCms.getImportExportManager().overwriteCollidingResources();
// check if the resource already exists
CmsResource currentResource = null;
try {
currentResource = readResource(dbc, resourcePath, CmsResourceFilter.ALL);
} catch (CmsVfsResourceNotFoundException e) {
// if the resource does exist, we need to either overwrite it,
// or create a sibling - this will be handled later
}
CmsResource parentFolder;
String parentFolderName;
String createdResourceName = resourcePath;
int contentLength;
if (currentResource != null) {
if (currentResource.getState() == CmsResource.STATE_DELETED) {
if (!currentResource.isFolder()) {
// if a non-folder resource was deleted it's treated like a new resource
currentResource = null;
}
} else {
if (!importCase) {
// direct "overwrite" of a resource is possible only during import,
// or if the resource has been deleted
throw new CmsVfsResourceAlreadyExistsException(org.opencms.db.generic.Messages.get().container(
org.opencms.db.generic.Messages.ERR_RESOURCE_WITH_NAME_ALREADY_EXISTS_1,
dbc.removeSiteRoot(resource.getRootPath())));
}
// the resource already exists
if (!resource.isFolder()
&& useLostAndFound
&& (!currentResource.getResourceId().equals(resource.getResourceId()))) {
// new resource must be created in "lost and found"
createdResourceName = moveToLostAndFound(dbc, resourcePath, false);
// current resource must remain unchanged, new will be created in "lost and found"
currentResource = null;
}
}
}
// need to provide the parent folder id for resource creation
parentFolderName = CmsResource.getParentFolder(createdResourceName);
parentFolder = readFolder(dbc, parentFolderName, CmsResourceFilter.IGNORE_EXPIRATION);
// check the permissions
if (currentResource == null) {
// resource does not exist - check parent folder
m_securityManager.checkPermissions(
dbc,
parentFolder,
CmsPermissionSet.ACCESS_WRITE,
false,
CmsResourceFilter.IGNORE_EXPIRATION);
} else {
// resource already exists - check existing resource
m_securityManager.checkPermissions(
dbc,
currentResource,
CmsPermissionSet.ACCESS_WRITE,
!importCase,
CmsResourceFilter.ALL);
}
// extract the name (without path)
String targetName = CmsResource.getName(createdResourceName);
// modify target name and content length in case of folder creation
if (resource.isFolder()) {
// folders never have any content
contentLength = -1;
// must cut of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -