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

📄 cmsfckeditorfilebrowser.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/editors/fckeditor/CmsFCKEditorFileBrowser.java,v $
 * Date   : $Date: 2006/04/28 15:20:52 $
 * Version: $Revision: 1.3 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2005 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.editors.fckeditor;

import org.opencms.db.CmsDbSqlException;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.CmsVfsResourceAlreadyExistsException;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypeImage;
import org.opencms.flex.CmsFlexController;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionViolationException;
import org.opencms.util.CmsRequestUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.xml.CmsXmlUtils;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

import org.apache.commons.fileupload.FileItem;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * Implements the OpenCms Connector for integration of the FCKeditor file browser.<p>
 * 
 * Supports browsing the OpenCms virtual file system (VFS), creating folders and uploading files to the VFS.<br>
 * Details about the connector implementation of the FCKeditor file browser can be 
 * found at http://wiki.fckeditor.net/Developer%27s_Guide/Participating/Server_Side_Integration.<p>
 * 
 * @author Andreas Zahner
 * 
 * @version $Revision: 1.3 $ 
 * 
 * @since 6.1.7
 */
public class CmsFCKEditorFileBrowser extends CmsDialog {

    /** Value for the action: create folder. */
    public static final int ACTION_CREATEFOLDER = 502;

    /** Value for the action: upload file. */
    public static final int ACTION_FILEUPLOAD = 503;

    /** Value for the action: get folders. */
    public static final int ACTION_GETFOLDERS = 500;

    /** Value for the action: get folders and files. */
    public static final int ACTION_GETFOLDERS_FILES = 501;

    /** Attribute name for the command attribute. */
    public static final String ATTR_COMMAND = "command";

    /** Attribute name for the name attribute. */
    public static final String ATTR_NAME = "name";

    /** Attribute name for the number attribute. */
    public static final String ATTR_NUMBER = "number";

    /** Attribute name for the path attribute. */
    public static final String ATTR_PATH = "path";

    /** Attribute name for the resourceType attribute. */
    public static final String ATTR_RESOURCETYPE = "resourceType";

    /** Attribute name for the size attribute. */
    public static final String ATTR_SIZE = "size";

    /** Attribute name for the url attribute. */
    public static final String ATTR_URL = "url";

    /** Name for the create folder command. */
    public static final String COMMAND_CREATEFOLDER = "CreateFolder";

    /** Name for the file upload command. */
    public static final String COMMAND_FILEUPLOAD = "FileUpload";

    /** Name for the get folders command. */
    public static final String COMMAND_GETFOLDERS = "GetFolders";

    /** Name for the get folders and files command. */
    public static final String COMMAND_GETFOLDERS_FILES = "GetFoldersAndFiles";

    /** Content type setting HTML for the response. */
    public static final String CONTENTTYPE_HTML = "text/html";

    /** Content type setting XML for the response. */
    public static final String CONTENTTYPE_XML = "text/xml";

    /** The dialog type. */
    public static final String DIALOG_TYPE = "FCKeditor_file_browser";

    /** Error code for creating folders: folder already exists. */
    public static final String ERROR_CREATEFOLDER_EXISTS = "101";

    /** Error code for creating folders: invalid folder name. */
    public static final String ERROR_CREATEFOLDER_INVALIDNAME = "102";

    /** Error code for creating folders: no permissions. */
    public static final String ERROR_CREATEFOLDER_NOPERMISSIONS = "103";

    /** Error code for creating folders: all ok. */
    public static final String ERROR_CREATEFOLDER_OK = "0";

    /** Error code for creating folders: unknown error. */
    public static final String ERROR_CREATEFOLDER_UNKNOWNERROR = "110";

    /** Error code for uploading files: invalid file. */
    public static final String ERROR_UPLOAD_INVALID = "202";

    /** Error code for uploading files: all ok. */
    public static final String ERROR_UPLOAD_OK = "0";

    /** Node name for the Connector node. */
    public static final String NODE_CONNECTOR = "Connector";

    /** Node name for the CurrentFolder node. */
    public static final String NODE_CURRENTFOLDER = "CurrentFolder";

    /** Node name for the Error node. */
    public static final String NODE_ERROR = "Error";

    /** Node name for the File node. */
    public static final String NODE_FILE = "File";

    /** Node name for the Files node. */
    public static final String NODE_FILES = "Files";

    /** Node name for the Folder node. */
    public static final String NODE_FOLDER = "Folder";

    /** Node name for the Folders node. */
    public static final String NODE_FOLDERS = "Folders";

    /** Request parameter name for the command. */
    public static final String PARAM_COMMAND = "Command";

    /** Request parameter name for the current folder. */
    public static final String PARAM_CURRENTFOLDER = "CurrentFolder";

    /** Request parameter name for the new folder name. */
    public static final String PARAM_NEWFOLDERNAME = "NewFolderName";

    /** Request parameter name for the server path. */
    public static final String PARAM_SERVERPATH = "ServerPath";

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

    /** Name for the browser resource type "File". */
    public static final String TYPE_FILE = "File";

    /** Name for the browser resource type "Flash". */
    public static final String TYPE_FLASH = "Flash";

    /** Name for the browser resource type "Image". */
    public static final String TYPE_IMAGE = "Image";

    /** Name for the browser resource type "Media". */
    public static final String TYPE_MEDIA = "Media";

    /** The XML document that is returned in the response. */
    private Document m_document;

    /** The list of multi part file items (if available). */
    private List m_multiPartFileItems;

    /** The Command parameter. */
    private String m_paramCommand;

    /** The CurrentFolder parameter. */
    private String m_paramCurrentFolder;

    /** The NewFolderName parameter. */
    private String m_paramNewFolderName;

    /** The ServerPath parameter. */
    private String m_paramServerPath;

    /** The Type parameter. */
    private String m_paramType;

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

        super(jsp);
    }

    /**
     * Public constructor with JSP variables.<p>
     * 
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     */
    public CmsFCKEditorFileBrowser(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        this(new CmsJspActionElement(context, req, res));
    }

    /**
     * Creates the output for the file browser depending on the executed command.<p>
     * 
     * @return the output for the file browser depending on the executed command
     */
    public String displayDialog() {

        switch (getAction()) {
            case ACTION_CREATEFOLDER:
                return createFolder();
            case ACTION_FILEUPLOAD:
                return uploadFile();
            case ACTION_GETFOLDERS:
                return getFolders(false);
            case ACTION_GETFOLDERS_FILES:
            default:
                return getFolders(true);
        }
    }

    /**
     * Fills all class parameter values from the data provided in the current request.<p>
     * 
     * For this class, the parameters are filled manually from the request, because the needed parameter
     * names for the file browser are in mixed case and not lower case.<p>
     * 
     * @param request the current JSP request
     */
    public void fillParamValues(HttpServletRequest request) {

        // ensure a multipart request is parsed only once (for "forward" scenarios with reports)
        if (null == request.getAttribute(REQUEST_ATTRIBUTE_MULTIPART)) {
            // check if this is a multipart request 
            m_multiPartFileItems = CmsRequestUtil.readMultipartFileItems(request);
            if (m_multiPartFileItems != null) {
                // this was indeed a multipart form request
                CmsRequestUtil.readParameterMapFromMultiPart(
                    getCms().getRequestContext().getEncoding(),
                    m_multiPartFileItems);
                request.setAttribute(REQUEST_ATTRIBUTE_MULTIPART, Boolean.TRUE);
            }
        }

        // manually fill the required request parameters in the members
        setParamCommand(decodeParamValue(PARAM_COMMAND, request.getParameter(PARAM_COMMAND)));
        setParamCurrentFolder(decodeParamValue(PARAM_CURRENTFOLDER, request.getParameter(PARAM_CURRENTFOLDER)));
        setParamNewFolderName(decodeParamValue(PARAM_NEWFOLDERNAME, request.getParameter(PARAM_NEWFOLDERNAME)));
        setParamServerPath(decodeParamValue(PARAM_SERVERPATH, request.getParameter(PARAM_SERVERPATH)));
        setParamType(decodeParamValue(PARAM_TYPE, request.getParameter(PARAM_TYPE)));
    }

    /**
     * Returns the Command parameter.<p>
     * 
     * @return the Command parameter
     */
    public String getParamCommand() {

        return m_paramCommand;
    }

    /**
     * Returns the CurrentFolder parameter.<p>
     * 
     * @return the CurrentFolder parameter
     */
    public String getParamCurrentFolder() {

        return m_paramCurrentFolder;
    }

    /**
     * Returns the NewFolderName parameter.<p>
     * 
     * @return the NewFolderName parameter
     */
    public String getParamNewFolderName() {

        return m_paramNewFolderName;
    }

    /**
     * Returns the ServerPath parameter.<p>
     * 
     * @return the ServerPath parameter
     */
    public String getParamServerPath() {

        return m_paramServerPath;

⌨️ 快捷键说明

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