cmstree.java

来自「找了很久才找到到源代码」· Java 代码 · 共 875 行 · 第 1/3 页

JAVA
875
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsTree.java,v $
 * Date   : $Date: 2007-08-29 13:30:26 $
 * Version: $Revision: 1.27 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * 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 Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project 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 org.opencms.workplace.explorer;

import org.opencms.db.CmsResourceState;
import org.opencms.file.CmsFolder;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.loader.CmsLoaderException;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.site.CmsSite;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;

/**
 * Generates the tree view for the OpenCms Workplace.<p> 
 * 
 * The following Workplace files use this class:
 * <ul>
 * <li>/views/explorer/tree_fs.jsp
 * <li>/views/explorer/tree_files.jsp
 * </ul>
 * <p>
 *
 * @author  Alexander Kandzior 
 * 
 * @version $Revision: 1.27 $ 
 * 
 * @since 6.0.0 
 */
public class CmsTree extends CmsWorkplace {

    /** Request parameter name for the includesfiles parameter. */
    public static final String PARAM_INCLUDEFILES = "includefiles";

    /** Request parameter name for the lastknown parameter. */
    public static final String PARAM_LASTKNOWN = "lastknown";

    /** Request parameter name for the projectaware parameter. */
    public static final String PARAM_PROJECTAWARE = "projectaware";

    /** Request parameter name for the resource parameter. */
    public static final String PARAM_RESOURCE = "resource";

    /** Request parameter name for the rootloaded parameter. */
    public static final String PARAM_ROOTLOADED = "rootloaded";

    /** Request parameter name for the showsiteselector parameter. */
    public static final String PARAM_SHOWSITESELECTOR = "showsiteselector";

    /** Request parameter name for the treesite parameter. */
    public static final String PARAM_TREESITE = "treesite";

    /** Request parameter name for the type parameter. */
    public static final String PARAM_TYPE = "type";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsTree.class);

    /** Type name for showing the tree when copying resources. */
    private static final String TYPE_COPY = "copy";

    /** Type name for showing the tree when creating page links in the editor. */
    private static final String TYPE_PAGELINK = "pagelink";

    /** Type name for showing the tree in preferences dialog. */
    private static final String TYPE_PREFERENCES = "preferences";

    /** Type name for showing the tree when creating siblings. */
    private static final String TYPE_SIBLING = "sibling";

    /** Type name for showing the tree in a widget dialog. */
    private static final String TYPE_VFSWIDGET = "vfswidget";

    /** Indicates if only folders or files and folders should be included in the tree. */
    private boolean m_includeFiles;

    /** Indicates if a complete new tree should be created. */
    private boolean m_newTree;

    /** Indicates project awareness, ie. if resources outside of the current project should be displayed as normal. */
    private boolean m_projectAware = true;

    /** The name of the root folder to display the tree from, usually "/". */
    private String m_rootFolder;

    /** Flag to indicate if the site selector should be shown in popup tree window. */
    private boolean m_showSiteSelector;

    /** The name of the start folder (or "last known" folder) to be loaded. */
    private String m_startFolder;

    /** The name of the target folder to be loaded. */
    private String m_targetFolder;

    /** The type of the tree (e.g. "copy", "project" etc.). */
    private String m_treeType;

    /**
     * Public constructor.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsTree(CmsJspActionElement jsp) {

        super(jsp);
    }

    /**
     * Returns the HTML for the tree initialization.<p>
     * 
     * @param cms the CmsObject
     * @param encoding the current encoding
     * @param skinUri the current skin URI
     * @return the HTML for the tree initialization
     */
    public static String initTree(CmsObject cms, String encoding, String skinUri) {

        StringBuffer retValue = new StringBuffer(512);
        String servletUrl = OpenCms.getSystemInfo().getOpenCmsContext();

        // get the localized workplace messages
        // TODO: Why a new message object, can it not be obtained from session?
        Locale locale = cms.getRequestContext().getLocale();
        CmsMessages messages = OpenCms.getWorkplaceManager().getMessages(locale);

        retValue.append("function initTreeResources() {\n");
        retValue.append("\tinitResources(\"");
        retValue.append(encoding);
        retValue.append("\", \"");
        retValue.append(PATH_WORKPLACE);
        retValue.append("\", \"");
        retValue.append(skinUri);
        retValue.append("\", \"");
        retValue.append(servletUrl);
        retValue.append("\");\n");

        // get all available resource types
        List allResTypes = OpenCms.getResourceManager().getResourceTypes();
        for (int i = 0; i < allResTypes.size(); i++) {
            // loop through all types
            I_CmsResourceType type = (I_CmsResourceType)allResTypes.get(i);
            int curTypeId = type.getTypeId();
            String curTypeName = type.getTypeName();
            // get the settings for the resource type
            CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(curTypeName);
            if (settings == null) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn(Messages.get().getBundle().key(Messages.LOG_MISSING_SETTINGS_ENTRY_1, curTypeName));
                }
                settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
                    CmsResourceTypePlain.getStaticTypeName());
            }
            retValue.append("\taddResourceType(");
            retValue.append(curTypeId);
            retValue.append(", \"");
            retValue.append(curTypeName);
            retValue.append("\",\t\"");
            retValue.append(messages.key(settings.getKey()));
            retValue.append("\",\t\"filetypes/");
            retValue.append(settings.getIcon());
            retValue.append("\");\n");
        }

        retValue.append("}\n\n");
        retValue.append("initTreeResources();\n");

        return retValue.toString();
    }

    /**
     * Determines the root folder of the current tree dependent on users setting of explorer view restriction.<p>
     * 
     * @return the root folder resource name to display
     */
    public String getRootFolder() {

        if (m_rootFolder == null) {
            String folder = "/";
            if ((getTreeType() == null) && getSettings().getUserSettings().getRestrictExplorerView()) {
                folder = getSettings().getUserSettings().getStartFolder();
            }
            try {
                getCms().readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
            } catch (CmsException e) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(e);
                }
                folder = "/";
            }
            m_rootFolder = folder;
        }
        return m_rootFolder;
    }

    /**
     * Returns the HTML for the site selector box for the explorer tree window.<p>
     * 
     * @param htmlAttributes optional attributes for the &lt;select&gt; tag
     * @return HTML code for the site selector box
     */
    public String getSiteSelector(String htmlAttributes) {

        List options = new ArrayList();
        List values = new ArrayList();
        int selectedIndex = 0;
        String preSelection = getSettings().getTreeSite(getTreeType());
        if (preSelection == null) {
            if ("".equals(getCms().getRequestContext().getSiteRoot())) {
                // we are in the root site, getCurrentSite(CmsObject) includes NOT the root site
                preSelection = "";
            } else {
                // get the site root of the current site
                preSelection = OpenCms.getSiteManager().getCurrentSite(getCms()).getSiteRoot();
            }
            // set the tree site to avoid discrepancies between selector and tree
            getSettings().setTreeSite(getTreeType(), preSelection);
        }

        boolean includeRootSite = true;
        boolean showSiteUrls = false;
        if (TYPE_PAGELINK.equals(getTreeType())) {
            // in wysiwyg editor link dialog, don't show root site, but show site URLs
            includeRootSite = false;
            showSiteUrls = true;
        }
        List sites = OpenCms.getSiteManager().getAvailableSites(getCms(), includeRootSite);

        Iterator i = sites.iterator();
        int pos = 0;
        while (i.hasNext()) {
            CmsSite site = (CmsSite)i.next();
            values.add(site.getSiteRoot());
            String curOption = site.getTitle();
            if (showSiteUrls) {
                // show the site URL in editor link dialog tree 
                curOption = site.getUrl() + " (" + curOption + ")";
                if (getCms().getRequestContext().getSiteRoot().equals(site.getSiteRoot())) {
                    // mark the current workplace site in selector
                    curOption = "*" + curOption;
                }
            }

⌨️ 快捷键说明

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