📄 cmsdbaccess.java
字号:
} catch (CmsException e){
if (e.getType() != CmsException.C_FILE_EXISTS){
throw e;
}
}
}
return readFolder(project.getId(), foldername);
}
/**
* Creates a new resource from an given CmsResource object.
*
* @param project The project in which the resource will be used.
* @param onlineProject The online project of the OpenCms.
* @param newResource The resource to be written to the Cms.
* @param filecontent The filecontent if the resource is a file
* @param userId The ID of the current user.
* @param parentId The parentId of the resource.
*
* @return resource The created resource.
*
* @throws CmsException Throws CmsException if operation was not succesful
*/
public CmsResource createResource(CmsProject project,
CmsProject onlineProject,
CmsResource newResource,
byte[] filecontent,
int userId, boolean isFolder)
throws CmsException {
String usedPool = null;
String usedStatement = null;
Connection con = null;
PreparedStatement statement = null;
// check the resource name
if (newResource.getResourceName().length() > C_MAX_LENGTH_RESOURCE_NAME){
throw new CmsException("["+this.getClass().getName()+"] "+"Resourcename too long(>"+C_MAX_LENGTH_RESOURCE_NAME+") ",CmsException.C_BAD_NAME);
}
int state=0;
int modifiedBy = userId;
long dateModified = newResource.isTouched() ? newResource.getDateLastModified() : System.currentTimeMillis();
if (project.equals(onlineProject)) {
state= newResource.getState();
usedPool = m_poolNameOnline;
usedStatement = "_ONLINE";
modifiedBy = newResource.getResourceLastModifiedBy();
dateModified = newResource.getDateLastModified();
} else {
state=C_STATE_NEW;
usedPool = m_poolName;
usedStatement = "";
}
// Test if the file is already there and marked as deleted.
// If so, delete it.
// If the file exists already and is not marked as deleted then throw exception
try {
readResource(project,newResource.getResourceName());
throw new CmsException("["+this.getClass().getName()+"] ",CmsException.C_FILE_EXISTS);
} catch (CmsException e) {
// if the resource is marked as deleted remove it!
if (e.getType() == CmsException.C_RESOURCE_DELETED) {
if(isFolder){
removeFolder(project.getId(),(CmsFolder)newResource);
} else {
removeFile(project.getId(), newResource.getResourceName());
}
state=C_STATE_CHANGED;
//throw new CmsException("["+this.getClass().getName()+"] ",CmsException.C_FILE_EXISTS);
}
if (e.getType() == CmsException.C_FILE_EXISTS) {
throw e;
}
}
int newFileId = -1;
int resourceId = nextId(m_cq.get("C_TABLE_RESOURCES"+usedStatement));
// now write the resource
try {
con = DriverManager.getConnection(usedPool);
if(!isFolder){
// first write the file content
newFileId = nextId(m_cq.get("C_TABLE_FILES"+usedStatement));
try {
createFileContent(newFileId, filecontent, 0, usedPool, usedStatement);
} catch (CmsException se) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(C_OPENCMS_CRITICAL, "[CmsDbAccess] " + se.getMessage());
}
}
}
// now write the file header
statement = con.prepareStatement(m_cq.get("C_RESOURCES_WRITE"+usedStatement));
statement.setInt(1, resourceId);
statement.setInt(2, newResource.getParentId());
statement.setString(3, newResource.getResourceName());
statement.setInt(4, newResource.getType());
statement.setInt(5, newResource.getFlags());
statement.setInt(6, newResource.getOwnerId());
statement.setInt(7, newResource.getGroupId());
statement.setInt(8, project.getId());
statement.setInt(9, newFileId);
statement.setInt(10, newResource.getAccessFlags());
statement.setInt(11, state);
statement.setInt(12, newResource.isLockedBy());
statement.setInt(13, newResource.getLauncherType());
statement.setString(14, newResource.getLauncherClassname());
statement.setTimestamp(15, new Timestamp(newResource.getDateCreated()));
statement.setTimestamp(16, new Timestamp(dateModified));
statement.setInt(17, newResource.getLength());
statement.setInt(18, modifiedBy);
statement.executeUpdate();
statement.close();
} catch (SQLException e){
throw new CmsException("["+this.getClass().getName()+"] "+e.getMessage(),CmsException.C_SQL_ERROR, e);
} finally {
// close all db-resources
if(statement != null) {
try {
statement.close();
} catch(SQLException exc) {
// nothing to do here
}
}
if(con != null) {
try {
con.close();
} catch(SQLException exc) {
// nothing to do here
}
}
}
return readResource(project, newResource.getResourceName());
}
/**
* Creates a new projectResource from an given CmsResource object.
*
* @param project The project in which the resource will be used.
* @param resource The resource to be written to the Cms.
*
*
* @throws CmsException Throws CmsException if operation was not succesful
*/
public void createProjectResource(int projectId, String resourceName) throws CmsException {
// do not create entries for online-project
PreparedStatement statement = null;
Connection con = null;
try {
readProjectResource(projectId, resourceName);
throw new CmsException("[" + this.getClass().getName() + "] ", CmsException.C_FILE_EXISTS);
} catch (CmsException e) {
if (e.getType() == CmsException.C_FILE_EXISTS) {
throw e;
}
}
try {
con = DriverManager.getConnection(m_poolName);
statement = con.prepareStatement(m_cq.get("C_PROJECTRESOURCES_CREATE"));
// write new resource to the database
statement.setInt(1, projectId);
statement.setString(2, resourceName);
statement.executeUpdate();
} catch (SQLException e) {
throw new CmsException("[" + this.getClass().getName() + "] " + e.getMessage(), CmsException.C_SQL_ERROR, e);
} finally {
if (statement != null) {
try{
statement.close();
} catch (SQLException e){
}
}
if (con != null){
try{
con.close();
} catch (SQLException e){
}
}
}
}
/**
* Add a new group to the Cms.<BR/>
*
* Only the admin can do this.<P/>
*
* @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 name The name of the parent group (or null).
*
* @return Group
*
* @throws CmsException Throws CmsException if operation was not succesfull.
*/
public CmsGroup createGroup(String name, String description, int flags,String parent)
throws CmsException {
int parentId=C_UNKNOWN_ID;
CmsGroup group=null;
Connection con = null;
PreparedStatement statement = null;
try{
// get the id of the parent group if nescessary
if ((parent != null) && (!"".equals(parent))) {
parentId=readGroup(parent).getId();
}
con = DriverManager.getConnection(m_poolName);
// create statement
statement=con.prepareStatement(m_cq.get("C_GROUPS_CREATEGROUP"));
// write new group to the database
statement.setInt(1,nextId(C_TABLE_GROUPS));
statement.setInt(2,parentId);
statement.setString(3,name);
statement.setString(4,checkNull(description));
statement.setInt(5,flags);
statement.executeUpdate();
// create the user group by reading it from the database.
// this is nescessary to get the group id which is generated in the
// database.
group=readGroup(name);
} catch (SQLException e){
throw new CmsException("[" + this.getClass().getName() + "] "+e.getMessage(),CmsException.C_SQL_ERROR, e);
} finally {
if(statement != null) {
try {
statement.close();
} catch(SQLException exc) {
// nothing to do here
}
}
if(con != null) {
try {
con.close();
} catch(SQLException exc) {
// nothing to do here
}
}
}
return group;
}
/**
* Creates a project.
*
* @param owner The owner of this project.
* @param group The group for this project.
* @param managergroup The managergroup for this project.
* @param task The task.
* @param name The name of the project to create.
* @param description The description for the new project.
* @param flags The flags for the project (e.g. archive).
* @param type the type for the project (e.g. normal).
*
* @throws CmsException Throws CmsException if something goes wrong.
*/
public CmsProject createProject(CmsUser owner, CmsGroup group, CmsGroup managergroup,
CmsTask task, String name, String description,
int flags, int type)
throws CmsException {
if ((description==null) || (description.length()<1)) {
description=" ";
}
Timestamp createTime = new Timestamp(new java.util.Date().getTime());
Connection con = null;
PreparedStatement statement = null;
int id = nextId(C_TABLE_PROJECTS);
try {
con = DriverManager.getConnection(m_poolName);
// write data to database
statement = con.prepareStatement(m_cq.get("C_PROJECTS_CREATE"));
statement.setInt(1,id);
statement.setInt(2,owner.getId());
statement.setInt(3,group.getId());
statement.setInt(4,managergroup.getId());
statement.setInt(5,task.getId());
statement.setString(6,name);
statement.setString(7,description);
statement.setInt(8,flags);
statement.setTimestamp(9,createTime);
// no publish data
//statement.setNull(10,Types.TIMESTAMP);
//statement.setInt(11,C_UNKNOWN_ID);
statement.setInt(10,type);
statement.executeUpdate();
}
catch (SQLException e){
throw new CmsException("["+this.getClass().getName()+"]"+e.getMessage(),CmsException.C_SQL_ERROR, e);
} finally {
if(statement != null) {
try {
statement.close();
} catch(SQLException exc) {
// nothing to do here
}
}
if(con != null) {
try {
con.close();
} catch(SQLException exc) {
// nothing to do here
}
}
}
return readProject(id);
}
/**
* Creates the propertydefinitions for the resource type.<BR/>
*
* Only the admin can do this.
*
* @param name The name of the propertydefinitions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -