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

📄 cmsexplorertree.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        
        //check if a folder parameter was included in the request.        
        // if a foldername was included, overwrite the value in the session for later use.
        foldername = cms.getRequestContext().getRequest().getParameter(C_PARA_FOLDER);
        if(foldername != null) {
            session.putValue(C_PARA_FOLDER, foldername);
        }
        
        // get the current folder to be displayed as maximum folder in the tree.
        currentFolder = (String)session.getValue(C_PARA_FOLDER);
        if(currentFolder == null) {
            currentFolder = cms.rootFolder().getAbsolutePath();
        }
        
        //check if a filelist  parameter was included in the request.        
        // if a filelist was included, overwrite the value in the session for later use.
        filelist = cms.getRequestContext().getRequest().getParameter(C_PARA_FILELIST);
        if(filelist != null) {
            session.putValue(C_PARA_FILELIST, filelist);
        }
        
        // get the current folder to be displayed as maximum folder in the tree.
        currentFilelist = (String)session.getValue(C_PARA_FILELIST);
        if(currentFilelist == null) {
            currentFilelist = cms.rootFolder().getAbsolutePath();
        }
        
        // get current and root folder
        rootFolder = cms.rootFolder().getAbsolutePath();
        
        //get the template
        CmsXmlWpTemplateFile template = (CmsXmlWpTemplateFile)doc;
        if(filelist != null) {
            template.setData("PREVIOUS", filelist);
        }
        else {
            template.setData("PREVIOUS", currentFilelist);
        }
        String tab = template.getProcessedDataValue(C_TREEIMG_EMPTY0, this);
        showTree(cms, rootFolder, currentFolder, currentFilelist, template, output, tab);
        return output.toString();
    }
    
    /**
     * 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;
    }
    
    /**
     * Generates a subtree of the folder tree.
     * @param cms The CmsObject.
     * @param curFolder The rootfolder of ther subtree to display
     * @param endfolder The last folder to be displayed.
     * @param filelist The folder that is displayed in the file list
     * @param template The foldertree template file.
     * @param output The output buffer where all data is written to.
     * @param tab The prefix-HTML code fo this subtree.
     */
    
    private void showTree(CmsObject cms, String curfolder, String endfolder, String filelist, 
            CmsXmlWpTemplateFile template, StringBuffer output, String tab) throws CmsException {
        String newtab = new String();
        String folderimg = new String();
        String treeswitch = new String();
        CmsFolder lastFolder = null;
        Vector subfolders = new Vector();
        Vector list = new Vector();
        Vector untestedSubfolders = new Vector();
        
        // remove invisible folders
        Vector untestedlist = cms.getSubFolders(curfolder);
        for(int i = 0;i < untestedlist.size();i++) {
            CmsFolder subfolder = (CmsFolder)untestedlist.elementAt(i);
            if(checkAccess(cms, subfolder)) {
                list.addElement(subfolder);
            }
        }
        Enumeration enum = list.elements();
        if(list.size() > 0) {
            lastFolder = (CmsFolder)list.lastElement();
        }
        else {
            lastFolder = null;
        }
        while(enum.hasMoreElements()) {
            CmsFolder folder = (CmsFolder)enum.nextElement();
            
            // check if this folder is visible
            if(checkAccess(cms, folder)) {
                untestedSubfolders = cms.getSubFolders(folder.getAbsolutePath());
                subfolders = new Vector();
                
                // now filter all invisible subfolders
                for(int i = 0;i < untestedSubfolders.size();i++) {
                    CmsFolder subfolder = (CmsFolder)untestedSubfolders.elementAt(i);
                    if(checkAccess(cms, subfolder)) {
                        subfolders.addElement(subfolder);
                    }
                }
                
                // check if this folder must diplayes open
                if(folder.getAbsolutePath().equals(filelist)) {
                    folderimg = template.getProcessedDataValue(C_TREEIMG_FOLDEROPEN, this);
                }
                else {
                    folderimg = template.getProcessedDataValue(C_TREEIMG_FOLDERCLOSE, this);
                }
                
                // now check if a treeswitch has to displayed                
                // is this the last element of the current folder, so display the end image
                if(folder.getAbsolutePath().equals(lastFolder.getAbsolutePath())) {
                    
                    // if there are any subfolders extisintg, use the + or - box
                    if(subfolders.size() > 0) {
                        
                        // test if the + or minus must be displayed
                        if(endfolder.startsWith(folder.getAbsolutePath())) {
                            template.setData(C_TREELINK, C_WP_EXPLORER_TREE + "?" + C_PARA_FOLDER + "=" 
                                    + Encoder.escape(curfolder,
                                    cms.getRequestContext().getEncoding()));
                            treeswitch = template.getProcessedDataValue(C_TREEIMG_MEND, this);
                        }
                        else {
                            template.setData(C_TREELINK, C_WP_EXPLORER_TREE + "?" + C_PARA_FOLDER + "=" 
                                    + Encoder.escape(folder.getAbsolutePath(),
                                    cms.getRequestContext().getEncoding()));
                            treeswitch = template.getProcessedDataValue(C_TREEIMG_PEND, this);
                        }
                    }
                    else {
                        treeswitch = template.getProcessedDataValue(C_TREEIMG_END, this);
                    }
                }
                else {
                    
                    // use the cross image                    
                    // if there are any subfolders extisintg, use the + or - box
                    if(subfolders.size() > 0) {
                        
                        // test if the + or minus must be displayed
                        if(endfolder.startsWith(folder.getAbsolutePath())) {
                           template.setData(C_TREELINK, C_WP_EXPLORER_TREE + "?" + C_PARA_FOLDER + "=" 
                                    + Encoder.escape(curfolder,
                                    cms.getRequestContext().getEncoding()));
                            treeswitch = template.getProcessedDataValue(C_TREEIMG_MCROSS, this);
                        }
                        else {
                            template.setData(C_TREELINK, C_WP_EXPLORER_TREE + "?" + C_PARA_FOLDER + "=" 
                                    + Encoder.escape(folder.getAbsolutePath(),
                                    cms.getRequestContext().getEncoding()));
                            treeswitch = template.getProcessedDataValue(C_TREEIMG_PCROSS, this);
                        }
                    }
                    else {
                        treeswitch = template.getProcessedDataValue(C_TREEIMG_CROSS, this);
                    }
                }
                if(folder.getAbsolutePath().equals(lastFolder.getAbsolutePath())) {
                    newtab = tab + template.getProcessedDataValue(C_TREEIMG_EMPTY, this);
                }
                else {
                    newtab = tab + template.getProcessedDataValue(C_TREEIMG_VERT, this);
                }
                
                // test if the folder is in the current project
                if(folder.inProject(cms.getRequestContext().currentProject())) {
                    template.setData(C_TREESTYLE, C_FILE_INPROJECT);
                }
                else {
                    template.setData(C_TREESTYLE, C_FILE_NOTINPROJECT);
                }
                
                // set all data for the treeline tag
                template.setData(C_FILELIST, C_WP_EXPLORER_FILELIST + "?" + C_PARA_FILELIST + "=" 
                        + folder.getAbsolutePath());
                template.setData(C_TREELIST, C_WP_EXPLORER_TREE + "?" + C_PARA_FILELIST + "=" 
                        + folder.getAbsolutePath());
                template.setData(C_TREEENTRY, folder.getName());
                template.setData(C_TREETAB, tab);
                template.setData(C_TREEFOLDER, folderimg);
                template.setData(C_TREESWITCH, treeswitch);
                output.append(template.getProcessedDataValue(C_TREELINE, this));
                
                //finally process all subfolders if nescessary
                if(endfolder.startsWith(folder.getAbsolutePath())) {
                    showTree(cms, folder.getAbsolutePath(), endfolder, filelist, template, output, newtab);
                }
            }
        }
    }
}

⌨️ 快捷键说明

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