📄 cmsresourcetypefolder.java
字号:
cms.doChmod(bodyFolder, flags);
}catch(CmsException ex) {
// no folder is there, so do nothing
}
}
}
// now modify all files in the subfolders
for(int i = 0;i < allFiles.size();i++) {
CmsFile newfile = (CmsFile)allFiles.elementAt(i);
if(newfile.getState() != C_STATE_DELETED) {
try{
cms.chmod(newfile.getAbsolutePath(), flags);
} catch (CmsException e){
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_CRITICAL, "["+this.getClass().getName()+"] "+newfile.getAbsolutePath()+": "+e.getStackTraceAsString());
}
}
}
}
}
}else{
throw new CmsException("[" + this.getClass().getName() + "] " + filename,
CmsException.C_NO_ACCESS);
}
}
/**
* Changes the owner of a resource.
* <br>
* Only the owner of a resource in an offline project can be changed. The state
* of the resource is set to CHANGED (1).
* If the content of this resource is not existing in the offline project already,
* it is read from the online project and written into the offline project.
* The user may change this, if he is admin of the resource.
* <p>
* <B>Security:</B>
* Access is granted, if:
* <ul>
* <li>the user has access to the project</li>
* <li>the user is owner of the resource or the user is admin</li>
* <li>the resource is locked by the callingUser</li>
* </ul>
*
* @param filename the complete path to the resource.
* @param newOwner the name of the new owner for this resource.
* @param chRekursive shows if the subResources (of a folder) should be changed too.
*
* @throws CmsException if operation was not successful.
*/
public void chown(CmsObject cms, String filename, String newOwner, boolean chRekursive) throws CmsException{
CmsFolder folder = cms.readFolder(filename);
// check if the current user has the right to change the owner of the
// resource. Only the owner of a file and the admin are allowed to do this.
if((cms.getRequestContext().currentUser().equals(cms.readOwner(folder)))
|| (cms.userInGroup(cms.getRequestContext().currentUser().getName(), C_GROUP_ADMIN))) {
// change the owner
cms.doChown(filename, newOwner);
String bodyFolder = C_VFS_PATH_BODIES.substring(0,
C_VFS_PATH_BODIES.lastIndexOf("/")) + folder.getAbsolutePath();
try {
cms.readFolder(bodyFolder);
cms.doChown(bodyFolder, newOwner);
}
catch(CmsException ex) {
// no folder is there, so do nothing
}
// the rekursive flag was set do a recursive chmod on all files and subfolders
if(chRekursive) {
// get all subfolders and files
Vector allFolders = new Vector();
Vector allFiles = new Vector();
getAllResources(cms, filename, allFiles, allFolders);
// now modify all subfolders
for(int i = 0;i < allFolders.size();i++) {
CmsFolder curfolder = (CmsFolder)allFolders.elementAt(i);
if(curfolder.getState() != C_STATE_DELETED) {
cms.doChown(curfolder.getAbsolutePath(), newOwner);
// check if there is a corresponding directory in the content body folder
bodyFolder = C_VFS_PATH_BODIES.substring(0,
C_VFS_PATH_BODIES.lastIndexOf("/")) + curfolder.getAbsolutePath();
try {
cms.readFolder(bodyFolder);
cms.doChown(bodyFolder, newOwner);
}catch(CmsException ex) {
// no folder is there, so do nothing
}
}
}
// now modify all files in the subfolders
for(int i = 0;i < allFiles.size();i++) {
CmsFile newfile = (CmsFile)allFiles.elementAt(i);
if(newfile.getState() != C_STATE_DELETED) {
try{
cms.chown(newfile.getAbsolutePath(), newOwner);
} catch (CmsException e){
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(A_OpenCms.C_OPENCMS_CRITICAL, "["+this.getClass().getName()+"] "+newfile.getAbsolutePath()+": "+e.getStackTraceAsString());
}
}
}
}
}
}else{
throw new CmsException("[" + this.getClass().getName() + "] " + filename,
CmsException.C_NO_ACCESS);
}
}
/**
* Change the timestamp of a folder.
*
* @param resourceName the name of the resource to change
* @param timestamp timestamp the new timestamp of the changed resource
* @param boolean flag to touch recursively all sub-resources in case of a folder
*/
public void touch( CmsObject cms, String resourceName, long timestamp, boolean touchRecursive ) throws CmsException {
Vector allFolders = new Vector();
Vector allFiles = new Vector();
Vector unvisited = new Vector();
// create a valid resource
CmsFolder currentFolder = cms.readFolder( resourceName );
CmsFile currentFile = null;
// check the access rights
if((cms.getRequestContext().currentUser().equals(cms.readOwner(currentFolder))) || (cms.userInGroup(cms.getRequestContext().currentUser().getName(), C_GROUP_ADMIN))) {
if (touchRecursive) {
// collect all folders and files by traversing the tree on a breadth first search
unvisited.add( currentFolder );
while (unvisited.size()>0) {
// visit all unvisited folders
Enumeration unvisitedFolders = unvisited.elements();
while (unvisitedFolders.hasMoreElements()) {
currentFolder = (CmsFolder)unvisitedFolders.nextElement();
// remove the current folder from the unvisited folders
unvisited.remove( (CmsFolder)currentFolder );
// add the current folder to the set of all folders to be touched
allFolders.add( (CmsFolder)currentFolder );
// add the files in the current folder to the set of all files to be touched
allFiles.addAll( cms.getFilesInFolder(currentFolder.getAbsolutePath(), true) );
// add all sub-folders in the current folder to visit them in the next iteration
unvisited.addAll( cms.getSubFolders(currentFolder.getAbsolutePath(),true) );
}
}
}
else {
allFolders.add( (CmsFolder)currentFolder );
}
// touch the folders that we collected before
Enumeration touchFolders = allFolders.elements();
while (touchFolders.hasMoreElements()) {
currentFolder = (CmsFolder)touchFolders.nextElement();
if (DEBUG>0) System.err.println( "touching: " + currentFolder.getAbsolutePath() );
// touch the folder itself
cms.doTouch( currentFolder.getAbsolutePath(), timestamp );
// touch its counterpart under content/bodies
String bodyFolder = C_VFS_PATH_BODIES.substring( 0, C_VFS_PATH_BODIES.lastIndexOf("/")) + currentFolder.getAbsolutePath();
try {
cms.readFolder( bodyFolder );
cms.doTouch( bodyFolder, timestamp );
}
catch(CmsException e) {}
}
// touch the files/resources that we collected before
Enumeration touchFiles = allFiles.elements();
while (touchFiles.hasMoreElements()) {
currentFile = (CmsFile)touchFiles.nextElement();
if (DEBUG>0) System.err.println( "touching: " + currentFile.getAbsolutePath() );
if(currentFile.getState()!=I_CmsConstants.C_STATE_DELETED) {
// touch the file itself
cms.touch( currentFile.getAbsolutePath(), timestamp, false );
}
}
}
}
/**
* Changes the resourcetype of a resource.
* <br>
* Only the resourcetype of a resource in an offline project can be changed. The state
* of the resource is set to CHANGED (1).
* If the content of this resource is not exisiting in the offline project already,
* it is read from the online project and written into the offline project.
* The user may change this, if he is admin of the resource.
* <p>
* <B>Security:</B>
* Access is granted, if:
* <ul>
* <li>the user has access to the project</li>
* <li>the user is owner of the resource or is admin</li>
* <li>the resource is locked by the callingUser</li>
* </ul>
*
* @param filename the complete path to the resource.
* @param newType the name of the new resourcetype for this resource.
*
* @throws CmsException if operation was not successful.
*/
public void chtype(CmsObject cms, String filename, String newType) throws CmsException{
// it is not possible to change the type of a folder
throw new CmsException("[" + this.getClass().getName() + "] " + filename,
CmsException.C_ACCESS_DENIED);
}
/**
* Copies a Resource.
*
* @param source the complete path of the sourcefile.
* @param destination the complete path of the destinationfolder.
* @param keepFlags <code>true</code> if the copy should keep the source file's flags,
* <code>false</code> if the copy should get the user's default flags.
*
* @throws CmsException if the file couldn't be copied, or the user
* has not the appropriate rights to copy the file.
*/
public void copyResource(CmsObject cms, String source, String destination, boolean keepFlags) throws CmsException{
// we have to copy the folder and all resources in the folder
Vector allSubFolders = new Vector();
Vector allSubFiles = new Vector();
// first valid the destination name
validResourcename(destination);
getAllResources(cms, source, allSubFiles, allSubFolders);
if (!destination.endsWith("/")){
destination = destination +"/";
}
if (!destination.startsWith("/")){
destination = "/"+destination ;
}
// first the folder
cms.doCopyFolder(source, destination);
if(!keepFlags){
setDefaultFlags(cms, destination);
}
// now the subfolders
for (int i=0; i<allSubFolders.size(); i++){
CmsFolder curFolder = (CmsFolder) allSubFolders.elementAt(i);
if(curFolder.getState() != C_STATE_DELETED){
String curDestination = destination + curFolder.getAbsolutePath().substring(source.length());
cms.doCopyFolder(curFolder.getAbsolutePath(), curDestination );
if(!keepFlags){
setDefaultFlags(cms, curDestination);
}
}
}
// now all the little files
for (int i=0; i<allSubFiles.size(); i++){
CmsFile curFile = (CmsFile)allSubFiles.elementAt(i);
if(curFile.getState() != C_STATE_DELETED){
String curDest = destination + curFile.getAbsolutePath().substring(source.length());
cms.copyResource(curFile.getAbsolutePath(), curDest, keepFlags);
}
}
// copy the content bodys
try{
copyResource(cms, C_VFS_PATH_BODIES + source.substring(1), C_VFS_PATH_BODIES + destination.substring(1), keepFlags);
// finaly lock the copy in content bodys if it exists.
cms.lockResource(C_VFS_PATH_BODIES + destination.substring(1));
}catch(CmsException e){
}
}
/**
* Copies a resource from the online project to a new, specified project.
* <br>
* Copying a resource will copy the file header or folder into the specified
* offline project and set its state to UNCHANGED.
*
* @param resource the name of the resource.
* @throws CmsException if operation was not successful.
*/
public void copyResourceToProject(CmsObject cms, String resourceName) throws CmsException {
// copy the folder to the current project
cms.doCopyResourceToProject(resourceName);
// try to copy the corresponding folder in C_VFS_PATH_BODIES to the project
try{
CmsResource contentFolder = (CmsResource)cms.readFolder(C_VFS_PATH_BODIES.substring(0, C_VFS_PATH_BODIES.lastIndexOf("/"))+resourceName, true);
if (contentFolder != null){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -