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

📄 cmsjsptageditable.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagEditable.java,v $
 * Date   : $Date: 2006/10/26 12:25:35 $
 * Version: $Revision: 1.24 $
 *
 * 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.jsp;

import org.opencms.file.CmsBackupResourceHandler;
import org.opencms.file.CmsObject;
import org.opencms.flex.CmsFlexController;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.editors.directedit.CmsDirectEditJspIncludeProvider;
import org.opencms.workplace.editors.directedit.CmsDirectEditMode;
import org.opencms.workplace.editors.directedit.CmsDirectEditParams;
import org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider;

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;

/**
 * Implementation of the <code>&lt;cms:editable/&gt;</code> tag.<p>
 * 
 * This class is also used to generate the direct edit buttons for the 
 * <code>&lt;cms:include editable="..." /&gt;</code> and <code>&lt;cms:contentload editable="..." /&gt;</code> tags.<p>
 * 
 * Since OpenCms version 6.2.3, the direct edit button HTML generated is controlled by an instance of {@link I_CmsDirectEditProvider}.
 * The default direct edit provider used can be configured in <code>opencms-workplace.xml</code> in the 
 * <code>&lt;directeditprovider class="..." /&gt;</code> node. The standard provider is
 * {@link org.opencms.workplace.editors.directedit.CmsDirectEditDefaultProvider}.
 * It's possible to override the default provider onm a page-by-page basis by initializing direct edit with 
 * <code>&lt;cms:editable provider="...." /&gt;</code> on top of the page.<p>
 * 
 * Since OpenCms version 6.2.3, it is also possible to place the HTML of the direct edit buttons manually.
 * This is intended for pages where the template HTML is not compatible with the direct edit HTML,
 * which usually results in a funny placement of the direct edit buttons in a totally wrong position.
 * To do manual placement of the direct edit buttons, you need to place <code>&lt;cms:editable mode="manual"&gt;</code> and
 * <code>&lt;/cms:editable&gt;</code> around your HTML. Both tags (start and end) will insert HTML according to 
 * the used {@link I_CmsDirectEditProvider}. The direct edit provider used must also support manual 
 * placing, or the manual tags will be ignored and the HTML will be inserted at the automatic position. 
 * A provider which support manual placing is the {@link org.opencms.workplace.editors.directedit.CmsDirectEditTextButtonProvider}.<p>
 * 
 * @version $Revision: 1.24 $ 
 * 
 * @since 6.0.0 
 */
public class CmsJspTagEditable extends BodyTagSupport {

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

    /** Serial version UID required for safe serialization. */
    private static final long serialVersionUID = 4137789622146499225L;

    /** File with editable elements. */
    protected String m_file;

    /** Indicates which direct edit mode is active. */
    protected CmsDirectEditMode m_mode;

    /** Class name of the direct edit provider. */
    protected String m_provider;

    /** Indicates if the tag is the first on the page, this mean the header file must be included. */
    private boolean m_firstOnPage;

    /** Indicates if the direct edit HTML is to be placed manually. */
    private boolean m_manualPlacement;

    /**
     * Editable action method.<p>
     * 
     * @param context the current JSP page context
     * @param provider the class name of the direct edit privider to use (may be <code>null</code>, which means use the default)
     * @param mode the direct edit mode to use (may be <code>null</code>, which means current use mode on page)
     * @param fileName optional filename parameter for the direct edit provider (may be <code>null</code>, which means use the default)
     * 
     * @throws JspException in case something goes wrong
     */
    public static void editableTagAction(PageContext context, String provider, CmsDirectEditMode mode, String fileName)
    throws JspException {

        if (mode == CmsDirectEditMode.FALSE) {
            // direct edit is turned off
            return;
        }

        ServletRequest req = context.getRequest();
        if (CmsBackupResourceHandler.isBackupRequest(req)) {
            // don't display direct edit buttons on a backup resource
            return;
        }

        CmsFlexController controller = CmsFlexController.getController(req);
        CmsObject cms = controller.getCmsObject();

        if (!cms.getRequestContext().currentProject().isOnlineProject()) {
            // direct edit is never enabled in the online project
            I_CmsDirectEditProvider eb = getDirectEditProvider(context);
            if (eb == null) {
                if (CmsStringUtil.isNotEmpty(fileName) && CmsStringUtil.isEmpty(provider)) {
                    // if only a filename but no provider class is given, use JSP includes for backward compatibility
                    provider = CmsDirectEditJspIncludeProvider.class.getName();
                }
                // no provider available in page context
                if (CmsStringUtil.isNotEmpty(provider)) {
                    try {
                        // create a new instance of the selected provider
                        eb = (I_CmsDirectEditProvider)Class.forName(provider).newInstance();
                    } catch (Exception e) {
                        // log error
                        LOG.error(Messages.get().getBundle().key(Messages.ERR_DIRECT_EDIT_PROVIDER_1, provider), e);
                    }
                }
                if (eb == null) {
                    // use configured direct edit provider as a fallback
                    eb = OpenCms.getWorkplaceManager().getDirectEditProvider();
                }
                if (mode == null) {
                    // use automatic placement by default
                    mode = CmsDirectEditMode.AUTO;
                }
                eb.init(cms, mode, fileName);
                // store the provider in the page context
                setDirectEditProvider(context, eb);
            }
            if (eb.isManual(mode)) {
                // manual mode, insert required HTML
                CmsDirectEditParams params = getDirectEditProviderParams(context);
                if (params != null) {
                    // insert direct edit start HTML
                    eb.insertDirectEditStart(context, params);
                } else {
                    // insert direct edit end HTML
                    eb.insertDirectEditEnd(context);
                }
            } else {
                // insert direct edit header HTML
                eb.insertDirectEditIncludes(context, new CmsDirectEditParams(cms.getRequestContext().getUri()));
            }
        }
    }

    /**
     * Closes the current direct edit element.<p>
     * 
     * @param context the current JSP page context
     * 
     * @throws JspException in case something goes wrong
     */
    public static void endDirectEdit(PageContext context) throws JspException {

        // get the direct edit bean from the context
        I_CmsDirectEditProvider eb = getDirectEditProvider(context);

        if (eb != null) {
            // the direct edit bean must be available
            eb.insertDirectEditEnd(context);
        }
    }

    /**
     * Returns the current initialized instance of the direct edit provider.<p>
     * 
     * @param context the current JSP page context
     * 
     * @return the current initialized instance of the direct edit provider
     */
    public static I_CmsDirectEditProvider getDirectEditProvider(PageContext context) {

        // get the direct edit provider from the request attributes
        return (I_CmsDirectEditProvider)context.getRequest().getAttribute(
            I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER);
    }

    /**

⌨️ 快捷键说明

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