📄 cmsjsploader.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/Attic/CmsJspLoader.java,v $
* Date : $Date: 2002/05/10 21:07:30 $
* Version: $Revision: 1.1.2.1 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2002 The OpenCms Group
*
* 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 OpenCms, please see the
* OpenCms 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 java.util.*;
import java.io.*;
import javax.servlet.http.*;
import com.opencms.file.*;
import com.opencms.core.*;
import com.opencms.launcher.*;
import com.opencms.flex.*;
import com.opencms.flex.cache.*;
import com.opencms.flex.jsp.*;
/**
* This implements the JSP launcher.
* The JSP launcher enables the execution of JSP in OpenCms.
*
* It does NOT inherit from A_CmsLauncher, since JSP are not related
* to the OpenCms Template mechanism.
*
* @author Alexander Kandzior (a.kandzior@alkacon.com)
* @version $Revision: 1.1.2.1 $
*/
public class CmsJspLoader implements I_CmsLauncher, I_CmsLogChannels, I_CmsConstants, I_CmsJspConstants, I_CmsResourceLoader {
/** The directory to store the generated JSP pages in */
private static String m_jspRepository = null;
/** The CmsFlexCache used to store generated cache entries in */
private static CmsFlexCache m_cache;
/** Special JSP Tag start */
public static String C_JSPFILENAME_START = "<cms:jspfilename>";
/** Special JSP Tag end */
public static String C_JSPFILENAME_END = "</cms:jspfilename>";
/** Flag for debugging output */
private static int DEBUG = 0;
// ---------------------------- 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
*/
public void setOpenCms(A_OpenCms openCms) {
init(openCms);
}
/**
* Returns the ID that indicates the type of the launcher.
* The IDs are usually constants in the I_CmsLauncher interface.
*
* @return launcher ID
*/
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.
*
* @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
* @exception CmsException
*/
public void initlaunch(CmsObject cms, CmsFile file, String startTemplateClass, A_OpenCms openCms) throws CmsException {
if (cms.getRequestContext().getRequest() instanceof com.opencms.core.CmsExportRequest) {
if (DEBUG > 1) System.err.println("FlexJspLoader: Export requested for " + file.getAbsolutePath());
com.opencms.launcher.I_CmsLauncher dumpLauncher = cms.getLauncherManager().getLauncher(com.opencms.launcher.I_CmsLauncher.C_TYPE_DUMP);
dumpLauncher.initlaunch(cms, file, startTemplateClass, openCms);
// TODO: Add dumping of processed JSP in case suffix is not "*.jsp", must check with I_CmsRequest and I_CmsResponse from com.opencms.core package
} else {
HttpServletRequest req = (HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest();
HttpServletResponse res = (HttpServletResponse)cms.getRequestContext().getResponse().getOriginalResponse();
load(cms, file, req, res);
}
}
// ---------------------------- Implementation of interface com.opencms.flex.I_CmsResourceLoader
/** Destroy this ResourceLoder */
public void destroy() {
// NOOP
}
/**
* Return a String describing the ResourceLoader.
*
* @return A describing String for the ResourceLoader
*/
public String getResourceLoaderInfo() {
return "The OpenCms default resource loader for JSP";
}
/**
* Initialize the ResourceLoader.
* Here the cache is created in case it does not exist already.
*
* @param openCms An OpenCms object to use for initalizing.
*/
public void init(A_OpenCms openCms) {
m_jspRepository = com.opencms.boot.CmsBase.getBasePath() + File.separator + "jsp";
m_cache = (CmsFlexCache)openCms.getRuntimeProperty(this.C_LOADER_CACHENAME);
if (m_cache == null) {
source.org.apache.java.util.Configurations c = openCms.getConfiguration();
boolean enabled = c.getBoolean("flex.cache.enabled", true);
boolean cacheOffline = c.getBoolean("flex.cache.offline", true);
m_cache = new CmsFlexCache(enabled, cacheOffline);
openCms.setRuntimeProperty(this.C_LOADER_CACHENAME, m_cache);
}
log(this.getClass().getName() + " initialized!");
}
/**
* Basic top-page processing method for the Loader.
* This method is directly called by OpenCms.
*
* @param cms The initialized CmsObject which provides user permissions
* @param file The requested OpenCms VFS resource
* @param req The original servlet request
* @param res The original servlet response
* @throws CmsException In case the Loader can not process the requested resource
*/
public void load(CmsObject cms, CmsFile file, HttpServletRequest req, HttpServletResponse res)
throws CmsException {
long timer1 = 0;
if (DEBUG > 0) {
timer1 = System.currentTimeMillis();
System.err.println("========== JspLoader loading: " + file.getAbsolutePath());
}
boolean streaming = false;
try {
// Read caching property from requested VFS resource
String stream = cms.readProperty(file.getAbsolutePath(), I_CmsResourceLoader.C_LOADER_STREAMPROPERTY);
if (stream != null) {
if ("yes".equalsIgnoreCase(stream) || "true".equalsIgnoreCase(stream)) streaming = true;
}
} catch (CmsException e) {
throw new CmsException("FlexJspLoader: Error while loading stream properties for " + file.getAbsolutePath() + "\n" + e, e);
}
if (DEBUG > 1) System.err.println("========== JspLoader stream=" + streaming);
CmsFlexRequest w_req;
CmsFlexResponse w_res;
if (req instanceof CmsFlexRequest) {
w_req = (CmsFlexRequest)req;
} else {
w_req = new CmsFlexRequest(req, file, m_cache, cms);
}
if (res instanceof CmsFlexResponse) {
w_res = (CmsFlexResponse)res;
} else {
w_res = new CmsFlexResponse(res, streaming);
}
try {
res.setHeader("Connection", "keep-alive");
w_req.getCmsRequestDispatcher(file.getAbsolutePath()).include(w_req, w_res);
} catch (java.net.SocketException e) {
// Uncritical, might happen if client (browser) does not wait until end of page delivery
if (DEBUG > 1) System.err.println("JspLoader.load() ignoring SocketException " + e);
} catch (Exception e) {
System.err.println("Error in CmsJspLoader.load() while loading: " + e.toString());
System.err.println(com.opencms.util.Utils.getStackTrace(e));
throw new CmsException("Error in CmsJspLoader.load() while loading " + file.getAbsolutePath() + "\n" + e, CmsException.C_LAUNCH_ERROR, e);
}
if (! streaming && ! w_res.isSuspended()) {
try {
if (! res.isCommitted()) {
// If a JSP errorpage was triggered the response will be already committed here
byte[] result = w_res.getWriterBytes();
res.setContentLength(result.length);
w_res.processHeaders(w_res.getHeaders(), res);
res.getOutputStream().write(result);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -