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

📄 cmseditor.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsEditor.java,v $
* Date   : $Date: 2004/01/07 10:57:09 $
* Version: $Revision: 1.42.2.1 $
*
* 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.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsXmlTemplateFile;
import com.opencms.util.Encoder;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;

/**
 * Template class for displaying the text editor of the OpenCms workplace.<P>
 * Reads the edirtor layout from a editor template file of the content type
 * <code>CmsXmlWpTemplateFile</code>.
 *
 * @author Alexander Lucas
 * @version $Revision: 1.42.2.1 $ $Date: 2004/01/07 10:57:09 $
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 */

public class CmsEditor extends CmsWorkplaceDefault {

    /**
     * Get the name of the section that should be loaded from the editor's
     * template file for displaying the editor.
     * MS IE and Netscape Navigator use different ways to display
     * the text editor, so we must distinguish here.
     * @param cms cms object for accessing the original HTTP request
     * @param templateFile the editor's template file containing different sections
     * @return name of the browser specific section in <code>templateFile</code>
     */
    protected String getBrowserSpecificSection(CmsObject cms, CmsXmlTemplateFile templateFile, Hashtable parameters) {
        HttpServletRequest orgReq = (HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest();
        String browser = orgReq.getHeader("user-agent");
        String result = null;
        // if the following parameter is given and MSIE is used,
        // the template "ns" must be selected because there might be no ActiveX control
        String noactivex = (String)parameters.get("noactivex");

        // check browser and return a valid template selector
        if(browser.indexOf("MSIE") > -1) {
            if(templateFile.hasSection("ie")) {
                if(!"true".equalsIgnoreCase(noactivex)){
                    result = "ie";
                } else {
                    // there is no ActiveX Control so use the textarea
                    if(templateFile.hasSection("ns")) {
                        result = "ns";
                    }
                }
            }
        }
        else {
            if(templateFile.hasSection("ns")) {
                result = "ns";
            }
        }
        return result;
    }

    /**
     * Displays the editor described by the template file <code>templateFile</code>.
     * This can be either the HTML editor or the text editor.
     * <p>
     * The given template file will be scanned for special section "ie" and "ns"
     * that can be used to generate browser specific versions of the editors
     * (MS IE or Netscape Navigator). If no such section exists, the default
     * section will be displayed.
     *
     * @see #getContent(CmsObject, String, String, Hashtable, String)
     * @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.
     */
    public byte[] getContent(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {

        I_CmsSession session = cms.getRequestContext().getSession(true);
        String saveerror = "";
        // Get all editor parameters
        String file = (String)parameters.get(C_PARA_FILE);
        // try to get the value from the session because we might come from the error page
        if((file == null) || ("".equals(file))){
            file = (String)session.getValue(C_PARA_FILE);
            session.removeValue(C_PARA_FILE);
        }        
        if((file != null) && (! "".equals(file))) {
            file = file.trim();
            session.putValue("te_file", file);
        }
        String content = (String)parameters.get(C_PARA_CONTENT);
        // try to get the value from the session because we might come from the error page
        if((content == null) || ("".equals(content))){
            content = (String)session.getValue(C_PARA_CONTENT);
            if(content != null){
                parameters.put(C_PARA_CONTENT, content);
            }
            session.removeValue(C_PARA_CONTENT);
        }
        String action = (String)parameters.get(C_PARA_ACTION);
        String jsfile = (String)parameters.get(C_ROOT_TEMPLATE_NAME + "." + C_PARA_JSFILE);
        // try to get the value from the session because we might come from the error page
        if((jsfile == null) || ("".equals(jsfile))){
            jsfile = (String)session.getValue(C_PARA_JSFILE);
            session.removeValue(C_PARA_JSFILE);
        }
        String editorframe = (String)parameters.get("root.editorframe");
        if((editorframe == null) || ("".equals(editorframe))){
            editorframe = (String)session.getValue("editorframe");
            session.removeValue("editorframe");
        }

        boolean checkit = false;
        boolean existsFileParam = ((file != null) && (!"".equals(file)));
        boolean saveRequested = ((action != null) && (C_EDIT_ACTION_SAVE.equals(action)
                || C_EDIT_ACTION_SAVEEXIT.equals(action)));
        boolean exitRequested = ((action != null) && (C_EDIT_ACTION_EXIT.equals(action)
                || C_EDIT_ACTION_SAVEEXIT.equals(action)));

        // CmsFile object of the file to be edited
        CmsFile editFile = null;

        // If there is a file parameter and no content, try to read the file.
        // If the user requested a "save file", also load the file.
        if(existsFileParam && (content == null || saveRequested)) {
            editFile = readFile(cms, file);
            checkit = true;

            // Read file encoding from the property of the file 
            String encoding = cms.getRequestContext().getEncoding();
            encoding = cms.readProperty(file, C_PROPERTY_CONTENT_ENCODING, true, encoding);

            // If there is no content set, this is the first request of the editor.
            // So load the file content and set the "content" parameter.

⌨️ 快捷键说明

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