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

📄 cmseditor.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsEditor.java,v $
 * Date   : $Date: 2006/11/21 14:16:29 $
 * Version: $Revision: 1.41 $
 *
 * 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.workplace.editors;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsFrameset;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;

/**
 * Provides basic methods for building the file editors of OpenCms.<p> 
 * 
 * The editor classes have to extend this class and implement action methods for common editor actions.<p>
 *
 * @author  Andreas Zahner 
 * 
 * @version $Revision: 1.41 $ 
 * 
 * @since 6.0.0 
 */
public abstract class CmsEditor extends CmsDialog {

    /** Value for the action: change the body. */
    public static final int ACTION_CHANGE_BODY = 124;

    /** Value for the action: delete the current locale. */
    public static final int ACTION_DELETELOCALE = 140;

    /** Value for the action: exit. */
    public static final int ACTION_EXIT = 122;

    /** Value for the action: show a preview. */
    public static final int ACTION_PREVIEW = 126;

    /** Value for the action: save. */
    public static final int ACTION_SAVE = 121;

    /** Constant value for the customizable action button. */
    public static final int ACTION_SAVEACTION = 130;

    /** Value for the action: save and exit. */
    public static final int ACTION_SAVEEXIT = 123;

    /** Value for the action: show the editor. */
    public static final int ACTION_SHOW = 125;

    /** Value for the action: an error occured. */
    public static final int ACTION_SHOW_ERRORMESSAGE = 127;

    /** Value for the action parameter: change the element. */
    public static final String EDITOR_CHANGE_ELEMENT = "changeelement";

    /** Value for the action parameter: cleanup content. */
    public static final String EDITOR_CLEANUP = "cleanup";

    /** Value for the action parameter: close browser window (accidentally). */
    public static final String EDITOR_CLOSEBROWSER = "closebrowser";

    /** Value for the action parameter: delete the current locale. */
    public static final String EDITOR_DELETELOCALE = "deletelocale";

    /** Value for the action parameter: exit editor. */
    public static final String EDITOR_EXIT = "exit";

    /** Value for the action parameter: show a preview. */
    public static final String EDITOR_PREVIEW = "preview";

    /** Value for the action parameter: save content. */
    public static final String EDITOR_SAVE = "save";

    /** Value for the customizable action button. */
    public static final String EDITOR_SAVEACTION = "saveaction";

    /** Value for the action parameter: save and exit. */
    public static final String EDITOR_SAVEEXIT = "saveexit";

    /** Value for the action parameter: show the editor. */
    public static final String EDITOR_SHOW = "show";

    /** Value for the action parameter: an error occured. */
    public static final String EDITOR_SHOW_ERRORMESSAGE = "error";

    /** Marker for empty locale in locale selection. */
    public static final String EMPTY_LOCALE = " [-]";

    /** Stores the VFS editor path. */
    public static final String PATH_EDITORS = PATH_WORKPLACE + "editors/";

    /** Parameter name for the request parameter "backlink". */
    public static final String PARAM_BACKLINK = "backlink";

    /** Parameter name for the request parameter "content". */
    public static final String PARAM_CONTENT = "content";

    /** Parameter name for the request parameter "directedit". */
    public static final String PARAM_DIRECTEDIT = "directedit";

    /** Parameter name for the request parameter "editastext". */
    public static final String PARAM_EDITASTEXT = "editastext";

    /** Parameter name for the request parameter "editormode". */
    public static final String PARAM_EDITORMODE = "editormode";

    /** Parameter name for the request parameter "element language". */
    public static final String PARAM_ELEMENTLANGUAGE = "elementlanguage";

    /** Parameter name for the request parameter "loaddefault". */
    public static final String PARAM_LOADDEFAULT = "loaddefault";

    /** Parameter name for the request parameter "modified". */
    public static final String PARAM_MODIFIED = "modified";

    /** Parameter name for the request parameter "old element language". */
    public static final String PARAM_OLDELEMENTLANGUAGE = "oldelementlanguage";

    /** Parameter name for the request parameter "tempfile". */
    public static final String PARAM_TEMPFILE = "tempfile";

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

    /** The encoding to use (will be read from the file property). */
    private String m_fileEncoding;

    // some private members for parameter storage
    private String m_paramBackLink;
    private String m_paramContent;
    private String m_paramDirectedit;
    private String m_paramEditAsText;
    private String m_paramEditormode;
    private String m_paramElementlanguage;
    private String m_paramLoadDefault;
    private String m_paramModified;
    private String m_paramOldelementlanguage;
    private String m_paramTempFile;

    /** Helper variable to store the uri to the editors pictures. */
    private String m_picsUri;

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

        super(jsp);
    }

    /**
     * Unlocks the edited resource when in direct edit mode or when the resource was not modified.<p>
     * 
     * @param forceUnlock if true, the resource will be unlocked anyway
     */
    public abstract void actionClear(boolean forceUnlock);

    /**
     * Performs the exit editor action.<p>
     * 
     * @throws CmsException if something goes wrong
     * @throws IOException if a forward fails
     * @throws ServletException if a forward fails
     * @throws JspException if including an element fails
     */
    public abstract void actionExit() throws CmsException, IOException, ServletException, JspException;

    /**
     * Performs the save content action.<p>
     * 
     * @throws IOException if a redirection fails
     * @throws JspException if including an element fails
     */
    public abstract void actionSave() throws IOException, JspException;

    /**
     * Builds the html String for the element language selector.<p>
     *  
     * @param attributes optional attributes for the &lt;select&gt; tag
     * @param resource the name of the resource to edit
     * @param selectedLocale the currently selected Locale
     * @return the html for the element language selectbox
     */
    public String buildSelectElementLanguage(String attributes, String resource, Locale selectedLocale) {

        // get locale names based on properties and global settings
        List locales = OpenCms.getLocaleManager().getAvailableLocales(getCms(), resource);
        List options = new ArrayList(locales.size());
        List selectList = new ArrayList(locales.size());
        int currentIndex = -1;

        String filename = resource;

        //get the locales already used in the resource
        List contentLocales = new ArrayList();
        try {

            CmsResource res = getCms().readResource(filename);

            String temporaryFilename = CmsResource.getFolderPath(resource)
                + CmsWorkplace.TEMP_FILE_PREFIX
                + res.getName();
            if (getCms().existsResource(temporaryFilename)) {
                res = getCms().readResource(temporaryFilename);
            }
            CmsFile file = CmsFile.upgrade(res, getCms());
            CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file);
            contentLocales = xmlContent.getLocales();
        } catch (CmsException e) {
            // to nothing here in case the resource could not be opened
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_GET_LOCALES_1, filename), e);
            }
        }

        for (int counter = 0; counter < locales.size(); counter++) {
            // create the list of options and values
            Locale curLocale = (Locale)locales.get(counter);
            selectList.add(curLocale.toString());
            StringBuffer buf = new StringBuffer();
            buf.append(curLocale.getDisplayName(getLocale()));
            if (!contentLocales.contains(curLocale)) {
                buf.append(EMPTY_LOCALE);
            }
            options.add(buf.toString());
            if (curLocale.equals(selectedLocale)) {
                // set the selected index of the selector
                currentIndex = counter;
            }
        }

        if (currentIndex == -1) {
            // no matching element language found, use first element language in list
            if (selectList.size() > 0) {
                currentIndex = 0;
                setParamElementlanguage((String)selectList.get(0));
            }
        }

        return buildSelect(attributes, options, selectList, currentIndex, false);
    }

    /**
     * Generates a button for the OpenCms editor.<p>
     * 
     * @param href the href link for the button, if none is given the button will be disabled
     * @param target the href link target for the button, if none is given the target will be same window
     * @param image the image name for the button, skin path will be automattically added as prefix
     * @param label the label for the text of the button 
     * @param type 0: image only (default), 1: image and text, 2: text only
     * @param useCustomImage if true, the button has to be placed in the editors "custom pics" folder
     * 
     * @return a button for the OpenCms editor
     */
    public String button(String href, String target, String image, String label, int type, boolean useCustomImage) {

        if (useCustomImage) {
            // search the picture in the "custom pics" folder
            return button(href, target, image, label, type, getPicsUri());
        } else {
            // search the picture in the common "buttons" folder
            return button(href, target, image, label, type);
        }
    }

    /**
     * Returns the editor action for a "cancel" button.<p>
     * 
     * This overwrites the cancel method of the CmsDialog class.<p>
     * 
     * Always use this value, do not write anything directly in the html page.<p>
     * 
     * @return the default action for a "cancel" button
     */
    public String buttonActionCancel() {

        String target = null;
        if (Boolean.valueOf(getParamDirectedit()).booleanValue()) {
            // editor is in direct edit mode
            if (CmsStringUtil.isNotEmpty(getParamBacklink())) {

⌨️ 快捷键说明

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