Author: rich
Date: Fri Dec  3 20:55:36 2004
New Revision: 109767

URL: http://svn.apache.org/viewcvs?view=rev&rev=109767
Log:
- Moved the configuration of "module config locators" (classes that locate 
generated Struts module configuration files) from a context-param in web.xml 
("moduleConfigLocators") to a <module-config-locators> element in 
netui-config.xml.
- Changed AutoRegisterActionServlet to look for module configuration files on 
the classpath in addition to the ServletContext.  This allows the files to live 
in jars in WEB-INF/lib.
- Sketched out a processing method in PageFlowRequestProcessor that will allow 
pages to be loaded by means other than server forwards.
- Changed PageFlowPageFilter to perform Page Flow initializations that should 
occur at deploy time.  In some cases, this class may be the first to receive 
initialization callbacks (before PageFlowActionServlet, when 
PageFlowContextListener is not registered).

DRT: netui (WinXP)
BB: self (linux)


Modified:
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
   incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
   
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
   incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml
   
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java&r1=109766&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java&r2=109767
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
 Fri Dec  3 20:55:36 2004
@@ -62,10 +62,15 @@
 
 import org.apache.beehive.netui.util.Bundle;
 import org.apache.beehive.netui.util.ServletUtils;
+import org.apache.beehive.netui.util.DiscoveryUtils;
+import org.apache.beehive.netui.util.config.ConfigUtil;
+import org.apache.beehive.netui.util.config.bean.PageflowConfig;
+import org.apache.beehive.netui.util.config.bean.ModuleConfigLocators;
 import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.beehive.netui.pageflow.internal.ContextCache;
 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
 import org.apache.beehive.netui.pageflow.internal.RequestValues;
+import org.apache.beehive.netui.pageflow.internal.InternalConstants;
 import org.apache.beehive.netui.pageflow.handler.ForwardRedirectHandler;
 
 
@@ -85,71 +90,92 @@
     private transient Digester _cachedConfigDigester = null;
     private Map _configParams = null;
     private ModuleConfigLocator[] _moduleConfigLocators = null;
+    private ContextCache _contextCache;
     
     private static final Logger _log = Logger.getInstance( 
AutoRegisterActionServlet.class );
 
     private static final ModuleConfig NONEXISTANT_MODULE_CONFIG = new 
