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

📄 cmsnewresourcefolder.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                            // try to unlock the folder, ignore the Exception (the parent folder is looked)
                            //try{
                            //    cms.unlockResource(folder.getAbsolutePath());
                            //}catch(CmsException e){
                            //}
                            // prepare to call the new Page dialog
                            xmlTemplateDocument.setData("indexlocation", folder.getAbsolutePath());
                            session.putValue(C_PARA_FILELIST, folder.getAbsolutePath());
                            template = "update2";
                        } else{
                            template = "update";
                        }
                        // we dont need our session entrys anymore
                        clearSession(session);
                    }catch(CmsException ex) {
                        xmlTemplateDocument.setData("details", Utils.getStackTrace(ex));
                        return startProcessing(cms, xmlTemplateDocument, "", parameters, "error_system");
                    }
                }else{
                    // user pressed backbutton. show the first template again
                    xmlTemplateDocument.setData("name", newFolder);
                    xmlTemplateDocument.setData("title", Encoder.escapeXml(title));
                    if (navtitle != null){
                        xmlTemplateDocument.setData("navtext", navtitle);
                    }else{
                        // deaktivate the linklayer
                        xmlTemplateDocument.setData("doOnload", "checkInTheBox();");
                    }
                    template = null;
                }
            }else if("fromerror".equalsIgnoreCase(step)){
                // error while creating the folder go to firs page and set the stored parameter
                template = null;
                xmlTemplateDocument.setData("name", (String)session.getValue(C_SESSIONHEADER + C_PARA_NEWFOLDER));
                xmlTemplateDocument.setData("title", Encoder.escapeXml((String)session.getValue(C_SESSIONHEADER + C_PARA_TITLE)));
                navtitle = (String)session.getValue(C_SESSIONHEADER + C_PARA_NAVTEXT);
                if (navtitle != null){
                    xmlTemplateDocument.setData("navtext", navtitle);
                }else{
                    // deaktivate the linklayer
                    xmlTemplateDocument.setData("doOnload", "checkInTheBox();");
                }
            }
        }
        // process the selected template
        return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
    }

    /**
     * Gets all required navigation information from the files and subfolders of a folder.
     * A file list of all files and folder is created, for all those resources, the navigation
     * property is read. The list is sorted by their navigation position.
     * @param cms The CmsObject.
     * @return Hashtable including three arrays of strings containing the filenames,
     * nicenames and navigation positions.
     * @throws Throws CmsException if something goes wrong.
     */

    private Hashtable getNavData(CmsObject cms) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(true);
        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        String[] filenames;
        String[] nicenames;
        String[] positions;
        Hashtable storage = new Hashtable();
        CmsFolder folder = null;
        CmsFile file = null;
        String nicename = null;
        String currentFilelist = null;
        int count = 1;
        float max = 0;

        // get the current folder
        currentFilelist = (String)session.getValue(C_PARA_FILELIST);
        if(currentFilelist == null) {
            currentFilelist = cms.rootFolder().getAbsolutePath();
        }

        // get all files and folders in the current filelist.
        Vector files = cms.getFilesInFolder(currentFilelist);
        Vector folders = cms.getSubFolders(currentFilelist);

        // combine folder and file vector
        Vector filefolders = new Vector();
        Enumeration enum = folders.elements();
        while(enum.hasMoreElements()) {
            folder = (CmsFolder)enum.nextElement();
            filefolders.addElement(folder);
        }
        enum = files.elements();
        while(enum.hasMoreElements()) {
            file = (CmsFile)enum.nextElement();
            filefolders.addElement(file);
        }
        if(filefolders.size() > 0) {

            // Create some arrays to store filename, nicename and position for the
            // nav in there. The dimension of this arrays is set to the number of
            // found files and folders plus two more entrys for the first and last
            // element.
            filenames = new String[filefolders.size() + 2];
            nicenames = new String[filefolders.size() + 2];
            positions = new String[filefolders.size() + 2];

            //now check files and folders that are not deleted and include navigation
            // information
            enum = filefolders.elements();
            while(enum.hasMoreElements()) {
                CmsResource res = (CmsResource)enum.nextElement();

                // check if the resource is not marked as deleted
                if(res.getState() != C_STATE_DELETED) {
                    String navpos = cms.readProperty(res.getAbsolutePath(), C_PROPERTY_NAVPOS);

                    // check if there is a navpos for this file/folder
                    if(navpos != null) {
                        nicename = cms.readProperty(res.getAbsolutePath(), C_PROPERTY_NAVTEXT);
                        if(nicename == null) {
                            nicename = res.getName();
                        }

                        // add this file/folder to the storage.
                        filenames[count] = res.getAbsolutePath();
                        nicenames[count] = nicename;
                        positions[count] = navpos;
                        if(new Float(navpos).floatValue() > max) {
                            max = new Float(navpos).floatValue();
                        }
                        count++;
                    }
                }
            }
        }
        else {
            filenames = new String[2];
            nicenames = new String[2];
            positions = new String[2];
        }

        // now add the first and last value
        filenames[0] = "FIRSTENTRY";
        nicenames[0] = lang.getLanguageValue("input.firstelement");
        positions[0] = "0";
        filenames[count] = "LASTENTRY";
        nicenames[count] = lang.getLanguageValue("input.lastelement");
        positions[count] = new Float(max + 1).toString();

        // finally sort the nav information.
        sort(cms, filenames, nicenames, positions, count);

        // put all arrays into a hashtable to return them to the calling method.
        storage.put("FILENAMES", filenames);
        storage.put("NICENAMES", nicenames);
        storage.put("POSITIONS", positions);
        storage.put("COUNT", new Integer(count));
        return storage;
    }

    /**
     * Gets the files displayed in the navigation select box.
     * @param cms The CmsObject.
     * @param lang The langauge definitions.
     * @param names The names of the new rescources.
     * @param values The links that are connected with each resource.
     * @param parameters Hashtable of parameters (not used yet).
     * @return The vectors names and values are filled with data for building the navigation.
     * @throws Throws CmsException if something goes wrong.
     */

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

        I_CmsSession session = cms.getRequestContext().getSession(true);
        String preselect = (String)session.getValue(C_SESSIONHEADER + C_PARA_NAVPOS);
        int retValue = -1;
       // get the nav information
        Hashtable storage = getNavData(cms);
        if(storage.size() > 0) {
            String[] nicenames = (String[])storage.get("NICENAMES");
            int count = ((Integer)storage.get("COUNT")).intValue();

            // finally fill the result vectors
            for(int i = 0;i <= count;i++) {
                names.addElement(Encoder.escapeHtml(nicenames[i]));
                values.addElement(Encoder.escapeHtml(nicenames[i]));
                if ((preselect != null) && (preselect.equals(nicenames[i]))){
                    retValue = values.size() -1;
                }
            }
        }
        else {
            values = new Vector();
        }
        if (retValue == -1){
            return new Integer(values.size() - 1);
        }else{
            return new Integer(retValue);
        }
    }

    /**
     * Gets the templates displayed in the template select box.
     * @param cms The CmsObject.
     * @param names Will be filled with the display names of the found templates.
     * @param values Will be filled with the file names of the found templates.
     * @param parameters Hashtable of parameters (not used yet).
     * @return The return value is always 0
     * @throws Throws CmsException if something goes wrong.
     */
    public Integer getTemplates(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
            Vector values, Hashtable parameters) throws CmsException {

        // Gather templates from the VFS
        CmsHelperMastertemplates.getTemplateElements(cms, I_CmsWpConstants.C_VFS_DIR_TEMPLATES, names, values);

        // Always return 0
        return new Integer(0);
    }

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

    /**
     * Sorts a set of three String arrays containing navigation information depending on
     * their navigation positions.
     * @param cms Cms Object for accessign files.
     * @param filenames Array of filenames
     * @param nicenames Array of well formed navigation names
     * @param positions Array of navpostions
     */

    private void sort(CmsObject cms, String[] filenames, String[] nicenames, String[] positions, int max) {

⌨️ 快捷键说明

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