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/09 17:23:58 UTC

svn commit: r472961 - in /struts/sandbox/trunk/tiles: tiles-core/src/main/java/org/apache/tiles/access/ tiles-core/src/main/java/org/apache/tiles/factory/ tiles-core/src/main/java/org/apache/tiles/impl/ tiles-core/src/main/java/org/apache/tiles/taglib/...

Author: ddewolf
Date: Thu Nov  9 08:23:57 2006
New Revision: 472961

URL: http://svn.apache.org/viewvc?view=rev&rev=472961
Log:
Adding initContainer and destroyContainer tags

Added:
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java   (with props)
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java   (contents, props changed)
      - copied, changed from r472909, struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitDefinitionsTag.java
    struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp   (with props)
Removed:
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitDefinitionsTag.java
Modified:
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/access/TilesAccess.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.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/taglib/ContainerTagSupport.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld
    struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml
    struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/access/TilesAccess.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/access/TilesAccess.java?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/access/TilesAccess.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/access/TilesAccess.java Thu Nov  9 08:23:57 2006
@@ -48,6 +48,16 @@
 
     public static void setContainer(Object context, TilesContainer container)
         throws TilesException {
+
+        if (container == null) {
+            if(LOG.isInfoEnabled()) {
+                LOG.info("Removing TilesContext for context: " + context.getClass().getName());
+            }
+            removeAttribute(context, CONTAINER_ATTRIBUTE);
+        }
+        if (container != null && LOG.isInfoEnabled()) {
+            LOG.info("Publishing TilesContext for context: " + context.getClass().getName());
+        }
         setAttribute(context, CONTAINER_ATTRIBUTE, container);
     }
 
@@ -59,16 +69,6 @@
         return (TilesApplicationContext) getAttribute(context, CONTEXT_ATTRIBUTE);
     }
 
-    /**
-     * @param context
-     * @param
-     * @deprecated temporarily added for backwards compatibility.
-     */
-    public static void setApplicationContext(Object context, TilesApplicationContext tilesContext)
-        throws TilesException {
-        setAttribute(context, CONTEXT_ATTRIBUTE, tilesContext);
-    }
-
     private static Object getAttribute(Object context, String attributeName) {
         try {
             Class contextClass = context.getClass();
@@ -91,4 +91,14 @@
         }
     }
 
+    private static void removeAttribute(Object context, String name)
+        throws TilesException {
+        try {
+            Class contextClass = context.getClass();
+            Method attrMethod = contextClass.getMethod("removeAttribute", String.class);
+            attrMethod.invoke(context, name);
+        } catch (Exception e) {
+            throw new TilesException("Unable to remove attribute for specified context: '" + context + "'");
+        }
+    }
 }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java Thu Nov  9 08:23:57 2006
@@ -22,14 +22,16 @@
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.TilesContainer;
 import org.apache.tiles.TilesException;
-import org.apache.tiles.util.ClassUtil;
-import org.apache.tiles.preparer.BasicPreparerFactory;
-import org.apache.tiles.preparer.PreparerFactory;
 import org.apache.tiles.context.BasicTilesContextFactory;
 import org.apache.tiles.context.TilesContextFactory;
 import org.apache.tiles.definition.DefinitionsFactory;
 import org.apache.tiles.definition.UrlDefinitionsFactory;
 import org.apache.tiles.impl.BasicTilesContainer;
+import org.apache.tiles.impl.mgmt.CachingTilesContainer;
+import org.apache.tiles.mgmt.MutableTilesContainer;
+import org.apache.tiles.preparer.BasicPreparerFactory;
+import org.apache.tiles.preparer.PreparerFactory;
+import org.apache.tiles.util.ClassUtil;
 
 import java.lang.reflect.Method;
 import java.util.Enumeration;
@@ -49,6 +51,9 @@
     public static final String CONTAINER_FACTORY_INIT_PARAM =
         "org.apache.tiles.CONTAINER_FACTORY";
 
+    public static final String CONTAINER_FACTORY_MUTABLE_INIT_PARAM =
+        "org.apache.tiles.CONTAINER_FACTORY.mutable";
+
     public static final String CONTEXT_FACTORY_INIT_PARAM =
         "org.apache.tiles.CONTEXT_FACTORY";
 
@@ -58,6 +63,7 @@
     public static final String PREPARER_FACTORY_INIT_PARAM =
         "org.apache.tiles.PREPARER_FACTORY";
 
+
     private static final Map<String, String> DEFAULTS =
         new HashMap<String, String>();
 
@@ -79,7 +85,7 @@
      * factories.
      *
      * @param context the executing applications context.
-     *        Typically a ServletContext or PortletContext
+     *                Typically a ServletContext or PortletContext
      * @return a tiles container
      * @throws TilesException if an error occurs creating the factory.
      */
@@ -89,10 +95,32 @@
             .createFactory(context, CONTAINER_FACTORY_INIT_PARAM);
     }
 
+    public TilesContainer createContainer(Object context) throws TilesException {
+        String value = getInitParameter(context, CONTAINER_FACTORY_MUTABLE_INIT_PARAM);
+        if (Boolean.parseBoolean(value)) {
+            return createMutableTilesContainer(context);
+        } else {
+            return createTilesContainer(context);
+        }
+    }
 
-    public TilesContainer createContainer(Object context)
+    public TilesContainer createTilesContainer(Object context)
         throws TilesException {
         BasicTilesContainer container = new BasicTilesContainer();
+        initializeContainer(context, container);
+        return container;
+    }
+
+    public MutableTilesContainer createMutableTilesContainer(Object context)
+        throws TilesException {
+        CachingTilesContainer container = new CachingTilesContainer();
+        initializeContainer(context, container);
+        return container;
+    }
+
+    public void initializeContainer(Object context,
+                                    BasicTilesContainer container)
+        throws TilesException {
 
         TilesContextFactory contextFactory =
             (TilesContextFactory) createFactory(context, CONTEXT_FACTORY_INIT_PARAM);
@@ -113,7 +141,6 @@
 
         container.init(getInitParameterMap(context));
 
-        return container;
     }
 
 
@@ -128,7 +155,7 @@
             method = contextClass.getMethod("getInitParameter", String.class);
             while (e.hasMoreElements()) {
                 String key = (String) e.nextElement();
-                initParameters.put(key, (String)method.invoke(context, key));
+                initParameters.put(key, (String) method.invoke(context, key));
             }
         } catch (Exception e) {
             throw new TilesException("Unable to retrieve init parameters." +
@@ -147,19 +174,24 @@
 
     public static String resolveFactoryName(Object context, String parameterName)
         throws TilesException {
+        Object factoryName = getInitParameter(context, parameterName);
+        return factoryName == null
+            ? DEFAULTS.get(parameterName)
+            : factoryName.toString();
+    }
 
-        Object factoryName;
+    private static String getInitParameter(Object context, String parameterName)
+        throws TilesException {
+        Object value;
         try {
             Class contextClass = context.getClass();
             Method getInitParameterMethod =
                 contextClass.getMethod("getInitParameter", String.class);
-            factoryName = getInitParameterMethod.invoke(context, parameterName);
+            value = getInitParameterMethod.invoke(context, parameterName);
         } catch (Exception e) {
             throw new TilesException("Unrecognized context.  Is this context" +
                 "a ServletContext, PortletContext, or similar?", e);
         }
-        return factoryName == null
-            ? DEFAULTS.get(parameterName)
-            : factoryName.toString();
+        return value == null ? null : value.toString();
     }
 }

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=472961&r1=472960&r2=472961
==============================================================================
--- 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 Thu Nov  9 08:23:57 2006
@@ -309,8 +309,7 @@
             LOG.debug("Render request recieved for definition '" + definitionName + "'");
         }
 
-        ComponentDefinition definition =
-            definitionsFactory.getDefinition(definitionName, request);
+        ComponentDefinition definition = getDefinition(definitionName, request);
 
         if (definition == null) {
             if (LOG.isWarnEnabled()) {
@@ -355,6 +354,12 @@
         }
     }
 