NonexistantModuleConfig();
     
     
-    public void init( ServletConfig config )
+    public void init( ServletConfig servletConfig )
         throws ServletException
     {
-        _moduleConfigLocators = getDefaultModuleConfigLocators();
+        _contextCache = ContextCache.get( servletConfig.getServletContext() );
+        setupModuleConfigLocators( servletConfig );
+        super.init( servletConfig );
+    }
+    
+    private void setupModuleConfigLocators( ServletConfig servletConfig )
+    {
+        ModuleConfigLocator[] defaultLocators = 
getDefaultModuleConfigLocators();
+        ArrayList< ModuleConfigLocator > locators = new ArrayList< 
ModuleConfigLocator >();
+        
+        for ( int i =0; i < defaultLocators.length; ++i )
+        {
+            locators.add( defaultLocators[i] );
+        }
         
         //
-        // Look for ModuleConfigLocators specified in web.xml.
-        // TODO: move this to netui-config.xml
+        // Look for ModuleConfigLocators in netui-config.xml.
         //
-        String configLocatorList = config.getInitParameter( 
MODULE_CONFIG_LOCATOR_CLASS_ATTR );
+        PageflowConfig pfConfig = ConfigUtil.getConfig().getPageflowConfig();
         
-        if ( configLocatorList != null )
+        if ( pfConfig != null )
         {
-            ArrayList locators = new ArrayList();
-            ModuleConfigLocator[] currentLocators = 
getDefaultModuleConfigLocators();
+            ModuleConfigLocators mcLocators = 
pfConfig.getModuleConfigLocators();
             
-            for ( int i =0; i < currentLocators.length; ++i )
+            if ( mcLocators != null )
+            {
+                ModuleConfigLocators.ModuleConfigLocator[] array = 
mcLocators.getModuleConfigLocatorArray();
+                
+                for ( int i = 0; i < array.length; i++ )
+                {
+                    addModuleConfigLocator( array[i].getLocatorClass().trim(), 
locators );
+                }
+            }
+        }
+        
+        //
+        // Look for ModuleConfigLocators specified in web.xml (deprecated 
method for specifying them).
+        //
+        String configLocatorList = servletConfig.getInitParameter( 
MODULE_CONFIG_LOCATOR_CLASS_ATTR );
+        
+        if ( configLocatorList != null )
+        {
+            if ( _log.isWarnEnabled() )
             {
-                locators.add( currentLocators[i] );
+                _log.warn( "Found module-config-locators list in 
context-parameter " + MODULE_CONFIG_LOCATOR_CLASS_ATTR
+                           + ", which is deprecated.  Please use the 
<module-config-locators> element in "
+                           + InternalConstants.NETUI_CONFIG_PATH + " instead." 
);
             }
             
             String[] configLocatorClassNames = configLocatorList.split( "," );
             
             for ( int i = 0; i < configLocatorClassNames.length; ++i )
             {
-                String configLocatorClassName = 
configLocatorClassNames[i].trim();
-                
-                try
-                {
-                    Object locator = Class.forName( configLocatorClassName 
).newInstance();
-                    
-                    if ( locator instanceof ModuleConfigLocator )
-                    {
-                        locators.add( locator );
-                    }
-                    else
-                    {
-                        if ( _log.isErrorEnabled() )
-                        {
-                            _log.error( "init-parameter \"" + 
MODULE_CONFIG_LOCATOR_CLASS_ATTR
-                                        + "\" specifies a class that does not 
implement "
-                                        + ModuleConfigLocator.class.getName() 
+ "." );
-                        }
-                    }
-                }
-                catch ( Exception e )
-                {
-                    if ( _log.isErrorEnabled() )
-                    {
-                        _log.error( "Could not create an instance of " + 
configLocatorClassName
-                                    + " specified in init-parameter \"" + 
MODULE_CONFIG_LOCATOR_CLASS_ATTR + "\".", e );
-                    }
-                }
+                addModuleConfigLocator( configLocatorClassNames[i].trim(), 
locators );
             }
-            
-            _moduleConfigLocators = ( ModuleConfigLocator[] ) 
locators.toArray( new ModuleConfigLocator[0] );
         }
         
