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

📄 cmsjsploader.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/Attic/CmsJspLoader.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;

import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.CmsExportRequest;
import com.opencms.core.I_CmsConstants;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsRequestContext;
import com.opencms.file.CmsResource;
import com.opencms.flex.cache.CmsFlexCache;
import com.opencms.flex.cache.CmsFlexController;
import com.opencms.flex.cache.CmsFlexRequest;
import com.opencms.flex.cache.CmsFlexResponse;
import com.opencms.launcher.I_CmsLauncher;
import com.opencms.util.Encoder;
import com.opencms.util.Utils;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * The JSP loader which enables the execution of JSP in OpenCms.<p>
 *
 * It does NOT extend {@link com.opencms.launcher.A_CmsLauncher}, since JSP are not related
 * to the OpenCms Template mechanism. However, it implements the
 * launcher interface so that JSP can be sub-elements in XMLTemplace pages.
 *
 * @author  Alexander Kandzior (a.kandzior@alkacon.com)
 *
 * @version $Revision: 1.24.2.1 $
 * @since FLEX alpha 1
 * 
 * @see I_CmsResourceLoader
 * @see com.opencms.launcher.I_CmsLauncher
 */
public class CmsJspLoader implements I_CmsLauncher, I_CmsResourceLoader {

    /** The directory to store the generated JSP pages in (absolute path) */
    private static String m_jspRepository = null;
    
    /** The directory to store the generated JSP pages in (relative path in web application */
    private static String m_jspWebAppRepository = null;
    
    /** The CmsFlexCache used to store generated cache entries in */
    private static CmsFlexCache m_cache;
    
    /** Export URL for JSP pages */
    private static String m_jspExportUrl;
    
    /** Flag to indicate if error pages are mared a "commited" */
    // TODO: This is a hack, investigate this issue with different runtime environments
    private static boolean m_errorPagesAreNotCommited = false; // should work for Tomcat 4.1

    /** Special JSP directive tag start (<code>&lt;%@</code>)*/
    public static final String C_DIRECTIVE_START = "<%@";

    /** Special JSP directive tag start (<code>%&gt;</code>)*/
    public static final String C_DIRECTIVE_END ="%>";
    
    /** Encoding to write JSP files to disk (<code>ISO-8859-1</code>) */
    public static final String C_DEFAULT_JSP_ENCODING = "ISO-8859-1";
    
    /** Extension for JSP managed by OpenCms (<code>.jsp</code>) */
    public static final String C_JSP_EXTENSION = ".jsp";      

    // Static export related stuff
    /** Parameter constant to indicate that the export is requested */
    private static final String C_EXPORT_PARAM = "_flex_export"; 
    
    /** Parameter constant to indicate a body previously discovered in an XMLTemplate */
    private static final String C_EXPORT_BODY = "_flex_export_body";       
    
    /** Parameter constant to indicate encoding used in calling template */
    private static final String C_EXPORT_ENCODING = "_flex_export_encoding";     
    
    /** Header constant to indicate the found links in the response return headers */
    private static final String C_EXPORT_HEADER = "_flex_export_links";

    /** Separator constant to separate return headers */
    private static final String C_EXPORT_HEADER_SEP = "/";
    
    /** Name of export URL runtime property */
    public static final String C_LOADER_JSPEXPORTURL = "flex.jsp.exporturl";
    
    /** Name of "error pages are commited or not" runtime property*/ 
    public static final String C_LOADER_ERRORPAGECOMMIT = "flex.jsp.errorpagecommit";
    
    /** Flag for debugging output. Set to 9 for maximum verbosity. */ 
    private static final int DEBUG = 0;
        
    /**
     * The constructor of the class is empty, the initial instance will be 
     * created by the launcher manager upon startup of OpenCms.<p>
     * 
     * To initilize the fields in this class, the <code>setOpenCms()</code>
     * method will be called by the launcher.
     * 
     * @see com.opencms.launcher.CmsLauncherManager
     * @see #setOpenCms(A_OpenCms openCms)
     */
    public CmsJspLoader() {
        // NOOP
    }
    
    // ---------------------------- Implementation of interface com.opencms.launcher.I_CmsLauncher          
    
    /**
     * This is part of the I_CmsLauncher interface, but for JSP so far this 
     * is a NOOP.
     */
    public void clearCache() {
        // NOOP
    }
    
    /**
     * This is part of the I_CmsLauncher interface, 
     * used here to call the init() method.
     * 
     * @see #init(A_OpenCms openCms)
     */
    public void setOpenCms(A_OpenCms openCms) {
        init(openCms);
    }    
    
    /** 
     * Returns the ID that indicates the type of the launcher.
     * 
     * The IDs for all launchers of the core distributions are constants 
     * in the I_CmsLauncher interface.
     * The value returned is <code>com.opencms.launcher.I_CmsLauncher.C_TYPE_JSP</code>.
     *
     * @return launcher ID
     * 
     * @see com.opencms.launcher.I_CmsLauncher
     */
    public int getLauncherId() {
        return com.opencms.launcher.I_CmsLauncher.C_TYPE_JSP;
    }
    
    /** 
     * Start launch method called by the OpenCms system to show a resource,
     * this basically processes the resource and returns the output.<p>
     * 
     * This is part of the Launcher interface.
     * All requests will be forwarded to the <code>load()</code> method of this 
     * class. That forms the link between the Launcher and Loader interfaces.<p>
     * 
     * Exceptions thrown in the <code>load()</code> method of this loader
     * will be handled here, usually by wrapping them in a CmsException
     * that will then be shown in the OpenCms error dialog.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param file CmsFile Object with the selected resource to be shown.
     * @param startTemplateClass Name of the template class to start with.
     * @param openCms a instance of A_OpenCms for redirect-needs
     * @throws CmsException all exeptions in the load process of a JSP will be caught here and wrapped to a CmsException
     * 
     * @see com.opencms.launcher.I_CmsLauncher
     * @see #load(CmsObject cms, CmsFile file, HttpServletRequest req, HttpServletResponse res) 
     */
    public void initlaunch(CmsObject cms, CmsFile file, String startTemplateClass, A_OpenCms openCms) throws CmsException {
        HttpServletRequest req;
        HttpServletResponse res;

        if (cms.getRequestContext().getRequest() instanceof CmsExportRequest) {
            // request is an export request 
            if (DEBUG > 1) System.err.println("FlexJspLoader: Export requested for " + file.getAbsolutePath());
            // get the contents of the exported page
            byte[] export = exportJsp(cms, file);
            // try to write the result to the current output stream
            try {
                OutputStream output = cms.getRequestContext().getResponse().getOutputStream();
                output.write(export);
            } catch (IOException e) {
                throw new CmsException("IOException writing contents of exported JSP for URI " + cms.getRequestContext().getUri(), 
                    CmsException.C_FLEX_LOADER, e);
            }
        } else {
            // wrap request and response
            req = (HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest();
            res = (HttpServletResponse)cms.getRequestContext().getResponse().getOriginalResponse();            
            // check if this is an export request
            int oldMode = exportCheckMode(cms, req);            
            // load and process the JSP 
            try {
                // load the resource
                load(cms, file, req, res);
            } catch (Exception e) {
                // all Exceptions are caught here and get translated to a CmsException for display in the OpenCms error dialog
                if (DEBUG > 1) System.err.println("Error in Flex loader: " + e + Utils.getStackTrace(e));
                throw new CmsException("Error in Flex loader", CmsException.C_FLEX_LOADER, e, true);
            } finally {
                exportResetMode(cms, oldMode);
            }
        }        

⌨️ 快捷键说明

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