You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by dd...@apache.org on 2006/11/01 21:15:11 UTC

svn commit: r470071 [1/2] - in /struts/sandbox/trunk/tiles: tiles-api/src/main/java/org/apache/tiles/ tiles-core/src/main/java/org/apache/tiles/ tiles-core/src/main/java/org/apache/tiles/definition/ tiles-core/src/main/java/org/apache/tiles/filter/ til...

Author: ddewolf
Date: Wed Nov  1 12:15:09 2006
New Revision: 470071

URL: http://svn.apache.org/viewvc?view=rev&rev=470071
Log:
Removing the publishing of ComponentDefinitions.  Hiding the refresh logic within the Definitions Factory.  Step 1 of the refactoring of DefinitionsFactory that will occur. More discussion to come. . .

Added:
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/UrlDefinitionsFactoryTest.java   (with props)
Modified:
    struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsUtil.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtil.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesContainerListener.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesListener.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/servlet/TilesServlet.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/BaseInsertTag.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestReloadableDefinitionsFactory.java
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestTilesServlet.java
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockDefinitionsReader.java
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java

Modified: struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java (original)
+++ struts/sandbox/trunk/tiles/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java Wed Nov  1 12:15:09 2006
@@ -17,6 +17,8 @@
  */
 package org.apache.tiles;
 
+import javax.servlet.jsp.PageContext;
+
 /**
  * An encapsulation of the tiles framework.  This interface is
  * used to expose tiles features to frameworks which leverage
@@ -33,20 +35,45 @@
      * configuration.
      * 
      * @param context
+     * @throws TilesException
      */
-    void init(TilesApplicationContext context)
-            throws org.apache.tiles.TilesException;
+    void init(TilesApplicationContext context) throws TilesException;
 
     /**
      * Retrieve the containers context.
+     * @return
      */
     TilesApplicationContext getApplicationContext();
 
     /**
+     * 
+     * @param request
+     * @param response
+     * @param definition
+     */
+    void prepare(Object request, Object response, String definition) throws TilesException;
+
+    /**
+     * 
+     * @param pageContext
+     * @param definition
+     * @throws TilesException
+     */
+    void prepare(PageContext pageContext, String definition) throws TilesException;
+
+
+    /**
      * Render the given tiles request
      *
      * @param request
      */
-    void render(TilesRequestContext request, String definition) throws TilesException;
+    void render(Object request, Object response, String definition) throws TilesException;
 
+    /**
+     *
+     * @param pageContext
+     * @param definition
+     * @throws TilesException
+     */
+    void render(PageContext pageContext, String definition) throws TilesException;
 }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java Wed Nov  1 12:15:09 2006
@@ -20,8 +20,6 @@
 
 import java.io.Serializable;
 import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -577,120 +575,6 @@
     return isVisited;
     }
 
-    /**
-     * Resolve inheritance.
-     * First, resolve parent's inheritance, then set path to the parent's path.
-     * Also copy attributes setted in parent, and not set in child
-     * If instance doesn't extend anything, do nothing.
-     * @throws NoSuchDefinitionException If an inheritance can not be solved.
-     * @deprecated Each {@link ComponentDefinitions} should provide its own
-     * strategy to resolve inheritances.
-     */
-  public void resolveInheritance( ComponentDefinitions definitionsSet )
-    throws NoSuchDefinitionException
-    {
-      // Already done, or not needed ?
-    if( isVisited || !isExtending() )
-      return;
-
-    if(log.isDebugEnabled())
-      log.debug( "Resolve definition for child name='" + getName()
-              + "' extends='" + getExtends() + "'.");
-
-      // Set as visited to avoid endless recurisvity.
-    setIsVisited( true );
-
-      // Resolve parent before itself.
-    ComponentDefinition parent = definitionsSet.getDefinition( getExtends() );
-    if( parent == null )
-      { // error
-      String msg = "Error while resolving definition inheritance: child '"
-                           + getName() +    "' can't find its ancestor '"
-                           + getExtends() + "'. Please check your description file.";
-      log.error( msg );
-        // to do : find better exception
-      throw new NoSuchDefinitionException( msg );
-      }
-
-    parent.resolveInheritance( definitionsSet );
-
-      // Iterate on each parent's attribute and add it if not defined in child.
-    Iterator parentAttributes = parent.getAttributes().keySet().iterator();
-    while( parentAttributes.hasNext() )
-      {
-      String name = (String)parentAttributes.next();
-      if( !getAttributes().containsKey(name) )
-        put( name, parent.getAttribute(name) );
-      }
-      // Set path and role if not setted
-    if( path == null )
-      setPath( parent.getPath() );
-    if( role == null )
-      setRole( parent.getRole() );
-    if( preparer==null )
-      {
-      setPreparer( parent.getPreparer());
-      setPreparerType( parent.getPreparerType());
-      }
-    }
-
-    /**
-     * Resolve locale-specific inheritance.
-     * First, resolve parent's inheritance, then set path to the parent's path.
-     * Also copy attributes setted in parent, and not set in child
-     * If instance doesn't extend anything, do nothing.
-     * @throws NoSuchDefinitionException If an inheritance can not be solved.
-     * @deprecated Each {@link ComponentDefinitions} should provide its own
-     * strategy to resolve inheritances.
-     */
-  public void resolveInheritance( ComponentDefinitions definitionsSet, Locale locale)
-    throws NoSuchDefinitionException
-    {
-      // Already done, or not needed ?
-    if( isVisited || !isExtending() )
-      return;
-
-    if(log.isDebugEnabled())
-      log.debug( "Resolve definition for child name='" + getName()
-              + "' extends='" + getExtends() + "'.");
-
-      // Set as visited to avoid endless recurisvity.
-    setIsVisited( true );
-
-      // Resolve parent before itself.
-    ComponentDefinition parent = definitionsSet.getDefinition( getExtends(), 
-            locale );
-    if( parent == null )
-      { // error
-      String msg = "Error while resolving definition inheritance: child '"
-                           + getName() +    "' can't find its ancestor '"
-                           + getExtends() + "'. Please check your description file.";
-      log.error( msg );
-        // to do : find better exception
-      throw new NoSuchDefinitionException( msg );
-      }
-
-    parent.resolveInheritance( definitionsSet, locale );
-
-      // Iterate on each parent's attribute and add it if not defined in child.
-    Iterator parentAttributes = parent.getAttributes().keySet().iterator();
-    while( parentAttributes.hasNext() )
-      {
-      String name = (String)parentAttributes.next();
-      if( !getAttributes().containsKey(name) )
-        put( name, parent.getAttribute(name) );
-      }
-      // Set path and role if not setted
-    if( path == null )
-      setPath( parent.getPath() );
-    if( role == null )
-      setRole( parent.getRole() );
-    if( preparer==null )
-      {
-      setPreparer( parent.getPreparer());
-      setPreparerType( parent.getPreparerType());
-      }
-    }
 
   /**
    * Overload this definition with passed child.

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java Wed Nov  1 12:15:09 2006
@@ -18,7 +18,6 @@
 
 package org.apache.tiles;
 
-import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -55,7 +54,7 @@
      * @param params The Map of configuration properties.
      * @throws DefinitionsFactoryException if an initialization error occurs.
      */
-    public void init(Map params) throws DefinitionsFactoryException;
+    public void init(Map<String, String> params) throws DefinitionsFactoryException;
     
     /**
      * Returns a ComponentDefinition object that matches the given name and

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsUtil.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsUtil.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsUtil.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsUtil.java Wed Nov  1 12:15:09 2006
@@ -24,23 +24,16 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.taglib.ComponentConstants;
 
 /**
  * Utilities class for definitions impl.
  * Also define userDebugLevel property (TODO to be moved from this class ?).
- * @deprecated Use {@link TilesUtil#createDefinitionsFactory(TilesApplicationContext, DefinitionsFactoryConfig)}
+ * @deprecated Use {@link TilesUtil#createDefinitionsFactory(DefinitionsFactoryConfig)}
  */
 public class DefinitionsUtil extends TilesUtil implements ComponentConstants {
 
     /** 
-     * Commons Logging instance. 
-     */
-    protected static Log log = LogFactory.getLog(DefinitionsUtil.class);
-
-    /** 
      * Global user defined debug level.
      * @deprecated This will be removed in a release after Struts 1.2. 
      */
@@ -149,50 +142,7 @@
         return createDefinitionsFactory(factoryConfig);
     }
 