-        super.init( config );
+        _moduleConfigLocators = locators.toArray( new ModuleConfigLocator[0] 
); 
+    }
+    
+    private static void addModuleConfigLocator( String locatorClassName, 
ArrayList< ModuleConfigLocator > locators )
+    {
+        try
+        {
+            Class locatorClass = DiscoveryUtils.loadServiceClass( 
locatorClassName, ModuleConfigLocator.class );
+            ModuleConfigLocator locator = ( ModuleConfigLocator ) 
locatorClass.newInstance();
+            locators.add( locator );
+        }
+        catch ( IllegalAccessException e )
+        {
+            _log.error( "Could not create an instance of specified 
module-config-locator " + locatorClassName, e );
+        }
+        catch ( InstantiationException e )
+        {
+            _log.error( "Could not create an instance of specified 
module-config-locator " + locatorClassName, e );
+        }
     }
     
     /**
@@ -211,10 +237,7 @@
                 
                 try
                 {
-                    if ( getServletContext().getResource( moduleConfigPath ) 
!= null )
-                    {
-                        return moduleConfigPath;
-                    }
+                    if ( getConfigResource( moduleConfigPath ) != null ) 
return moduleConfigPath;
                 }
                 catch ( MalformedURLException e )
                 {
@@ -345,67 +368,75 @@
      * This method is almost exactly the same as the base class 
initModuleConfig.  The only difference
      * is that it does not throw an UnavailableException if a module 
configuration file is missing or
      * invalid.
-     * 
+     *
      * @exclude
      */
     protected ModuleConfig initModuleConfig
-        (String prefix, String paths) throws ServletException {
+            ( String prefix, String paths ) throws ServletException
+    {
 
-        if (log.isDebugEnabled()) {
-            log.debug("Initializing module path '" + prefix +
-                "' configuration from '" + paths + "'");
+        if ( _log.isDebugEnabled() )
+        {
+            _log.debug( "Initializing module path '" + prefix + "' 
configuration from '" + paths + "'" );
         }
 
         // Parse the configuration for this module
         ModuleConfig config = null;
         InputStream input = null;
         String mapping = null;
-        try {
+        try
+        {
             ModuleConfigFactory factoryObject =
-                ModuleConfigFactory.createFactory();
-            config = factoryObject.createModuleConfig(prefix);
+                    ModuleConfigFactory.createFactory();
+            config = factoryObject.createModuleConfig( prefix );
 
             // Support for module-wide ActionMapping type override
-            mapping = getServletConfig().getInitParameter("mapping");
-            if (mapping != null) {
-                config.setActionMappingClass(mapping);
+            mapping = getServletConfig().getInitParameter( "mapping" );
+            if ( mapping != null )
+            {
+                config.setActionMappingClass( mapping );
             }
 
             // Configure the Digester instance we will use
             Digester digester = initConfigDigester();
 
             // Process each specified resource path
-            while (paths.length() > 0) {
-                digester.push(config);
+            while ( paths.length() > 0 )
+            {
+                digester.push( config );
                 String path = null;
-                int comma = paths.indexOf(',');
-                if (comma >= 0) {
-                    path = paths.substring(0, comma).trim();
-                    paths = paths.substring(comma + 1);
-                } else {
+                int comma = paths.indexOf( ',' );
+                if ( comma >= 0 )
+                {
+                    path = paths.substring( 0, comma ).trim();
+                    paths = paths.substring( comma + 1 );
+                }
+                else
+                {
                     path = paths.trim();
                     paths = "";
                 }
-                if (path.length() < 1) {
+                if ( path.length() < 1 )
+                {
                     break;
                 }
-                URL url = getServletContext().getResource(path);
+                
+                URL url = getConfigResource( path );
                 
                 //
                 // THIS IS THE MAIN DIFFERENCE: we're doing a null-check here.
                 //
                 if ( url != null )
                 {
-                    InputSource is = new InputSource(url.toExternalForm());
-                    input = getServletContext().getResourceAsStream(path);
-                    is.setByteStream(input);
+                    InputSource is = new InputSource( url.toExternalForm() );
+                    input = getConfigResourceAsStream( path );
+                    is.setByteStream( input );
                     
                     // also, we're not letting it fail here either.
                     try
                     {
-                        digester.parse(is);
-                        getServletContext().setAttribute
-                            (Globals.MODULE_KEY + prefix, config);
+                        digester.parse( is );
+                        getServletContext().setAttribute( Globals.MODULE_KEY + 
prefix, config );
                     }
                     catch ( Exception e )
                     {
@@ -441,16 +472,23 @@
                 }
             }
 
-        } catch (Throwable t) {
-            log.error(internal.getMessage("configParse", paths), t);
-            throw new UnavailableException
-                (internal.getMessage("configParse", paths));
-        } finally {
-            if (input != null) {
-                try {
+        }
+        catch ( Throwable t )
+        {
+            _log.error( internal.getMessage( "configParse", paths ), t );
+            throw new UnavailableException( internal.getMessage( 
"configParse", paths ) );
+        }
+        finally
+        {
+            if ( input != null )
+            {
+                try
+                {
                     input.close();
-                } catch (IOException e) {
-                    ;
+                }
+                catch ( IOException e )
+                {
+                    // ignore
                 }
             }
         }
@@ -458,25 +496,28 @@
         // Force creation and registration of DynaActionFormClass instances
         // for all dynamic form beans we wil be using
         FormBeanConfig fbs[] = config.findFormBeanConfigs();
-        for (int i = 0; i < fbs.length; i++) {
-            if (fbs[i].getDynamic()) {
-                DynaActionFormClass.createDynaActionFormClass(fbs[i]);
+        for ( int i = 0; i < fbs.length; i++ )
+        {
+            if ( fbs[i].getDynamic() )
+            {
+                DynaActionFormClass.createDynaActionFormClass( fbs[i] );
             }
         }
 
         // Special handling for the default module (for
         // backwards compatibility only, will be removed later)
-        if (prefix.length() < 1) {
-            defaultControllerConfig(config);
-            defaultMessageResourcesConfig(config);
-            defaultFormBeansConfig(config);
-            defaultForwardsConfig(config);
-            defaultMappingsConfig(config);
+        if ( prefix.length() < 1 )
+        {
+            defaultControllerConfig( config );
+            defaultMessageResourcesConfig( config );
+            defaultFormBeansConfig( config );
+            defaultForwardsConfig( config );
+            defaultMappingsConfig( config );
         }
 
         // Return the completed configuration object
         //config.freeze();  // Now done after plugins init
-        return (config);
+        return ( config );
 
     }
 
@@ -488,6 +529,39 @@
         }
     }
 
+    
+    /**
+     * Get a resource URL for a module configuration file.  By default, this 
looks in the ServletContext
+     * and in the context classloader.
+     * 
+     * @param path the path to the resource.
+     * @return an URL for the resource, or <code>null</code> if the resource 
is not found.
+     * @throws MalformedURLException
+     */ 
+    protected URL getConfigResource( String path )
+        throws MalformedURLException
+    {
+        URL resource = getServletContext().getResource( path );
+        if ( resource != null ) return resource;
+        if ( path.startsWith( "/" ) ) path = path.substring( 1 );
+        return Thread.currentThread().getContextClassLoader().getResource( 
path );
+    }
+
+    /**
+     * Get a resource stream for a module configuration file.  By default, 
this looks in the ServletContext
+     * and in the context classloader.
+     * 
+     * @param path the path to the resource.
+     * @return an InputStream for the resource, or <code>null</code> if the 
resource is not found.
+     */ 
+    protected InputStream getConfigResourceAsStream( String path )
+    {
+        InputStream stream = getServletContext().getResourceAsStream( path );
+        if ( stream != null ) return stream;
+        if ( path.startsWith( "/" ) ) path = path.substring( 1 );
+        return 
Thread.currentThread().getContextClassLoader().getResourceAsStream( path );
+    }
+    
     /**
      * Register a Struts module, initialized by the given configuration file.
      * 
@@ -543,7 +617,7 @@
         // First, reinitialize the page flow classloader, for reloading when 
recompile occurs in dev mode.
         //
         ServletContext servletContext = getServletContext();
-        ContextCache.get( servletContext ).getReloadableClassHandler().reinit( 
request );
+        _contextCache.getReloadableClassHandler().reinit( request );
         
         String modulePath = PageFlowUtils.getModulePathForRelativeURI( 
InternalUtils.getDecodedServletPath( request ) );
         ModuleConfig registeredApp;
@@ -605,7 +679,7 @@
                     sfActionURI.append( '/' );
                     sfActionURI.append( ServletUtils.getBaseName( relativeURI 
) );
                     RequestValues.setOriginalServletPath( request, relativeURI 
);
-                    ForwardRedirectHandler frh = ContextCache.get( 
servletContext ).getForwardRedirectHandler();
+                    ForwardRedirectHandler frh = 
_contextCache.getForwardRedirectHandler();
                     frh.forward( sfActionURI.toString(), request, response );
                     return;
                 }

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java&r1=109766&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java&r2=109767
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java
     (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowActionServlet.java
     Fri Dec  3 20:55:36 2004
@@ -101,8 +101,6 @@
     public void init( ServletConfig config )
             throws ServletException
     {
-        super.init( config );
-        
         //
         // Ensure that PageFlowContextListener gets to do its initializations, 
even if it's not registered in web.xml.
         //
@@ -111,6 +109,8 @@
         {
             PageFlowContextListener.performInitializations( servletContext );
         }
+        
+        super.init( config );
     }
 
     /**

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java&r1=109766&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java&r2=109767
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
        (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
        Fri Dec  3 20:55:36 2004
@@ -48,7 +48,7 @@
 
 
 /**
- * Base class for Servlet Filters that run before page requests.
+ * Base class for Servlet Filters that run before Page Flow page requests.
  */ 
 public abstract class PageFlowPageFilter implements Filter
 {
@@ -63,10 +63,22 @@
     protected PageFlowPageFilter()
     {
     }
+    
+    PageFlowPageFilter( ServletContext servletContext )
+    {
+        _servletContext = servletContext;
+        _serverAdapter = ServerAdapterManager.getServerAdapter( 
_servletContext );
+    }
 
     public void init( FilterConfig filterConfig ) throws ServletException
     {
         _servletContext = filterConfig.getServletContext();
+        
+        if ( ! PageFlowContextListener.isInit( _servletContext ) )
+        {
+            PageFlowContextListener.performInitializations( _servletContext );
+        }
+        
         _serverAdapter = ServerAdapterManager.getServerAdapter( 
_servletContext );
     }
     
@@ -97,8 +109,9 @@
             
             String requestURI = httpRequest.getRequestURI();
             String extension = FileUtils.getFileExtension( requestURI );
+            Set validFileExtensions = getValidFileExtensions();
             
-            if ( ! getValidFileExtensions().contains( extension ) )
+            if ( validFileExtensions != null && ! 
validFileExtensions.contains( extension ) )
             {
                 if ( _log.isDebugEnabled() )
                 {

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java&r1=109766&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java&r2=109767
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
  (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProcessor.java
  Fri Dec  3 20:55:36 2004
@@ -40,14 +40,25 @@
 import javax.servlet.http.HttpSession;
 import javax.servlet.ServletException;
 import javax.servlet.ServletContext;
+import javax.servlet.FilterChain;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.Filter;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 import java.io.IOException;
 import java.io.Serializable;
+import java.io.InputStream;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Properties;
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.lang.reflect.Field;
@@ -55,6 +66,7 @@
 import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.beehive.netui.util.ServletUtils;
 import org.apache.beehive.netui.util.FileUtils;
+import org.apache.beehive.netui.util.DiscoveryUtils;
 import org.apache.beehive.netui.core.urls.URLRewriterService;
 import org.apache.beehive.netui.pageflow.config.PageFlowActionForward;
 import org.apache.beehive.netui.pageflow.config.PageFlowActionMapping;
@@ -107,6 +119,8 @@
     private Map< String, Class > _formBeanClasses = new HashMap< String, Class 
>();
     private Map< String, List< ActionMapping > > _overloadedActions = new 
HashMap< String, List< ActionMapping > >();
     private ServerAdapter _serverAdapter;
+    private ConcurrentHashMap< String, Class > _pageServletClasses = new 
ConcurrentHashMap< String, Class >();
+    private PageFlowPageFilter _pageServletFilter;
     
 
     protected Action processActionCreate( HttpServletRequest request, 
HttpServletResponse response,
@@ -981,6 +995,22 @@
         // Cache a reference to the ServerAdapter.
         //
         _serverAdapter = ServerAdapterManager.getServerAdapter( 
getServletContext() );
+        
+        
+        _pageServletFilter = new PageServletFilter();
+    }
+    
+    private class PageServletFilter extends PageFlowPageFilter
+    {
+        public PageServletFilter()
+        {
+            super( getServletContext() );
+        }
+
+        protected Set getValidFileExtensions()
+        {
+            return null;    // accept all
+        }
     }
     
     private void cacheOverloadedActionMappings()
@@ -1518,8 +1548,161 @@
         
         if ( ! securityRedirected )
         {
-            ForwardRedirectHandler fwdRedirectHandler = 
contextCache.getForwardRedirectHandler();
-            fwdRedirectHandler.forward( uri, request, response );
+            if ( ! processPageForward( uri, request, response ) )
+            {
+                ForwardRedirectHandler fwdRedirectHandler = 
contextCache.getForwardRedirectHandler();
+                fwdRedirectHandler.forward( uri, request, response );
+            }
+        }
+    }
+    
+    /**
+     * An opportunity to process a page forward in a different way than 
performing a server forward.  The default
+     * implementation looks for a file on classpath called
+     * META-INF/pageflow-page-servlets/<i>path-to-page</i>.properties (e.g., 
+     * "/META-INF/pageflow-page-servlets/foo/bar/hello.jsp.properties").  This 
file contains mappings from
+     * <i>platform-name</i> (the value returned by [EMAIL PROTECTED] 
ServerAdapter#getPlatformName}) to the name of a Servlet
+     * class that will process the page request.  If the current platform name 
is not found, the value "default" is
+     * tried.  An example file might look like this:
+     * <pre>
+     *     tomcat=org.apache.jsp.foo.bar.hello_jsp
+     *     default=my.servlets.foo.bar.hello
+     * </pre>
+     * @param pagePath the webapp-relative path to the page, e.g., 
"/foo/bar/hello.jsp"
+     * @param request the current HttpServletRequest
+     * @param response the current HttpServletResponse
+     * @return <code>true</code> if the method handled the request, in which 
case it should not be forwarded.
+     * @throws IOException
+     * @throws ServletException
+     */ 
+    private boolean processPageForward( String pagePath, HttpServletRequest 
request, HttpServletResponse response )
+        throws IOException, ServletException
+    {
+        Class pageServletClass = _pageServletClasses.get( pagePath );
+        
+        if ( pageServletClass == null )
+        {
+            pageServletClass = Void.class;
+            ClassLoader cl = DiscoveryUtils.getClassLoader();
+            String path = "META-INF/pageflow-page-servlets" + pagePath + 
".properties";
+            InputStream in = cl.getResourceAsStream( path );
+            
+            if ( in != null )
+            {
+                String className = null;
+                
+                try
+                {
+                    Properties props = new Properties();
+                    props.load( in );
+                    className = props.getProperty( 
_serverAdapter.getPlatformName() );
+                    if ( className == null ) className = props.getProperty( 
"default" );
+                    
+                    if ( className != null )
+                    {
+                        pageServletClass = cl.loadClass( className );
+                        
+                        if ( Servlet.class.isAssignableFrom( pageServletClass 
) )
+                        {
+                            if ( _log.isInfoEnabled() )
+                            {
+                                _log.info( "Loaded page Servlet class " + 
className + " for path " + pagePath );
+                            }
+                        }
+                        else
+                        {
+                            pageServletClass = Void.class;
+                            _log.error( "Page Servlet class " + className + " 
for path " + pagePath
+                                        + " does not extend " + 
Servlet.class.getName() );
+                        }
+                    }
+                }
+                catch ( IOException e )
+                {
+                    _log.error( "Error while reading " + path, e );
+                }
+                catch ( ClassNotFoundException e )
+                {
+                    _log.error( "Error while loading page Servlet class " + 
className, e );
+                }
+            }
+            
+            _pageServletClasses.put( pagePath, pageServletClass );
+        }
+        
+        if ( pageServletClass.equals( Void.class ) )
+        {
+            return false;
+        }
+        
+        try
+        {
+            Servlet pageServlet = ( Servlet ) pageServletClass.newInstance();
+            pageServlet.init( new PageServletConfig( pagePath ) );
+            _pageServletFilter.doFilter( request, response, new 
PageServletFilterChain( pageServlet ) );
+            return true;
+        }
+        catch ( InstantiationException e )
+        {
+            _log.error( "Error while instantiating page Servlet of type " + 
pageServletClass.getName(), e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            _log.error( "Error while instantiating page Servlet of type " + 
pageServletClass.getName(), e );
+        }
+        
+        return false;
+    }
+    
+    /**
+     * Used by [EMAIL PROTECTED] PageFlowRequestProcessor#processPageForward} 
to run a page Servlet.
+     */ 
+    private static class PageServletFilterChain implements FilterChain
+    {
+        private Servlet _pageServlet;
+        
+        public PageServletFilterChain( Servlet pageServlet )
+        {
+            _pageServlet= pageServlet;
+        }
+        
+        public void doFilter( ServletRequest request, ServletResponse response 
)
+                throws IOException, ServletException
+        {
+            _pageServlet.service( request, response );
+        }
+    }
+    
+    /**
+     * Used by [EMAIL PROTECTED] PageFlowRequestProcessor#processPageForward} 
to initialize a page Servlet.
+     */ 
+    private class PageServletConfig implements ServletConfig
+    {
+        private String _pagePath;
+        
+        public PageServletConfig( String pagePath )
+        {
+            _pagePath = pagePath;
+        }
+        
+        public String getServletName()
+        {
+            return _pagePath;
+        }
+
+        public ServletContext getServletContext()
+        {
+            return PageFlowRequestProcessor.this.getServletContext();
+        }
+
+        public String getInitParameter( String s )
+        {
+            return null;
+        }
+
+        public Enumeration getInitParameterNames()
+        {
+            return Collections.enumeration( Collections.EMPTY_LIST );
         }
     }
     

Modified: incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd&r1=109766&p2=incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd&r2=109767
==============================================================================
--- incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd      
(original)
+++ incubator/beehive/trunk/netui/src/util/schema/netui-config.xsd      Fri Dec 
 3 20:55:36 2004
@@ -60,6 +60,19 @@
             <xsd:element name="exceptions-handler-class" type="xsd:string" 
minOccurs="0" maxOccurs="1"/>
         </xsd:sequence>
     </xsd:complexType>
+    
+    <xsd:complexType name="module-config-locators">
+        <xsd:sequence>
+            <xsd:element name="module-config-locator" minOccurs="0" 
maxOccurs="unbounded">
+                <xsd:complexType>
+                    <xsd:sequence>
+                        <xsd:element name="description" type="xsd:string" 
minOccurs="0" maxOccurs="1"/>
+                        <xsd:element name="locator-class" type="xsd:string" 
minOccurs="1" maxOccurs="1"/>
+                    </xsd:sequence>
+                </xsd:complexType>
+            </xsd:element>
+        </xsd:sequence>
+    </xsd:complexType>
        
     <xsd:complexType name="pageflow-config">
         <xsd:sequence>
@@ -76,6 +89,7 @@
                     </xsd:restriction>
                 </xsd:simpleType>
             </xsd:element>
+            <xsd:element name="module-config-locators" 
type="netui:module-config-locators" minOccurs="0" maxOccurs="1"/>
         </xsd:sequence>
     </xsd:complexType>
     

Modified: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml&r1=109766&p2=incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml&r2=109767
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
       (original)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml
       Fri Dec  3 20:55:36 2004
@@ -39,6 +39,12 @@
 
     <pageflow-config>
         <multipart-handler>memory</multipart-handler>
+        <module-config-locators>
+            <module-config-locator>
+                <description>For /miniTests/moduleConfigLocator.</description>
+                <locator-class>moduleConfigLocator.Locator1</locator-class>
+            </module-config-locator>
+        </module-config-locators>
     </pageflow-config>
 
     <jsp-tag-config>

Modified: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml&r1=109766&p2=incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml&r2=109767
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml      
(original)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/web.xml      
Fri Dec  3 20:55:36 2004
@@ -120,9 +120,10 @@
       <param-value>/WEB-INF/struts-config.xml</param-value>
     </init-param>
 
+    <!-- This is for miniTests/moduleConfigLocator.  The other one is in 
netui-config.xml. -->
     <init-param>
       <param-name>moduleConfigLocators</param-name>
-      
<param-value>moduleConfigLocator.Locator1,moduleConfigLocator.Locator2</param-value>
+      <param-value>moduleConfigLocator.Locator2</param-value>
     </init-param>
 
          <!--

Modified: 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml?view=diff&rev=109767&p1=incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml&r1=109766&p2=incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml&r2=109767
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
   (original)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
   Fri Dec  3 20:55:36 2004
@@ -3149,7 +3149,6 @@
          <webapp>coreWeb</webapp>
          <categories>
             <category>bvt</category>
-            <category>drt</category>
             <category>corePageFlow</category>
          </categories>
          <features>

Reply via email to