Author: mgrigorov
Date: Tue Jul  5 12:03:43 2011
New Revision: 1143015

URL: http://svn.apache.org/viewvc?rev=1143015&view=rev
Log:
WICKET-3870 Restore the functionality for unmounting already mounted 
IRequestMappers from 1.4


Added:
    
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/mapper/CompoundRequestMapperTest.java
Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
    
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/CompoundRequestMapper.java
    
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/ICompoundRequestMapper.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java?rev=1143015&r1=1143014&r2=1143015&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
 Tue Jul  5 12:03:43 2011
@@ -361,6 +361,17 @@ public abstract class WebApplication ext
        }
 
        /**
+        * Unregisters all {@link IRequestMapper}s which would match on a this 
path
+        * 
+        * @param path
+        *            the path to unmount
+        */
+       public final void unmount(final String path)
+       {
+               getRootRequestMapperAsCompound().unmount(path);
+       }
+
+       /**
         * Partly unmounts/ignores a path that normally would map to another 
mount path. Like
         * mount("/mypage", MyPage.class); and then "/mypage/arealdir" should 
be ignored. This can be
         * done by calling unMount("/mypage/arealdir");

Modified: 
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/CompoundRequestMapper.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/CompoundRequestMapper.java?rev=1143015&r1=1143014&r2=1143015&view=diff
==============================================================================
--- 
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/CompoundRequestMapper.java
 (original)
+++ 
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/CompoundRequestMapper.java
 Tue Jul  5 12:03:43 2011
@@ -16,10 +16,12 @@
  */
 package org.apache.wicket.request.mapper;
 
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.wicket.request.IRequestHandler;
@@ -176,9 +178,65 @@ public class CompoundRequestMapper imple
                return score;
        }
 
-       /** {@inheritDoc} */
        public Iterator<IRequestMapper> iterator()
        {
                return mappers.iterator();
        }
+
+       public void unmount(String path)
+       {
+               final Url url = Url.parse(path);
+               final Request request = createRequest(url);
+
+               for (Iterator<IRequestMapper> itor = iterator(); 
itor.hasNext();)
+               {
+                       IRequestMapper mapper = itor.next();
+                       if (mapper.mapRequest(request) != null)
+                       {
+                               remove(mapper);
+                       }
+               }
+       }
+
+       int size()
+       {
+               return mappers.size();
+       }
+
+       Request createRequest(final Url url)
+       {
+               Request request = new Request()
+               {
+                       @Override
+                       public Url getUrl()
+                       {
+                               return url;
+                       }
+
+                       @Override
+                       public Locale getLocale()
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Object getContainerRequest()
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Url getClientUrl()
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Charset getCharset()
+                       {
+                               return null;
+                       }
+               };
+               return request;
+       }
 }

Modified: 
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/ICompoundRequestMapper.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/ICompoundRequestMapper.java?rev=1143015&r1=1143014&r2=1143015&view=diff
==============================================================================
--- 
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/ICompoundRequestMapper.java
 (original)
+++ 
wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/mapper/ICompoundRequestMapper.java
 Tue Jul  5 12:03:43 2011
@@ -41,4 +41,12 @@ public interface ICompoundRequestMapper 
         * @return {@code this} for chaining
         */
        ICompoundRequestMapper remove(IRequestMapper encoder);
+
+       /**
+        * Unregisters all {@link IRequestMapper}s which would match on a this 
path
+        * 
+        * @param path
+        *            the path to unmount
+        */
+       void unmount(String path);
 }
\ No newline at end of file

Added: 
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/mapper/CompoundRequestMapperTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/mapper/CompoundRequestMapperTest.java?rev=1143015&view=auto
==============================================================================
--- 
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/mapper/CompoundRequestMapperTest.java
 (added)
+++ 
wicket/trunk/wicket-request/src/test/java/org/apache/wicket/request/mapper/CompoundRequestMapperTest.java
 Tue Jul  5 12:03:43 2011
@@ -0,0 +1,62 @@
+/*
+ * 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.wicket.request.mapper;
+
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.handler.EmptyRequestHandler;
+import org.apache.wicket.request.mapper.mount.MountMapper;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for {@link CompoundRequestMapper}
+ */
+public class CompoundRequestMapperTest extends Assert
+{
+
+       private static final String MOUNT_PATH_3 = "mount/path/3";
+       private static final String MOUNT_PATH_2 = "mount/path/2";
+       private static final String MOUNT_PATH_1 = "mount/path/1";
+
+       /**
+        * 
+        */
+       @Test
+       public void unmount()
+       {
+               CompoundRequestMapper compound = new CompoundRequestMapper();
+
+               compound.add(new MountMapper(MOUNT_PATH_1, new 
EmptyRequestHandler()));
+               compound.add(new MountMapper(MOUNT_PATH_2, new 
EmptyRequestHandler()));
+               compound.add(new MountMapper(MOUNT_PATH_3, new 
EmptyRequestHandler()));
+
+               assertEquals(3, compound.size());
+
+               compound.unmount(MOUNT_PATH_2);
+               assertEquals(2, compound.size());
+
+               assertTrue(
+                       "Mount path 1 should match",
+                       
compound.mapRequest(compound.createRequest(Url.parse(MOUNT_PATH_1))) instanceof 
EmptyRequestHandler);
+               assertNull("Mount path 2 should not match",
+                       
compound.mapRequest(compound.createRequest(Url.parse(MOUNT_PATH_2))));
+               assertTrue(
+                       "Mount path 3 should match",
+                       
compound.mapRequest(compound.createRequest(Url.parse(MOUNT_PATH_3))) instanceof 
EmptyRequestHandler);
+       }
+
+}


Reply via email to