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

📄 cmschanneltree.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsChannelTree.java,v $
* Date   : $Date: 2003/03/07 14:44:13 $
* Version: $Revision: 1.12 $
*
* 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 com.opencms.core.CmsException;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsFolder;
import com.opencms.file.CmsGroup;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsResource;
import com.opencms.file.I_CmsResourceType;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.util.Encoder;

import java.util.Enumeration;
import java.util.Hashtable;
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.12 $ $Date: 2003/03/07 14:44:13 $
 */

public class CmsChannelTree extends CmsWorkplaceDefault implements I_CmsWpConstants {


    /** 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() == C_STATE_DELETED){
            return false;
        }
        int accessflags = res.getAccessFlags();

        // First check if the user may have access by one of his groups.
        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_VISIBLE) > 0)
                || (cms.readOwner(res).equals(cms.getRequestContext().currentUser()) && (accessflags & C_ACCESS_OWNER_VISIBLE) > 0)
                || (groupAccess && (accessflags & C_ACCESS_GROUP_VISIBLE) > 0)
                || (cms.getRequestContext().isAdmin())) {
            access = true;
        }
        return access;
    }

    /**
     * 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 {
        boolean access = false;
        int 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;
        }
        return access;
    }

    /**
     * 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 = cms.getRequestContext().getSession(true);

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

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

        // check if the files should be displayed as well
        String files = (String)parameters.get(C_PARA_VIEWFILE);
        if(files != null) {
            if(files.equals("yes")) {
                session.putValue(C_PARA_VIEWFILE, files);
            }
            else {
                session.removeValue(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.getResourceTypeName());
        // no icon was found, so check if there is a icon file in the filesystem
        if(icon == null) {
            String filename = C_ICON_PREFIX + type.getResourceTypeName().toLowerCase() + C_ICON_EXTENSION;
            try {
                // read the icon file
                cms.readFileHeader(I_CmsWpConstants.C_VFS_PATH_SYSTEMPICS + filename);
                // add the icon to the cache
                icon = filename;
                m_iconCache.put(type.getResourceTypeName(), icon);

⌨️ 快捷键说明

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