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

📄 cmsjspactionelement.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/jsp/CmsJspActionElement.java,v $
 * Date   : $Date: 2003/05/13 13:18:20 $
 * Version: $Revision: 1.24.2.1 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2002 - 2003 Alkacon Software (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, 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 com.opencms.flex.jsp;

import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsRequestContext;
import com.opencms.file.CmsResource;
import com.opencms.flex.CmsJspLoader;
import com.opencms.flex.CmsJspTemplate;
import com.opencms.flex.cache.CmsFlexController;
import com.opencms.flex.util.CmsMessages;
import com.opencms.launcher.CmsDumpLauncher;
import com.opencms.launcher.CmsLinkLauncher;
import com.opencms.launcher.CmsXmlLauncher;
import com.opencms.launcher.I_CmsLauncher;
import com.opencms.template.CmsXmlTemplate;
import com.opencms.util.Utils;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

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

/**
 * Bean to be used in JSP scriptlet code that provides direct 
 * access to the functionality offered by the opencms taglib.<p>
 * 
 * By instanciating a bean of this type and accessing the methods provided by 
 * the instance, all functionality of the OpenCms JSP taglib can be easily 
 * used from within JSP scriplet code,<p>
 * 
 * Initialize this bean at the beginning of your JSP like this:
 * <pre>
 * &lt;jsp:useBean id="cms" class="com.opencms.flex.jsp.CmsJspActionElement"&gt;
 * &lt% cms.init(pageContext, request, response); %&gt;
 * &lt;/jsp:useBean&gt;
 * </pre>
 * 
 * All exceptions that occur when calling any method of this class are catched 
 * and written to the log output only, so that a template still has a chance of
 * working at last in some elements.<p>
 *
 * @author  Alexander Kandzior (a.kandzior@alkacon.com)
 * @version $Revision: 1.24.2.1 $
 * 
 * @since 5.0 beta 2
 */
public class CmsJspActionElement {

    /** OpenCms JSP request */
    private HttpServletRequest m_request;

    /** OpenCms JSP response */
    private HttpServletResponse m_response;
    
    /** OpenCms core CmsObject */
    private CmsFlexController m_controller;

    /** JSP page context */
    private PageContext m_context;    
    
    /** JSP navigation builder */
    private CmsJspNavBuilder m_navigation = null;    
    
    /** Flag to indicate that this bean was properly initialized */
    private boolean m_notInitialized;
    
    /** Flag to indicate if we want default or custom Exception handling */
    private boolean m_handleExceptions = true;
        
    /** Error message in case bean was not properly initialized */
    public final static String C_NOT_INITIALIZED = "+++ CmsJspActionElement not initialized +++";

    /** DEBUG flag */
    private static final int DEBUG = 0;
    
    /**
     * Empty constructor, required for every JavaBean.
     */
    public CmsJspActionElement() {
        m_notInitialized = true;
    }
    
    /**
     * Constructor, with parameters.
     * 
     * @param content the JSP page context object
     * @param req the JSP request 
     * @param res the JSP response 
     */
    public CmsJspActionElement(PageContext context, HttpServletRequest req, HttpServletResponse res) {
        m_notInitialized = true;
        init(context, req, res);
    }    
    
    /**
     * Initialize the bean with the current page context, request and response.<p>
     * 
     * It is required to call one of the init() methods before you can use the 
     * instance of this bean.
     * 
     * @param content the JSP page context object
     * @param req the JSP request 
     * @param res the JSP response 
     */
    public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) {
        m_controller = (CmsFlexController)req.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
        if (m_controller == null) {
            // controller not found - this request was not initialized properly
            
        }
        m_context = context;
        m_request = req;
        m_response = res;
        m_notInitialized = false;
    }    
    
    /**
     * Returns <code>true</code> if Exceptions are handled by the class instace, or
     * <code>false</code> if they will be thrown and have to be handled by the calling class.<p>
     * 
     * The default is <code>true</code>.
     * If set to <code>false</code> Exceptions that occur internally will be wrapped into
     * a RuntimeException and thrown to the calling class instance.<p>
     * 
     * <b>Important:</b> Exceptions that occur during a call to {@link #includeSilent(String, String, Map)}
     * will NOT be handled.
     * 
     * @return <code>true</code> if Exceptions are handled by the class instace, or
     *      <code>false</code> if they will be thrown and have to be handled by the calling class
     */
    public boolean getHandleExceptions() {
        return m_handleExceptions;
    }

    /**
     * Controls if Exceptions that occur in methods of this class are supressed (true)
     * or not (false).<p>
     * 
     * The default is <code>true</code>.
     * If set to <code>false</code> all Exceptions that occur internally will be wrapped into
     * a RuntimeException and thrown to the calling class instance.<p>
     * 
     * <b>Important:</b> Exceptions that occur during a call to {@link #includeSilent(String, String, Map)}
     * will NOT be handled.
     * 
     * @param the value to set the Exception handing to
     */
    public void setHandleExceptions(boolean value) {
        m_handleExceptions = value;
    }    
    
    /**
     * Returns the request wrapped by the element.<p>
     * 
     * @return the request wrapped by the element
     */
    public HttpServletRequest getRequest() {
        if (m_notInitialized) return null;
        return m_request;        
    }
    
    /**
     * Returns the reponse wrapped by this element.<p>
     * 
     * @return the reponse wrapped by this element
     */
    public HttpServletResponse getResponse() {
        if (m_notInitialized) return null;
        return m_response;        
    }    
    
    /**
     * Returns the JSP page context wrapped by this element.<p>
     * 
     * @return the JSP page context wrapped by this element
     */    
    public PageContext getPageContext() {
        if (m_notInitialized) return null;
        return m_context;           
    }

    /**
     * Returns the CmsObject from the wrapped request.<p>
     *
     * This is a convenience method in case you need access to
     * the CmsObject in your JSP scriplets.
     *
     * @return the CmsObject from the wrapped request
     */
    public CmsObject getCmsObject() {
        if (m_notInitialized) return null;
        try { 
            return m_controller.getCmsObject();
        } catch (Throwable t) {
            handleException(t);
        }      
        return null;            
    }
    
    /**
     * Include a sub-element without paramters from the OpenCms VFS, same as
     * using the <code>&lt;cms:include file="..." /&gt;</code> tag.
     * 
     * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)
     * @throws JspException in case there were problems including the target
     *
     * @see com.opencms.flex.jsp.CmsJspTagInclude
     */
    public void include(String target) throws JspException {
        this.include(target, null, null);
    }
    
    /**
     * Include a named sub-element without paramters from the OpenCms VFS, same as
     * using the <code>&lt;cms:include file="..." element="..." /&gt;</code> tag.
     * 
     * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute)

⌨️ 快捷键说明

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