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

📄 cmsadminprojectnew.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                // all the required data has been entered, display 'Please wait'
                templateSelector = "wait";
                action = "start";
            }
        }

        // is the wait-page showing?
        if("working".equals(action)) {
            // create new Project
            try {
                // append the C_VFS_GALLERY_PICS and C_VFS_GALLERY_DOWNLOAD path to the list of all resources
                String picspath = getConfigFile(cms).getPicGalleryPath();
                String downloadpath = getConfigFile(cms).getDownGalleryPath();
                String linkpath = getConfigFile(cms).getLinkGalleryPath();
                String htmlPath = getConfigFile(cms).getHtmlGalleryPath();
                allResources = allResources + ";" + picspath + ";"
                        + downloadpath + ";" + linkpath + ";" + htmlPath;
                if(extendedNavigation){
                    allResources = allResources + ";" + C_VFS_PATH_DEFAULTMODULE + "elements/";
                }
                // 'allResurces' has the "form res1;res2;...resk;"
                // this is because the simpler 'getParameterValues' method doesn't work with Silverstream
                Vector folders = parseResources(allResources);
                int numRes = folders.size();
                for(int i = 0;i < numRes;i++) {
                    // modify the foldername if nescessary (the root folder is always given
                    // as a nice name)
                    if(lang.getLanguageValue("title.rootfolder").equals(folders.elementAt(i))) {
                        folders.setElementAt("/", i);
                    }
                }
                checkRedundancies(folders);
                numRes = folders.size(); // could have been changed
                // now get the vector for the channels
                Vector channels = parseResources(allChannels);
                int numChan = channels.size();
                for(int j = 0;j < numChan;j++) {
                    // modify the channelname if nescessary (the root folder is always given
                    // as a nice name)
                    if(lang.getLanguageValue("title.rootfolder").equals(channels.elementAt(j))) {
                        channels.setElementAt("/", j);
                    }
                }
                checkRedundancies(channels);
                numChan = channels.size();
                // finally create the project
                CmsProject project = cms.createProject(newName, newDescription, newGroup,
                        newManagerGroup, projectType);
                // change the current project
                reqCont.setCurrentProject(project.getId());
                // copy the resources to the current project
                try {
                    for(int i = 0;i < folders.size();i++) {
                        cms.copyResourceToProject((String)folders.elementAt(i));
                    }
                    //now copy the channels to the project
                    cms.setContextToCos();
                    for(int j = 0; j < channels.size(); j++){
                        cms.copyResourceToProject((String)channels.elementAt(j));
                    }
                    cms.setContextToVfs();
                } catch(CmsException e) {
                    cms.setContextToVfs();
                    // if there are no projectresources in the project delete the project
                    Vector projectResources = cms.readAllProjectResources(project.getId());
                    if((projectResources == null) || (projectResources.size() == 0)){
                        cms.deleteProject(project.getId());
                        reqCont.setCurrentProject(C_PROJECT_ONLINE_ID);
                    }
                    if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                        A_OpenCms.log(A_OpenCms.C_OPENCMS_CRITICAL, e.getMessage());
                    }
                    throw e;
                }
                // project ready; clear the session
                session.removeValue(C_NEWNAME);
                session.removeValue(C_NEWGROUP);
                session.removeValue(C_NEWDESCRIPTION);
                session.removeValue(C_NEWMANAGERGROUP);
                session.removeValue(C_NEWFOLDER);
                session.removeValue(C_NEWTYPE);
                session.removeValue(C_NEWRESOURCES);
                session.removeValue(C_NEWCHANNELS);
                session.removeValue("lasturl");
                session.removeValue("newProjectCallingFrom");
                return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "done");
            } catch(CmsException exc) {
                xmlTemplateDocument.setData("details", Utils.getStackTrace(exc));
                templateSelector = "errornewproject"+errorTemplateAddOn;
            }
        }
        // after an error the form data is retrieved and filled into the template
        xmlTemplateDocument.setData(C_NEWNAME, newName);
        xmlTemplateDocument.setData(C_NEWDESCRIPTION, newDescription);
        xmlTemplateDocument.setData(C_NEWTYPE, newType);

        // Now load the template file and start the processing
        return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
                templateSelector);
    }

    /**
     * Gets all groups, that may work for a project.
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the current value in the vectors.
     * @throws CmsException
     */

    public Integer getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
            Vector values, Hashtable parameters) throws CmsException {

        // get all groups
        Vector groups = cms.getGroups();
        int retValue = -1;
        String defaultGroup = C_GROUP_USERS;
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String enteredGroup = (String)session.getValue(C_NEWGROUP);
        if(enteredGroup != null && !enteredGroup.equals("")) {

            // if an error has occurred before, take the previous entry of the user
            defaultGroup = enteredGroup;
        }

        // fill the names and values
        int n = 0;
        for(int z = 0;z < groups.size();z++) {
            if(((CmsGroup)groups.elementAt(z)).getProjectCoWorker()) {
                String name = ((CmsGroup)groups.elementAt(z)).getName();
                if(defaultGroup.equals(name)) {
                    retValue = n;
                }
                names.addElement(name);
                values.addElement(name);
                n++; // count the number of ProjectCoWorkers
            }
        }
        return new Integer(retValue);
    }

    /**
     * Gets all groups, that may manage a project.
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the current value in the vectors.
     * @throws CmsException
     */

    public Integer getManagerGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
            Vector values, Hashtable parameters) throws CmsException {

        // get all groups
        Vector groups = cms.getGroups();
        int retValue = -1;
        String defaultGroup = C_GROUP_PROJECTLEADER;
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String enteredGroup = (String)session.getValue(C_NEWMANAGERGROUP);
        if(enteredGroup != null && !enteredGroup.equals("")) {

            // if an error has occurred before, take the previous entry of the user
            defaultGroup = enteredGroup;
        }

        // fill the names and values
        int n = 0;
        for(int z = 0;z < groups.size();z++) {
            if(((CmsGroup)groups.elementAt(z)).getProjectmanager()) {
                String name = ((CmsGroup)groups.elementAt(z)).getName();
                if(defaultGroup.equals(name)) {
                    retValue = n;
                }
                names.addElement(name);
                values.addElement(name);
                n++; // count the number of project managers
            }
        }
        return new Integer(retValue);
    }

    public Integer getSelectedResources(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
            Vector values, Hashtable parameters) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        String[] newProjectResources = (String[])session.getValue(C_NEWRESOURCES);
        if(newProjectResources != null) {
            for(int i = 0;i < newProjectResources.length;i++) {
                names.addElement(newProjectResources[i]);
                values.addElement(newProjectResources[i]);
            }
        }

        // no current folder, set index to -1
        return new Integer(-1);
    }

    /**
     * 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;
    }

    /** Parse the string which holds all resources
     *
     * @param resources containts the full pathnames of all the resources, separated by semicolons
     * @return A vector with the same resources
     */

    private Vector parseResources(String resources) {
        Vector ret = new Vector();
        if(resources != null) {
            StringTokenizer resTokenizer = new StringTokenizer(resources, ";");
            while(resTokenizer.hasMoreElements()) {
                String path = (String)resTokenizer.nextElement();
                ret.addElement(path);
            }
        }
        return ret;
    }

    /** gets the projectname for a contexgenerated project
     *
     * @param cms the cmsObject
     * @param resource the name of the resource
     * @return A vector with the same resources
     */

    private String getProjectName(CmsObject cms, String resource) {
        String ret = resource;
        if (ret.endsWith("/")){
            ret = ret.substring(0, ret.length()-1);
        }
        ret = ret.substring(ret.lastIndexOf('/')+1);
        if (ret.length() > 14){
            ret = ret.substring(0,13);
        }
        try{
            Vector allProjects = cms.getAllAccessibleProjects();
            Vector theNames = new Vector();
            // count all projects starting with the same name
            int count = 0;
            for (int i = 0; i < allProjects.size(); i++){
                String currProject = ((CmsProject)allProjects.elementAt(i)).getName();
                if (currProject.startsWith(ret)){
                    count++;
                    theNames.addElement(currProject);
                }
            }
            if ((count > 0) && (count < 99)){
                // get the highest version nummber
                int version = 1;
                for (int i = 0; i<theNames.size(); i++){
                    int currVersion = 0;
                    try{
                        currVersion = Integer.parseInt(((String)theNames.elementAt(i)).substring(ret.length()+1));
                    }catch(Exception e){
                    }
                    if ((currVersion > version)&& (currVersion < 100)){
                        version = currVersion;
                    }
                }
                if (version < 99){
                    ret = ret + "_" + (version + 1);
                }
            }
        }catch(CmsException e){
        }
        return ret;
    }
}

⌨️ 快捷键说明

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