You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2007/03/22 15:49:24 UTC

svn commit: r521297 - in /tiles/framework/trunk/tiles-jsp: ./ src/main/java/org/apache/tiles/jsp/taglib/definition/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/tiles/ src/test/java/org/apache/tiles/def...

Author: apetrelli
Date: Thu Mar 22 07:49:23 2007
New Revision: 521297

URL: http://svn.apache.org/viewvc?view=rev&rev=521297
Log:
TILES-137
Now the init parameters are put into a Hashtable that is populated with init parameters of the root context at creation.
Added a test case.

Added:
    tiles/framework/trunk/tiles-jsp/src/test/
    tiles/framework/trunk/tiles-jsp/src/test/java/
    tiles/framework/trunk/tiles-jsp/src/test/java/org/
    tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/
    tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/
    tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/
    tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java   (with props)
Modified:
    tiles/framework/trunk/tiles-jsp/pom.xml
    tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/InitContainerTag.java

Modified: tiles/framework/trunk/tiles-jsp/pom.xml
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/pom.xml?view=diff&rev=521297&r1=521296&r2=521297
==============================================================================
--- tiles/framework/trunk/tiles-jsp/pom.xml (original)
+++ tiles/framework/trunk/tiles-jsp/pom.xml Thu Mar 22 07:49:23 2007
@@ -210,6 +210,13 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.shale</groupId>
+      <artifactId>shale-test</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
 </project>

Modified: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/InitContainerTag.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/InitContainerTag.java?view=diff&rev=521297&r1=521296&r2=521297
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/InitContainerTag.java (original)
+++ tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/InitContainerTag.java Thu Mar 22 07:49:23 2007
@@ -44,6 +44,8 @@
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -152,7 +154,7 @@
     /**
      * A servlet context created "on the fly" for container initialization.
      */
-    public class RuntimeConfiguredContext implements ServletContext {
+    public static class RuntimeConfiguredContext implements ServletContext {
 
         /**
          * The root servlet context.
@@ -162,7 +164,7 @@
         /**
          * The custom init parameters.
          */
-        private Map<String, String> initParameters;
+        private Hashtable<String, String> initParameters;
 
 
         /**
@@ -170,9 +172,17 @@
          *
          * @param rootContext The "real" servlet context. 
          */
+        @SuppressWarnings("unchecked")
         public RuntimeConfiguredContext(ServletContext rootContext) {
             this.rootContext = rootContext;
-            this.initParameters = new HashMap<String, String>();
+            this.initParameters = new Hashtable<String, String>();
+            Enumeration<String> enumeration = rootContext
+                    .getInitParameterNames();
+            while (enumeration.hasMoreElements()) {
+                String paramName = enumeration.nextElement();
+                initParameters.put(paramName, rootContext
+                        .getInitParameter(paramName));
+            }
         }
 
         /** {@inheritDoc} */
@@ -273,10 +283,7 @@
          * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
          */
         public String getInitParameter(String string) {
-            if (initParameters.containsKey(string)) {
-                return initParameters.get(string);
-            }
-            return rootContext.getInitParameter(string);
+            return initParameters.get(string);
         }
 
         /**
@@ -297,8 +304,7 @@
          */
         @SuppressWarnings("unchecked")
         public Enumeration getInitParameterNames() {
-            // FIXME This implementation is wrong!
-            return rootContext.getInitParameterNames();
+            return initParameters.keys();
         }
 
         /** {@inheritDoc} */
@@ -325,6 +331,49 @@
         /** {@inheritDoc} */
         public String getServletContextName() {
             return rootContext.getServletContextName();
+        }
+
+        /**
+         * Composes an enumeration and an iterator into a single enumeration.
+         */
+        @SuppressWarnings("unchecked")
+        static class CompositeEnumeration implements Enumeration {
+
+            /**
+             * The first enumeration to consider.
+             */
+            private Enumeration first;
+
+            /**
+             * The second enumeration to consider.
+             */
+            private Iterator second;
+
+
+            /**
+             * Constructor.
+             *
+             * @param first The first enumeration to consider.
+             * @param second The second enumeration to consider.
+             */
+            public CompositeEnumeration(Enumeration first, Iterator second) {
+                this.first = first;
+                this.second = second;
+            }
+
+            /** {@inheritDoc} */
+            public boolean hasMoreElements() {
+                return first.hasMoreElements() || second.hasNext();
+            }
+
+            /** {@inheritDoc} */
+            public Object nextElement() {
+                if(first.hasMoreElements()) {
+                    return first.nextElement();
+                }
+
+                return second.next();
+            }
         }
     }
 

Added: tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java?view=auto&rev=521297
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java (added)
+++ tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java Thu Mar 22 07:49:23 2007
@@ -0,0 +1,79 @@
+/*
+ * $Id$
+ *
+ * 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.definition;
+
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.shale.test.mock.MockServletContext;
+import org.apache.tiles.jsp.taglib.definition.InitContainerTag.RuntimeConfiguredContext;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests {@link RuntimeConfiguredContext}
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestRuntimeConfiguredContext extends TestCase {
+    
+    /**
+     * The context to test.
+     */
+    RuntimeConfiguredContext context;
+    
+    /** {@inheritDoc} */
+    @Override
+    protected void setUp() throws Exception {
+        MockServletContext rootContext = new MockServletContext();
+        rootContext.addInitParameter("initParameter1", "parameterValue1");
+        rootContext.addInitParameter("initParameter2", "parameterValue2");
+        context = new RuntimeConfiguredContext(rootContext);
+        context.setInitParameter("initParameter1", "newParameterValue1");
+        context.setInitParameter("newInitParameter", "newParameterValue2");
+    }
+
+    /**
+     * Test init parameters.
+     */
+    @SuppressWarnings("unchecked")
+    public void testGetInitParameters() {
+        assertEquals(context.getInitParameter("initParameter1"), "newParameterValue1");
+        assertEquals(context.getInitParameter("initParameter2"), "parameterValue2");
+        assertEquals(context.getInitParameter("newInitParameter"), "newParameterValue2");
+        
+        Set<String> paramSet = new HashSet<String>();
+        paramSet.add("initParameter1");
+        paramSet.add("initParameter2");
+        paramSet.add("newInitParameter");
+        Enumeration<String> names = context.getInitParameterNames();
+        while (names.hasMoreElements()) {
+            String name = names.nextElement();
+            assertTrue(paramSet.contains(name));
+            paramSet.remove(name);
+        }
+        
+        assertTrue(paramSet.isEmpty());
+    }
+
+}

Propchange: tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/definition/TestRuntimeConfiguredContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL