📄 tilesplugin.java
字号:
/*
* $Header: /sfroot/cvs/esimple/src/core/org/apache/struts/tiles/TilesPlugin.java,v 1.1.1.1 2004/09/08 06:38:37 lava Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/09/08 06:38:37 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.tiles;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.config.ControllerConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;
import org.apache.struts.util.RequestUtils;
/**
* Tiles Plugin used to initialize Tiles.
* This plugin is to be used with Struts 1.1 in association with
* {@link TilesRequestProcessor}.
* <br>
* This plugin creates one definition factory for each Struts-module. The definition factory
* configuration is read first from 'web.xml' (backward compatibility), then it is
* overloaded with values found in the plugin property values.
* <br>
* The plugin changes the Struts configuration by specifying a {@link TilesRequestProcessor} as
* request processor. If you want to use your own RequestProcessor,
* it should subclass TilesRequestProcessor.
* <br>
* This plugin can also be used to create one single factory for all modules.
* This behavior is enabled by specifying <code>moduleAware=false</code> in each
* plugin properties. In this case, the definition factory
* configuration file is read by the first Tiles plugin to be initialized. The order is
* determined by the order of modules declaration in web.xml. The first module
* is always the default one if it exists.
* The plugin should be declared in each struts-config.xml file in order to
* properly initialize the request processor.
* @author Cedric Dumoulin
* @since 1.1
*/
public class TilesPlugin implements PlugIn {
/** Commons Logging instance. */
protected static Log log = LogFactory.getLog(TilesPlugin.class);
/** Is the factory module aware ? */
protected boolean moduleAware = false;
/** Tiles util implementation classname. This property can be set
* by user in the plugin declaration
*/
protected String tilesUtilImplClassname = null;
/** Associated definition factory */
protected DefinitionsFactory definitionFactory;
/** The plugin config object provided by the ActionServlet initializing
* this plugin.
*/
protected PlugInConfig currentPlugInConfigObject;
/**
* Get the module aware flag.
* @return <code>true</code>: user wants a single factory instance,
* <code>false:</code> user wants multiple factory instances (one per module with Struts)
*/
public boolean isModuleAware() {
return moduleAware;
}
/**
* Set the module aware flag.
* This flag is only meaningful if the property <code>tilesUtilImplClassname</code> is not
* set.
* @param moduleAware <code>true</code>: user wants a single factory instance,
* <code>false:</code> user wants multiple factory instances (one per module with Struts)
*/
public void setModuleAware(boolean moduleAware) {
this.moduleAware = moduleAware;
}
/**
* <p>Receive notification that the specified module is being
* started up.</p>
*
* @param servlet ActionServlet that is managing all the modules
* in this web application.
* @param moduleConfig ModuleConfig for the module with which
* this plugin is associated.
*
* @exception ServletException if this <code>PlugIn</code> cannot
* be successfully initialized.
*/
public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException
{
// Create factory config object
DefinitionsFactoryConfig factoryConfig = readFactoryConfig(servlet, moduleConfig);
// Set the module name in the config. This name will be used to compute
// the name under which the factory is stored.
factoryConfig.setFactoryName(moduleConfig.getPrefix());
// Set RequestProcessor class
initRequestProcessorClass(moduleConfig);
// Set Tiles util implementation according to properties 'tilesUtilImplClassname'
// and 'moduleAware'.
// These properties are taken into account only once. A
// side effect is that only the values set in the first initialized plugin
// are effectively taken into account.
if( !TilesUtil.isTilesUtilImplSet())
{ // TilesUtilImpl not set , do it
// Check if user has specified a TilesUtil implementation classname or not.
// If no implementation is specified, check if user has specified one
// shared single factory for all module, or one factory for each module.
if( getTilesUtilImplClassname() == null )
{ // No implementation specified, check if moduleAware is set
if (isModuleAware())
{ // Use appropriate TilesUtil implementation
TilesUtil.setTilesUtil(new TilesUtilStrutsModulesImpl());
}
else
{ // Use appropriate TilesUtil implementation
TilesUtil.setTilesUtil(new TilesUtilStrutsImpl());
}
}
else
{ // A classname is specified for the tilesUtilImp, use it.
try
{
TilesUtilStrutsImpl impl =
(TilesUtilStrutsImpl) RequestUtils
.applicationClass(getTilesUtilImplClassname())
.newInstance();
TilesUtil.setTilesUtil(impl);
}
catch( ClassCastException ex )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -