opencmsservlet.java

来自「找了很久才找到到源代码」· Java 代码 · 共 345 行 · 第 1/2 页

JAVA
345
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/main/OpenCmsServlet.java,v $
 * Date   : $Date: 2007-08-13 16:29:59 $
 * Version: $Revision: 1.59 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 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.main;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResourceFilter;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.staticexport.CmsStaticExportData;
import org.opencms.staticexport.CmsStaticExportRequest;
import org.opencms.util.CmsRequestUtil;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;

/**
 * This the main servlet of the OpenCms system.<p>
 * 
 * From here, all operations that are results of HTTP requests are invoked.
 * Any incoming request is handled in multiple steps:
 * 
 * <ol><li>The requesting <code>{@link org.opencms.file.CmsUser}</code> is authenticated 
 * and a <code>{@link org.opencms.file.CmsObject}</code> with this users context information
 * is created. This <code>{@link org.opencms.file.CmsObject}</code> is used to access all functions of OpenCms, limited by
 * the authenticated users permissions. If the user is not identified, it is set to the default user, usually named "Guest".</li>
 * 
 * <li>The requested <code>{@link org.opencms.file.CmsResource}</code> is loaded into OpenCms and depending on its type 
 * (and the users persmissions to display or modify it), 
 * it is send to one of the OpenCms <code>{@link org.opencms.loader.I_CmsResourceLoader}</code> implementations
 * do be processed.</li>
 * 
 * <li>
 * The <code>{@link org.opencms.loader.I_CmsResourceLoader}</code> will then decide what to do with the 
 * contents of the requested <code>{@link org.opencms.file.CmsResource}</code>. 
 * In case of a JSP resource the JSP handling mechanism is invoked with the <code>{@link org.opencms.loader.CmsJspLoader}</code>, 
 * in case of an image (or another static resource) this will be returned by the <code>{@link org.opencms.loader.CmsDumpLoader}</code>
 * etc.
 * </li></ol>
 *
 * @author Alexander Kandzior 
 * @author Michael Emmerich 
 * 
 * @version $Revision: 1.59 $ 
 * 
 * @since 6.0.0 
 * 
 * @see org.opencms.main.CmsShell
 * @see org.opencms.file.CmsObject
 * @see org.opencms.main.OpenCms
 */
public class OpenCmsServlet extends HttpServlet implements I_CmsRequestHandler {

    /** Name of the <code>DefaultWebApplication</code> parameter in the <code>web.xml</code> OpenCms servlet configuration. */
    public static final String SERVLET_PARAM_DEFAULT_WEB_APPLICATION = "DefaultWebApplication";

    /** 
     * The name of the servlet initialization parameter <code>OnErrorExitWithoutException</code>
     * in the <code>web.xml</code> OpenCms servlet configuration to control whether 
     * to exit with an exception, or not, in the case of an error during initialization,
     * this is important while the setup/update wizard is enabled.<p>
     * The default value of 'false' should work for almost all servlet containers.
     * But if using BEA WLS 9.x, you should set this parameter to 'true'.<p>
     */
    public static final String SERVLET_PARAM_ON_ERROR_EXIT_WITHOUT_EXCEPTION = "OnErrorExitWithoutException";

    /** Name of the <code>OpenCmsHome</code> parameter in the <code>web.xml</code> OpenCms servlet configuration. */
    public static final String SERVLET_PARAM_OPEN_CMS_HOME = "OpenCmsHome";

    /** Name of the <code>OpenCmsServlet</code> parameter in the <code>web.xml</code> OpenCms servlet configuration. */
    public static final String SERVLET_PARAM_OPEN_CMS_SERVLET = "OpenCmsServlet";

    /** 
     * The name of the servlet initialization parameter <code>RequestErrorPageAttribute</code>
     * in the <code>web.xml</code> OpenCms servlet configuration to set an replacement 
     * request attribute for the {@link HttpServletRequest#getPathInfo()} method, which 
     * is just needed if this method is not properly implemented like in BEA WLS 9.x.<p>
     * If using BEA WLS 9.x, you should set this parameter to 'weblogic.servlet.errorPage'.<p>
     */
    public static final String SERVLET_PARAM_REQUEST_ERROR_PAGE_ATTRIBUTE = "RequestErrorPageAttribute";

    /** Name of the <code>WebApplicationContext</code> parameter in the <code>web.xml</code> OpenCms servlet configuration. */
    public static final String SERVLET_PARAM_WEB_APPLICATION_CONTEXT = "WebApplicationContext";

    /** Handler prefix. */
    private static final String HANDLE_PATH = "/handle";

    /** Path to handler "error page" files in the VFS. */
    private static final String HANDLE_VFS_PATH = "/system/handler" + HANDLE_PATH;

    /** Handler "error page" file suffix. */
    private static final String HANDLE_VFS_SUFFIX = ".html";

    /** Handler implementation names. */
    private static final String[] HANDLER_NAMES = {"404"};

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(OpenCmsServlet.class);

    /** Serial version UID required for safe serialization. */
    private static final long serialVersionUID = 4729951599966070050L;

    /**
     * OpenCms servlet main request handling method.<p>
     * 
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

        // check to OpenCms runlevel
        int runlevel = OpenCmsCore.getInstance().getRunLevel();

        // write OpenCms server identification in the response header
        res.setHeader(CmsRequestUtil.HEADER_SERVER, OpenCmsCore.getInstance().getSystemInfo().getVersion());

        if (runlevel != OpenCms.RUNLEVEL_4_SERVLET_ACCESS) {
            // not the "normal" servlet runlevel
            if (runlevel == OpenCms.RUNLEVEL_3_SHELL_ACCESS) {
                // we have shell runlevel only, upgrade to servlet runlevel (required after setup wizard)
                init(getServletConfig());
            } else {
                // illegal runlevel, we can't process requests
                // sending status code 403, indicating the server understood the request but refused to fulfill it
                res.sendError(HttpServletResponse.SC_FORBIDDEN);
                // goodbye
                return;
            }
        }

        String path = OpenCmsCore.getInstance().getPathInfo(req);
        if (path.startsWith(HANDLE_PATH)) {
            // this is a request to an OpenCms handler URI
            invokeHandler(req, res);
        } else {
            // standard request to a URI in the OpenCms VFS 
            OpenCmsCore.getInstance().showResource(req, res);
        }
    }

⌨️ 快捷键说明

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