+    protected ComponentDefinition getDefinition(String definitionName, TilesRequestContext request) throws DefinitionsFactoryException {
+        ComponentDefinition definition =
+            definitionsFactory.getDefinition(definitionName, request);
+        return definition;
+    }
+
     private boolean isPermitted(TilesRequestContext request, String role) {
         if(role == null) {
             return true;
@@ -415,8 +420,7 @@
 
     private boolean isValidDefinition(TilesRequestContext context, String definitionName) {
         try {
-            ComponentDefinition definition =
-                definitionsFactory.getDefinition(definitionName, context);
+            ComponentDefinition definition = getDefinition(definitionName, context);
             return definition != null;
         }
         catch (NoSuchDefinitionException nsde) {

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java Thu Nov  9 08:23:57 2006
@@ -41,19 +41,14 @@
  * Provides standard support for security, and provides access
  * to the container and component context.
  * </p>
- * This tag takes special care to ensure that the component context is
- * reset to it's original state after the execution of the tag is
- * complete. This ensures that all all included attributes in subsequent
- * tiles are scoped properly and do not bleed outside their intended
- * scope.
+
  *
  * @since Tiles 2.0
  * @version $Rev$
  * 
  */
-public abstract class ContainerTagSupport extends BodyTagSupport
-    implements TryCatchFinally {
-
+public abstract class ContainerTagSupport extends BodyTagSupport {
+    
     /**
      * The log instance for this tag.
      */
@@ -63,8 +58,6 @@
     protected TilesContainer container;
     protected ComponentContext componentContext;
 
-    private Map<String, ComponentAttribute> originalState;
-
     public String getRole() {
         return role;
     }
@@ -73,12 +66,6 @@
         this.role = role;
     }
 
-    public int doStartTag() {
-        container = TilesAccess.getContainer(pageContext.getServletContext());
-        componentContext = container.getComponentContext(pageContext);
-        cacheState();
-        return isAccessAllowed() ? EVAL_BODY_BUFFERED : SKIP_BODY;
-    }
 
     public int doEndTag() throws JspException {
         if (isAccessAllowed()) {
@@ -98,20 +85,12 @@
     }
 
 
-    public void doCatch(Throwable throwable) throws Throwable {
-        // noop;
-    }
-
-    public void doFinally() {
-        restoreState();
-    }
 
     public void release() {
         super.release();
         this.role = null;
         this.container = null;
         this.componentContext = null;
-        originalState = null;
     }
 
     protected abstract void execute() throws TilesException, JspException, IOException;
@@ -121,21 +100,5 @@
         return (role == null || req.isUserInRole(role));
     }
 
-    private void cacheState() {
-        originalState = new HashMap<String, ComponentAttribute>();
-        Iterator<String> i = componentContext.getAttributeNames();
-        while(i.hasNext()) {
-            String name = i.next();
-            ComponentAttribute original = componentContext.getAttribute(name);
-            ComponentAttribute a = new ComponentAttribute(
-                original.getValue(), original.getRole(), original.getType()
-            );
-            originalState.put(name, a);
-        }
-    }
 
-    private void restoreState() {
-        originalState.clear();
-        originalState.putAll(originalState);
-    }
 }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java Thu Nov  9 08:23:57 2006
@@ -21,28 +21,41 @@
 
 import org.apache.tiles.ComponentAttribute;
 import org.apache.tiles.TilesException;
+import org.apache.tiles.access.TilesAccess;
 import org.apache.tiles.taglib.PutTag;
 import org.apache.tiles.taglib.PutTagParent;
 
 import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TryCatchFinally;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 /**
  * Support for all tags which render (a template, or definition).
  * </p>
  * Properly invokes the defined preparer and invokes the abstract
  * render method upon completion.
+ * </p>
+ * This tag takes special care to ensure that the component context is
+ * reset to it's original state after the execution of the tag is
+ * complete. This ensures that all all included attributes in subsequent
+ * tiles are scoped properly and do not bleed outside their intended
+ * scope.
  *
  * @version $Rev$
  * @since Tiles 2.0
  */
 public abstract class RenderTagSupport extends ContainerTagSupport
-    implements PutTagParent {
+    implements TryCatchFinally, PutTagParent {
 
     protected String preparer;
     protected boolean flush;
     protected boolean ignore;
 
+    private Map<String, ComponentAttribute> originalState;
+
     public String getPreparer() {
         return preparer;
     }
@@ -75,6 +88,21 @@
         super.release();
     }
 
+        public int doStartTag() {
+        container = TilesAccess.getContainer(pageContext.getServletContext());
+        componentContext = container.getComponentContext(pageContext);
+        cacheState();
+        return isAccessAllowed() ? EVAL_BODY_BUFFERED : SKIP_BODY;
+    }
+
+    public void doCatch(Throwable throwable) throws Throwable {
+        // noop;
+    }
+
+    public void doFinally() {
+        restoreState();
+    }
+
     /**
      * Execute the tag by invoking the preparer, if defined, and then
      * rendering.
@@ -120,6 +148,24 @@
             nestedTag.getName(),
             attribute
         );
+    }
+
+    private void cacheState() {
+        originalState = new HashMap<String, ComponentAttribute>();
+        Iterator<String> i = componentContext.getAttributeNames();
+        while(i.hasNext()) {
+            String name = i.next();
+            ComponentAttribute original = componentContext.getAttribute(name);
+            ComponentAttribute a = new ComponentAttribute(
+                original.getValue(), original.getRole(), original.getType()
+            );
+            originalState.put(name, a);
+        }
+    }
+
+    private void restoreState() {
+        originalState.clear();
+        originalState.putAll(originalState);
     }
 
 }

Added: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java?view=auto&rev=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java (added)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java Thu Nov  9 08:23:57 2006
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.taglib.definition;
+
+import org.apache.tiles.TilesException;
+import org.apache.tiles.access.TilesAccess;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+public class DestroyContainerTag extends TagSupport {
+
+    public int doEndTag() throws JspException {
+        try {
+            TilesAccess.setContainer(pageContext.getServletContext(), null);
+        } catch (TilesException e) {
+            throw new JspException(e);
+        }
+        return EVAL_PAGE;
+    }
+}

Propchange: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DestroyContainerTag.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Copied: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java (from r472909, struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitDefinitionsTag.java)
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java?view=diff&rev=472961&p1=struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitDefinitionsTag.java&r1=472909&p2=struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitDefinitionsTag.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java Thu Nov  9 08:23:57 2006
@@ -21,73 +21,229 @@
 
 package org.apache.tiles.taglib.definition;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.access.TilesAccess;
+import org.apache.tiles.factory.TilesContainerFactory;
+import org.apache.tiles.impl.BasicTilesContainer;
+import org.apache.tiles.mgmt.MutableTilesContainer;
 import org.apache.tiles.taglib.ComponentConstants;
+import org.apache.tiles.taglib.PutTagParent;
+import org.apache.tiles.taglib.PutTag;
 
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.TagSupport;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Init definitions impl.
  */
-public class InitDefinitionsTag extends TagSupport implements ComponentConstants {
+public class InitContainerTag extends BodyTagSupport
+    implements PutTagParent {
 
+    private static final Log LOG =
+        LogFactory.getLog(InitContainerTag.class);
 
-    /**
-     * Default constructor.
-     */
-    public InitDefinitionsTag() {
-        super();
+    private String containerFactory;
+    private Map<String, String> initParameters;
+
+
+    public String getContainerFactory() {
+        return containerFactory;
     }
 
-    /**
-     * Release all allocated resources.
-     */
-    public void release() {
+    public void setContainerFactory(String containerFactory) {
+        this.containerFactory = containerFactory;
+    }
 
-        super.release();
+
+    public void processNestedTag(PutTag nestedTag) throws JspException {
+        initParameters.put(nestedTag.getName(), nestedTag.getValue().toString());
     }
 
     /**
-     * Set file.
+     * Release all allocated resources.
      */
-    public void setFile(String name) {
+    public void release() {
+        super.release();
+        containerFactory = null;
+        initParameters = null;
     }
 
-    /**
-     * Set classname.
-     */
-    public void setClassname(String classname) {
+    public int doStartTag() {
+        initParameters = new HashMap<String, String>();
+        return EVAL_BODY_INCLUDE;
     }
 
     /**
      * TODO Add a MutableContainer so that this can be done?
      * Do start tag.
      */
-    public int doStartTag() throws JspException {
-//        DefinitionsFactory factory = TilesUtil.getDefinitionsFactory();
-//        if (factory != null) {
-//            return SKIP_BODY;
-//        }
-//
-//        DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
-//        factoryConfig.setFactoryClassname(classname);
-//        factoryConfig.setDefinitionConfigFiles(filename);
-//
-//        try {
-//            factory = TilesUtil.createDefinitionsFactory(factoryConfig);
-//        } catch (DefinitionsFactoryException ex) {
-//            ex.printStackTrace();
-//            throw new JspException(ex);
-//        }
+    public int doEndTag() throws JspException {
+        TilesContainer container =
+            TilesAccess.getContainer(pageContext.getServletContext());
 
-        return SKIP_BODY;
-    }
+        if (container != null) {
+            LOG.warn("TilesContainer allready instantiated for this context. Ignoring request to define.");
+            return SKIP_BODY;
+        }
+
+        RuntimeConfiguredContext context =
+            new RuntimeConfiguredContext(pageContext.getServletContext());
+
+        if (containerFactory != null) {
+            context.setInitParameter(
+                TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM,
+                containerFactory);
+        }
+
+        for(Map.Entry<String, String> entry : initParameters.entrySet()) {
+            context.setInitParameter(entry.getKey(), entry.getValue());
+        }
+
+        try {
+            MutableTilesContainer mutableContainer =
+                TilesContainerFactory.getFactory(context)
+                    .createMutableTilesContainer(context);
+            TilesAccess.setContainer(context, mutableContainer);
+        }
+        catch (TilesException e) {
+            throw new JspException("Error creating tiles container.", e);
+        }
 
-    /**
-     * Do end tag.
-     */
-    public int doEndTag() throws JspException {
         return EVAL_PAGE;
-}
+    }
+
+
+
+
+    @SuppressWarnings("deprecated")
+    public class RuntimeConfiguredContext implements ServletContext {
+
+        private ServletContext rootContext;
+        private Map<String, String> initParameters;
+
+
+        public RuntimeConfiguredContext(ServletContext rootContext) {
+            this.rootContext = rootContext;
+            this.initParameters = new HashMap<String, String>();
+        }
+
+        public ServletContext getContext(String string) {
+            return rootContext.getContext(string);
+        }
+
+        public int getMajorVersion() {
+            return rootContext.getMajorVersion();
+        }
+
+        public int getMinorVersion() {
+            return rootContext.getMinorVersion();
+        }
+
+        public String getMimeType(String string) {
+            return rootContext.getMimeType(string);
+        }
+
+        public Set getResourcePaths(String string) {
+            return rootContext.getResourcePaths(string);
+        }
+
+        public URL getResource(String string) throws MalformedURLException {
+            return rootContext.getResource(string);
+        }
+
+        public InputStream getResourceAsStream(String string) {
+            return rootContext.getResourceAsStream(string);
+        }
+
+        public RequestDispatcher getRequestDispatcher(String string) {
+            return rootContext.getRequestDispatcher(string);
+        }
+
+        public RequestDispatcher getNamedDispatcher(String string) {
+            return rootContext.getNamedDispatcher(string);
+        }
+
+        public Servlet getServlet(String string) throws ServletException {
+            return rootContext.getServlet(string);
+        }
+
+        public Enumeration getServlets() {
+            return rootContext.getServlets();
+        }
+
+        public Enumeration getServletNames() {
+            return rootContext.getServletNames();
+        }
+
+        public void log(String string) {
+            rootContext.log(string);
+        }
+
+        public void log(Exception exception, String string) {
+            rootContext.log(exception, string);
+        }
+
+        public void log(String string, Throwable throwable) {
+            rootContext.log(string, throwable);
+        }
+
+        public String getRealPath(String string) {
+            return rootContext.getRealPath(string);
+        }
+
+        public String getServerInfo() {
+            return rootContext.getServerInfo();
+        }
+
+        public String getInitParameter(String string) {
+            if (initParameters.containsKey(string)) {
+                return initParameters.get(string);
+            }
+            return rootContext.getInitParameter(string);
+        }
+
+        public void setInitParameter(String name, String value) {
+            initParameters.put(name, value);
+        }
+
+        public Enumeration getInitParameterNames() {
+            return rootContext.getInitParameterNames();
+        }
+
+        public Object getAttribute(String string) {
+            return rootContext.getAttribute(string);
+        }
+
+        public Enumeration getAttributeNames() {
+            return rootContext.getAttributeNames();
+        }
+
+        public void setAttribute(String string, Object object) {
+            rootContext.setAttribute(string, object);
+        }
+
+        public void removeAttribute(String string) {
+            rootContext.removeAttribute(string);
+        }
+
+        public String getServletContextName() {
+            return rootContext.getServletContextName();
+        }
+    }
 
 }

Propchange: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld Thu Nov  9 08:23:57 2006
@@ -19,8 +19,8 @@
  * under the License.
  */
 -->
-<!DOCTYPE taglib PUBLIC 
-    "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 
+<!DOCTYPE taglib PUBLIC
+    "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
     "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
 <taglib>
    <tlib-version>2.0</tlib-version>
@@ -715,43 +715,43 @@
       </attribute>
    </tag>
    <tag>
-      <name>initComponentDefinitions</name>
-      <tag-class>org.apache.tiles.taglib.definition.InitDefinitionsTag</tag-class>
-      <body-content>empty</body-content>
+      <!-- <name>initComponentDefinitions</name> -->
+       <name>initContainer</name>
+      <tag-class>org.apache.tiles.taglib.definition.InitContainerTag</tag-class>
+      <body-content>JSP</body-content>
       <description>
       <![CDATA[
-      <p><strong>Initialize Tile/Component definitions factory.</strong></p>
+      <p><strong>Initialize the TilesContainer.</strong></p>
       <p>
-      In order to use Tile/Component definitions factory, you need to initialize the factory.
-      This is generally done in a initializing servlet. In particular, it is done in
-      "ComponentActionServlet" if you use it.
-      If you don't initialize factory in a servlet, you can initialize it using this tag. You need
-      to provide the description file name, and optionally the factory classname.
-      Initialization is done only once, at the first call of this tag. Subsequent calls
-      are ignored (tag checks existence of the factory.
+      In order to use the Tiles system, a TilesContainer must be instantiated.
+      This initialization is generally done by the TilesListener (or perhaps the
+      TilesServlet or TilesFilter).
+      </p>
+      <p>
+      If the intialization needs to be dynamic, you can initialize the container using
+      this tag.  Realize however, that this tag MUST be executed prior to invoking
+      any other definitions.  Additionally, the initilization may only be done once,
+      and any subsequent invocations will be ignored.
       </p>
       ]]>
       </description>
       <attribute>
-         <name>file</name>
-         <required>true</required>
-         <rtexprvalue>true</rtexprvalue>
-         <description>
-         <![CDATA[
-         <p>Definition file name.</p>
-         ]]>
-         </description>
-      </attribute>
-      <attribute>
-         <name>classname</name>
+         <name>containerFactory</name>
          <required>false</required>
          <rtexprvalue>true</rtexprvalue>
-         <description>
-         <![CDATA[
-         <p>If specified, classname of the factory to create and initialized.</p>
-         ]]>
-         </description>
+         <description> <![CDATA[ <p>Container Factory implementation used to instantiate the container.</p> ]]> </description>
       </attribute>
    </tag>
+
+    <tag>
+        <name>destroyContainer</name>
+        <tag-class>org.apache.tiles.taglib.definition.DestroyContainerTag</tag-class>
+        <body-content>empty</body-content>
+        <description>
+            <![CDATA[
+            <p><strong>Destroy the TilesContainer.</strong></p>
+            ]]>
+        </description>
+    </tag>
 </taglib>
 

Modified: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml (original)
+++ struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/WEB-INF/web.xml Thu Nov  9 08:23:57 2006
@@ -1,25 +1,4 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- *
- */
--->
 
 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -31,6 +10,11 @@
     <context-param>
         <param-name>org.apache.tiles.CONTEXT_FACTORY</param-name>
         <param-value>org.apache.tiles.context.enhanced.EnhancedContextFactory</param-value>
+    </context-param>
+
+    <context-param>
+        <param-name>org.apache.tiles.CONTAINER_FACTORY.mutable</param-name>
+        <param-value>true</param-value>
     </context-param>
   
   <!-- Standard Action Servlet Configuration -->

Modified: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp?view=diff&rev=472961&r1=472960&r2=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp (original)
+++ struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/index.jsp Thu Nov  9 08:23:57 2006
@@ -41,6 +41,9 @@
     <a href="testimportattribute.jsp">Test importAttribute Tag</a><br/>
     <a href="testimportattribute_all.jsp">Test importAttribute Tag with no name</a><br/>
 
+    <h2>Container Management Tags</h2>
+    <a href="testinitcontainer.jsp">Test Initialize Container</a><br/>
+
     <h2>Currently not working tests</h2>
     <a href="testdef.jsp">Test Definition Tag</a><br/>
     <!-- Currently all the tests work.-->

Added: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp?view=auto&rev=472961
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp (added)
+++ struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp Thu Nov  9 08:23:57 2006
@@ -0,0 +1,12 @@
+<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:destroyContainer/>
+<tiles:initContainer containerFactory="org.apache.tiles.factory.TilesContainerFactory">
+    <tiles:put name="definitions-config" value="/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml"/>
+    <tiles:put name="org.apache.tiles.CONTEXT_FACTORY"
+               value="org.apache.tiles.context.enhanced.EnhancedContextFactory"/>
+    <tiles:put name="org.apache.tiles.CONTAINER_FACTORY.mutable"
+               value="true"/>
+</tiles:initContainer>
+
+<tiles:insertDefinition name="test.definition" />

Propchange: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/sandbox/trunk/tiles/tiles-test/src/main/webapp/testinitcontainer.jsp
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev