⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsresourcebroker.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            fileSystemChanged(false);
        } else {
            throw new CmsException("[" + this.getClass().getName() + "] " + filename,
                CmsException.C_NO_ACCESS);
        }
    }
/**
 * Changes the owner for this 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 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. <br>
 *
 * <B>Security:</B>
 * Access is cranted, 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 currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @param filename The complete path to the resource.
 * @param newOwner The name of the new owner for this resource.
 *
 * @exception CmsException  Throws CmsException if operation was not succesful.
 */
public void chown(CmsUser currentUser, CmsProject currentProject, String filename, String newOwner) throws CmsException {
    CmsResource resource = null;
    // read the resource to check the access
    if (filename.endsWith("/")) {
        resource = readFolder(currentUser, currentProject, filename);
    } else {
        resource = (CmsFile) readFileHeader(currentUser, currentProject, filename);
    }

    // has the user write-access? and is he owner or admin?
    if (((resource.getOwnerId() == currentUser.getId()) || isAdmin(currentUser, currentProject)) &&
            (resource.isLockedBy() == currentUser.getId() &&
             resource.getLockedInProject() == currentProject.getId())) {
        CmsUser owner = readUser(currentUser, currentProject, newOwner);
        resource.setUserId(owner.getId());
        // write-acces  was granted - write the file.
        if (filename.endsWith("/")) {
            if (resource.getState() == C_STATE_UNCHANGED) {
                resource.setState(C_STATE_CHANGED);
            }
            m_dbAccess.writeFolder(currentProject, (CmsFolder) resource, true, currentUser.getId());
            // update the cache
            this.clearResourceCache(filename);
        } else {
            m_dbAccess.writeFileHeader(currentProject, (CmsFile) resource, true, currentUser.getId());
            if (resource.getState() == C_STATE_UNCHANGED) {
                resource.setState(C_STATE_CHANGED);
            }
            // update the cache
            this.clearResourceCache(filename);
        }
        m_accessCache.clear();
        // inform about the file-system-change
        fileSystemChanged(false);
    } else {
        throw new CmsException("[" + this.getClass().getName() + "] " + filename, CmsException.C_NO_ACCESS);
    }
}
     /**
     * Changes the state for this resource<BR/>
     *
     * The user may change this, if he is admin of the resource.
     *
     * <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 state The new state of this resource.
     *
     * @exception CmsException will be thrown, if the user has not the rights
     * for this resource.
     */
    public void chstate(CmsUser currentUser, CmsProject currentProject,
                        String filename, int state)
        throws CmsException {
        boolean isFolder=false;
        CmsResource resource=null;
        // read the resource to check the access
        if (filename.endsWith("/")) {
            isFolder=true;
            resource = readFolder(currentUser,currentProject,filename);
             } else {
            resource = (CmsFile)readFileHeader(currentUser,currentProject,filename);
        }

        // has the user write-access?
        if( accessWrite(currentUser, currentProject, resource)) {

            resource.setState(state);
            // write-acces  was granted - write the file.
            if (filename.endsWith("/")) {
                m_dbAccess.writeFolder(currentProject,(CmsFolder)resource,false, currentUser.getId());
                // update the cache
                this.clearResourceCache(filename);
            } else {
                m_dbAccess.writeFileHeader(currentProject,(CmsFile)resource,false, currentUser.getId());
                // update the cache
                this.clearResourceCache(filename);
            }
            // inform about the file-system-change
            fileSystemChanged(isFolder);
        } else {
            throw new CmsException("[" + this.getClass().getName() + "] " + filename,
                CmsException.C_NO_ACCESS);
        }
    }
     /**
     * Changes the resourcetype for this 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. <br>
     *
     * <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 currentUser The user who requested this method.
     * @param currentProject The current project of the user.
     * @param filename The complete path to the resource.
     * @param newType The name of the new resourcetype for this resource.
     *
     * @exception CmsException  Throws CmsException if operation was not succesful.
     */
    public void chtype(CmsUser currentUser, CmsProject currentProject,
                      String filename, String newType)
        throws CmsException {

        I_CmsResourceType type = getResourceType(currentUser, currentProject, newType);

        // read the resource to check the access
        CmsResource resource = readFileHeader(currentUser,currentProject, filename);

        // has the user write-access? and is he owner or admin?
        if( accessWrite(currentUser, currentProject, resource) &&
            ( (resource.getOwnerId() == currentUser.getId()) ||
              isAdmin(currentUser, currentProject))) {

            // write-acces  was granted - write the file.
            resource.setType(type.getResourceType());
            resource.setLauncherType(type.getLauncherType());
            m_dbAccess.writeFileHeader(currentProject, (CmsFile)resource,true, currentUser.getId());
            if (resource.getState()==C_STATE_UNCHANGED) {
                resource.setState(C_STATE_CHANGED);
            }
            // update the cache
            this.clearResourceCache(filename);

            // inform about the file-system-change
            fileSystemChanged(false);
        } else {
            throw new CmsException("[" + this.getClass().getName() + "] " + filename,
                CmsException.C_NO_ACCESS);
        }
    }
    /**
     * Clears all internal DB-Caches.
     */
    public void clearcache() {
        m_userCache.clear();
        m_groupCache.clear();
        m_usergroupsCache.clear();
        m_projectCache.clear();
        m_resourceCache.clear();
        m_subresCache.clear();
        m_propertyCache.clear();
        m_propertyDefCache.clear();
        m_propertyDefVectorCache.clear();
        m_onlineProjectCache = null;
        m_accessCache.clear();

        CmsTemplateClassManager.clearCache();

    }
    /**
     * Copies a file in the Cms. <br>
     *
     * <B>Security:</B>
     * Access is cranted, if:
     * <ul>
     * <li>the user has access to the project</li>
     * <li>the user can read the sourceresource</li>
     * <li>the user can create the destinationresource</li>
     * <li>the destinationresource dosn't exists</li>
     * </ul>
     *
     * @param currentUser The user who requested this method.
     * @param currentProject The current project of the user.
     * @param source The complete path of the sourcefile.
     * @param destination The complete path to the destination.
     *
     * @exception CmsException  Throws CmsException if operation was not succesful.
     */
    public void copyFile(CmsUser currentUser, CmsProject currentProject,
                         String source, String destination)
        throws CmsException {

        // the name of the new file.
        String filename;
        // the name of the folder.
        String foldername;

        // checks, if the destinateion is valid, if not it throws a exception
        validFilename(destination.replace('/', 'a'));

        // read the source-file, to check readaccess
        CmsResource file = readFileHeader(currentUser, currentProject, source);

        // split the destination into file and foldername
        if (destination.endsWith("/")) {
            filename = file.getName();
            foldername = destination;
        }else{
            foldername = destination.substring(0, destination.lastIndexOf("/")+1);
            filename = destination.substring(destination.lastIndexOf("/")+1,
                                             destination.length());
        }

        CmsFolder cmsFolder = readFolder(currentUser,currentProject, foldername);
        if( accessCreate(currentUser, currentProject, (CmsResource)cmsFolder) ) {
            if(( accessOther(currentUser, currentProject, file, C_ACCESS_PUBLIC_WRITE) ||
                accessOwner(currentUser, currentProject, file, C_ACCESS_OWNER_WRITE) ||
                accessGroup(currentUser, currentProject, file, C_ACCESS_GROUP_WRITE) )){
                // write-acces  was granted - copy the file and the metainfos
                m_dbAccess.copyFile(currentProject, onlineProject(currentUser, currentProject),
                              currentUser.getId(),source,cmsFolder.getResourceId(), foldername + filename);

                this.clearResourceCache(foldername + filename);
                // copy the metainfos
                lockResource(currentUser, currentProject, destination, true);
                writeProperties(currentUser,currentProject, destination,
                            readAllProperties(currentUser,currentProject,file.getResourceName()));
                m_accessCache.clear();
                // inform about the file-system-change
                fileSystemChanged(file.isFolder());
            } else {
                throw new CmsException("[" + this.getClass().getName() + "] " + source,
                    CmsException.C_NO_ACCESS);
            }
        } else {
            throw new CmsException("[" + this.getClass().getName() + "] " + destination,
                CmsException.C_NO_ACCESS);
        }
    }
     /**
     * Copies a folder in the Cms. <br>
     *
     * <B>Security:</B>
     * Access is granted, if:
     * <ul>
     * <li>the user has access to the project</li>
     * <li>the user can read the sourceresource</li>
     * <li>the user can create the destinationresource</li>
     * <li>the destinationresource dosn't exists</li>
     * </ul>
     *
     * @param currentUser The user who requested this method.
     * @param currentProject The current project of the user.
     * @param source The complete path of the sourcefolder.
     * @param destination The complete path to the destination.
     *
     * @exception CmsException  Throws CmsException if operation was not succesful.
     */
    public void copyFolder(CmsUser currentUser, CmsProject currentProject,
                           String source, String destination)
        throws CmsException {

        // the name of the new file.
        String filename;
        // the name of the folder.
        String foldername;

        // checks, if the destinateion is valid, if not it throws a exception
        validFilename(destination.replace('/', 'a'));
        foldername = destination.substring(0, destination.substring(0,destination.length()-1).lastIndexOf("/")+1);
        CmsFolder cmsFolder = readFolder(currentUser,currentProject, foldername);
        if( accessCreate(currentUser, currentProject, (CmsResource)cmsFolder) ) {
            // write-acces  was granted - copy the folder and the properties
            CmsFolder folder=readFolder(currentUser,currentProject,source);
            // check write access to the folder that has to be copied
            if(( accessOther(currentUser, currentProject, (CmsResource)folder, C_ACCESS_PUBLIC_WRITE) ||
                accessOwner(currentUser, currentProject, (CmsResource)folder, C_ACCESS_OWNER_WRITE) ||
                accessGroup(currentUser, currentProject, (CmsResource)folder, C_ACCESS_GROUP_WRITE) )){
                m_dbAccess.createFolder(currentUser,currentProject,onlineProject(currentUser, currentProject),folder,cmsFold

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -