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

📄 cmssyncfolder.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    //}
                    if(!checkWriteable(cms, theFolder)) {
                        notWriteable.addElement(theFolder);
                        templateSelector = "error";
                    }
                }

                if(!"error".equals(templateSelector)) {
                    // set the currentProject to the synchronizeProject
                    Vector allProjects = cms.getAllAccessibleProjects();
                    int count = 0;
                    CmsProject cmsProject = null;
                    int projectId = cms.getRequestContext().currentProject().getId();
                    String projectName = cms.getRegistry().getSystemValue(C_SYNCHRONISATION_PROJECT);
                    for( int i = 0; i < allProjects.size(); i++ ) {
                        cmsProject = (CmsProject)allProjects.elementAt(i);
                        if (cmsProject.getName().equals(projectName)){
                            projectId = cmsProject.getId();
                            count++;
                        }
                    }
                    if (count == 1){
                        // only one syncproject was found, so set this project
                        reqCont.setCurrentProject(projectId);
                        m_newProject = false;
                    } else if (count == 0){
                        // there is no syncproject, so create a new one and set this as the current project
                        // the necessary resources will be copied later to this project
                        reqCont.setCurrentProject(cms.createProject(projectName, "Project for synchronisation", "Users", "Projectmanager", C_PROJECT_TYPE_NORMAL).getId());
                        m_newProject = true;
                    } else {
                        // there are too many projects with the name of the syncproject, so return an error
                        xmlTemplateDocument.setData("details", "Too many projects for synchronisation.");
                        return startProcessing(cms, xmlTemplateDocument, elementName,
                            parameters, "error");
                    }
                    // start the thread for: synchronize the resources
                    // first clear the session entry if necessary
                    if(session.getValue(C_SESSION_THREAD_ERROR) != null) {
                        session.removeValue(C_SESSION_THREAD_ERROR);
                    }
                    A_CmsReportThread doSyncFolder = new CmsSyncFolderThread(cms, synchronizeResources, m_newProject, session);
                    doSyncFolder.start();
                    session.putValue(C_SYNCFOLDER_THREAD, doSyncFolder);
                    xmlTemplateDocument.setData("time", "5");
                    templateSelector = "wait";
                } else {
                    // at least one of the choosen folders was not writeable -> don't synchronize.
                    xmlTemplateDocument.setData("details", "The following folders were not writeable:"
                            + notWriteable.toString());
                }
            } catch(Exception exc) {
                xmlTemplateDocument.setData("details", Utils.getStackTrace(exc));
                templateSelector = "error";
            }
        }
        // Now load the template file and start the processing
        return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
                templateSelector);
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */

    public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }

    /** Check whether some of the resources are redundant because a superfolder has also
     *  been selected.
     *
     * @param resources containts the full pathnames of all the resources
     * @return A vector with the same resources, but the paths in the return value are disjoint
     */

    private void checkRedundancies(Vector resources) {
        int i, j;
        if(resources == null) {
            return ;
        }
        Vector redundant = new Vector();
        int n = resources.size();
        if(n < 2) {
            // no check needed, because there is only one resource or
            // no resources selected, return empty Vector
            return ;
        }
        for(i = 0;i < n;i++) {
            redundant.addElement(new Boolean(false));
        }
        for(i = 0;i < n - 1;i++) {
            for(j = i + 1;j < n;j++) {
                if(((String)resources.elementAt(i)).length() <
                        ((String)resources.elementAt(j)).length()) {
                    if(((String)resources.elementAt(j)).startsWith((String)resources.elementAt(i))) {
                        redundant.setElementAt(new Boolean(true), j);
                    }
                }
                else {
                    if(((String)resources.elementAt(i)).startsWith((String)resources.elementAt(j))) {
                        redundant.setElementAt(new Boolean(true), i);
                    }
                }
            }
        }
        for(i = n - 1;i >= 0;i--) {
            if(((Boolean)redundant.elementAt(i)).booleanValue()) {
                resources.removeElementAt(i);
            }
        }
    }

    /**
     * Check if this resource is writeable.
     *
     * @param cms The CmsObject
     * @param res The resource to be checked.
     * @return True or false.
     * @throws CmsException if something goes wrong.
     */

    private boolean checkWriteable(CmsObject cms, String resPath) {
        boolean access = false;
        int accessflags;
        CmsResource res = null;
        try {
            if(resPath.endsWith("/")){
                res = cms.readFolder(resPath);
            } else {
                res = cms.readFileHeader(resPath);
            }
            accessflags = res.getAccessFlags();
            boolean groupAccess = false;
            Enumeration allGroups = cms.getGroupsOfUser(cms.getRequestContext().currentUser().getName()).elements();
            while((!groupAccess) && allGroups.hasMoreElements()) {
                groupAccess = cms.readGroup(res).equals((CmsGroup)allGroups.nextElement());
            }
            if(((accessflags & C_ACCESS_PUBLIC_WRITE) > 0)
                    || (cms.getRequestContext().isAdmin())
                    || (cms.readOwner(res).equals(cms.getRequestContext().currentUser())
                    && (accessflags & C_ACCESS_OWNER_WRITE) > 0)
                    || (groupAccess && (accessflags & C_ACCESS_GROUP_WRITE) > 0)) {
                access = true;
            }
        }
        catch(CmsException e) {
            access = false;
        }
        return access;
    }
    /**
     * Parse the hashtable which holds all resources
     *
     * @param resources containts the full pathnames of all the resources
     * @return A vector with the same resources
     */

    private Vector parseResources(Hashtable resources) {
        Vector ret = new Vector();
        int numRes = resources.size();
        for (int i=1 ; i<numRes+1; i++) {
            String path = (String)resources.get("res"+i);
            ret.addElement(path);
        }
        return ret;
    }
}

⌨️ 快捷键说明

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