-    /**
-     * Create Definition impl.
-     * Create configuration object from servlet web.xml file, then create
-     * ConfigurableDefinitionsFactory and initialized it with object.
-     * <p>
-     * If checkIfExist is true, start by checking if impl already exist. If yes,
-     * return it. If no, create a new one.
-     * <p>
-     * If checkIfExist is false, impl is always created.
-     * <p>
-     * Convenience method. Calls createDefinitionsFactory(ServletContext servletContext, DefinitionsFactoryConfig factoryConfig)
-     *
-     * @param tilesContext The current Tiles application context.
-     * @param checkIfExist Check if impl already exist. If true and impl exist, return it.
-     * If true and impl doesn't exist, create it. If false, create it in all cases.
-     * @return newly created impl of type ConfigurableDefinitionsFactory.
-     * @throws DefinitionsFactoryException If an error occur while initializing impl
-     */
-    public static DefinitionsFactory createDefinitionsFactory(
-        TilesApplicationContext tilesContext,
-        boolean checkIfExist)
-        throws DefinitionsFactoryException {
-
-        if (checkIfExist) {
-            // Check if already exist in context
-            DefinitionsFactory factory = getDefinitionsFactory(tilesContext);
-            if (factory != null)
-                return factory;
-        }
 
-        return createDefinitionsFactory(tilesContext);
-    }
-
-    /**
-     * Get definition impl from appropriate servlet context.
-     *
-     * @param tilesContext the current Tiles application context.
-     * @return Definitions impl or null if not found.
-     * @deprecated Use {@link TilesUtil#getDefinitionsFactory(TilesApplicationContext)
-     * @since 20020708
-     */
-    public static DefinitionsFactory getDefinitionsFactory(TilesApplicationContext tilesContext) {
-        return (DefinitionsFactory) tilesContext.getApplicationScope().get(DEFINITIONS_FACTORY);
-    }
 
     /**
      * Get Definition stored in jsp context by an action.

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtil.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtil.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtil.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtil.java Wed Nov  1 12:15:09 2006
@@ -22,8 +22,6 @@
 
 import javax.servlet.jsp.PageContext;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Class containing utility methods for Tiles.
@@ -37,9 +35,6 @@
  * if the underlying implementation doesn't support the operation.
  */
 public class TilesUtil {
-
-    /** Commons Logging instance.*/
-    protected static Log log = LogFactory.getLog(TilesUtil.class);
 
     /** The implementation of tilesUtilImpl */
     protected static TilesUtilImpl tilesUtilImpl;

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java Wed Nov  1 12:15:09 2006
@@ -199,11 +199,7 @@
             throw new DefinitionsFactoryException("Problem with filename URL: ", e);
         }
 
-        ComponentDefinitions definitions = factory.readDefinitions();
-
-        // Make impl accessible from jsp tags (push it in appropriate context)
         makeDefinitionsFactoryAccessible(factory);
-        makeDefinitionsAccessible(definitions);
 
         return factory;
     }
@@ -269,16 +265,7 @@
         applicationContext.getApplicationScope().put(DEFINITIONS_FACTORY, factory);
     }
 
-    /**
-     * Make definition impl accessible to Tags.
-     * Factory is stored in servlet context.
-     * @param definitions Definition impl to be made accessible
-     */
-    protected void makeDefinitionsAccessible(
-        ComponentDefinitions definitions) {
 
-        applicationContext.getApplicationScope().put(DEFINITIONS_OBJECT, definitions);
-    }
 
     /**
      * Parses a comma-delimited string for a list of config filenames.

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java Wed Nov  1 12:15:09 2006
@@ -15,173 +15,150 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.tiles.definition;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+
 import org.apache.tiles.util.RequestUtils;
 import org.apache.tiles.*;
 import org.apache.tiles.digester.DigesterDefinitionsReader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * {@link org.apache.tiles.DefinitionsFactory DefinitionsFactory} implementation
  * that manages ComponentDefinitions configuration data from URLs.
- *
- * <p>The ComponentDefinition objects are read from the 
+ * <p/>
+ * <p>The ComponentDefinition objects are read from the
  * {@link org.apache.tiles.digester.DigesterDefinitionsReader DigesterDefinitionsReader}
  * class unless another implementation is specified.</p>
  *
- * @version $Rev$ $Date$ 
+ * @version $Rev$ $Date$
  */
-public class UrlDefinitionsFactory 
+public class UrlDefinitionsFactory
         implements DefinitionsFactory, ReloadableDefinitionsFactory {
 
     /**
+     * LOG instance for all UrlDefinitionsFactory instances.
+     */
+    private static final Log LOG = LogFactory.getLog(UrlDefinitionsFactory.class);
+
+    /**
      * Contains the URL objects identifying where configuration data is found.
      */
-    protected List sources;
+    protected List<Object> sources;
+
     /**
      * Reader used to get definitions from the sources.
      */
     protected DefinitionsReader reader;
+
     /**
      * Contains the dates that the URL sources were last modified.
      */
-    protected Map lastModifiedDates;
+    protected Map<String, Long> lastModifiedDates;
+
     /**
      * Contains a list of locales that have been processed.
      */
-    private List processedLocales;
-    
+    private List<Locale> processedLocales;
+
+
+    private ComponentDefinitions definitions;
+
     /**
-     * ComponentDefinitions class name.
+     * Creates a new instance of UrlDefinitionsFactory
      */
-    private String definitionsClassName;
-    
-    /** Creates a new instance of UrlDefinitionsFactory */
     public UrlDefinitionsFactory() {
-        sources = new ArrayList();
-	lastModifiedDates = new HashMap();
-        processedLocales = new ArrayList();
+        sources = new ArrayList<Object>();
+        lastModifiedDates = new HashMap<String, Long>();
+        processedLocales = new ArrayList<Locale>();
     }
 
     /**
      * Initializes the DefinitionsFactory and its subcomponents.
-     * 
+     * <p/>
      * Implementations may support configuration properties to be passed in via
      * the params Map.
-     * 
+     *
      * @param params The Map of configuration properties.
      * @throws DefinitionsFactoryException if an initialization error occurs.
      */
-    public void init(Map params) throws DefinitionsFactoryException {
-        if (params != null) {
-            String readerClassName = (String) params.get(
-                    DefinitionsFactory.READER_IMPL_PROPERTY);
-            if (readerClassName != null) {
-                try {
-                    Class readerClass = 
-                        RequestUtils.applicationClass(readerClassName);
-                    reader = (DefinitionsReader) readerClass.newInstance();
-                } catch (ClassNotFoundException e) {
-                    throw new DefinitionsFactoryException(
-                            "Cannot find reader class.", e);
-                } catch (InstantiationException e) {
-                    throw new DefinitionsFactoryException(
-                            "Unable to instantiate reader class.", e);
-                } catch (IllegalAccessException e) {
-                    throw new DefinitionsFactoryException(
-                            "Unable to access reader class.", e);
-                }
-            }
+    public void init(Map<String, String> params) throws DefinitionsFactoryException {
+        String readerClassName =
+            params.get(DefinitionsFactory.READER_IMPL_PROPERTY);
 
-            definitionsClassName = (String) params.get(
-                    DefinitionsFactory.DEFINITIONS_IMPL_PROPERTY);
-            if (definitionsClassName != null) {
-                // Attempt to create it just to verify.
-                ComponentDefinitions definitions = createDefinitionsImpl(
-                        definitionsClassName);
-            }
-        }
-        
-        if (reader == null) {
+        if (readerClassName != null) {
+            createReader(readerClassName);
+        } else {
             reader = new DigesterDefinitionsReader();
         }
-        
         reader.init(params);
     }
 
+    private ComponentDefinitions getComponentDefinitions()
+    throws DefinitionsFactoryException {
+        if(definitions == null) {
+            definitions = readDefinitions();
+        }
+        return definitions;
+    }
+
+
     /**
      * Returns a ComponentDefinition object that matches the given name and
      * Tiles context
      *
-     * @param name The name of the ComponentDefinition to return.
+     * @param name         The name of the ComponentDefinition to return.
      * @param tilesContext The Tiles context to use to resolve the definition.
      * @return the ComponentDefinition matching the given name or null if none
-     *  is found.
+     *         is found.
      * @throws DefinitionsFactoryException if an error occurs reading definitions.
      */
     public ComponentDefinition getDefinition(String name,
-            TilesRequestContext tilesContext) throws DefinitionsFactoryException {
-        Map appScoped = TilesUtil.getTilesUtil().getApplicationContext().getApplicationScope();
-        ComponentDefinitions definitions = (ComponentDefinitions)
-                appScoped.get(TilesUtilImpl.DEFINITIONS_OBJECT);
-        ComponentDefinition definition = definitions.getDefinition(
-                name, tilesContext.getRequestLocale());
-        
-        if (definition == null) {
-            if (!isContextProcessed(tilesContext)) {
-                // FIXME This will modify the impl as well as the definitions
-                // but we are only locking the definitions.
-                // 
-                // We'll have to refactor again to remove this issue.
-                synchronized (definitions) {
-                    addDefinitions(definitions, tilesContext);
-                }
+                                             TilesRequestContext tilesContext)
+            throws DefinitionsFactoryException {
+
+        ComponentDefinitions definitions = getComponentDefinitions();
+        Locale locale = tilesContext.getRequestLocale();
+        if (!isLocaleProcessed(tilesContext)) {
+            synchronized (definitions) {
+                addDefinitions(definitions, tilesContext);
             }
-            
-            definition = definitions.getDefinition(name,
-                    tilesContext.getRequestLocale());
         }
-        
-        return definition;
+
+        return definitions.getDefinition(name, locale);
     }
 
     /**
      * Adds a source where ComponentDefinition objects are stored.
-     * 
+     * <p/>
      * Implementations should publish what type of source object they expect.
      * The source should contain enough information to resolve a configuration
      * source containing definitions.  The source should be a "base" source for
      * configurations.  Internationalization and Localization properties will be
      * applied by implementations to discriminate the correct data sources based
      * on locale.
-     * 
+     *
      * @param source The configuration source for definitions.
      * @throws DefinitionsFactoryException if an invalid source is passed in or
-     *      an error occurs resolving the source to an actual data store.
+     *                                     an error occurs resolving the source to an actual data store.
      */
     public void addSource(Object source) throws DefinitionsFactoryException {
         if (source == null) {
             throw new DefinitionsFactoryException(
                     "Source object must not be null");
         }
-        
+
         if (!(source instanceof URL)) {
             throw new DefinitionsFactoryException(
                     "Source object must be an URL");
         }
-        
+
         sources.add(source);
     }
 
@@ -189,35 +166,36 @@
      * Appends locale-specific {@link ComponentDefinition} objects to an existing
      * {@link ComponentDefinitions} set by reading locale-specific versions of
      * the applied sources.
-     * 
-     * @param definitions The ComponentDefinitions object to append to.
+     *
+     * @param definitions  The ComponentDefinitions object to append to.
      * @param tilesContext The requested locale.
      * @throws DefinitionsFactoryException if an error occurs reading definitions.
      */
-    protected void addDefinitions(ComponentDefinitions definitions, TilesRequestContext tilesContext)
+    protected void addDefinitions(ComponentDefinitions definitions,
+                                  TilesRequestContext tilesContext)
             throws DefinitionsFactoryException {
-        
+
         Locale locale = tilesContext.getRequestLocale();
-        List postfixes = calculatePostixes(locale);
-        
-        if (isContextProcessed(tilesContext)) {
+        List<String> postfixes = calculatePostixes(locale);
+
+        if (isLocaleProcessed(tilesContext)) {
             return;
         } else {
             processedLocales.add(locale);
         }
 
-        for (int i = 0; i < sources.size(); i++) {
-            URL url = (URL) sources.get(i);
+        for (Object source : sources) {
+            URL url = (URL) source;
             String path = url.toExternalForm();
 
-            for (int j = 0; j < postfixes.size(); j++) {
-                String newPath = concatPostfix(path, (String) postfixes.get(j));
+            for (Object postfixe : postfixes) {
+                String newPath = concatPostfix(path, (String) postfixe);
                 try {
                     URL newUrl = new URL(newPath);
                     URLConnection connection = newUrl.openConnection();
                     connection.connect();
-                    lastModifiedDates.put(newUrl.toExternalForm(), 
-                            new Long(connection.getLastModified()));
+                    lastModifiedDates.put(newUrl.toExternalForm(),
+                            connection.getLastModified());
                     Map defsMap = reader.read(connection.getInputStream());
                     definitions.addDefinitions(defsMap,
                             tilesContext.getRequestLocale());
@@ -232,24 +210,22 @@
     }
 
     /**
-     * Creates and returns a {@link ComponentDefinitions} set by reading 
+     * Creates and returns a {@link ComponentDefinitions} set by reading
      * configuration data from the applied sources.
-     * 
-     * @throws DefinitionsFactoryException if an error occurs reading the 
-     *      sources.
+     *
+     * @throws DefinitionsFactoryException if an error occurs reading the
+     *                                     sources.
      */
-    public ComponentDefinitions readDefinitions() 
+    public ComponentDefinitions readDefinitions()
             throws DefinitionsFactoryException {
-        
-        ComponentDefinitions definitions = 
-                createDefinitionsImpl(definitionsClassName);
+        ComponentDefinitions definitions = new ComponentDefinitionsImpl();
         try {
-            for (int i = 0; i < sources.size(); i++) {
-                URL source = (URL) sources.get(i);
+            for (Object source1 : sources) {
+                URL source = (URL) source1;
                 URLConnection connection = source.openConnection();
                 connection.connect();
-                lastModifiedDates.put(source.toExternalForm(), 
-				new Long(connection.getLastModified()));
+                lastModifiedDates.put(source.toExternalForm(),
+                        connection.getLastModified());
                 Map defsMap = reader.read(connection.getInputStream());
                 definitions.addDefinitions(defsMap);
             }
@@ -258,31 +234,28 @@
         }
         return definitions;
     }
-    
+
     /**
      * Indicates whether a given locale has been processed or not.
-     * 
+     * <p/>
      * This method can be used to avoid unnecessary synchronization of the
      * DefinitionsFactory in multi-threaded situations.  Check the return of
-     * isLoacaleProcessed before synchronizing the object and reading 
+     * isLoacaleProcessed before synchronizing the object and reading
      * locale-specific definitions.
      *
      * @param tilesContext The Tiles context to check.
      * @return true if the given lcoale has been processed and false otherwise.
      */
-    protected boolean isContextProcessed(TilesRequestContext tilesContext) {
-	if (processedLocales.contains(tilesContext.getRequestLocale())) {
-	    return true;
-	} else {
-	    return false;
-	}
+    protected boolean isLocaleProcessed(TilesRequestContext tilesContext) {
+        return processedLocales.contains(tilesContext.getRequestLocale());
     }
 
     /**
      * Concat postfix to the name. Take care of existing filename extension.
      * Transform the given name "name.ext" to have "name" + "postfix" + "ext".
      * If there is no ext, return "name" + "postfix".
-     * @param name Filename.
+     *
+     * @param name    Filename.
      * @param postfix Postfix to add.
      * @return Concatenated filename.
      */
@@ -303,15 +276,17 @@
         name = name.substring(0, dotIndex);
         return name + postfix + ext;
     }
-    
+
     /**
      * Calculate the postixes along the search path from the base bundle to the
      * bundle specified by baseName and locale.
      * Method copied from java.util.ResourceBundle
+     *
      * @param locale the locale
+     * @return a list of
      */
-    protected static List calculatePostixes(Locale locale) {
-        final List result = new ArrayList();
+    protected static List<String> calculatePostixes(Locale locale) {
+        final List<String> result = new ArrayList<String>();
         final String language = locale.getLanguage();
         final int languageLength = language.length();
         final String country = locale.getCountry();
@@ -350,70 +325,59 @@
         }
     }
 
-    /** 
-     * Creates the ComponentDefinitions instance specified by the initialization
-     * parameter or the default if none is specified.
-     *
-     * @param classname The class of the ComponentDefinitins to create.
-     * @return the instantiated ComponentDefinitions object.
-     * @throws DefinitionsFactoryException if a problem occurs.
-     */
-    protected ComponentDefinitions createDefinitionsImpl(String classname) 
-            throws DefinitionsFactoryException {
-        
-        ComponentDefinitions definitions = null;
-        if (classname != null) {
-            try {
-                Class defsClass = 
-                    RequestUtils.applicationClass(classname);
-                definitions = (ComponentDefinitions) defsClass.newInstance();
-            } catch (ClassNotFoundException e) {
-                throw new DefinitionsFactoryException(
-                        "Cannot find definitions class.", e);
-            } catch (InstantiationException e) {
-                throw new DefinitionsFactoryException(
-                        "Unable to instantiate definitions class.", e);
-            } catch (IllegalAccessException e) {
-                throw new DefinitionsFactoryException(
-                        "Unable to access definitions class.", e);
-            }
-        }
-        
-        if (definitions == null) {
-            definitions = new ComponentDefinitionsImpl();
+
+    public void refresh() throws DefinitionsFactoryException {
+        LOG.debug("Updating Tiles definitions. . .");
+        synchronized (definitions) {
+            ComponentDefinitions newDefs = readDefinitions();
+            definitions.reset();
+            definitions.addDefinitions(newDefs.getBaseDefinitions());
         }
-        
-        return definitions;
     }
 
+
     /**
      * Indicates whether the DefinitionsFactory is out of date and needs to be
      * reloaded.
      */
     public boolean refreshRequired() {
-	boolean status = false;
+        boolean status = false;
 
-	Set urls = lastModifiedDates.keySet();
+        Set<String> urls = lastModifiedDates.keySet();
 
-	try {
-	    Iterator i = urls.iterator();
-	    while (i.hasNext()) {
-		String urlPath = (String) i.next();
-		Long lastModifiedDate = (Long) lastModifiedDates.get(urlPath);
-		URL url = new URL(urlPath);
-		URLConnection connection = url.openConnection();
-		connection.connect();
-		long newModDate = connection.getLastModified();
-		if (newModDate != lastModifiedDate.longValue()) {
-		    status = true;
-		    break;
-		}
-	    }
-	} catch (Exception e) {
-            // Should probably log here.
+        try {
+            for (String urlPath : urls) {
+                Long lastModifiedDate = lastModifiedDates.get(urlPath);
+                URL url = new URL(urlPath);
+                URLConnection connection = url.openConnection();
+                connection.connect();
+                long newModDate = connection.getLastModified();
+                if (newModDate != lastModifiedDate) {
+                    status = true;
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            LOG.warn("Exception while monitoring update times.", e);
             return true;
-	}
-	return status;
+        }
+        return status;
+    }
+
+    private void createReader(String readerClassName) throws DefinitionsFactoryException {
+        try {
+            Class readerClass =
+                    RequestUtils.applicationClass(readerClassName);
+            reader = (DefinitionsReader) readerClass.newInstance();
+        } catch (ClassNotFoundException e) {
+            throw new DefinitionsFactoryException(
+                    "Cannot find reader class '" + readerClassName + "'.", e);
+        } catch (InstantiationException e) {
+            throw new DefinitionsFactoryException(
+                    "Unable to instantiate reader class '" + readerClassName + "'.", e);
+        } catch (IllegalAccessException e) {
+            throw new DefinitionsFactoryException(
+                    "Unable to access reader class '" + readerClassName + "'.", e);
+        }
     }
-    
 }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/filter/TilesFilter.java Wed Nov  1 12:15:09 2006
@@ -21,14 +21,9 @@
 import java.io.IOException;
 import javax.servlet.*;
 
-import org.apache.tiles.ComponentDefinitions;
 import org.apache.tiles.DefinitionsFactory;
 import org.apache.tiles.ReloadableDefinitionsFactory;
-import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.TilesUtil;
-import org.apache.tiles.TilesUtilImpl;
-import org.apache.tiles.context.TilesContextFactory;
-import org.apache.tiles.context.BasicTilesContextFactory;
 
 /**
  * Processes Reloadable Tiles Definitions.
@@ -64,30 +59,13 @@
 
         try {
             DefinitionsFactory factory = TilesUtil.getDefinitionsFactory();
-
             if (factory instanceof ReloadableDefinitionsFactory) {
-                if (((ReloadableDefinitionsFactory) factory).refreshRequired()) {
-                    if (debug) {
-                        log("Updating Tiles definitions.");
-                    }
-
-                    ComponentDefinitions newDefs = null;
-                    synchronized (factory) {
-                         newDefs = factory.readDefinitions();
-                    }
-
-                    ComponentDefinitions definitions = (ComponentDefinitions)
-                            filterConfig.getServletContext().getAttribute(
-                            TilesUtilImpl.DEFINITIONS_OBJECT);
-                    synchronized (definitions) {
-                        definitions.reset();
-                        definitions.addDefinitions(newDefs.getBaseDefinitions());
-                    }
+                ReloadableDefinitionsFactory rFactory = (ReloadableDefinitionsFactory) factory;
+                if (rFactory.refreshRequired()) {
+                    rFactory.refreshRequired();
                 }
             }
-
             chain.doFilter(request, response);
-
         } catch(Exception e) {
             throw new ServletException("Error processing request.", e);
         }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java Wed Nov  1 12:15:09 2006
@@ -18,15 +18,19 @@
 package org.apache.tiles.impl;
 
 import org.apache.tiles.*;
+import org.apache.tiles.preparer.PreparerFactory;
+import org.apache.tiles.preparer.PreparerException;
 import org.apache.tiles.context.TilesContextFactory;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.Log;
 
+import javax.servlet.jsp.PageContext;
 import java.util.Map;
 import java.util.List;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
 import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
  * Basic implementation of the tiles container interface.
@@ -61,6 +65,8 @@
 
     private TilesApplicationContext context;
     private DefinitionsFactory definitionsFactory;
+    private PreparerFactory preparerFactory;
+
     private TilesContextFactory contextFactory;
 
     /**
@@ -80,12 +86,15 @@
         String resourceString = getResourceString();
         List<String> resources = getResourceNames(resourceString);
         try {
-            for(String resource : resources) {
-                definitionsFactory.addSource(context.getResource(resource));
+            for (String resource : resources) {
+                URL resourceUrl = context.getResource(resource);
+                if (resourceUrl != null) {
+                    definitionsFactory.addSource(resourceUrl);
+                }
             }
         } catch (MalformedURLException e) {
             throw new DefinitionsFactoryException("Unable to parse definitions from "
-                    +resourceString, e);
+                    + resourceString, e);
         }
     }
 
@@ -112,6 +121,23 @@
         return context;
     }
 
+    public TilesRequestContext getRequestContext(Object request, Object response) {
+        return getContextFactory().createRequestContext(
+                getApplicationContext(),
+                request,
+                response
+        );
+    }
+
+
+    public TilesContextFactory getContextFactory() {
+        return contextFactory;
+    }
+
+    public void setContextFactory(TilesContextFactory contextFactory) {
+        checkInit();
+        this.contextFactory = contextFactory;
+    }
 
     /**
      * Standard Getter
@@ -123,7 +149,8 @@
     }
 
     /**
-     * Standard Setter
+     * Set the definitions factory. This method first ensures
+     * that the container has not yet been initialized.
      *
      * @param definitionsFactory the definitions factory for this instance.
      */
@@ -132,15 +159,55 @@
         this.definitionsFactory = definitionsFactory;
     }
 
+    /**
+     * Standard Getter
+     *
+     * @return return the preparer factory used by this container.
+     */
+    public PreparerFactory getPreparerFactory() {
+        return preparerFactory;
+    }
 
-    public TilesContextFactory getContextFactory() {
-        checkInit();
-        return contextFactory;
+    /**
+     * Set the preparer factory.  This method first ensures
+     * that the container has not yet been initialized.
+     *
+     * @param preparerFactory the preparer factory for this conainer.
+     */
+    public void setPreparerFactory(PreparerFactory preparerFactory) {
+        this.preparerFactory = preparerFactory;
     }
 
-    public void setContextFactory(TilesContextFactory contextFactory) {
-        checkInit();
-        this.contextFactory = contextFactory;
+    public void prepare(Object request, Object response, String preparer)
+            throws TilesException {
+        TilesRequestContext requestContext = getContextFactory().createRequestContext(
+                getApplicationContext(),
+                request,
+                response
+        );
+        prepare(requestContext, preparer);
+    }
+
+    public void prepare(PageContext context, String preparer)
+            throws TilesException {
+        TilesRequestContext requestContext = getContextFactory().createRequestContext(
+                getApplicationContext(), context
+        );
+        prepare(requestContext, preparer);
+    }
+
+    private void prepare(TilesRequestContext context, String preparerName)
+        throws TilesException {
+        ViewPreparer preparer = preparerFactory.getPreparer(preparerName, null);
+        ComponentContext componentContext = ComponentContext.getContext(context);
+
+
+        // TODO: Temporary while preparer gets refactored to throw a more specific exception.
+        try {
+            preparer.execute(context, componentContext);
+        } catch (Exception e) {
+           throw new PreparerException(e.getMessage(), e); 
+        }
     }
 
     /**
@@ -149,7 +216,25 @@
      * @param request the TilesRequestContext
      * @throws TilesException
      */
-    public void render(TilesRequestContext request, String definitionName)
+    public void render(Object request, Object response, String definitionName)
+            throws TilesException {
+        TilesRequestContext requestContext = getContextFactory().createRequestContext(
+                getApplicationContext(),
+                request,
+                response
+        );
+        render(requestContext, definitionName);
+    }
+
+    public void render(PageContext context, String definitionName)
+            throws TilesException {
+        TilesRequestContext requestContext = getContextFactory().createRequestContext(
+                getApplicationContext(), context
+        );
+        render(requestContext, definitionName);
+    }
+
+    private void render(TilesRequestContext request, String definitionName)
             throws TilesException {
         ComponentDefinition definition =
                 definitionsFactory.getDefinition(definitionName, request);
@@ -162,7 +247,9 @@
             throw new NoSuchDefinitionException(definitionName);
         }
 
-        ComponentContext context = getComponentContext(request, definition);
+        ComponentContext originalContext = ComponentContext.getContext(request);
+        ComponentContext subContext = new ComponentContext(definition.getAttributes());
+        ComponentContext.setContext(subContext, request);
 
         try {
             ViewPreparer preparer = definition.getOrCreatePreparer();
@@ -170,7 +257,7 @@
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Executing tiles preparer [" + preparer + "]");
                 }
-                preparer.execute(request, context);
+                preparer.execute(request, subContext);
             }
 
             String dispatchPath = definition.getPath();
@@ -182,20 +269,9 @@
             // TODO it would be nice to make the preparer throw a more specific
             // tiles exception so that it doesn't need to be rethrown.
             throw new TilesException(e.getMessage(), e);
+        } finally {
+            ComponentContext.setContext(originalContext, request);
         }
-
-    }
-
-    protected ComponentContext getComponentContext(TilesRequestContext request,
-                                                   ComponentDefinition definition) {
-        ComponentContext context = ComponentContext.getContext(request);
-        if (context == null) {
-            context = new ComponentContext(definition.getAttributes());
-            ComponentContext.setContext(context, request);
-        } else {
-            context.addMissing(definition.getAttributes());
-        }
-        return context;
     }
 
     /**

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesContainerListener.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesContainerListener.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesContainerListener.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesContainerListener.java Wed Nov  1 12:15:09 2006
@@ -21,12 +21,12 @@
 import org.apache.tiles.TilesException;
 import org.apache.tiles.TilesContainer;
 import org.apache.tiles.access.TilesAccess;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContext;
-import java.util.logging.Logger;
-import java.util.logging.Level;
 
 public class TilesContainerListener
         implements ServletContextListener {
@@ -34,8 +34,8 @@
     /**
      * Logger instance.
      */
-    protected static final Logger LOG =
-            Logger.getLogger(TilesListener.class.getName());
+    protected static final Log LOG =
+            LogFactory.getLog(TilesListener.class);
 
     /**
      * Initialize the TilesContainer and place it
@@ -49,7 +49,8 @@
             TilesContainer container = createContainer(servletContext);
             TilesAccess.setContainer(servletContext, container);
         } catch (TilesException e) {
-            LOG.log(Level.SEVERE, "Unable to retrieve tiles factory.");
+            LOG.fatal("Unable to retrieve tiles factory.",e);
+            throw new IllegalStateException("Unable to instantiate container.");
         }
     }
 
@@ -62,7 +63,7 @@
         try {
             TilesAccess.setContainer(servletContext, null);
         } catch (TilesException e) {
-            LOG.log(Level.SEVERE, "Unable to remove tiles container from service.");
+            LOG.warn("Unable to remove tiles container from service.");
         }
     }
 

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesListener.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesListener.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesListener.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/listener/TilesListener.java Wed Nov  1 12:15:09 2006
@@ -21,7 +21,6 @@
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Enumeration;
-import java.util.logging.Logger;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
@@ -32,6 +31,8 @@
 import org.apache.tiles.access.TilesAccess;
 import org.apache.tiles.context.BasicTilesContextFactory;
 import org.apache.tiles.context.TilesContextFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * @version $Rev$ $Date$
@@ -39,10 +40,9 @@
 public class TilesListener implements ServletContextListener {
 
     /**
-     * The logger for this class
+     * The LOG for this class
     */
-   protected static Logger logger = Logger.getLogger(TilesListener.class.
-                                                                      getName());
+   private static final Log LOG = LogFactory.getLog(TilesListener.class);
 
 
     /**
@@ -77,7 +77,7 @@
     private String configFiles = null;
 
     public void contextInitialized(ServletContextEvent event) {
-        logger.info("Initializing TilesListener");
+        LOG.info("Initializing TilesListener");
         configFiles = event.getServletContext().getInitParameter(DEFAULT_CONFIG_FILE_PARAM);
 
         try {
@@ -126,11 +126,11 @@
 
         try {
             if(configFiles != null) {
-                logger.info("CONFIG FILES DEFINED IN WEB.XML");
+                LOG.info("CONFIG FILES DEFINED IN WEB.XML");
                map.put(DEFAULT_CONFIG_FILE_PARAM, configFiles);
            }
             else {
-                logger.info("CONFIG FILES WERE NOT DEFINED IN WEB.XML, " +
+                LOG.info("CONFIG FILES WERE NOT DEFINED IN WEB.XML, " +
                               "LOOKING FOR " + DEFAULT_CONFIG_FILE);
                map.put(DEFAULT_CONFIG_FILE_PARAM, DEFAULT_CONFIG_FILE);
             }
@@ -155,7 +155,7 @@
    private void initDefinitionsFactory(ServletContext servletContext,
                                        DefinitionsFactoryConfig factoryConfig)
                                                     throws ServletException {
-        logger.info("initializing definitions impl...");
+        LOG.info("initializing definitions impl...");
         // Create configurable impl
         try {
             // Eventually this can be made dynamic
@@ -178,9 +178,9 @@
      * @param ex An exception
      */
     private void saveExceptionMessage(ServletContext context, Exception ex) {
-       logger.warning("Caught exception when initializing definitions impl");
-       logger.warning(ex.getMessage());
-       logger.warning(ex.toString());
+       LOG.warn("Caught exception when initializing definitions impl");
+       LOG.warn(ex.getMessage());
+       LOG.warn(ex.toString());
        context.setAttribute("TILES_INIT_EXCEPTION", ex.getMessage());
     }
 

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/servlet/TilesServlet.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/servlet/TilesServlet.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/servlet/TilesServlet.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/servlet/TilesServlet.java Wed Nov  1 12:15:09 2006
@@ -41,15 +41,15 @@
  * Add this servlet to your web.xml file,
  * like this:
  * <pre>
-&lt;web-app&gt;
-   ...
-&lt;servlet&gt;
-   &lt;servlet-name&gt;<strong>Tiles Servlet</strong>&lt;/servlet-name&gt;
-   &lt;servlet-class&gt;<strong>org.apache.tiles.servlets.TilesServlet</strong>&lt;/servlet-class&gt;
-   &lt;load-on-startup/&gt;
-&lt;/servlet&gt;
-   ...
-&lt;/web-app&gt;
+ * &lt;web-app&gt;
+ * ...
+ * &lt;servlet&gt;
+ * &lt;servlet-name&gt;<strong>Tiles Servlet</strong>&lt;/servlet-name&gt;
+ * &lt;servlet-class&gt;<strong>org.apache.tiles.servlets.TilesServlet</strong>&lt;/servlet-class&gt;
+ * &lt;load-on-startup/&gt;
+ * &lt;/servlet&gt;
+ * ...
+ * &lt;/web-app&gt;
  * </pre>Notice there are no mappings for this servlet. That's because
  * this servlet does everything when it's loaded. After that, it does not
  * service requests. This is not a front-controller servlet, like the Struts or JSF servlets.<br/><br/>
@@ -58,97 +58,98 @@
  * tag libraries. You can specify a configuration file like this:
  * <p/>
  * <pre>&lt;web-app&gt;
-   ...
-&lt;servlet&gt;
-   &lt;servlet-name&gt;Tiles Servlet&lt;/servlet-name&gt;
-   &lt;servlet-class&gt;org.apache.tiles.servlets.TilesServlet&lt;/servlet-class&gt;
-   &lt;init-param&gt;
-      &lt;param-name&gt;<strong>definitions-config</strong>&lt;/param-name&gt;
-      &lt;param-value&gt;<strong>/WEB-INF/tiles.xml</strong>&lt;/param-value&gt;
-   &lt;/init-param&gt;
-   &lt;load-on-startup/&gt;
-&lt;/servlet&gt;
-   ...
-&lt;/web-app&gt;</pre>Notice that we didn't specify a config file in the first servlet
-definition. In that case, Tiles assumes the existence of a file named /WEB-INF/tiles.xml. You
-can also define multiple configuration files like this:
-<p/><pre>&lt;web-app&gt;
-   ...
-&lt;servlet&gt;
-   &lt;servlet-name&gt;Tiles Servlet&lt;/servlet-name&gt;
-   &lt;servlet-class&gt;org.apache.tiles.servlets.TilesServlet&lt;/servlet-class&gt;
-   &lt;init-param&gt;
-      &lt;param-name&gt;<strong>definitions-config</strong>&lt;/param-name&gt;
-      &lt;param-value&gt;<strong>/WEB-INF/tile-adaptors.xml, /WEB-INF/tiles.xml</strong>&lt;/param-value&gt;
-   &lt;/init-param&gt;
-   &lt;load-on-startup/&gt;
-&lt;/servlet&gt;
-   ...
-&lt;/web-app&gt;</pre>Here, we've specified two config files for Tiles to process. Both
- * files must exist and each can reference definitions made in the other. 
+ * ...
+ * &lt;servlet&gt;
+ * &lt;servlet-name&gt;Tiles Servlet&lt;/servlet-name&gt;
+ * &lt;servlet-class&gt;org.apache.tiles.servlets.TilesServlet&lt;/servlet-class&gt;
+ * &lt;init-param&gt;
+ * &lt;param-name&gt;<strong>definitions-config</strong>&lt;/param-name&gt;
+ * &lt;param-value&gt;<strong>/WEB-INF/tiles.xml</strong>&lt;/param-value&gt;
+ * &lt;/init-param&gt;
+ * &lt;load-on-startup/&gt;
+ * &lt;/servlet&gt;
+ * ...
+ * &lt;/web-app&gt;</pre>Notice that we didn't specify a config file in the first servlet
+ * definition. In that case, Tiles assumes the existence of a file named /WEB-INF/tiles.xml. You
+ * can also define multiple configuration files like this:
+ * <p/><pre>&lt;web-app&gt;
+ * ...
+ * &lt;servlet&gt;
+ * &lt;servlet-name&gt;Tiles Servlet&lt;/servlet-name&gt;
+ * &lt;servlet-class&gt;org.apache.tiles.servlets.TilesServlet&lt;/servlet-class&gt;
+ * &lt;init-param&gt;
+ * &lt;param-name&gt;<strong>definitions-config</strong>&lt;/param-name&gt;
+ * &lt;param-value&gt;<strong>/WEB-INF/tile-adaptors.xml, /WEB-INF/tiles.xml</strong>&lt;/param-value&gt;
+ * &lt;/init-param&gt;
+ * &lt;load-on-startup/&gt;
+ * &lt;/servlet&gt;
+ * ...
+ * &lt;/web-app&gt;</pre>Here, we've specified two config files for Tiles to process. Both
+ * files must exist and each can reference definitions made in the other.
  * <p/>
  * <strong>Exception Handling</strong>
  * <p/>
  * When Tiles was bundled with Struts it reliably produced the same error message if anything
  * was amiss in your Tiles configuration file: <i>Can't find definitions config file.</i>
  * Tiles 2, OTOH, will display explicit error messages, such as <i>Error while parsing file
- * '/WEB-INF/tiles.xml'. The element type "tiles-definitions" must be terminated by the matching 
+ * '/WEB-INF/tiles.xml'. The element type "tiles-definitions" must be terminated by the matching
  * end-tag tiles-definitions".</i> The following explains how it works.
  * <p/>
- * The Tiles servlet reads your tile configuration file(s) when the Tiles servlet is loaded. If 
- * problems are found with your configuration files, the Tiles servlet of yesteryear would 
- * throw a <code>FactoryNotFound</code> exception and log the error message to the servlet 
- * container's log. Subsequently, when the <code>tiles:insert</code> tag blows up because 
+ * The Tiles servlet reads your tile configuration file(s) when the Tiles servlet is loaded. If
+ * problems are found with your configuration files, the Tiles servlet of yesteryear would
+ * throw a <code>FactoryNotFound</code> exception and log the error message to the servlet
+ * container's log. Subsequently, when the <code>tiles:insert</code> tag blows up because
  * there's no definition impl, Tiles would throw an exception with the familiar
- * <i>Cant find definitions config file</i> message. It was up to you to dig through 
+ * <i>Cant find definitions config file</i> message. It was up to you to dig through
  * the servlet container's log to find out what really went wrong.
- *
+ * <p/>
  * The Tiles 2 servlet, OTOH, places the exception's message in application scope
- * and retrieves it when tiles:insert blows up. It throws an exception with the original error 
+ * and retrieves it when tiles:insert blows up. It throws an exception with the original error
  * message, which is subsequently displayed in the browser, saving you the trouble of looking
  * at the log file.
- * <p>
+ * <p/>
+ *
  * @author David Geary
  */
 public class TilesServlet extends HttpServlet {
 
 
     /**
-     * The logger for this class
-    */
-   protected static Logger logger = Logger.getLogger(TilesServlet.class.
-                                                                      getName());
+     * The LOG for this class
+     */
+    protected static Logger logger = Logger.getLogger(TilesServlet.class.
+            getName());
 
 
     /**
      * The default name of a context init parameter that specifies the Tiles configuration file
-    */
+     */
     private static final String DEFAULT_CONFIG_FILE_PARAM = "definitions-config";
 
 
     /**
      * The default name of the Tiles configuration file
-    */
+     */
     private static final String DEFAULT_CONFIG_FILE = "/WEB-INF/tiles.xml";
 
 
     /**
      * An error message stating that something went wrong during initialization
-    */
+     */
     private static final String CANT_POPULATE_FACTORY_ERROR =
-         "CAN'T POPULATE TILES DEFINITION FACTORY";
+            "CAN'T POPULATE TILES DEFINITION FACTORY";
 
 
     /**
      * The Tiles definition impl
-    */
-   protected DefinitionsFactory definitionFactory = null;
+     */
+    protected DefinitionsFactory definitionFactory = null;
 
 
     /**
      * A comma-separated list of filenames representing the
      * application's Tiles configuration files.
-    */
+     */
     private String configFiles = null;
 
 
@@ -160,7 +161,7 @@
      * @param config The servlet config
      */
     public void init(ServletConfig config)
-        throws javax.servlet.ServletException {
+            throws javax.servlet.ServletException {
         super.init(config);
         logger.info("Initializing TilesServlet");
         configFiles = config.getInitParameter("definitions-config");
@@ -176,10 +177,9 @@
             TilesAccess.setApplicationContext(context, tilesContext);
             TilesUtil.setTilesUtil(new TilesUtilImpl(tilesContext));
             initDefinitionsFactory(context, fconfig);
-        }
-        catch(Exception ex) {
-            saveExceptionMessage(config, ex);
-                    throw new ServletException(ex.getMessage(), ex);
+        } catch (TilesException e) {
+            saveExceptionMessage(config, e);
+            throw new ServletException(e.getMessage(), e);
         }
     }
 
@@ -195,19 +195,18 @@
      * file is <code>/WEB-INF/tiles.xml</code>.
      */
     protected DefinitionsFactoryConfig readFactoryConfig(ServletConfig config)
-        throws ServletException {
+            throws ServletException {
         DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
         Map map = new HashMap();
 
         try {
-            if(configFiles != null) {
+            if (configFiles != null) {
                 logger.info("CONFIG FILES DEFINED IN WEB.XML");
-               map.put(DEFAULT_CONFIG_FILE_PARAM, configFiles);
-           }
-            else {
+                map.put(DEFAULT_CONFIG_FILE_PARAM, configFiles);
+            } else {
                 logger.info("CONFIG FILES WERE NOT DEFINED IN WEB.XML, " +
-                              "LOOKING FOR " + DEFAULT_CONFIG_FILE);
-               map.put(DEFAULT_CONFIG_FILE_PARAM, DEFAULT_CONFIG_FILE);
+                        "LOOKING FOR " + DEFAULT_CONFIG_FILE);
+                map.put(DEFAULT_CONFIG_FILE_PARAM, DEFAULT_CONFIG_FILE);
             }
 
             populateConfigParameterMap(config, map);
@@ -215,7 +214,7 @@
         }
         catch (Exception ex) {
             saveExceptionMessage(getServletConfig(), ex);
-           throw new UnavailableException(CANT_POPULATE_FACTORY_ERROR + ex.getMessage());
+            throw new UnavailableException(CANT_POPULATE_FACTORY_ERROR + ex.getMessage());
         }
         return factoryConfig;
     }
@@ -225,19 +224,19 @@
      * Initializes the Tiles definitions impl.
      *
      * @param servletContext The servlet context
-     * @param factoryConfig The definitions impl config
+     * @param factoryConfig  The definitions impl config
      */
-   private void initDefinitionsFactory(ServletContext servletContext,
-                                       DefinitionsFactoryConfig factoryConfig)
-        throws ServletException {
+    private void initDefinitionsFactory(ServletContext servletContext,
+                                        DefinitionsFactoryConfig factoryConfig)
+            throws ServletException {
         logger.info("initializing definitions impl...");
         // Create configurable impl
         try {
 
             definitionFactory = DefinitionsUtil.createDefinitionsFactory(
-                                factoryConfig);
+                    factoryConfig);
         } catch (DefinitionsFactoryException ex) {
-                    ex.printStackTrace();
+            ex.printStackTrace();
             throw new ServletException(ex.getMessage(), ex);
         }
     }
@@ -250,19 +249,19 @@
      * activated.
      *
      * @param config The servlet configuration
-     * @param ex An exception
+     * @param ex     An exception
      */
     private void saveExceptionMessage(ServletConfig config, Exception ex) {
-       logger.warning("Caught exception when initializing definitions impl");
-       logger.warning(ex.getMessage());
-       logger.warning(ex.toString());
-       //config.getServletContext().setAttribute(Globals.TILES_INIT_EXCEPTION, ex.getMessage());
+        logger.warning("Caught exception when initializing definitions impl");
+        logger.warning(ex.getMessage());
+        logger.warning(ex.toString());
+        //config.getServletContext().setAttribute(Globals.TILES_INIT_EXCEPTION, ex.getMessage());
     }
 
     /**
      * Populates a map with the parameters contained in the servlet configuration.
      *
-     * @param config The servlet configuration
+     * @param config   The servlet configuration
      * @param paramMap The map to fill
      */
     private void populateConfigParameterMap(ServletConfig config, Map paramMap) {

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/BaseInsertTag.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/BaseInsertTag.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/BaseInsertTag.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/BaseInsertTag.java Wed Nov  1 12:15:09 2006
@@ -523,9 +523,7 @@
                 if (preparer != null) {
                     try {
                         TilesRequestContext tilesContext = TagUtils
-                                .getTilesRequestContext(
-                                        pageContext.getRequest(),
-                                        pageContext.getResponse());
+                                .getTilesRequestContext(pageContext);
                         preparer.execute(tilesContext, subCompContext);
                     } catch (Exception e) {
                         throw new ServletException(e);

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java Wed Nov  1 12:15:09 2006
@@ -97,9 +97,7 @@
     protected TagHandler processDefinitionName(String name) throws JspException {
         
         try {
-            TilesRequestContext tilesContext = TagUtils.getTilesRequestContext(
-                    pageContext.getRequest(),
-                    pageContext.getResponse());
+            TilesRequestContext tilesContext = TagUtils.getTilesRequestContext(pageContext);
             ComponentDefinition definition = null;
             definition = TagUtils.getComponentDefinition(name, pageContext,
                     tilesContext);

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java Wed Nov  1 12:15:09 2006
@@ -66,9 +66,11 @@
         return TilesAccess.getApplicationContext(context);
     }
 
-    public static TilesRequestContext getTilesRequestContext(
-            ServletRequest request,
-            ServletResponse response) {
+    public static TilesRequestContext getTilesRequestContext(PageContext context) {
+        ServletRequest request = context.getRequest();
+        ServletResponse response = context.getResponse();
+        ServletContext ctx = context.getServletContext();
+
         return TilesUtil.createRequestContext(request, response);
     }
 
@@ -179,9 +181,7 @@
      * @return Requested bean or <code>null</code> if not found.
      */
     public static Object findAttribute(String beanName, PageContext pageContext) {
-        TilesRequestContext tilesContext = getTilesRequestContext(
-                pageContext.getRequest(),
-              pageContext.getResponse());
+        TilesRequestContext tilesContext = getTilesRequestContext(pageContext);
         ComponentContext compContext = ComponentContext.getContext(tilesContext);
 
         if (compContext != null) {
@@ -205,9 +205,7 @@
      */
     public static Object getAttribute(String beanName, int scope, PageContext pageContext) {
         if (scope == ComponentConstants.COMPONENT_SCOPE) {
-            TilesRequestContext tilesContext = getTilesRequestContext(
-                    pageContext.getRequest(),
-                  pageContext.getResponse());
+            TilesRequestContext tilesContext = getTilesRequestContext(pageContext);
             ComponentContext compContext = ComponentContext.getContext(tilesContext);
             return compContext.getAttribute(beanName);
         }
@@ -374,10 +372,7 @@
                 definition = (ComponentDefinition) definitionCandidate;
             } else {
                 if (tilesContext == null) {
-                    tilesContext = getTilesRequestContext(
-                            pageContext.getRequest(),
-                          pageContext.getResponse()
-                    );
+                    tilesContext = getTilesRequestContext(pageContext);
                 }
                 definition = TilesUtil.getDefinition(name, tilesContext);
             }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestReloadableDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestReloadableDefinitionsFactory.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestReloadableDefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestReloadableDefinitionsFactory.java Wed Nov  1 12:15:09 2006
@@ -18,13 +18,12 @@
 
 package org.apache.tiles;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
+import java.io.*;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.HashMap;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -33,15 +32,17 @@
 /**
  * Tests the reloadable definitions impl.
  *
- * @version $Rev$ $Date$ 
+ * @version $Rev$ $Date$
  */
 public class TestReloadableDefinitionsFactory extends TestCase {
-    
-    /** Creates a new instance of TestReloadableDefinitionsFactory */
+
+    /**
+     * Creates a new instance of TestReloadableDefinitionsFactory
+     */
     public TestReloadableDefinitionsFactory(String name) {
         super(name);
     }
-  
+
     /**
      * Start the tests.
      *
@@ -49,7 +50,7 @@
      */
     public static void main(String[] theArgs) {
         junit.textui.TestRunner.main(
-            new String[] { TestReloadableDefinitionsFactory.class.getName()});
+                new String[]{TestReloadableDefinitionsFactory.class.getName()});
     }
 
     /**
@@ -63,103 +64,98 @@
     /**
      * Tests reloading definitions impl.
      */
-    public void testReloadableDefinitionsFactory() {
-        try {
-            DefinitionsFactory factory = new UrlDefinitionsFactory();
+    public void testReloadableDefinitionsFactory() throws Exception {
+        DefinitionsFactory factory = new UrlDefinitionsFactory();
 
-            // Set up multiple data sources.
-            URL url = this.getClass().getClassLoader().getResource(
-                    "org/apache/tiles/config/temp-defs.xml");
-            
-            URI uri = null;
-            String urlPath = null;
-
-            // The following madness is necessary b/c of the way Windows hanndles URLs.
-            // We must add a slash to the protocol if Windows does not.  But we cannot
-            // add a slash to Unix paths b/c they already have one.
-            if (url.getPath().startsWith("/")) {
-                urlPath = "file:" + url.getPath();
-            } else {
-                urlPath = "file:/" + url.getPath();
-            }
-            
-            // The following second madness is necessary b/c sometimes spaces
-            // are encoded as '%20', sometimes they are not. For example in
-            // Windows 2000 under Eclipse they are encoded, under the prompt of
-            // Windows 2000 they are not.
-            // It seems to be in the different behaviour of
-            // sun.misc.Launcher$AppClassLoader (called under Eclipse) and
-            // java.net.URLClassLoader (under maven).
-            // And an URL accepts spaces while URIs need '%20'.
-            try {
-                uri = new URI(urlPath);
-            } catch (URISyntaxException e) {
-                uri = new URI(urlPath.replaceAll(" ", "%20"));
-            }
-
-            String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
-             "<!DOCTYPE tiles-definitions PUBLIC " +
-                   "\"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN\" " +
-                   "\"http://struts.apache.org/dtds/tiles-config_1_1.dtd\">\n\n" +
-            "<tiles-definitions>" +
-            "<definition name=\"rewrite.test\" path=\"/test.jsp\">" +
-                      "<put name=\"testparm\" value=\"testval\"/>" +
-              "</definition>" +
-            "</tiles-definitions>";
-            
-	    File file = new File(uri);
-	    FileOutputStream fileOut = new FileOutputStream(file);
-	    BufferedWriter writer = new BufferedWriter(
-                    new OutputStreamWriter(fileOut)); 
-	    writer.write(xml);
-	    writer.close();
-
-            factory.init(null);
-            factory.addSource(url);
-
-            // Parse files.
-            ComponentDefinitions definitions = factory.readDefinitions();
-            
-            assertNotNull("rewrite.test definition not found.", 
-                    definitions.getDefinition("rewrite.test"));
-            assertEquals("Incorrect initial path value", "/test.jsp",
-			 definitions.getDefinition("rewrite.test").getPath());
-
-	    ReloadableDefinitionsFactory reloadable = (ReloadableDefinitionsFactory) factory;
-	    assertEquals("Factory should be fresh.", false, 
-                    reloadable.refreshRequired());
-
-	    // Make sure the system actually updates the timestamp.
-	    Thread.sleep(30000);
-
-            // Set up multiple data sources.
-            xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
-             "<!DOCTYPE tiles-definitions PUBLIC " +
-                   "\"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN\" " +
-                   "\"http://struts.apache.org/dtds/tiles-config_1_1.dtd\">\n\n" +
-            "<tiles-definitions>" +
-            "<definition name=\"rewrite.test\" path=\"/newtest.jsp\">" +
-                      "<put name=\"testparm\" value=\"testval\"/>" +
-              "</definition>" +
-            "</tiles-definitions>";
-            
-	    file = new File(uri);
-	    fileOut = new FileOutputStream(file);
-	    writer = new BufferedWriter(new OutputStreamWriter(fileOut)); 
-	    writer.write(xml);
-	    writer.close();
-
-
-	    assertEquals("Factory should be stale.", true, 
-                    reloadable.refreshRequired());
-	    definitions = factory.readDefinitions();
-            assertNotNull("rewrite.test definition not found.", 
-                    definitions.getDefinition("rewrite.test"));
-            assertEquals("Incorrect initial path value", "/newtest.jsp",
-			 definitions.getDefinition("rewrite.test").getPath());
-        } catch (Exception e) {
-            fail("Error running test: " + e);
+        // Set up multiple data sources.
+        URL url = this.getClass().getClassLoader().getResource(
+                "org/apache/tiles/config/temp-defs.xml");
+
+        URI uri = null;
+        String urlPath = null;
+
+        // The following madness is necessary b/c of the way Windows hanndles URLs.
+        // We must add a slash to the protocol if Windows does not.  But we cannot
+        // add a slash to Unix paths b/c they already have one.
+        if (url.getPath().startsWith("/")) {
+            urlPath = "file:" + url.getPath();
+        } else {
+            urlPath = "file:/" + url.getPath();
         }
-        
+
+        // The following second madness is necessary b/c sometimes spaces
+        // are encoded as '%20', sometimes they are not. For example in
+        // Windows 2000 under Eclipse they are encoded, under the prompt of
+        // Windows 2000 they are not.
+        // It seems to be in the different behaviour of
+        // sun.misc.Launcher$AppClassLoader (called under Eclipse) and
+        // java.net.URLClassLoader (under maven).
+        // And an URL accepts spaces while URIs need '%20'.
+        try {
+            uri = new URI(urlPath);
+        } catch (URISyntaxException e) {
+            uri = new URI(urlPath.replaceAll(" ", "%20"));
+        }
+
+        String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
+                "<!DOCTYPE tiles-definitions PUBLIC " +
+                "\"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN\" " +
+                "\"http://struts.apache.org/dtds/tiles-config_1_1.dtd\">\n\n" +
+                "<tiles-definitions>" +
+                "<definition name=\"rewrite.test\" path=\"/test.jsp\">" +
+                "<put name=\"testparm\" value=\"testval\"/>" +
+                "</definition>" +
+                "</tiles-definitions>";
+
+        File file = new File(uri);
+        FileOutputStream fileOut = new FileOutputStream(file);
+        BufferedWriter writer = new BufferedWriter(
+                new OutputStreamWriter(fileOut));
+        writer.write(xml);
+        writer.close();
+
+        factory.init(new HashMap());
+        factory.addSource(url);
+
+        // Parse files.
+        ComponentDefinitions definitions = factory.readDefinitions();
+
+        assertNotNull("rewrite.test definition not found.",
+                definitions.getDefinition("rewrite.test"));
+        assertEquals("Incorrect initial path value", "/test.jsp",
+                definitions.getDefinition("rewrite.test").getPath());
+
+        ReloadableDefinitionsFactory reloadable = (ReloadableDefinitionsFactory) factory;
+        assertEquals("Factory should be fresh.", false,
+                reloadable.refreshRequired());
+
+        // Make sure the system actually updates the timestamp.
+        Thread.sleep(30000);
+
+        // Set up multiple data sources.
+        xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
+                "<!DOCTYPE tiles-definitions PUBLIC " +
+                "\"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN\" " +
+                "\"http://struts.apache.org/dtds/tiles-config_1_1.dtd\">\n\n" +
+                "<tiles-definitions>" +
+                "<definition name=\"rewrite.test\" path=\"/newtest.jsp\">" +
+                "<put name=\"testparm\" value=\"testval\"/>" +
+                "</definition>" +
+                "</tiles-definitions>";
+
+        file = new File(uri);
+        fileOut = new FileOutputStream(file);
+        writer = new BufferedWriter(new OutputStreamWriter(fileOut));
+        writer.write(xml);
+        writer.close();
+
+
+        assertEquals("Factory should be stale.", true,
+                reloadable.refreshRequired());
+        definitions = factory.readDefinitions();
+        assertNotNull("rewrite.test definition not found.",
+                definitions.getDefinition("rewrite.test"));
+        assertEquals("Incorrect initial path value", "/newtest.jsp",
+                definitions.getDefinition("rewrite.test").getPath());
     }
 }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestTilesServlet.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestTilesServlet.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestTilesServlet.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestTilesServlet.java Wed Nov  1 12:15:09 2006
@@ -24,24 +24,27 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 import servletunit.ServletConfigSimulator;
-import servletunit.ServletContextSimulator;
 
 import org.apache.tiles.mock.MockComponentDefinitions;
 import org.apache.tiles.mock.MockDefinitionsReader;
 import org.apache.tiles.servlet.TilesServlet;
 
+import javax.servlet.ServletException;
+
 /**
  * Verifies the functionality of the TilesServlet
  *
  * @version $Rev$ $Date$
  */
 public class TestTilesServlet extends TestCase {
-    
-    /** Creates a new instance of TestTilesServlet */
+
+    /**
+     * Creates a new instance of TestTilesServlet
+     */
     public TestTilesServlet(String name) {
         super(name);
     }
-    
+
     /**
      * Start the tests.
      *
@@ -49,7 +52,7 @@
      */
     public static void main(String[] theArgs) {
         TestRunner.main(
-            new String[] { TestTilesServlet.class.getName()});
+                new String[]{TestTilesServlet.class.getName()});
     }
 
     /**
@@ -66,9 +69,9 @@
     public void testInitTilesServlet() {
         try {
             ServletConfigSimulator servletConfig = new ServletConfigSimulator();
-            servletConfig.setInitParameter("definitions-config", 
+            servletConfig.setInitParameter("definitions-config",
                     "org/apache/tiles/config/tiles-defs.xml");
-            
+
             TilesServlet servlet = new TilesServlet();
             servlet.init(servletConfig);
         } catch (Exception e) {
@@ -80,38 +83,22 @@
      * Executes the servlet init() method with a custom definitions reader and
      * a custom component definitions.
      */
-    public void testCustomizedInitTilesServlet() {
+    public void testCustomizedInitTilesServlet() throws ServletException {
         int readerInstanceCount = MockDefinitionsReader.getInstanceCount();
         int defsInstanceCount = MockComponentDefinitions.getInstanceCount();
-        
-        try {
-            ServletConfigSimulator servletConfig = new ServletConfigSimulator();
-            servletConfig.setInitParameter("definitions-config", 
-                    "org/apache/tiles/config/tiles-defs.xml");
-            servletConfig.setInitParameter(
-                    DefinitionsFactory.READER_IMPL_PROPERTY,
-                    "org.apache.tiles.mock.MockDefinitionsReader");
-            servletConfig.setInitParameter(
-                    DefinitionsFactory.DEFINITIONS_IMPL_PROPERTY,
-                    "org.apache.tiles.mock.MockComponentDefinitions");
-            
-            TilesServlet servlet = new TilesServlet();
-            servlet.init(servletConfig);
-            
-            assertEquals("MockDefinitionsReader not used.",  
-                    readerInstanceCount + 1,
-                    MockDefinitionsReader.getInstanceCount());
-            
-            // The reason of the "+ 2" is that MockComponentDefinitions is
-            // created twice, one in UrlDefinitionsFactory.init (that checks if
-            // the specific ComponentDefinitions implementation can be
-            // instantiated), the other in UrlDefinitionsFactory.readDefinitions
-            // (where the instance is really used).
-            assertEquals("MockComponentDefinitions not used.",  
-                    defsInstanceCount + 2,
-                    MockComponentDefinitions.getInstanceCount());
-        } catch (Exception e) {
-            fail("Exception initializing servlet: " + e);
-        }
+
+        ServletConfigSimulator servletConfig = new ServletConfigSimulator();
+        servletConfig.setInitParameter("definitions-config",
+                "org/apache/tiles/config/tiles-defs.xml");
+        servletConfig.setInitParameter(
+                DefinitionsFactory.READER_IMPL_PROPERTY,
+                "org.apache.tiles.mock.MockDefinitionsReader");
+
+        TilesServlet servlet = new TilesServlet();
+        servlet.init(servletConfig);
+
+        assertEquals("MockDefinitionsReader not used.",
+                readerInstanceCount + 1,
+                MockDefinitionsReader.getInstanceCount());
     }
 }