📄 cmsresourcetypeplain.java
字号:
* has not the appropriate rights to copy the file.
*/
public void copyResource(CmsObject cms, String source, String destination, boolean keepFlags) throws CmsException{
cms.doCopyFile(source, destination);
if(!keepFlags) {
setDefaultFlags(cms, destination);
}
}
/**
* Copies the resourcename to the current offline project
* @param cms The CmsObject
* @param resourceName The name of the resource
*
* @exception CmsException if operation was not successful.
*/
public void copyResourceToProject(CmsObject cms, String resourceName) throws CmsException{
cms.doCopyResourceToProject(resourceName);
};
/**
* Creates a new resource
*
* @param cms The CmsObject
* @param folder The name of the parent folder
* @param name The name of the file
* @param properties The properties of the file
* @param contents The file content
*
* @exception CmsException if operation was not successful.
*/
public CmsResource createResource(CmsObject cms, String folder, String name, Hashtable properties, byte[] contents) throws CmsException{
CmsResource res;
if (m_resourceTypeName == null) {
res = cms.doCreateFile(folder, name, contents, I_CmsConstants.C_TYPE_PLAIN_NAME, properties);
} else {
res = cms.doCreateFile(folder, name, contents, m_resourceTypeName, properties);
}
// lock the new file
cms.doLockResource(res.getAbsolutePath(), true);
return res;
}
/**
* Deletes a resource.
*
* @param filename the complete path of the file.
*
* @exception CmsException if the file couldn't be deleted, or if the user
* has not the appropriate rights to delete the file.
*/
public void deleteResource(CmsObject cms, String filename) throws CmsException{
cms.doDeleteFile(filename);
}
/**
* Deletes a resource.
*
* @param filename the complete path of the file.
*
* @exception CmsException if the file couldn't be deleted, or if the user
* has not the appropriate rights to delete the file.
*/
public void undeleteResource(CmsObject cms, String filename) throws CmsException{
cms.doUndeleteFile(filename);
}
/**
* Does the Linkmanagement when a resource will be exported.
* When a resource has to be exported, the ID磗 inside the
* Linkmanagement-Tags have to be changed to the corresponding URL磗
*
* @param file is the file that has to be changed
*/
public CmsFile exportResource(CmsObject cms, CmsFile file) throws CmsException {
// nothing to do here, because there couldn磘 be any Linkmanagement-Tags inside a plain-resource
return file;
}
/**
* Does the Linkmanagement when a resource is imported.
* When a resource has to be imported, the URL磗 of the
* Links inside the resources have to be saved and changed to the corresponding ID磗
*
* @param file is the file that has to be changed
*/
public CmsResource importResource(CmsObject cms, String source, String destination, String type, String user, String group, String access, Hashtable properties, String launcherStartClass, byte[] content, String importPath) throws CmsException {
CmsFile file = null;
String path = importPath + destination.substring(0, destination.lastIndexOf("/") + 1);
String name = destination.substring((destination.lastIndexOf("/") + 1), destination.length());
// first delete the file, so it can be overwritten
try {
lockResource(cms, path + name, true);
deleteResource(cms, path + name);
} catch (CmsException exc) {
// ignore the exception, the file dosen't exist
}
// now create the file
file = (CmsFile)createResource(cms, path, name, properties, content);
String fullname = file.getAbsolutePath();
lockResource(cms, fullname, true);
try{
cms.chmod(fullname, Integer.parseInt(access));
}catch(CmsException e){
System.out.println("chmod(" + access + ") failed ");
}
try{
cms.chgrp(fullname, group);
}catch(CmsException e){
System.out.println("chgrp(" + group + ") failed ");
}
try{
cms.chown(fullname, user);
}catch(CmsException e){
System.out.println("chown((" + user + ") failed ");
}
if(launcherStartClass != null){
file = cms.readFile(fullname);
file.setLauncherClassname(launcherStartClass);
cms.writeFile(file);
}
return file;
}
/**
* Locks a given resource.
* <br>
* A user can lock a resource, so he is the only one who can write this
* resource.
*
* @param resource the complete path to the resource to lock.
* @param force if force is <code>true</code>, a existing locking will be overwritten.
*
* @exception CmsException if the user has not the rights to lock this resource.
* It will also be thrown, if there is a existing lock and force was set to false.
*/
public void lockResource(CmsObject cms, String resource, boolean force) throws CmsException{
cms.doLockResource(resource, force);
}
/**
* Moves a resource to the given destination.
*
* @param source the complete path of the sourcefile.
* @param destination the complete path of the destinationfile.
*
* @exception CmsException if the user has not the rights to move this resource,
* or if the file couldn't be moved.
*/
public void moveResource(CmsObject cms, String source, String destination) throws CmsException{
cms.doMoveFile(source, destination);
}
/**
* Renames the file to the new name.
*
* @param oldname the complete path to the file which will be renamed.
* @param newname the new name of the file.
*
* @exception CmsException if the user has not the rights
* to rename the file, or if the file couldn't be renamed.
*/
public void renameResource(CmsObject cms, String oldname, String newname) throws CmsException{
cms.doRenameFile(oldname, newname);
}
/**
* Restores a file in the current project with a version in the backup
*
* @param cms The CmsObject
* @param versionId The version id of the resource
* @param filename The name of the file to restore
*
* @exception CmsException Throws CmsException if operation was not succesful.
*/
public void restoreResource(CmsObject cms, int versionId, String filename) throws CmsException{
if(!cms.accessWrite(filename)){
throw new CmsException(filename, CmsException.C_NO_ACCESS);
}
cms.doRestoreResource(versionId, filename);
}
/**
* Undo changes in a resource.
* <br>
*
* @param resource the complete path to the resource to be restored.
*
* @exception CmsException if the user has not the rights
* to write this resource.
*/
public void undoChanges(CmsObject cms, String resource) throws CmsException{
if(!cms.accessWrite(resource)){
throw new CmsException(resource, CmsException.C_NO_ACCESS);
}
cms.doUndoChanges(resource);
}
/**
* Unlocks a resource.
* <br>
* A user can unlock a resource, so other users may lock this file.
*
* @param resource the complete path to the resource to be unlocked.
*
* @exception CmsException if the user has not the rights
* to unlock this resource.
*/
public void unlockResource(CmsObject cms, String resource) throws CmsException{
cms.doUnlockResource(resource);
}
/**
* Set the access flags of the copied resource to the default values.
* @param cms The CmsObject.
* @param filename The name of the file.
* @exception Throws CmsException if something goes wrong.
*/
protected void setDefaultFlags(CmsObject cms, String filename)
throws CmsException {
Hashtable startSettings=null;
Integer accessFlags=null;
startSettings=(Hashtable)cms.getRequestContext().currentUser().getAdditionalInfo(C_ADDITIONAL_INFO_STARTSETTINGS);
if (startSettings != null) {
accessFlags=(Integer)startSettings.get(C_START_ACCESSFLAGS);
}
if (accessFlags == null) {
accessFlags = new Integer(C_ACCESS_DEFAULT_FLAGS);
}
chmod(cms, filename, accessFlags.intValue(), false);
}
/**
* Changes the project-id of the resource to the new project
* for publishing the resource directly
*
* @param newProjectId The Id of the new project
* @param resourcename The name of the resource to change
*/
public void changeLockedInProject(CmsObject cms, int newProjectId, String resourcename)
throws CmsException{
cms.doChangeLockedInProject(newProjectId, resourcename);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -