/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.portlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.MimeResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.StateAwareResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.core.OrderComparator;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.style.StylerUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.portlet.multipart.MultipartActionRequest;
import org.springframework.web.portlet.multipart.PortletMultipartResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewRendererServlet;
import org.springframework.web.servlet.ViewResolver;
/**
* Central dispatcher for use within the Portlet MVC framework, e.g. for web UI
* controllers. Dispatches to registered handlers for processing a portlet request.
*
* <p>This portlet is very flexible: It can be used with just about any workflow,
* with the installation of the appropriate adapter classes. It offers the
* following functionality that distinguishes it from other request-driven
* portlet MVC frameworks:
*
* <ul>
* <li>It is based around a JavaBeans configuration mechanism.
*
* <li>It can use any {@link HandlerMapping} implementation - pre-built or provided
* as part of an application - to control the routing of requests to handler objects.
* Default is a {@link org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping}.
* HandlerMapping objects can be defined as beans in the portlet's application context,
* implementing the HandlerMapping interface, overriding the default HandlerMapping if present.
* HandlerMappings can be given any bean name (they are tested by type).
*
* <li>It can use any {@link HandlerAdapter}; this allows for using any handler interface.
* The default adapter is {@link org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter}
* for Spring's {@link org.springframework.web.portlet.mvc.Controller} interface.
* A default {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter}
* will be registered as well. HandlerAdapter objects can be added as beans in the
* application context, overriding the default HandlerAdapter. Like HandlerMappings,
* HandlerAdapters can be given any bean name (they are tested by type).
*
* <li>The dispatcher's exception resolution strategy can be specified via a
* {@link HandlerExceptionResolver}, for example mapping certain exceptions to
* error pages. Default is none. Additional HandlerExceptionResolvers can be added
* through the application context. HandlerExceptionResolver can be given any
* bean name (they are tested by type).
*
* <li>Its view resolution strategy can be specified via a {@link ViewResolver}
* implementation, resolving symbolic view names into View objects. Default is
* {@link org.springframework.web.servlet.view.InternalResourceViewResolver}.
* ViewResolver objects can be added as beans in the application context,
* overriding the default ViewResolver. ViewResolvers can be given any bean name
* (they are tested by type).
*
* <li>The dispatcher's strategy for resolving multipart requests is determined by a
* {@link org.springframework.web.portlet.multipart.PortletMultipartResolver} implementation.
* An implementations for Jakarta Commons FileUpload is included:
* {@link org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver}.
* The MultipartResolver bean name is "portletMultipartResolver"; default is none.
* </ul>
*
* <p><b>NOTE: The {@code @RequestMapping} annotation will only be processed
* if a corresponding {@code HandlerMapping} (for type level annotations)
* and/or {@code HandlerAdapter} (for method level annotations)
* is present in the dispatcher.</b> This is the case by default.
* However, if you are defining custom {@code HandlerMappings} or
* {@code HandlerAdapters}, then you need to make sure that a
* corresponding custom {@code DefaultAnnotationHandlerMapping}
* and/or {@code AnnotationMethodHandlerAdapter} is defined as well
* - provided that you intend to use {@code @RequestMapping}.
*
* <p><b>A web application can define any number of DispatcherPortlets.</b>
* Each portlet will operate in its own namespace, loading its own application
* context with mappings, handlers, etc. Only the root application context
* as loaded by {@link org.springframework.web.context.ContextLoaderListener},
* if any, will be shared.
*
* <p>Thanks to Rainer Schmitz, Nick Lothian and Eric Dalquist for their suggestions!
*
* @author William G. Thompson, Jr.
* @author John A. Lewis
* @author Juergen Hoeller
* @since 2.0
* @see org.springframework.web.portlet.mvc.Controller
* @see org.springframework.web.servlet.ViewRendererServlet
* @see org.springframework.web.context.ContextLoaderListener
*/
public class DispatcherPortlet extends FrameworkPortlet {
/**
* Well-known name for the PortletMultipartResolver object in the bean factory for this namespace.
*/
public static final String MULTIPART_RESOLVER_BEAN_NAME = "portletMultipartResolver";
/**
* Well-known name for the HandlerMapping object in the bean factory for this namespace.
* Only used when "detectAllHandlerMappings" is turned off.
* @see #setDetectAllViewResolvers
*/
public static final String HANDLER_MAPPING_BEAN_NAME = "handlerMapping";
/**
* Well-known name for the HandlerAdapter object in the bean factory for this namespace.
* Only used when "detectAllHandlerAdapters" is turned off.
* @see #setDetectAllHandlerAdapters
*/
public static final String HANDLER_ADAPTER_BEAN_NAME = "handlerAdapter";
/**
* Well-known name for the HandlerExceptionResolver object in the bean factory for this
* namespace. Only used when "detectAllHandlerExceptionResolvers" is turned off.
* @see #setDetectAllViewResolvers
*/
public static final String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME = "handlerExceptionResolver";
/**
* Well-known name for the ViewResolver object in the bean factory for this namespace.
*/
public static final String VIEW_RESOLVER_BEAN_NAME = "viewResolver";
/**
* Default URL to ViewRend
评论1
最新资源