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

📄 cmsfoldertree.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsFolderTree.java,v $
* Date   : $Date: 2005/06/27 23:22:07 $
* Version: $Revision: 1.2 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


package com.opencms.workplace;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsFolder;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.i18n.CmsEncoder;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.workplace.CmsWorkplace;

import com.opencms.core.I_CmsSession;
import com.opencms.legacy.CmsXmlTemplateLoader;
import com.opencms.template.A_CmsXmlContent;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

/**
 * Template class for displaying a folder tree <P>
 * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
 *
 *
 * @author Michael Emmerich
 * @version $Revision: 1.2 $ $Date: 2005/06/27 23:22:07 $
 */

public class CmsFolderTree extends CmsWorkplaceDefault {


    /** Definition of the Datablock TREELINK */
    private static final String C_TREELINK = "TREELINK";


    /** Definition of the Datablock TREESTYLE */
    private static final String C_TREESTYLE = "TREESTYLE";


    /** Definition of the Datablock TREETAB */
    private static final String C_TREETAB = "TREETAB";


    /** Definition of the Datablock TREEENTRY */
    private static final String C_TREEENTRY = "TREEENTRY";


    /** Definition of the Datablock TREEVAR */
    private static final String C_TREEVAR = "TREEVAR";


    /** Definition of the Datablock TREEFOLDER */
    private static final String C_TREEFOLDER = "TREEFOLDER";


    /** Definition of the Datablock TREESWITCH */
    private static final String C_TREESWITCH = "TREESWITCH";


    /** Definition of the Datablock TREELINE */
    private static final String C_TREELINE = "TREELINE";


    /** Definition of the Datablock TREELINEDISABLED */
    private static final String C_TREELINEDISABLED = "TREELINEDISABLED";


    /** Definition of the Datablock TREEIMG_EMPTY0 */
    private static final String C_TREEIMG_EMPTY0 = "TREEIMG_EMPTY0";


    /** Definition of the Datablock TREEIMG_EMPTY */
    private static final String C_TREEIMG_EMPTY = "TREEIMG_EMPTY";


    /** Definition of the Datablock TREEIMG_FOLDEROPEN */
    private static final String C_TREEIMG_FOLDEROPEN = "TREEIMG_FOLDEROPEN";


    /** Definition of the Datablock TREEIMG_FOLDERCLOSE */
    private static final String C_TREEIMG_FOLDERCLOSE = "TREEIMG_FOLDERCLOSE";


    /** Definition of the Datablock TREEIMG_MEND */
    private static final String C_TREEIMG_MEND = "TREEIMG_MEND";


    /** Definition of the Datablock TREEIMG_PEND */
    private static final String C_TREEIMG_PEND = "TREEIMG_PEND";


    /** Definition of the Datablock TREEIMG_END */
    private static final String C_TREEIMG_END = "TREEIMG_END";


    /** Definition of the Datablock TREEIMG_MCROSS */
    private static final String C_TREEIMG_MCROSS = "TREEIMG_MCROSS";


    /** Definition of the Datablock TREEIMG_PCROSS */
    private static final String C_TREEIMG_PCROSS = "TREEIMG_PCROSS";


    /** Definition of the Datablock TREEIMG_CROSS */
    private static final String C_TREEIMG_CROSS = "TREEIMG_CROSS";


    /** Definition of the Datablock TREEIMG_VERT */
    private static final String C_TREEIMG_VERT = "TREEIMG_VERT";


    /** Style for files in a project. */
    private static final String C_FILE_INPROJECT = "treefolder";


    /** Style for files not in a project. */
    private static final String C_FILE_NOTINPROJECT = "treefoldernip";


    /** Definition of Treelist */
    private static final String C_TREELIST = "TREELIST";


    /** Definition of Treelist */
    private static final String C_FILELIST = "FILELIST";


    /** Storage for caching icons */
    private Hashtable m_iconCache = new Hashtable();

    /**
     * Check if this resource should be displayed in the filelist.
     * @param cms The CmsObject
     * @param res The resource to be checked.
     * @return True or false.
     * @throws CmsException if something goes wrong.
     */

    private boolean checkAccess(CmsObject cms, CmsResource res) throws CmsException {
        //boolean access = false;
        if(res.getState() == CmsResource.STATE_DELETED){
            return false;
        }
        
		return cms.hasPermissions(res, CmsPermissionSet.ACCESS_VIEW);
    }

    /**
     * Check if this resource should be displayed in the filelist.
     * @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, CmsResource res) throws CmsException {
    	return cms.hasPermissions(res, CmsPermissionSet.ACCESS_WRITE);
    }

    /**
     * Overwrites the getContent method of the CmsWorkplaceDefault.<br>
     * Gets the content of the foldertree template and processe the data input.
     * @param cms The CmsObject.
     * @param templateFile The foldertree template file
     * @param elementName not used
     * @param parameters Parameters of the request and the template.
     * @param templateSelector Selector of the template tag to be displayed.
     * @return Bytearre containgine the processed data of the template.
     * @throws Throws CmsException if something goes wrong.
     */

    public byte[] getContent(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {
        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);

        // get the formname
        String formname = (String)parameters.get(CmsWorkplaceDefault.C_PARA_FORMNAME);
        if(formname != null) {
            session.putValue(CmsWorkplaceDefault.C_PARA_FORMNAME, formname);
        }
        formname = (String)session.getValue(CmsWorkplaceDefault.C_PARA_FORMNAME);

        // get the varname
        String varname = (String)parameters.get(CmsWorkplaceDefault.C_PARA_VARIABLE);
        if(varname != null) {
            session.putValue(CmsWorkplaceDefault.C_PARA_VARIABLE, varname);
        }
        varname = (String)session.getValue(CmsWorkplaceDefault.C_PARA_VARIABLE);

        // check if the files should be displayed as well
        String files = (String)parameters.get(CmsWorkplaceDefault.C_PARA_VIEWFILE);
        if(files != null) {
            if(files.equals("yes")) {
                session.putValue(CmsWorkplaceDefault.C_PARA_VIEWFILE, files);
            }
            else {
                session.removeValue(CmsWorkplaceDefault.C_PARA_VIEWFILE);
            }
        }
        // check if the oflinefiles are selectable
        String offselect = (String)parameters.get("onlineselect");
        if(offselect != null){
            if ("yes".equals(offselect)){
                session.putValue("onlineselect_in_foldertree", offselect);
            }else{
                session.removeValue("onlineselect_in_foldertree");
            }
        }

        //set the required datablocks
        xmlTemplateDocument.setData("FORMNAME", formname);
        xmlTemplateDocument.setData("VARIABLE", varname);

        // process the selected template
        return startProcessing(cms, xmlTemplateDocument, "", parameters, "template");
    }

    /**
     * Selects the icon that is displayed in the file list.<br>
     * This method includes cache to prevent to look up in the filesystem for each
     * icon to be displayed
     * @param cms The CmsObject.
     * @param type The resource type of the file entry.
     * @param config The configuration file.
     * @return String containing the complete name of the iconfile.
     * @throws Throws CmsException if something goes wrong.
     */
    private String getIcon(CmsObject cms, I_CmsResourceType type, CmsXmlWpConfigFile config) throws CmsException {
        // check if this icon is in the cache already
        String icon = (String)m_iconCache.get(type.getTypeName());
        // no icon was found, so check if there is a icon file in the filesystem
        if(icon == null) {
            String filename = CmsWorkplaceDefault.C_ICON_PREFIX + type.getTypeName().toLowerCase() + CmsWorkplaceDefault.C_ICON_EXTENSION;
            try {
                // read the icon file
                cms.readResource(CmsWorkplace.VFS_PATH_RESOURCES + filename);
                // add the icon to the cache
                icon = filename;
                m_iconCache.put(type.getTypeName(), icon);
            }
            catch(CmsException e) {
                // no icon was found, so use the default
                icon = CmsWorkplaceDefault.C_ICON_DEFAULT;
                m_iconCache.put(type.getTypeName(), icon);
            }
        }
        return icon;
    }

⌨️ 快捷键说明

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