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

📄 cmsjsptageditable.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Includes the "direct edit" start element that adds HTML for the editable area to 
     * the output page.<p>
     * 
     * @param context the current JSP page context    
     * @param params the direct edit parameters
     * 
     * @return <code>true</code> in case a direct edit element has been opened
     * 
     * @throws JspException in case something goes wrong
     */
    public static boolean startDirectEdit(PageContext context, CmsDirectEditParams params) throws JspException {

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

        boolean result = false;
        if (eb != null) {
            // the direct edit bean must be available
            if (eb.isManual(params.getMode())) {
                // store the given parameters for the next manual call
                setDirectEditProviderParams(context, params);
            } else {
                // automatic mode, insert direct edit HTML
                result = eb.insertDirectEditStart(context, params);
            }
        }

        return result;
    }

    /**
     * Returns the current initialized instance of the direct edit provider parameters from the given page context.<p>
     * 
     * Also removes the parameters from the given page context.<p>
     * 
     * @param context the current JSP page context
     * 
     * @return the current initialized instance of the direct edit provider parameters
     */
    protected static CmsDirectEditParams getDirectEditProviderParams(PageContext context) {

        // get the current request
        ServletRequest req = context.getRequest();
        // get the direct edit params from the request attributes
        CmsDirectEditParams result = (CmsDirectEditParams)req.getAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS);
        if (result != null) {
            req.removeAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS);
        }
        return result;
    }

    /**
     * Sets the current initialized instance of the direct edit provider.<p>
     * 
     * @param context the current JSP page context
     * 
     * @param provider the current initialized instance of the direct edit provider to set
     */
    protected static void setDirectEditProvider(PageContext context, I_CmsDirectEditProvider provider) {

        // set the direct edit provider as attribute to the request
        context.getRequest().setAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER, provider);
    }

    /**
     * Sets the current initialized instance of the direct edit provider parameters to the page context.<p>
     * 
     * @param context the current JSP page context
     * @param params the current initialized instance of the direct edit provider parameters to set
     */
    protected static void setDirectEditProviderParams(PageContext context, CmsDirectEditParams params) {

        // set the direct edit params as attribute to the request
        context.getRequest().setAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS, params);
    }

    /**
     * Close the direct edit tag, also prints the direct edit HTML to the current page.<p>
     * 
     * @return {@link #EVAL_PAGE}
     * 
     * @throws JspException in case something goes wrong
     */
    public int doEndTag() throws JspException {

        if (m_firstOnPage || m_manualPlacement) {
            // only execute action for the first "editable" tag on the page (include file), or in manual mode
            editableTagAction(pageContext, m_provider, m_mode, m_file);
        }
        release();

        return EVAL_PAGE;
    }

    /**
     * Opens the direct edit tag, if manual mode is set then the next 
     * start HTML for the direct edit buttons is printed to the page.<p>
     * 
     * @return {@link #EVAL_BODY_INCLUDE}
     * 
     * @throws JspException in case something goes wrong
     */
    public int doStartTag() throws JspException {

        if (!CmsFlexController.isCmsOnlineRequest(pageContext.getRequest())) {
            // all this does NOT apply to the "online" project
            I_CmsDirectEditProvider eb = getDirectEditProvider(pageContext);
            // if no provider is available this is the first "editable" tag on the page
            m_firstOnPage = (eb == null);
            m_manualPlacement = false;
            if (m_mode == CmsDirectEditMode.MANUAL) {
                // manual mode requested, we may need to insert HTML
                if (!m_firstOnPage && (eb != null)) {
                    // first tag on a page is only for insertion of header HTML
                    if (eb.isManual(m_mode)) {
                        // the provider supports manual placement of buttons
                        m_manualPlacement = true;
                        editableTagAction(pageContext, m_provider, m_mode, m_file);
                    }
                }
            }
        } else {
            // this will ensure the "end" tag is also ignored in the online project
            m_firstOnPage = false;
            m_manualPlacement = false;
        }
        return EVAL_BODY_INCLUDE;
    }

    /**
     * Gets the file with elements for direct editing.<p>
     * 
     * @return the file
     */
    public String getFile() {

        return m_file != null ? m_file : "";
    }

    /**
     * Returns the direct edit mode.<p>
     *
     * @return the direct edit mode
     */
    public String getMode() {

        return m_mode != null ? m_mode.toString() : "";
    }

    /**
     * Returns the class name of the direct edit provider.<p>
     *
     * @return the class name of the direct edit provider
     */
    public String getProvider() {

        return m_provider != null ? m_provider : "";
    }

    /**
     * Releases any resources we may have (or inherit).<p>
     */
    public void release() {

        super.release();
        m_file = null;
        m_provider = null;
        m_mode = null;
        m_firstOnPage = false;
        m_manualPlacement = true;
    }

    /**
     * Sets the file with elements for direct editing.<p>
     * 
     * @param file the file to set 
     */
    public void setFile(String file) {

        if (file != null) {
            m_file = file;
        }
    }

    /**
     * Sets the direct edit mode.<p>
     *
     * @param mode the direct edit mode to set
     */
    public void setMode(String mode) {

        m_mode = CmsDirectEditMode.valueOf(mode);
    }

    /**
     * Sets the class name of the direct edit provider.<p>
     *
     * @param provider the class name of the direct edit provider to set
     */
    public void setProvider(String provider) {

        if (provider != null) {
            m_provider = provider;
        }
    }
}

⌨️ 快捷键说明

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