📄 cmsjsploader.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/loader/CmsJspLoader.java,v $
* Date : $Date: 2006/03/27 14:52:37 $
* Version: $Revision: 1.100 $
*
* 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.loader;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.flex.CmsFlexCache;
import org.opencms.flex.CmsFlexController;
import org.opencms.flex.CmsFlexRequest;
import org.opencms.flex.CmsFlexResponse;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsRequestUtil;
import org.opencms.workplace.CmsWorkplaceManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.SocketException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.logging.Log;
/**
* The JSP loader which enables the execution of JSP in OpenCms.<p>
*
* Parameters supported by this loader:<dl>
*
* <dt>jsp.repository</dt><dd>
* (Optional) This is the root directory in the "real" file system where generated JSPs are stored.
* The default is the web application path, e.g. in Tomcat if your web application is
* names "opencms" it would be <code>${TOMCAT_HOME}/webapps/opencms/</code>.
* The <code>jsp.folder</code> (see below) is added to this path.
* Usually the <code>jsp.repository</code> is not changed.
* </dd>
*
* <dt>jsp.folder</dt><dd>
* (Optional) A path relative to the <code>jsp.repository</code> path where the
* JSPs generated by OpenCms are stored. The default is to store the generated JSP in
* <code>/WEB-INF/jsp/</code>.
* This works well in Tomcat 4, and the JSPs are
* not accessible directly from the outside this way, only through the OpenCms servlet.
* <i>Please note:</i> Some servlet environments (e.g. BEA Weblogic) do not permit
* JSPs to be stored under <code>/WEB-INF</code>. For environments like these,
* set the path to some place where JSPs can be accessed, e.g. <code>/jsp/</code> only.
* </dd>
*
* <dt>jsp.errorpage.committed</dt><dd>
* (Optional) This parameter controls behaviour of JSP error pages
* i.e. <code><% page errorPage="..." %></code>. If you find that these don't work
* in your servlet environment, you should try to change the value here.
* The default <code>true</code> has been tested with Tomcat 4.1 and 5.0.
* Older versions of Tomcat like 4.0 require a setting of <code>false</code>.</dd>
* </dl>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.100 $
*
* @since 6.0.0
*
* @see I_CmsResourceLoader
*/
public class CmsJspLoader implements I_CmsResourceLoader, I_CmsFlexCacheEnabledLoader {
/** Property value for "cache" that indicates that the FlexCache should be bypassed. */
public static final String CACHE_PROPERTY_BYPASS = "bypass";
/** Property value for "cache" that indicates that the ouput should be streamed. */
public static final String CACHE_PROPERTY_STREAM = "stream";
/** Default jsp folder constant. */
public static final String DEFAULT_JSP_FOLDER = "/WEB-INF/jsp/";
/** Special JSP directive tag start (<code>%></code>). */
public static final String DIRECTIVE_END = "%>";
/** Special JSP directive tag start (<code><%(</code>). */
public static final String DIRECTIVE_START = "<%@";
/** Extension for JSP managed by OpenCms (<code>.jsp</code>). */
public static final String JSP_EXTENSION = ".jsp";
/** Cache max age parameter name. */
public static final String PARAM_CLIENT_CACHE_MAXAGE = "client.cache.maxage";
/** Error page commited parameter name. */
public static final String PARAM_JSP_ERRORPAGE_COMMITTED = "jsp.errorpage.committed";
/** Jsp folder parameter name. */
public static final String PARAM_JSP_FOLDER = "jsp.folder";
/** Jsp repository parameter name. */
public static final String PARAM_JSP_REPOSITORY = "jsp.repository";
/** The id of this loader. */
public static final int RESOURCE_LOADER_ID = 6;
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsJspLoader.class);
/** The maximum age for delivered contents in the clients cache. */
private static long m_clientCacheMaxAge;
/** The directory to store the generated JSP pages in (absolute path). */
private static String m_jspRepository;
/** The directory to store the generated JSP pages in (relative path in web application). */
private static String m_jspWebAppRepository;
/** The CmsFlexCache used to store generated cache entries in. */
private CmsFlexCache m_cache;
/** The resource loader configuration. */
private Map m_configuration;
/** Flag to indicate if error pages are marked as "commited". */
// TODO: This is a hack, investigate this issue with different runtime environments
private boolean m_errorPagesAreNotCommited; // default false should work for Tomcat > 4.1
/**
* The constructor of the class is empty, the initial instance will be
* created by the resource manager upon startup of OpenCms.<p>
*
* @see org.opencms.loader.CmsResourceManager
*/
public CmsJspLoader() {
m_configuration = new TreeMap();
}
/**
* Returns the absolute path in the "real" file system for the JSP repository
* toplevel directory.
*
* @return The full path to the JSP repository
*/
public static String getJspRepository() {
return m_jspRepository;
}
/**
* @see org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String, java.lang.String)
*/
public void addConfigurationParameter(String paramName, String paramValue) {
m_configuration.put(paramName, paramValue);
}
/** Destroy this ResourceLoder, this is a NOOP so far. */
public void destroy() {
// NOOP
}
/**
* @see org.opencms.loader.I_CmsResourceLoader#dump(org.opencms.file.CmsObject, org.opencms.file.CmsResource, java.lang.String, java.util.Locale, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public byte[] dump(
CmsObject cms,
CmsResource file,
String element,
Locale locale,
HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
// get the current Flex controller
CmsFlexController controller = CmsFlexController.getController(req);
CmsFlexController oldController = null;
if (controller != null) {
// for dumping we must create an new "top level" controller, save the old one to be restored later
oldController = controller;
}
byte[] result = null;
try {
// now create a new, temporary Flex controller
controller = getController(cms, file, req, res, false, false);
if (element != null) {
// add the element parameter to the included request
String[] value = new String[] {element};
Map parameters = Collections.singletonMap(I_CmsResourceLoader.PARAMETER_ELEMENT, value);
controller.getCurrentRequest().addParameterMap(parameters);
}
// dispatch to the JSP
result = dispatchJsp(controller);
// remove temporary controller
CmsFlexController.removeController(req);
} finally {
if (oldController != null) {
// update "date last modified"
oldController.updateDates(controller.getDateLastModified(), controller.getDateExpires());
// reset saved controller
CmsFlexController.setController(req, oldController);
}
}
return result;
}
/**
* @see org.opencms.loader.I_CmsResourceLoader#export(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public byte[] export(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// get the Flex controller
CmsFlexController controller = getController(cms, resource, req, res, false, true);
// dispatch to the JSP
byte[] result = dispatchJsp(controller);
// remove the controller from the request
CmsFlexController.removeController(req);
// return the contents
return result;
}
/**
* @see org.opencms.configuration.I_CmsConfigurationParameterHandler#getConfiguration()
*/
public Map getConfiguration() {
// return the configuration in an immutable form
return Collections.unmodifiableMap(m_configuration);
}
/**
* @see org.opencms.loader.I_CmsResourceLoader#getLoaderId()
*/
public int getLoaderId() {
return RESOURCE_LOADER_ID;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -