You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2005/06/14 23:59:17 UTC

svn commit: r190662 [4/6] - in /struts/sandbox/trunk/tiles: ./ core-library/ core-library/src/ core-library/src/conf/ core-library/src/java/ core-library/src/java/org/ core-library/src/java/org/apache/ core-library/src/java/org/apache/taglib/ core-library/src/java/org/apache/taglib/tiles/ core-library/src/java/org/apache/taglib/tiles/doc-files/ core-library/src/java/org/apache/taglib/tiles/util/ core-library/src/java/org/apache/tiles/ core-library/src/java/org/apache/tiles/beans/ core-library/src/java/org/apache/tiles/definition/ core-library/src/java/org/apache/tiles/doc-files/ core-library/src/java/org/apache/tiles/servlets/ core-library/src/java/org/apache/tiles/xmlDefinition/ core-library/src/java/org/apache/util/ core-library/src/test/ examples/ examples/simple/ examples/simple/WEB-INF/ examples/simple/WEB-INF/lib/ examples/simple/graphics/ examples/simple/graphics/flags/

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtil.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtil.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtil.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtil.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,231 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Class containing utility methods for Tiles.
+ * Methods of this class are static and thereby accessible from anywhere.
+ * The underlying implementation can be changed with
+ * {@link #setTilesUtil(TilesUtilImpl)}.
+ * <br>
+ * Real implementation classes should derive from the {@link TilesUtilImpl} class.
+ * <br>
+ * Some methods are specified to throw the <code>UnsupportedOperationException</code>
+ * if the underlying implementation doesn't support the operation.
+ *
+ * @author Cedric Dumoulin
+ * @author David Geary
+ */
+public class TilesUtil {
+    /** Commons Logging instance.*/
+    protected static Log log = LogFactory.getLog(TilesUtil.class);
+
+    /** The implementation of tilesUtilImpl */
+    protected static TilesUtilImpl tilesUtilImpl = new TilesUtilImpl();
+
+    /**
+     * Get the real implementation.
+     * @return The underlying implementation object.
+     */
+    static public TilesUtilImpl getTilesUtil() {
+        return tilesUtilImpl;
+    }
+
+    /**
+     * Set the real implementation.
+     * This method should be called only once.
+     * Successive calls have no effect.
+     * @param tilesUtil The implementaion.
+     */
+    static public void setTilesUtil(TilesUtilImpl tilesUtil) {
+        if (implAlreadySet) {
+            return;
+        }
+        tilesUtilImpl = tilesUtil;
+        implAlreadySet = true;
+    }
+
+    /**
+     * Getter to know if the underlying implementation is already set to another
+     * value than the default value.
+     * @return <code>true</code> if {@link #setTilesUtil} has already been called.
+     */
+    static boolean isTilesUtilImplSet() {
+        return implAlreadySet;
+    }
+
+    /** Flag to know if internal implementation has been set by the setter method */
+    private static boolean implAlreadySet = false;
+
+    /**
+     * Do a forward using request dispatcher.
+     *
+     * This method is used by the Tiles package anytime a forward is required.
+     * @param uri Uri or Definition name to forward.
+     * @param request Current page request.
+     * @param response Current page response.
+     * @param servletContext Current servlet context.
+     */
+    public static void doForward(
+        String uri,
+        HttpServletRequest request,
+        HttpServletResponse response,
+        ServletContext servletContext)
+        throws IOException, ServletException {
+            
+        tilesUtilImpl.doForward(uri, request, response, servletContext);
+    }
+
+    /**
+     * Do an include using request dispatcher.
+     *
+     * This method is used by the Tiles package when an include is required.
+     * The Tiles package can use indifferently any form of this method.
+     * @param uri Uri or Definition name to forward.
+     * @param request Current page request.
+     * @param response Current page response.
+     * @param servletContext Current servlet context.
+     */
+    public static void doInclude(
+        String uri,
+        HttpServletRequest request,
+        HttpServletResponse response,
+        ServletContext servletContext)
+        throws IOException, ServletException {
+            
+        tilesUtilImpl.doInclude(uri, request, response, servletContext);
+    }
+
+    /**
+     * Do an include using PageContext.include().
+     *
+     * This method is used by the Tiles package when an include is required.
+     * The Tiles package can use indifferently any form of this method.
+     * @param uri Uri or Definition name to forward.
+     * @param request Current page request.
+     * @param response Current page response.
+     * @param servletContext Current servlet context.
+     */
+    public static void doInclude(String uri, PageContext pageContext)
+        throws IOException, ServletException {
+        TilesUtilImpl.doInclude(uri, pageContext);
+    }
+
+    /**
+     * Get definition factory from appropriate servlet context.
+     * @return Definitions factory or <code>null</code> if not found.
+     */
+    public static DefinitionsFactory getDefinitionsFactory(
+        ServletRequest request,
+        ServletContext servletContext) {
+        return tilesUtilImpl.getDefinitionsFactory(request, servletContext);
+    }
+
+    /**
+     * Create Definition factory from specified configuration object.
+     * Create a ConfigurableDefinitionsFactory and initialize it with the configuration
+     * object. This later can contain the factory classname to use.
+     * Factory is made accessible from tags.
+     * <p>
+     * Fallback of several factory creation methods.
+     *
+     * @param servletContext Servlet Context passed to newly created factory.
+     * @param factoryConfig Configuration object passed to factory.
+     * @return newly created factory of type ConfigurableDefinitionsFactory.
+     * @throws DefinitionsFactoryException If an error occur while initializing factory
+     */
+    public static DefinitionsFactory createDefinitionsFactory(
+        ServletContext servletContext,
+        DefinitionsFactoryConfig factoryConfig)
+        throws DefinitionsFactoryException {
+        return tilesUtilImpl.createDefinitionsFactory(servletContext, factoryConfig);
+    }
+
+    /**
+     * Get a definition by its name.
+     * First, retrieve definition factory and then get requested definition.
+     * Throw appropriate exception if definition or definition factory is not found.
+     * @param definitionName Name of requested definition.
+     * @param request Current servelet request.
+     * @param servletContext current servlet context.
+     * @throws FactoryNotFoundException Can't find definition factory.
+     * @throws DefinitionsFactoryException General error in factory while getting definition.
+     * @throws NoSuchDefinitionException No definition found for specified name
+     */
+    public static ComponentDefinition getDefinition(
+        String definitionName,
+        ServletRequest request,
+        ServletContext servletContext)
+        throws FactoryNotFoundException, DefinitionsFactoryException {
+            
+        try {
+            return getDefinitionsFactory(request, servletContext).getDefinition(
+                definitionName,
+                (HttpServletRequest) request,
+                servletContext);
+                
+        } catch (NullPointerException ex) { // Factory not found in context
+				System.out.println("Couldn't find the Tiles definition factory");
+            throw new FactoryNotFoundException("Can't get definitions factory from context.");
+        }
+    }
+
+	 
+
+    /**
+     * Reset internal state.
+     * This method is used by test suites to reset the class to its original state.
+     */
+    protected static void testReset() {
+        implAlreadySet = false;
+        tilesUtilImpl = new TilesUtilImpl();
+    }
+
+	 /**
+	  * DG: I moved this method from org.apache.struts.util.RequestUtils
+	  *     to remove that dependency on Struts
+	  *
+	  * Return the <code>Class</code> object for the specified fully qualified
+     * class name, from this web application's class loader.
+     *
+     * @param className Fully qualified class name to be loaded
+     * @return Class object
+     * @exception ClassNotFoundException if the class cannot be found
+    */
+    public static Class applicationClass(String className) 
+		  														throws ClassNotFoundException {
+		// Look up the class loader to be used
+		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+		if (classLoader == null) {
+			classLoader = TilesUtil.class.getClassLoader();
+		}
+		// Attempt to load the specified class
+		return (classLoader.loadClass(className));
+   }
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilImpl.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilImpl.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilImpl.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+
+import java.util.logging.Logger;
+import org.apache.tiles.definition.ComponentDefinitionsFactoryWrapper;
+
+// DG: removed dependency to RequestUtils
+// import org.apache.util.RequestUtils;
+
+/**
+ * Default implementation of TilesUtil.
+ * This class contains default implementation of utilities. This implementation
+ * is intended to be used without Struts.
+ *
+ * @author Cedric Dumoulin
+ * @author David Geary
+ */
+public class TilesUtilImpl implements Serializable {
+    
+    /** Commons Logging instance.*/
+    protected Logger logger = Logger.getLogger(TilesUtil.class.getName());
+
+    /** Constant name used to store factory in servlet context */
+    public static final String DEFINITIONS_FACTORY =
+        "org.apache.tiles.DEFINITIONS_FACTORY";
+
+    /**
+     * Do a forward using request dispatcher.
+     *
+     * This method is used by the Tiles package anytime a forward is required.
+     * @param uri Uri or Definition name to forward.
+     * @param request Current page request.
+     * @param servletContext Current servlet context.
+     */
+    public void doForward(
+        String uri,
+        HttpServletRequest request,
+        HttpServletResponse response,
+        ServletContext servletContext)
+        throws IOException, ServletException {
+            
+        request.getRequestDispatcher(uri).forward(request, response);
+    }
+
+    /**
+     * Do an include using request dispatcher.
+     *
+     * This method is used by the Tiles package when an include is required.
+     * The Tiles package can use indifferently any form of this method.
+     * @param uri Uri or Definition name to forward.
+     * @param request Current page request.
+     * @param response Current page response.
+     * @param servletContext Current servlet context.
+     */
+    public void doInclude(
+        String uri,
+        HttpServletRequest request,
+        HttpServletResponse response,
+        ServletContext servletContext)
+        throws IOException, ServletException {
+            
+        request.getRequestDispatcher(uri).include(request, response);
+    }
+
+    /**
+     * Do an include using PageContext.include().
+     *
+     * This method is used by the Tiles package when an include is required.
+     * The Tiles package can use indifferently any form of this method.
+     * @param uri Uri or Definition name to forward.
+     * @param request Current page request.
+     * @param response Current page response.
+     * @param servletContext Current servlet context.
+     */
+    public static void doInclude(String uri, PageContext pageContext)
+        throws IOException, ServletException {
+            
+        pageContext.include(uri);
+    }
+
+    /**
+     * Get definition factory from appropriate servlet context.
+     * @return Definitions factory or <code>null</code> if not found.
+     */
+    public DefinitionsFactory getDefinitionsFactory(
+        ServletRequest request,
+        ServletContext servletContext) {
+            
+        return (DefinitionsFactory) servletContext.getAttribute(DEFINITIONS_FACTORY);
+    }
+
+    /**
+     * Create Definition factory from specified configuration object.
+     * Create an instance of the factory with the class specified in the config
+     * object. Then, initialize this factory and finally store the factory in
+     * appropriate context by calling
+     * {@link #makeDefinitionsFactoryAccessible(DefinitionsFactory, ServletContext)}.
+     * Factory creation is done by {@link #createDefinitionFactoryInstance(String)}.
+     * <p>
+     *
+     * @param servletContext Servlet Context passed to newly created factory.
+     * @param factoryConfig Configuration object passed to factory.
+     * @return newly created factory of type specified in the config object.
+     * @throws DefinitionsFactoryException If an error occur while initializing factory
+     */
+    public DefinitionsFactory createDefinitionsFactory(
+        ServletContext servletContext,
+        DefinitionsFactoryConfig factoryConfig)
+        throws DefinitionsFactoryException {
+            
+        // Create configurable factory
+        DefinitionsFactory factory =
+            createDefinitionFactoryInstance(factoryConfig.getFactoryClassname());
+           
+		  logger.info("Initializing Tile definition factory");
+		  try {
+           factory.init(factoryConfig, servletContext);
+		  }
+		  catch(Exception ex) {
+			  logger.info("CAUGHT TILES FACTORY INITIALIZATION ERROR: " + ex.toString());
+			  throw new DefinitionsFactoryException(ex.getMessage()); 
+	     }
+        
+		  logger.info("Making factory accessible to JSP tags");
+        // Make factory accessible from jsp tags (push it in appropriate context)
+        makeDefinitionsFactoryAccessible(factory, servletContext);
+        return factory;
+    }
+
+    /**
+     * Create Definition factory of specified classname.
+     * Factory class must extend the {@link DefinitionsFactory} class.
+     * The factory is wrapped appropriately with {@link DefinitionsFactory}
+     * if it is an instance of the deprecated DefinitionsFactory class.
+     * @param classname Class name of the factory to create.
+     * @return newly created factory.
+     * @throws DefinitionsFactoryException If an error occur while initializing factory
+     */
+    protected DefinitionsFactory createDefinitionFactoryInstance(String classname)
+        throws DefinitionsFactoryException {
+        
+		  logger.info("Creating Tiles definition factory");
+        try {
+            Class factoryClass = TilesUtil.applicationClass(classname);
+		  		System.out.println("factory class: " + factoryClass);
+            Object factory = factoryClass.newInstance();
+
+            // Backward compatibility : if factory classes implements old interface,
+            // provide appropriate wrapper
+            if (factory instanceof ComponentDefinitionsFactory) {
+                factory =
+                    new ComponentDefinitionsFactoryWrapper(
+                        (ComponentDefinitionsFactory) factory);
+            }
+            return (DefinitionsFactory) factory;
+            
+        } catch (ClassCastException ex) { // Bad classname
+				System.out.println("CLASS CAST EXCEPTION");
+            throw new DefinitionsFactoryException(
+                "Error - createDefinitionsFactory : Factory class '"
+                    + classname
+                    + " must implement 'TilesDefinitionsFactory'.",
+                ex);
+                
+        } catch (ClassNotFoundException ex) { // Bad classname
+				System.out.println("CLASS NOT FOUND EXCEPTION");
+            throw new DefinitionsFactoryException(
+                "Error - createDefinitionsFactory : Bad class name '"
+                    + classname
+                    + "'.",
+                ex);
+                
+        } catch (InstantiationException ex) { // Bad constructor or error
+				System.out.println("INSTANTIATION EXCEPTION");
+            throw new DefinitionsFactoryException(ex);
+            
+        } catch (IllegalAccessException ex) {
+				System.out.println("ILLEGAL ACCESS EXCEPTION");
+            throw new DefinitionsFactoryException(ex);
+
+        } catch (Exception ex) {
+				System.out.println("EXCEPTION: " + ex.getClass().getName());
+				ex.printStackTrace();
+            throw new DefinitionsFactoryException(ex);
+		 }
+    }
+    
+    /**
+     * Make definition factory accessible to Tags.
+     * Factory is stored in servlet context.
+     * @param factory Factory to be made accessible.
+     * @param servletContext Current servlet context.
+     */
+    protected void makeDefinitionsFactoryAccessible(
+        DefinitionsFactory factory,
+        ServletContext servletContext) {
+            
+        servletContext.setAttribute(DEFINITIONS_FACTORY, factory);
+    }
+
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilStrutsImpl.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilStrutsImpl.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilStrutsImpl.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/TilesUtilStrutsImpl.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles;
+
+
+import javax.servlet.ServletContext;
+
+/**
+ * TilesUtil implementation for Struts 1.1 with one single factory.
+ * This class contains default implementation of utilities. This implementation
+ * is intended to be used with Struts 1.1.
+ * This class is used as the base class for all Struts 1.1 implementations of TilesUtil.
+ *
+ * @author Cedric Dumoulin
+ * @author David Geary
+ */
+public class TilesUtilStrutsImpl extends TilesUtilImpl {
+
+    /**
+     * Get definition factory for the module attached to the specified moduleConfig.
+     * @param servletContext Current servlet context
+     * @param moduleConfig Module config of the module for which the factory is requested.
+     * @return Definitions factory or null if not found.
+     */
+    public DefinitionsFactory getDefinitionsFactory(ServletContext servletContext) {
+        return (DefinitionsFactory) servletContext.getAttribute(DEFINITIONS_FACTORY);
+    }
+
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UntypedAttribute.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UntypedAttribute.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UntypedAttribute.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UntypedAttribute.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles;
+
+/**
+ * Common implementation of attribute definition. 
+ */
+public class UntypedAttribute implements AttributeDefinition {
+
+    /**
+     * Role associated with this attribute.
+     */
+    protected String role = null;
+    
+    protected Object value=null;
+
+    /**
+     * Constructor.
+     * @param value Object to store.
+     */
+    public UntypedAttribute(Object value) {
+        this.value = value;
+    }
+
+    /**
+     * Constructor.
+     * @param value Object to store.
+     * @param role Asociated role.
+     */
+    public UntypedAttribute(Object value, String role) {
+        this.value = value;
+        this.role = role;
+    }
+
+    /**
+     * Get role.
+     */
+    public String getRole() {
+        return role;
+    }
+
+    /**
+     * Set role.
+     * @param role Associated role.
+     */
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    /**
+     * Get value.
+     */
+    public Object getValue() {
+        return value;
+    }
+
+    /**
+     * Set value.
+     * @param value New value.
+     */
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    /**
+     * Get String representation of this object.
+     */
+    public String toString() {
+        return value.toString();
+    }
+
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UrlController.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UrlController.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UrlController.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/UrlController.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles;
+
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Tiles controller including a local URL.
+ * @author Cedric Dumoulin
+ */
+
+public class UrlController implements Controller {
+
+    /** Url associated with this controller. */
+  protected String url;
+
+    /**
+     * Constructor.
+     * @param url URL.
+     */
+  public UrlController( String url ) {
+     this.url=url;
+  }
+
+   /**
+    * Method associated to a tile and called immediately before the tile is included.
+    * This implementation calls a Struts Action. No servlet is set by this method.
+    *
+    * @param tileContext Current tile context.
+    * @param request Current request.
+    * @param response Current response.
+    * @param servletContext Current servlet context.
+    */
+   public void perform(ComponentContext tileContext,
+                       HttpServletRequest request, HttpServletResponse response,
+                       ServletContext servletContext)
+     throws ServletException, IOException {
+      RequestDispatcher rd = servletContext.getRequestDispatcher( url );
+      if( rd == null )
+        throw new ServletException( "Controller can't find url '" + url + "'." );
+
+      rd.include( request, response );
+   }
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/MenuItem.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/MenuItem.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/MenuItem.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/MenuItem.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.beans;
+
+import java.io.Serializable;
+
+/**
+ * Interface for MenuItems.
+ * @see SimpleMenuItem
+ */
+public interface MenuItem extends Serializable {
+    
+    /**
+     * Set value property.
+     */
+    public void setValue(String value);
+
+    /**
+     * Get value property.
+     */
+    public String getValue();
+
+    /**
+     * Set link property.
+     */
+    public void setLink(String link);
+
+    /**
+     * Get link property.
+     */
+    public String getLink();
+
+    /**
+     * Set icon property.
+     */
+    public void setIcon(String link);
+
+    /**
+     * Get icon property.
+     */
+    public String getIcon();
+
+    /**
+     * Set tooltip property.
+     */
+    public void setTooltip(String link);
+
+    /**
+     * Get tooltip property.
+     */
+    public String getTooltip();
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/SimpleMenuItem.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/SimpleMenuItem.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/SimpleMenuItem.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/beans/SimpleMenuItem.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.beans;
+
+import java.io.Serializable;
+
+/**
+ * A MenuItem implementation.
+ * Used to read menu items in definitions.
+ */
+public class SimpleMenuItem implements MenuItem, Serializable {
+
+    private String value = null;
+
+    private String link = null;
+
+    private String icon = null;
+
+    private String tooltip = null;
+
+    /**
+     * Constructor.
+     */
+    public SimpleMenuItem() {
+        super();
+    }
+
+    /**
+     * Set value property.
+     */
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    /**
+     * Get value property.
+     */
+    public String getValue() {
+        return value;
+    }
+
+    /**
+     * Set link property.
+     */
+    public void setLink(String link) {
+        this.link = link;
+    }
+
+    /**
+     * Get link property.
+     */
+    public String getLink() {
+        return link;
+    }
+
+    /**
+     * Set icon property.
+     */
+    public void setIcon(String icon) {
+        this.icon = icon;
+    }
+
+    /**
+     * Get icon property.
+     */
+    public String getIcon() {
+        return icon;
+    }
+
+    /**
+     * Set tooltip property.
+     */
+    public void setTooltip(String tooltip) {
+        this.tooltip = tooltip;
+    }
+
+    /**
+     * Get tooltip property.
+     */
+    public String getTooltip() {
+        return tooltip;
+    }
+
+    /**
+     * Return String representation.
+     */
+    public String toString() {
+        StringBuffer buff = new StringBuffer("SimpleMenuItem[");
+
+        if (getValue() != null) {
+            buff.append("value=").append(getValue()).append(", ");
+        }
+
+        if (getLink() != null) {
+            buff.append("link=").append(getLink()).append(", ");
+        }
+
+        if (getTooltip() != null) {
+            buff.append("tooltip=").append(getTooltip()).append(", ");
+        }
+
+        if (getIcon() != null) {
+            buff.append("icon=").append(getIcon()).append(", ");
+        }
+
+        buff.append("]");
+        return buff.toString();
+    }
+
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ComponentDefinitionsFactoryWrapper.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ComponentDefinitionsFactoryWrapper.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ComponentDefinitionsFactoryWrapper.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ComponentDefinitionsFactoryWrapper.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.definition;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+
+import org.apache.tiles.ComponentDefinition;
+import org.apache.tiles.ComponentDefinitionsFactory;
+import org.apache.tiles.DefinitionsFactory;
+import org.apache.tiles.DefinitionsFactoryConfig;
+import org.apache.tiles.DefinitionsFactoryException;
+import org.apache.tiles.NoSuchDefinitionException;
+import org.apache.tiles.TilesUtil;
+
+/**
+ * Wrapper from new definition factory interface to old interface.
+ * This class provides mapping from the old interface's life cycle to the new life cycle.
+ * @author Cedric Dumoulin
+ * @author David Geary
+ * @since 20020708
+ */
+public class ComponentDefinitionsFactoryWrapper implements DefinitionsFactory {
+
+    /** 
+     * The underlying factory. 
+     */
+    private ComponentDefinitionsFactory factory = null;
+
+    /** 
+     * Factory configuration,
+     */
+    private DefinitionsFactoryConfig config = null;
+
+    /**
+     * Constructor.
+     * Create new wrapper for specified factory.
+     * @param factory The factory to create a wrapper for.
+     */
+    public ComponentDefinitionsFactoryWrapper(ComponentDefinitionsFactory factory) {
+        this.factory = factory;
+    }
+
+    /**
+     * Constructor.
+     * Create new wrapper.
+     * The config object passed to init method should reference a factory implementing
+     * {@link ComponentDefinitionsFactory}.
+     */
+    public ComponentDefinitionsFactoryWrapper() {
+        super();
+    }
+
+    /**
+     * Get requested definition.
+     * @param name Name of the definition.
+     * @param request The request we are processing.
+     * @param servletContext Our servlet context.
+     * @return ComponentDefition
+     */
+    public ComponentDefinition getDefinition(
+        String name,
+        ServletRequest request,
+        ServletContext servletContext)
+        throws NoSuchDefinitionException, DefinitionsFactoryException {
+
+        return factory.getDefinition(name, request, servletContext);
+    }
+
+    /**
+     * Call underlying factory init method.
+     * @param config DefinitionsFactoryConfig.
+     * @param servletContext Our servlet context.
+     */
+    public void init(DefinitionsFactoryConfig config, ServletContext servletContext)
+        throws DefinitionsFactoryException {
+
+        this.config = config;
+
+        // create factory and initialize it
+        if (factory == null) {
+            factory = createFactoryInstance(config.getFactoryClassname());
+        }
+
+        factory.initFactory(servletContext, createConfigMap(config));
+    }
+
+    /**
+     * Do nothing because old life cycle has no equivalent.
+     */
+    public void destroy() {
+        factory = null;
+    }
+
+    /**
+     * Set underlying factory configuration.
+     * @param config DefinitionsFactoryConfig to use.
+     * @param servletContext Our servlet context.
+     *
+     */
+    public void setConfig(
+        DefinitionsFactoryConfig config,
+        ServletContext servletContext)
+        throws DefinitionsFactoryException {
+
+        ComponentDefinitionsFactory newFactory =
+            createFactoryInstance(config.getFactoryClassname());
+
+        newFactory.initFactory(servletContext, createConfigMap(config));
+        factory = newFactory;
+    }
+
+    /**
+     * Get underlying factory configuration.
+     * @return DefinitionsFactoryConfig.
+     */
+    public DefinitionsFactoryConfig getConfig() {
+        return config;
+    }
+
+    /**
+     * Get internal factory.
+     * @return The internal ComponentDefitionsFactory.
+     */
+    public ComponentDefinitionsFactory getInternalFactory() {
+        return factory;
+    }
+
+    /**
+     * Create Definition factory from provided classname which must implement {@link ComponentDefinitionsFactory}.
+     * Factory class must extend {@link DefinitionsFactory}.
+     * @param classname Class name of the factory to create.
+     * @return newly created factory.
+     * @throws DefinitionsFactoryException If an error occur while initializing factory
+     */
+    protected ComponentDefinitionsFactory createFactoryInstance(String classname)
+        throws DefinitionsFactoryException {
+
+        try {
+            Class factoryClass = TilesUtil.applicationClass(classname);
+            Object factory = factoryClass.newInstance();
+            return (ComponentDefinitionsFactory) factory;
+
+        } catch (ClassCastException ex) { // Bad classname
+            throw new DefinitionsFactoryException(
+                "Error - createDefinitionsFactory : Factory class '"
+                    + classname
+                    + " must implement 'DefinitionsFactory'.",
+                ex);
+
+        } catch (ClassNotFoundException ex) { // Bad classname
+            throw new DefinitionsFactoryException(
+                "Error - createDefinitionsFactory : Bad class name '"
+                    + classname
+                    + "'.",
+                ex);
+
+        } catch (InstantiationException ex) { // Bad constructor or error
+            throw new DefinitionsFactoryException(ex);
+
+        } catch (IllegalAccessException ex) {
+            throw new DefinitionsFactoryException(ex);
+        }
+
+    }
+
+    /**
+     * Return String representation.
+     * Calls toString() on underlying factory.
+     * @return String representation.
+     */
+    public String toString() {
+        return getInternalFactory().toString();
+    }
+
+    /**
+     * Create map of configuration attributes from configuration object.
+     * Mapping is done between old names and new names.
+     * @param config The DefinitionsFactoryConfig to use.
+     * @return Map Map of name/value pairs.
+     */
+    public static Map createConfigMap(DefinitionsFactoryConfig config) {
+        Map map = new HashMap(config.getAttributes());
+        // Add property attributes using old names
+        map.put(
+            DefinitionsFactoryConfig.DEFINITIONS_CONFIG_PARAMETER_NAME,
+            config.getDefinitionConfigFiles());
+
+        map.put(
+            DefinitionsFactoryConfig.PARSER_VALIDATE_PARAMETER_NAME,
+            new Boolean(config.getParserValidate()).toString());
+
+        if (!"org.apache.tiles.xmlDefinition.I18nFactorySet"
+            .equals(config.getFactoryClassname())) {
+
+            map.put(
+                DefinitionsFactoryConfig.FACTORY_CLASSNAME_PARAMETER_NAME,
+                config.getFactoryClassname());
+        }
+
+        return map;
+    }
+
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,280 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.definition;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tiles.ComponentDefinition;
+import org.apache.tiles.ComponentDefinitionsFactory;
+import org.apache.tiles.DefinitionsFactoryException;
+import org.apache.tiles.FactoryNotFoundException;
+import org.apache.tiles.xmlDefinition.I18nFactorySet;
+import org.apache.tiles.TilesUtil;
+
+/**
+ * A reloadable factory.
+ * This factory is the main entrance to any factory implementation. It takes in
+ * charge real implementation instance, and allows reloading by creating a new
+ * instance.
+ *
+ * @author Cedric Dumoulin
+ * @author David Geary
+ * @since Struts 1.1
+ * @version $Revision: 1.8 $ $Date: 2003/07/09 00:14:01 $
+ */
+public class ReloadableDefinitionsFactory implements ComponentDefinitionsFactory {
+
+    /** 
+     * The real factory instance. 
+     */
+    protected ComponentDefinitionsFactory factory = null;
+
+    /** 
+     * Initialization parameters. 
+     */
+    protected Map properties = null;
+
+    /** 
+     * Name of init property carrying factory class name. 
+     */
+    public static final String DEFINITIONS_FACTORY_CLASSNAME =
+        "definitions-factory-class";
+
+    /**
+     * Constructor.
+     * Create a factory according to servlet settings.
+     * @param servletContext Our servlet context.
+     * @param servletConfig Our servlet config.
+     * @throws DefinitionsFactoryException If factory creation fail.
+     */
+    public ReloadableDefinitionsFactory(
+        ServletContext servletContext,
+        ServletConfig servletConfig)
+        throws DefinitionsFactoryException {
+
+        properties = new ServletPropertiesMap(servletConfig);
+        factory = createFactory(servletContext, properties);
+    }
+
+    /**
+     * Constructor.
+     * Create a factory according to servlet settings.
+     * @param servletContext Our servlet context.
+     * @param properties Map containing all properties.
+     * @throws DefinitionsFactoryException If factory creation fail.
+     */
+    public ReloadableDefinitionsFactory(
+        ServletContext servletContext,
+        Map properties)
+        throws DefinitionsFactoryException {
+
+        this.properties = properties;
+        factory = createFactory(servletContext, properties);
+    }
+
+    /**
+    * Create Definition factory from provided classname.
+    * If a factory class name is provided, a factory of this class is created. Otherwise,
+    * a default factory is created.
+    * Factory must have a constructor taking ServletContext and Map as parameter.
+    * @param classname Class name of the factory to create.
+    * @param servletContext Servlet Context passed to newly created factory.
+    * @param properties Map of name/property passed to newly created factory.
+    * @return newly created factory.
+    * @throws DefinitionsFactoryException If an error occur while initializing factory
+    */
+    public ComponentDefinitionsFactory createFactoryFromClassname(
+        ServletContext servletContext,
+        Map properties,
+        String classname)
+        throws DefinitionsFactoryException {
+
+        if (classname == null) {
+            return createFactory(servletContext, properties);
+        }
+
+        // Try to create from classname
+        try {
+            Class factoryClass = TilesUtil.applicationClass(classname);
+            ComponentDefinitionsFactory factory =
+                (ComponentDefinitionsFactory) factoryClass.newInstance();
+            factory.initFactory(servletContext, properties);
+            return factory;
+
+        } catch (ClassCastException ex) { // Bad classname
+            throw new DefinitionsFactoryException(
+                "Error - createDefinitionsFactory : Factory class '"
+                    + classname
+                    + " must implements 'ComponentDefinitionsFactory'.",
+                ex);
+
+        } catch (ClassNotFoundException ex) { // Bad classname
+            throw new DefinitionsFactoryException(
+                "Error - createDefinitionsFactory : Bad class name '"
+                    + classname
+                    + "'.",
+                ex);
+
+        } catch (InstantiationException ex) { // Bad constructor or error
+            throw new DefinitionsFactoryException(ex);
+
+        } catch (IllegalAccessException ex) {
+            throw new DefinitionsFactoryException(ex);
+        }
+
+    }
+
+    /**
+    * Create default Definition factory.
+    * Factory must have a constructor taking ServletContext and Map as parameter.
+    * In this implementation, default factory is of class I18nFactorySet
+    * @param servletContext Servlet Context passed to newly created factory.
+    * @param properties Map of name/property passed to newly created factory.
+    * @return newly created factory.
+    * @throws DefinitionsFactoryException If an error occur while initializing factory
+    */
+    public ComponentDefinitionsFactory createDefaultFactory(
+        ServletContext servletContext,
+        Map properties)
+        throws DefinitionsFactoryException {
+
+        ComponentDefinitionsFactory factory =
+            new I18nFactorySet(servletContext, properties);
+
+        return factory;
+    }
+
+    /**
+    * Create Definition factory.
+    * Convenience method. ServletConfig is wrapped into a Map allowing retrieval
+    * of init parameters. Factory classname is also retrieved, as well as debug level.
+    * Finally, approriate createDefinitionsFactory() is called.
+    * @param servletContext Servlet Context passed to newly created factory.
+    * @param properties Map containing all properties.
+    */
+    public ComponentDefinitionsFactory createFactory(
+        ServletContext servletContext,
+        Map properties)
+        throws DefinitionsFactoryException {
+
+        String classname = (String) properties.get(DEFINITIONS_FACTORY_CLASSNAME);
+
+        if (classname != null) {
+            return createFactoryFromClassname(servletContext, properties, classname);
+        }
+
+        return new I18nFactorySet(servletContext, properties);
+    }
+
+    /**
+     * Get a definition by its name.
+     * Call appropriate method on underlying factory instance.
+     * Throw appropriate exception if definition or definition factory is not found.
+     * @param definitionName Name of requested definition.
+     * @param request Current servlet request.
+     * @param servletContext Current servlet context.
+     * @throws FactoryNotFoundException Can't find definition factory.
+     * @throws DefinitionsFactoryException General error in factory while getting definition.
+     */
+    public ComponentDefinition getDefinition(
+        String definitionName,
+        ServletRequest request,
+        ServletContext servletContext)
+        throws FactoryNotFoundException, DefinitionsFactoryException {
+
+        return factory.getDefinition(
+            definitionName,
+            (HttpServletRequest) request,
+            servletContext);
+    }
+
+    /**
+     * Reload underlying factory.
+     * Reload is done by creating a new factory instance, and replacing the old instance
+     * with the new one.
+     * @param servletContext Current servlet context.
+     * @throws DefinitionsFactoryException If factory creation fails.
+     */
+    public void reload(ServletContext servletContext)
+        throws DefinitionsFactoryException {
+
+        ComponentDefinitionsFactory newInstance =
+            createFactory(servletContext, properties);
+
+        factory = newInstance;
+    }
+
+    /**
+     * Get underlying factory instance.
+     * @return ComponentDefinitionsFactory
+     */
+    public ComponentDefinitionsFactory getFactory() {
+        return factory;
+    }
+
+    /**
+      * Init factory.
+      * This method is required by interface ComponentDefinitionsFactory. It is
+      * not used in this implementation, as it manages itself the underlying creation
+      * and initialization.
+      * @param servletContext Servlet Context passed to newly created factory.
+      * @param properties Map of name/property passed to newly created factory.
+      * Map can contain more properties than requested.
+      * @throws DefinitionsFactoryException An error occur during initialization.
+    */
+    public void initFactory(ServletContext servletContext, Map properties)
+        throws DefinitionsFactoryException {
+        // do nothing
+    }
+
+    /**
+     * Return String representation.
+     * @return String representation.
+     */
+    public String toString() {
+        return factory.toString();
+    }
+
+    /**
+     * Inner class.
+     * Wrapper for ServletContext init parameters.
+     * Object of this class is an HashMap containing parameters and values
+     * defined in the servlet config file (web.xml).
+     */
+    class ServletPropertiesMap extends HashMap {
+        /**
+         * Constructor.
+         */
+        ServletPropertiesMap(ServletConfig config) {
+            // This implementation is very simple.
+            // It is possible to avoid creation of a new structure, but this would
+            // imply writing all of the Map interface.
+            Enumeration enum = config.getInitParameterNames();
+            while (enum.hasMoreElements()) {
+                String key = (String) enum.nextElement();
+                put(key, config.getInitParameter(key));
+            }
+        }
+    } // end inner class
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/doc-files/image001.gif
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/doc-files/image001.gif?rev=190662&view=auto
==============================================================================
Binary file - no diff available.

Propchange: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/doc-files/image001.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/doc-files/tilesUML.gif
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/doc-files/tilesUML.gif?rev=190662&view=auto
==============================================================================
Binary file - no diff available.

Propchange: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/doc-files/tilesUML.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/package.html
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/package.html?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/package.html (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/package.html Tue Jun 14 14:59:13 2005
@@ -0,0 +1,323 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html lang="en">
+<head>
+<title>Tiles Package</title>
+</head>
+<body>
+<div class="mainContent">
+    The Tiles taglib and framework allows building web pages by assembling reusable 
+    pieces of pages, called Tiles. A Tiles is usually a simple JSP page.
+<img src="doc-files/tilesUML.gif" alt="TagLib Tiles UML">
+
+<div class="section">
+<h2>Introduction</h2>
+    <p>The Tiles framework allows building pages by assembling reusable Tiles. 
+      As an example, the page in the next figure can be build by assembling a 
+      header, a footer, a menu and a body.</p>
+    <p><img src="doc-files/image001.gif" height="169" width="145" alt="doc-files/image001"></p>
+    <p>Each Tiles (header, menu, body, ...) is a JSP page and can itself be build 
+      by assembling other Tiles.</p>
+<p>Using Tiles can be compared as using Java methods:  You need to define the Tiles (the method body), and then you can "call" this body anywhere you want, passing it some parameters. In Tiles, parameters are called "attributes" in order to avoid confusion with the request parameters.</p>
+    <p>The Tiles body can be a simple JSP page, a Struts action or any URI pointing 
+      to a resource inside the current web site.</p>
+    <p>Inserting the body, or calling it, is done with the tag &lt;tiles:insert 
+      ...&gt; anywhere in a JSP page. Insertion can also be done by specifying 
+      a <em>definition name </em>as the path of a Struts forward or as input, 
+      forward or include attributes of a Struts action.</p>
+    <p>Tiles bodies are used to create layouts, reusable parts, ... Tiles insertions 
+      are used to insert Tiles. The same Tiles can be reused several times in 
+      the same site, or even in the same page.</p>
+<p>Insertion of a Tiles body can be associated to a logical name in what Tiles calls a "definition". A definition contains a logical name, a page used as body and some attribute values. The definition declaration doesn't insert the associated Tiles body. It just associates it with the name. A definition name can be used anywhere insertion of a Tiles body can occur. The associated Tiles body is then inserted with associated attributes.</p>
+    <p>The definition declarations can be done in JSP pages or in one or more 
+      centralized files. A definition can extend another one, overload some attributes, 
+      add new attributes ... This allows the declaration of a "master" definition 
+      declaring the common layout, header, menu and footer. All other definitions 
+      extend this master layout thereby making it possible to change the entire 
+      site look &amp; feel simply by changing the master definition. </p>
+</div>
+<div class="section">
+<h2>Simple Examples</h2>
+<div class="subsection1">
+      <h3>Insert a JSP page</h3>
+      <pre>&lt;tiles:insert <strong>page</strong>="/layouts/commonLayout.jsp" flush="true" /&gt;
+</pre>
+<p>This example inserts the specified page in place of the tag. The page attribute is any valid URL pointing to a resource inside the current site.</p>
+</div>
+<div class="subsection1">
+<a name="doc.InsertPageWithAttributes">
+<h3>Insert a Tiles passing some attributes</h3>
+<pre>
+&lt;tiles:insert page="/layouts/classicLayout.jsp" flush="true"&gt;
+  &lt;tiles:put name="title"  value="Page Title" /&gt;
+  &lt;tiles:put name="header" value="/common/header.jsp" /&gt;
+  &lt;tiles:put name="footer" value="/common/footer.jsp" /&gt;
+  &lt;tiles:put name="menu"   value="/common/menu.jsp" /&gt;
+  &lt;tiles:put name="body"   value="/tiles/mainBody.jsp" /&gt;
+&lt;/tiles:insert&gt;
+</pre>
+      <p>This example inserts the specified page, passing it the attributes. Attributes 
+        are stored in a Tiles context which is passed to the inserted pag and 
+        can then be accesssed by their names.</p>
+</div>
+<div class="subsection1">
+<h3>Retrieve an attribute value as String</h3>
+<pre>
+&lt;tiles:getAsString name="title" /&gt;
+</pre>
+<p>This example retrieves the value of the attribute "title" and prints it as a String in the current output stream. The method toString() is applied on the attribute value, allowing to pass any kind of object as value.</p>
+</div>
+<div class="subsection1">
+<h3>Insert Tiles referenced by an attribute</h3>
+<pre>
+&lt;tiles:insert attribute='menu' /&gt;
+</pre>
+      <p>This inserts the Tiles referenced by the attribute "menu" value. The 
+        specified attribute value is first retrieved from current Tiles's context, 
+        and then the value is used as a page target to insert.</p>
+</div>
+<div class="subsection1">
+<h3>Classic Layout </h3>
+      <p>This example is a layout assembling a page in the classic header-footer-menu-body 
+        fashion.</p>
+      <pre>
+&lt;%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %&gt;
+&lt;HTML&gt;
+  &lt;HEAD&gt;
+    &lt;link rel="stylesheet" href="&lt;%=request.getContextPath()%&gt;/layouts/stylesheet.css" 
+                  type="text/css"/&gt;
+    &lt;title&gt;&lt;tiles:getAsString name="title"/&gt;&lt;/title&gt;
+  &lt;/HEAD&gt;
+&lt;body&gt;
+&lt;table border="0" width="100%" cellspacing="5"&gt;
+&lt;tr&gt;
+  &lt;td colspan="2"&gt;&lt;tiles:insert attribute="header" /&gt;&lt;/td&gt;
+&lt;/tr&gt;
+&lt;tr&gt;
+  &lt;td width="140" valign="top"&gt;
+    &lt;tiles:insert attribute='menu' /&gt;
+  &lt;/td&gt;
+  &lt;td valign="top"  align="left"&gt;
+    &lt;tiles:insert attribute='body' /&gt;
+  &lt;/td&gt;
+&lt;/tr&gt;
+&lt;tr&gt;
+  &lt;td colspan="2"&gt;
+    &lt;tiles:insert attribute="footer" /&gt;
+  &lt;/td&gt;
+&lt;/tr&gt;
+&lt;/table&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+      <p>The layout is declared in a JSP page (ex: /layouts/classicLayout.jsp). 
+        It can be used in conjunction with the tag described in "<a href="#doc.InsertPageWithAttributes">Insert 
+        a page passing some attributes</a>". </p>
+</div>
+</div>
+<div class="section">
+<h2>Definitions</h2>
+    <p>A definition associates a logical name with the URL of a Tiles to be inserted 
+      and some attribute values. A definition doesn't insert the Tiles. This is 
+      done later using the definition name. A definition name can be inserted 
+      as often as you want in your site, making it easy to reuse a Tiles. </p>
+    <p>A definition can extend another definition and overload some attributes 
+      or add new ones. This makes easy factorization of definitions differing 
+      by some attributes. For example, you can define a master definition declaring 
+      the main header, menu, footer, and a default title. Then let each of your 
+      page definitions extend this master definition and overload the title and 
+      the body.</p>
+    <p>Definitions can be declared in a JSP page, or in one or more centralized 
+      files. To enable the definitions from centralized files, you need to initialize 
+      the "definitions factory" which will parse the definitions from the files 
+      and provide them to the Tiles framework.</p>
+<div class="subsection1">
+<h3>Enabling Definition Factory</h3>
+<p>To enable Tiles definitions described in one or more files, you need to write these files and to initialize the definition factory. </p>
+      <p>Initialization is different depending on the Struts version you use, 
+        or if you do not use Struts at all.</p>
+<div class="subsection2">
+<h4>Struts1.1</h4>
+        <p>Use the Tiles plug-in to enable Tiles definitions. This plug-in creates 
+          the definition factory and passese it a configuration object populated 
+          with parameters. Parameters can be specified in the web.xml file or 
+          as plug-in parameters. The plug-in first reads parameters from web.xml, 
+          and then overloads them with the ones found in the plug-in. All parameters 
+          are optional and can be omitted. The plug-in should be declared in each 
+          struts-config file:</p>
+<pre>
+  &lt;plug-in className="org.apache.tiles.TilesPlugin" &gt;
+    &lt;set-property property="definitions-config" 
+	                 value="/WEB-INF/tiles-defs.xml,
+                            /WEB-INF/tiles-tests-defs.xml,/WEB-INF/tiles-tutorial-defs.xml,
+                            /WEB-INF/tiles-examples-defs.xml" /&gt;
+    &lt;set-property property="moduleAware" value="true" /&gt;
+    &lt;set-property property="definitions-parser-validate" value="true" /&gt;
+  &lt;/plug-in&gt;
+</pre>
+<ul>
+<li>definitions-config: (optional) <ul>
+<li>Specify configuration file names. There can be several comma separated file names (default: ?? )</li>
+</ul>
+</li>
+          <li>definitions-parser-validate: (optional)
+<ul>
+              <li>Specify if XML parser should validate the Tiles configuration 
+                file 
+                <ul>
+                  <li>true : validate. DTD should be specified in file header (default)</li>
+<li>false : no validation	  </li>
+
+</ul>
+</li>
+</ul>
+</li>
+
+          <li>moduleAware: (optional)
+           <ul>
+              <li>Specify if the Tiles definition factory is module aware. If true (default), 
+			there will be one factory for each Struts module. 
+			If false, there will be one common factory for all module. In this later case, 
+			it is still needed to declare one plugin per module. The factory will be 
+			initialized with parameters found in the first initialized plugin (generally the
+			one associated with the default module). 
+            <ul>
+             <li>true : Tiles framework is module aware </li>
+             <li>false :Tiles framework has one single factoy shared among modules (default)</li>
+            </ul>
+           </li>
+</ul>
+</li>
+
+<li>tilesUtilImplClassname: (optional - for advanced user)
+ <ul>
+    <li>Specify The classname of the TilesUtil implementation to use. The specified class should
+	be a subclass of TilesUtilStrutsImpl. This option disable the moduleAware option.
+	<br>Specifying "TilesUtilStrutsImpl" is equivalent to moduleAware = false.</br>
+	<br>Specifying "TilesUtilStrutsModuleImpl" is equivalent to moduleAware = true.</br>
+	This option is taken into account only once, when it is first encountered. To avoid problems,
+	it is advice to specify the same values in all TilesPlugin declaration.
+    </li>
+ </ul>
+</li>
+
+</ul>
+        <p>The TilesPlugin class creates one definition factory for each struts module.
+		</p>
+		<p>
+		If the flag moduleAware is false, only one shared factory is created for all modules. 
+		In this later case, the factory is initialized with parameters found in the first plugin.
+		The plugins should be declared in all modules, and the moduleAware flag should be 
+		the same for the entire application.</p> 
+		<p>
+          Paths found in Tiles definitions are relative to the main context.</p>
+        <p>You don't need to specify a TilesRequestProcessor, this is automatically 
+          done by the plug-in. If, however, you want to specify your own RequestProcessor, 
+          it should extend the TilesRequestProcessor. The plug-in checks this 
+          constraint.</p>
+</div>
+<div class="subsection2">
+<h4>Struts1.0.x</h4>
+<p>You need to use a special servlet extending the Struts servlet. This is specified in the web.xml file of your application:</p>
+        <pre>
+  &lt;servlet&gt;
+    &lt;servlet-name&gt;action&lt;/servlet-name&gt;
+	&lt;servlet-class&gt;org.apache.tiles.ActionComponentServlet&lt;/servlet-class&gt;   
+        &lt;!-- Tiles Servlet parameter 
+		  Specify configuration file names. There can be several comma 
+		  separated file names
+		--&gt; 	
+	&lt;init-param&gt;
+      &lt;param-name&gt;definitions-config&lt;/param-name&gt;
+      &lt;param-value&gt;/WEB-INF/tiles-defs.xml&lt;/param-value&gt;
+    &lt;/init-param&gt;
+        &lt;!-- Tiles Servlet parameter 
+		Specify if XML parser should validate the Tiles configuration file(s).
+		true : validate. DTD should be specified in file header.
+		false : no validation
+		--&gt; 	
+    &lt;init-param&gt;
+      &lt;param-name&gt;definitions-parser-validate&lt;/param-name&gt;
+      &lt;param-value&gt;true&lt;/param-value&gt;
+    &lt;/init-param&gt;
+     ...
+  &lt;/servlet&gt;
+</pre>
+</div>
+<div class="subsection2">
+<h4>Without Struts</h4>
+<p>Tiles can be used without Struts. To initialize the definition factory, you can use the provided servlet. Declare it in the web.xml file of your application:</p>
+<pre>
+  &lt;servlet&gt;
+    &lt;servlet-name&gt;action&lt;/servlet-name&gt;
+    &lt;servlet-class&gt;org.apache.tiles.TilesServlet&lt;/servlet-class&gt;
+
+
+	&lt;init-param&gt;
+      &lt;param-name&gt;definitions-config&lt;/param-name&gt;
+      &lt;param-value&gt;/WEB-INF/tiles-defs.xml&lt;/param-value&gt;
+    &lt;/init-param&gt;
+    &lt;init-param&gt;
+      &lt;param-name&gt;definitions-parser-validate&lt;/param-name&gt;
+      &lt;param-value&gt;true&lt;/param-value&gt;
+    &lt;/init-param&gt;
+   ...
+</pre>
+<p>The parameters are the same as for Struts1.1 or 1.0.</p>
+</div>
+</div>
+<div class="subsection1">
+<h3>Definition File Syntax</h3>
+<p>The definition file syntax can be found in the 
+<a href="http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">tiles-config_1_1.dtd file</a>. 
+</p>
+<p>Following is a simple example:</p>
+      <pre>
+&lt;!DOCTYPE tiles-definitions PUBLIC
+       "-//Apache Software Foundation//DTD Tiles Configuration//EN"
+       "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"&gt;
+
+&lt;!-- Definitions for Tiles documentation   --&gt;
+&lt;tiles-definitions&gt;
+
+  &lt;!-- ========================================================== --&gt;
+  &lt;!-- Master definition                                          --&gt;
+  &lt;!-- ========================================================== --&gt;
+  &lt;!-- Main page layout used as a root for other page definitions --&gt;
+
+  &lt;definition name="site.mainLayout" path="/layouts/classicLayout.jsp"&gt;
+	  &lt;put name="title"  value="Tiles Blank Site" /&gt;
+	  &lt;put name="header" value="/tiles/common/header.jsp" /&gt;
+	  &lt;put name="menu"   value="site.menu.bar" /&gt;
+	  &lt;put name="footer" value="/tiles/common/footer.jsp" /&gt;
+	  &lt;put name="body"   value="/tiles/body.jsp" /&gt;
+  &lt;/definition&gt;
+
+  &lt;!-- ========================================================== --&gt;
+  &lt;!-- Index page definition                                      --&gt;
+  &lt;!-- ========================================================== --&gt;
+    &lt;!-- This definition inherits from the main definition.
+	  It overloads the page title and the body used.
+	  Use the same mechanism to define new pages sharing common 
+	  properties (here header, menu, footer, layout)
+	--&gt;
+
+  &lt;definition name="site.index.page" extends="site.mainLayout" &gt;
+	  &lt;put name="title"  value="Tiles Blank Site Index" /&gt;
+	  &lt;put name="body"   value="/tiles/body.jsp" /&gt;
+  &lt;/definition&gt;
+
+&lt;/tiles-definition&gt;
+</pre>
+</div>
+<div class="subsection1">
+<h3>Debugging</h3>
+<p>To debug a page made of Tiles, you can use following advices:</p>
+<ul>
+  <li>Check each Tiles separatly. Try to access nested Tiles directly to test 
+  if thes work properly.</li>
+  <li>Enable Tiles logging. See the commons-logging package help.</li>
+</ul>
+</div>
+</div>
+</div>
+</body>
+</html>

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/servlets/TilesServlet.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/servlets/TilesServlet.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/servlets/TilesServlet.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/servlets/TilesServlet.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+package org.apache.tiles.servlets;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tiles.*;
+
+/**
+ * This is the entry point for Tiles. The <code>TilesServlet</code> initializes
+ * Tiles by creating a factory of tile definitions.
+ * <p/>
+ * <strong>Using the Tiles Servlet</strong>
+ * <p/>
+ * 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;
+ * </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/>
+ * TilesServlet reads through your Tiles configuration file(s) and stores
+ * tile definitions in a factory. That factory is accessed by the Tiles
+ * 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. 
+ * <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>
+ * Standalone Tiles, 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 
+ * 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 
+ * there's no definition factory, Tiles would throw an exception with the familiar 
+ * <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.
+ *
+ * The standalone Tiles 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 
+ * message, which is subsequently displayed in the browser, saving you the trouble of looking
+ * at the log file.
+ * <p>
+ * @author David Geary
+ */
+public class TilesServlet extends HttpServlet {
+	 
+
+	/**
+	 * The logger 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";
+	 
+
+	/**
+	 * The Tiles definition factory
+	*/
+   protected DefinitionsFactory definitionFactory = null;
+	 
+
+	/**
+	 * A comma-separated list of filenames representing the 
+	 * application's Tiles configuration files.
+	*/
+	private String configFiles = null;
+	 
+
+	/**
+	 * Initializes the servlet by creating the Tiles definition
+	 * factory and placing that factory in application scope. The
+	 * Tiles tags will subsequently access that factory.
+	 *
+	 * @param config The servlet config
+	 */
+	public void init(ServletConfig config) 
+		throws javax.servlet.ServletException {
+		logger.info("Initializing TilesServlet");
+		configFiles = config.getInitParameter("definitions-config");
+
+		try {
+			// Create factory config object
+			DefinitionsFactoryConfig fconfig = readFactoryConfig();
+			fconfig.setModuleAware(false);
+
+			ServletContext context = config.getServletContext();
+			TilesUtil.setTilesUtil(new TilesUtilStrutsImpl());
+			initDefinitionsFactory(context, fconfig);
+		}
+		catch(Exception ex) {
+			saveExceptionMessage(config, ex);
+			throw new ServletException(ex.getMessage());
+		}
+	}
+
+
+	/**
+	 * Populates the tiles factory configuration. If a
+	 * context init param named <i>definitions-config</i>
+	 * was defined, that param's value is assumed to be
+	 * a comma-separated list of configuration file names,
+	 * all of which are processed. If a 
+	 * <i>definitions-config</i> context param was not
+	 * specified, Tiles assumes that your Tiles definition
+	 * file is <code>/WEB-INF/tiles.xml</code>.
+	 *
+	 * @param config The servlet config
+	 */
+	protected DefinitionsFactoryConfig readFactoryConfig() 
+		throws ServletException {
+		DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
+		Map map = new HashMap();
+
+		try {
+			if(configFiles != null) { 
+				logger.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, " +
+						      "LOOKING FOR " + DEFAULT_CONFIG_FILE);
+			   map.put(DEFAULT_CONFIG_FILE_PARAM, DEFAULT_CONFIG_FILE);
+			}
+
+			factoryConfig.populate(map);
+		} 
+		catch (Exception ex) {
+			saveExceptionMessage(getServletConfig(), ex);
+		   throw new UnavailableException(CANT_POPULATE_FACTORY_ERROR + ex.getMessage());
+		}
+		return factoryConfig;
+	}
+
+
+	/**
+	 * Initializes the Tiles definitions factory.
+	 *
+	 * @param servletContext The servlet context
+	 * @param factoryConfig The definitions factory config
+	 */
+   private void initDefinitionsFactory(ServletContext servletContext,
+        											DefinitionsFactoryConfig factoryConfig)
+        											throws ServletException {
+		logger.info("initializing definitions factory...");
+		// Create configurable factory
+		try {
+			definitionFactory = DefinitionsUtil.createDefinitionsFactory(
+											servletContext, factoryConfig);
+		} catch (DefinitionsFactoryException ex) {
+			saveExceptionMessage(getServletConfig(), ex);
+			throw new ServletException(ex.getMessage());
+		}
+	}
+
+
+	/**
+	 * Stores the message associated with any exception thrown in this
+	 * servlet in application scope. Tiles later accesses that message
+	 * if an exception is thrown when the tiles:insert tag is
+	 * activated.
+	 *
+	 * @param servletContext The servlet context
+	 * @param ex An exception
+	 */
+	private void saveExceptionMessage(ServletConfig config, Exception ex) {
+	   logger.warning("Caught exception when initializing definitions factory");
+	   logger.warning(ex.getMessage());
+	   logger.warning(ex.toString());
+	   config.getServletContext().setAttribute(Globals.TILES_INIT_EXCEPTION, ex.getMessage());
+	}
+}

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/DefinitionsFactory.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/DefinitionsFactory.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/DefinitionsFactory.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/DefinitionsFactory.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.xmlDefinition;
+
+import org.apache.tiles.ComponentDefinition;
+import org.apache.tiles.DefinitionsFactoryException;
+import org.apache.tiles.NoSuchDefinitionException;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.io.Serializable;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+
+/**
+ * A factory for definitions.
+ * This factory allows to retrieve definitions by their keys.
+ */
+public class DefinitionsFactory implements Serializable
+{
+     /** Underlying map containing all definitions.*/
+   protected Map definitions;
+
+   /**
+     * Get a definition by its name.
+     * @param name Name of the definition.
+     * @param request Servlet request.
+     * @param servletContext Servlet context.
+     * @throws DefinitionsFactoryException An error occur while getting
+     * definition.
+     * @throws NoSuchDefinitionException No definition found for specified name
+     * Implementation can throw more accurate exception as a subclass of this
+     * exception.
+     */
+   public ComponentDefinition getDefinition(String name, ServletRequest request, ServletContext servletContext)
+             throws NoSuchDefinitionException, DefinitionsFactoryException
+   {
+   return (ComponentDefinition)definitions.get(name);
+   }
+
+  /**
+   * Put definition in set.
+   * @param definition Definition to put.
+   */
+  public void putDefinition(ComponentDefinition definition)
+  {
+  definitions.put( definition.getName(), definition );
+  }
+
+   /**
+    * Constructor.
+    * Create a factory initialized with definitions from {@link XmlDefinitionsSet}.
+    * @param xmlDefinitions Resolved definition from XmlDefinitionSet.
+    * @throws NoSuchDefinitionException If an error occurs while resolving inheritance
+    */
+   public DefinitionsFactory(XmlDefinitionsSet xmlDefinitions)
+    throws NoSuchDefinitionException
+    {
+    definitions = new HashMap();
+
+      // First, resolve inheritance
+    xmlDefinitions.resolveInheritances();
+
+      // Walk thru xml set and copy each definitions.
+    Iterator i = xmlDefinitions.getDefinitions().values().iterator();
+    while( i.hasNext() )
+      {
+      XmlDefinition xmlDefinition = (XmlDefinition)i.next();
+        putDefinition( new ComponentDefinition( xmlDefinition) );
+      }  // end loop
+   }
+    /**
+     * Return String representation.
+     * @return String representation.
+     */
+  public String toString()
+    {
+    return definitions.toString();
+    }
+
+}
+

Added: struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/FactorySet.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/FactorySet.java?rev=190662&view=auto
==============================================================================
--- struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/FactorySet.java (added)
+++ struts/sandbox/trunk/tiles/core-library/src/java/org/apache/tiles/xmlDefinition/FactorySet.java Tue Jun 14 14:59:13 2005
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tiles.xmlDefinition;
+
+import org.apache.tiles.ComponentDefinitionsFactory;
+import org.apache.tiles.ComponentDefinition;
+import org.apache.tiles.NoSuchDefinitionException;
+import org.apache.tiles.DefinitionsFactoryException;
+import org.apache.tiles.FactoryNotFoundException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Component Definitions factory.
+ * This factory contains several factories identified by a key. The
+ * getDefinition() method first looks for the factory key, retrieves or creates this
+ * factory and then calls its getDefinition().
+ */
+public abstract class FactorySet implements ComponentDefinitionsFactory
+{
+
+    /** Loaded factories */
+  protected Map factories=null;
+
+  /**
+   * Extract key that will be used to get the sub factory.
+   * @param name Name of requested definition.
+   * @param request Current servlet request.
+   * @param servletContext Current servlet context.
+   * @return Object.
+   */
+  abstract protected Object getDefinitionsFactoryKey(String name, ServletRequest request, ServletContext servletContext);
+
+  /**
+   * Get default factory.
+   * @return Default factory.
+   */
+  abstract protected DefinitionsFactory getDefaultFactory();
+
+  /**
+   * Get a factory by its key.
+   * If key is <code>null</code>, return defaultFactory.
+   * Search in loaded factories. If not found, create factory and store return value in
+   * loaded factories.
+   * @param key Key of requested definition.
+   * @param request Current servlet request.
+   * @param servletContext Current servlet context.
+   * @throws DefinitionsFactoryException If an error occur while creating factory.
+   */
+  protected DefinitionsFactory getFactory(Object key, ServletRequest request, ServletContext servletContext)
+    throws DefinitionsFactoryException
+  {
+  if(key == null )
+    return getDefaultFactory();
+
+  Object factory = factories.get( key );
+  if( factory == null )
+    {
+      // synchronize creation to avoid double creation by separate threads.
+      // Also, check if factory hasn't been created while waiting for synchronized
+      // section.
+    synchronized(factories)
+      {
+      factory = factories.get( key );
+      if( factory == null )
+        {
+        factory = createFactory( key, request, servletContext);
+        factories.put( key, factory );
+        } // end if
+      } // end synchronized
+    } // end if
+  return (DefinitionsFactory)factory;
+  }
+
+  /**
+   * Get a definition by its name.
+   *
+   * @param name Name of requested definition.
+   * @param request Current servlet request.
+   * @param servletContext Current servlet context.
+   * @throws NoSuchDefinitionException No definition found for specified name
+   * @throws DefinitionsFactoryException General exception
+   */
+  public ComponentDefinition getDefinition(String name, ServletRequest request, ServletContext servletContext)
+    throws NoSuchDefinitionException, DefinitionsFactoryException
+  {
+  if( factories == null )
+    throw new FactoryNotFoundException( "No definitions factory defined" );
+
+  Object key = getDefinitionsFactoryKey( name, request, servletContext);
+  DefinitionsFactory factory = getFactory( key, request, servletContext);
+  return factory.getDefinition( name, request, servletContext );
+  }
+
+  /**
+   * Create a factory for specified key.
+   * This method is called by getFactory() when the requested factory doesn't already exist.
+   * Must return a factory, or a default one.
+   * Real implementation needs to provide this method.
+   * @param key Key of requested definition.
+   * @param request Current servlet request.
+   * @param servletContext Current servlet context
+   * @throws DefinitionsFactoryException If an error occur while creating factory.
+   */
+  abstract protected DefinitionsFactory createFactory(Object key, ServletRequest request, ServletContext servletContext)
+          throws DefinitionsFactoryException;
+
+  /**
+   * Init factory set.
+   * @param servletContext Current servlet context
+   * @param properties properties used to initialized factory set;
+   */
+  abstract public void initFactory(ServletContext servletContext, Map properties)
+    throws DefinitionsFactoryException;
+
+  /**
+   * Constructor.
+   */
+  public FactorySet()
+  {
+  factories = new HashMap();
+  }
+
+    /**
+     * Return String representation.
+     * @return String representation.
+     */
+  public String toString()
+    {
+    Iterator i = factories.values().iterator();
+    StringBuffer buff = new StringBuffer( "all FactorySet's factory : \n" );
+    while( i.hasNext() )
+      {
+      buff.append( i.next().toString() ).append("\n");
+      }
+    return buff.toString();
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org