Restore MountMapper and related classes as deprecated.

They are not used and will be removed in Wicket 8.0.0 but can stay until then 
for easier migration to 7.x


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/972c7152
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/972c7152
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/972c7152

Branch: refs/heads/master
Commit: 972c71522caddfa3c6836dafab6831a9643cbd08
Parents: 7c2f79a
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Sun Feb 2 10:21:11 2014 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Sun Feb 2 10:21:11 2014 +0100

----------------------------------------------------------------------
 .../mapper/mount/IMountedRequestMapper.java     |  70 ++++++++
 .../wicket/request/mapper/mount/Mount.java      |  73 ++++++++
 .../request/mapper/mount/MountMapper.java       | 174 +++++++++++++++++++
 .../request/mapper/mount/MountParameters.java   | 121 +++++++++++++
 .../mapper/mount/UnmountedMapperAdapter.java    |  80 +++++++++
 .../mount/UnmountedRequestHandlerAdapter.java   |  77 ++++++++
 6 files changed, 595 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/972c7152/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/IMountedRequestMapper.java
----------------------------------------------------------------------
diff --git 
a/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/IMountedRequestMapper.java
 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/IMountedRequestMapper.java
new file mode 100644
index 0000000..3100b78
--- /dev/null
+++ 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/IMountedRequestMapper.java
@@ -0,0 +1,70 @@
+/*
+ * 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.mount;
+
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.Request;
+
+/**
+ * TODO javadoc, explain "parameters resolved from the mount"
+ * 
+ * @author igor.vaynberg
+ * @deprecated Will be removed in Wicket 8.0
+ */
+@Deprecated
+public interface IMountedRequestMapper
+{
+       /**
+        * Returns {@link org.apache.wicket.request.IRequestHandler} for the 
request or <code>null</code> if the encoder does not
+        * recognize the URL.
+        *
+        * @param request
+        *            provides access to request data (i.e. Url and Parameters)
+        * @param mountParams
+        *            parameters resolved from the mount
+        * @return RequestHandler instance or <code>null</code>
+        */
+       IRequestHandler mapRequest(Request request, MountParameters 
mountParams);
+
+       /**
+        * Returns the score representing how compatible this request mapper is 
to processing the given
+        * request. When a request comes in all mappers are scored and are 
tried in order from highest
+        * score to lowest.
+        * <p>
+        * A good criteria for calculating the score is the number of matched 
url segments. For example
+        * when there are two encoders for mounted page, one mapped to 
<code>/foo</code> another to
+        * <code>/foo/bar</code> and the incomming reqest URL is 
</code>/foo/bar/baz</code>, the encoder
+        * mapped to <code>/foo/bar</code> will handle the request first as it 
has matching segments
+        * count of 2 while the first one has only matching segments count of 1.
+        * <p>
+        * Note that the method can return value greater then zero even if the 
encoder can not decode
+        * the request.
+        *
+        * @param request
+        * @return count of matching segments
+        */
+       int getCompatibilityScore(Request request);
+
+       /**
+        * Returns the {@link Mount} for given {@link 
org.apache.wicket.request.IRequestHandler} or <code>null</code> if the
+        * encoder does not recognize the request handler.
+        * 
+        * @param requestHandler
+        * @return Url instance or <code>null</code>.
+        */
+       Mount mapHandler(IRequestHandler requestHandler);
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/972c7152/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/Mount.java
----------------------------------------------------------------------
diff --git 
a/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/Mount.java
 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/Mount.java
new file mode 100644
index 0000000..5040bf7
--- /dev/null
+++ 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/Mount.java
@@ -0,0 +1,73 @@
+/*
+ * 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.mount;
+
+import org.apache.wicket.request.Url;
+
+/**
+ * @deprecated Will be removed in Wicket 8.0
+ */
+@Deprecated
+public class Mount
+{
+       /**
+        * The {@link org.apache.wicket.request.Url} to mount on
+        */
+       private final Url url;
+
+       /**
+        * A map of placeholder key/value pairs for the {@link #url}'s segments
+        */
+       private MountParameters mountParameters = new MountParameters();
+
+       /**
+        * Construct.
+        * 
+        * @param url
+        */
+       public Mount(final Url url)
+       {
+               this.url = url;
+       }
+
+       /**
+        * 
+        * @param mountParameters
+        */
+       public void setMountParameters(final MountParameters mountParameters)
+       {
+               this.mountParameters = mountParameters;
+       }
+
+       /**
+        * 
+        * @return mount parameters
+        */
+       public MountParameters getMountParameters()
+       {
+               return mountParameters;
+       }
+
+       /**
+        * 
+        * @return Url
+        */
+       public Url getUrl()
+       {
+               return url;
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/972c7152/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountMapper.java
----------------------------------------------------------------------
diff --git 
a/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountMapper.java
 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountMapper.java
new file mode 100644
index 0000000..40d0edd
--- /dev/null
+++ 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountMapper.java
@@ -0,0 +1,174 @@
+/*
+ * 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.mount;
+
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.IRequestMapper;
+import org.apache.wicket.request.Request;
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.mapper.AbstractMapper;
+import org.apache.wicket.util.lang.Args;
+import org.apache.wicket.util.lang.Checks;
+import org.apache.wicket.util.string.StringValue;
+
+/**
+ * {@link org.apache.wicket.request.IRequestMapper} that can mount requests 
onto urls. TODO docs and unit test
+ *
+ * @author igor.vaynberg
+ * @deprecated Will be removed in Wicket 8.0
+ */
+@Deprecated
+public class MountMapper extends AbstractMapper
+{
+       private final String[] mountSegments;
+       private final IMountedRequestMapper mapper;
+
+       /**
+        * Construct.
+        *
+        * @param mountPath
+        * @param mapper
+        */
+       public MountMapper(final String mountPath, final IMountedRequestMapper 
mapper)
+       {
+               Args.notEmpty(mountPath, "mountPath");
+               Args.notNull(mapper, "mapper");
+
+               mountSegments = getMountSegments(mountPath);
+               this.mapper = mapper;
+       }
+
+       /**
+        * Construct.
+        *
+        * @param mountPath
+        * @param mapper
+        */
+       public MountMapper(final String mountPath, final IRequestMapper mapper)
+       {
+               Args.notEmpty(mountPath, "mountPath");
+               Args.notNull(mapper, "mapper");
+
+               mountSegments = getMountSegments(mountPath);
+               this.mapper = new UnmountedMapperAdapter(mapper);
+       }
+
+       /**
+        * Construct.
+        *
+        * @param mountPath
+        * @param handler
+        */
+       public MountMapper(final String mountPath, final IRequestHandler 
handler)
+       {
+               Args.notEmpty(mountPath, "mountPath");
+               Args.notNull(handler, "handler");
+
+               mountSegments = getMountSegments(mountPath);
+               mapper = new UnmountedRequestHandlerAdapter(handler);
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.IRequestMapper#getCompatibilityScore(org.apache.wicket.request.Request)
+        */
+       @Override
+       public int getCompatibilityScore(final Request request)
+       {
+               if (urlStartsWith(request.getUrl(), mountSegments))
+               {
+                       return mountSegments.length + 
mapper.getCompatibilityScore(dismountRequest(request));
+               }
+               else
+               {
+                       return 0;
+               }
+       }
+
+       /**
+        *
+        * @param request
+        *            a {@link org.apache.wicket.request.Request} with the all 
mount segments - mount ones and the ones for the
+        *            delegated mapper
+        * @return a {@link org.apache.wicket.request.Request} with {@link 
org.apache.wicket.request.Url} without the mount segments
+        */
+       private Request dismountRequest(final Request request)
+       {
+               Url dismountedUrl = new Url(request.getUrl());
+               dismountedUrl.removeLeadingSegments(mountSegments.length);
+               return request.cloneWithUrl(dismountedUrl);
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
+        */
+       @Override
+       public final IRequestHandler mapRequest(final Request request)
+       {
+               final Url url = request.getUrl();
+
+               if ((url.getSegments().size() >= mountSegments.length) && 
urlStartsWith(url, mountSegments))
+               {
+                       MountParameters params = new MountParameters();
+                       for (int i = 0; i < mountSegments.length; i++)
+                       {
+                               String placeholder = 
getPlaceholder(mountSegments[i]);
+                               if (placeholder != null)
+                               {
+                                       params.setValue(placeholder, 
StringValue.valueOf(url.getSegments().get(i)));
+                               }
+                       }
+
+                       return mapper.mapRequest(dismountRequest(request), 
params);
+               }
+
+               return null;
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.IRequestMapper#mapHandler(org.apache.wicket.request.IRequestHandler)
+        */
+       @Override
+       public Url mapHandler(final IRequestHandler handler)
+       {
+               Mount mount = mapper.mapHandler(handler);
+               if (mount == null)
+               {
+                       return null;
+               }
+
+               Checks.notNull(mount.getUrl(), "Mount's Url should not be 
null");
+               Checks.notNull(mount.getMountParameters(), "Mount's parameters 
should not be null");
+
+               for (int i = mountSegments.length; i > 0; i--)
+               {
+                       String segment = mountSegments[i - 1];
+                       String placeholder = getPlaceholder(segment);
+                       String replacement = segment;
+
+                       if (placeholder != null)
+                       {
+                               replacement = 
mount.getMountParameters().getValue(placeholder).toString();
+                               Checks.notNull(replacement, "Cannot find a 
value for placeholder '%s'.",
+                                               placeholder);
+                       }
+
+                       mount.getUrl().getSegments().add(0, replacement);
+               }
+
+               return mount.getUrl();
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/972c7152/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountParameters.java
----------------------------------------------------------------------
diff --git 
a/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountParameters.java
 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountParameters.java
new file mode 100644
index 0000000..f5340fb
--- /dev/null
+++ 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/MountParameters.java
@@ -0,0 +1,121 @@
+/*
+ * 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.mount;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.wicket.util.string.StringValue;
+
+/**
+ * A container for the placeholders (e.g. ${placeholder}) found in the mount 
segments
+ * 
+ * @author igor.vaynberg
+ * @deprecated Will be removed in Wicket 8.0
+ */
+@Deprecated
+public class MountParameters
+{
+       private final Map<String, String> map = new HashMap<>();
+
+       /**
+        * 
+        * @param parameterName
+        *            the name of the placeholder
+        * @return a StringValue which contains either the actual value if 
there is a placeholder with
+        *         name <code>parameterName</code> or <code>null</code> 
otherwise
+        */
+       public final StringValue getValue(final String parameterName)
+       {
+               return StringValue.valueOf(map.get(parameterName));
+       }
+
+       /**
+        * Sets new placeholder name/pair
+        * 
+        * @param parameterName
+        * @param value
+        */
+       public final void setValue(final String parameterName, final 
StringValue value)
+       {
+               map.put(parameterName, value.toString());
+       }
+
+       /**
+        * @return an unmodifiable view of the parameters names
+        */
+       public final Collection<String> getParameterNames()
+       {
+               return Collections.unmodifiableCollection(map.keySet());
+       }
+
+       /**
+        * @see java.lang.Object#hashCode()
+        */
+       @Override
+       public int hashCode()
+       {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((map == null) ? 0 : map.hashCode());
+               return result;
+       }
+
+       /**
+        * @see java.lang.Object#equals(java.lang.Object)
+        */
+       @Override
+       public boolean equals(final Object obj)
+       {
+               if (this == obj)
+               {
+                       return true;
+               }
+               if (obj == null)
+               {
+                       return false;
+               }
+               if (getClass() != obj.getClass())
+               {
+                       return false;
+               }
+               MountParameters other = (MountParameters)obj;
+               if (map == null)
+               {
+                       if (other.map != null)
+                       {
+                               return false;
+                       }
+               }
+               else if (!map.equals(other.map))
+               {
+                       return false;
+               }
+               return true;
+       }
+
+       /**
+        * @see java.lang.Object#toString()
+        */
+       @Override
+       public String toString()
+       {
+               return "MountParameters [" + map + "]";
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/972c7152/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedMapperAdapter.java
----------------------------------------------------------------------
diff --git 
a/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedMapperAdapter.java
 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedMapperAdapter.java
new file mode 100644
index 0000000..a969b44
--- /dev/null
+++ 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedMapperAdapter.java
@@ -0,0 +1,80 @@
+/*
+ * 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.mount;
+
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.IRequestMapper;
+import org.apache.wicket.request.Request;
+import org.apache.wicket.request.Url;
+
+/**
+ * Adapts a {@link org.apache.wicket.request.IRequestMapper} to be used as a 
{@link IMountedRequestMapper}
+ * 
+ * TODO javadoc
+ * 
+ * @author igor.vaynberg
+ * @deprecated Will be removed in Wicket 8.0
+ */
+@Deprecated
+class UnmountedMapperAdapter implements IMountedRequestMapper
+{
+       private final IRequestMapper mapper;
+
+       /**
+        * Construct.
+        * 
+        * @param mapper
+        */
+       public UnmountedMapperAdapter(final IRequestMapper mapper)
+       {
+               super();
+               this.mapper = mapper;
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.mapper.mount.IMountedRequestMapper#getCompatibilityScore(org.apache.wicket.request.Request)
+        */
+       @Override
+       public int getCompatibilityScore(final Request request)
+       {
+               return mapper.getCompatibilityScore(request);
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.mapper.mount.IMountedRequestMapper#mapHandler(org.apache.wicket.request.IRequestHandler)
+        */
+       @Override
+       public Mount mapHandler(final IRequestHandler requestHandler)
+       {
+               Url url = mapper.mapHandler(requestHandler);
+               if (url != null)
+               {
+                       return new Mount(url);
+               }
+               return null;
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.mapper.mount.IMountedRequestMapper#mapRequest(org.apache.wicket.request.Request,
+        *      org.apache.wicket.request.mapper.mount.MountParameters)
+        */
+       @Override
+       public IRequestHandler mapRequest(final Request request, final 
MountParameters mountParams)
+       {
+               return mapper.mapRequest(request);
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/972c7152/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedRequestHandlerAdapter.java
----------------------------------------------------------------------
diff --git 
a/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedRequestHandlerAdapter.java
 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedRequestHandlerAdapter.java
new file mode 100644
index 0000000..7c345d5
--- /dev/null
+++ 
b/wicket-request/src/main/java/org/apache/wicket/request/mapper/mount/UnmountedRequestHandlerAdapter.java
@@ -0,0 +1,77 @@
+/*
+ * 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.mount;
+
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.Request;
+import org.apache.wicket.request.Url;
+
+/**
+ * Adapts a singleton {@link org.apache.wicket.request.IRequestHandler} 
instance to {@link IMountedRequestMapper}
+ * 
+ * TODO javadoc
+ * 
+ * @author igor.vaynberg
+ * @deprecated Will be removed in Wicket 8.0
+ */
+@Deprecated
+class UnmountedRequestHandlerAdapter implements IMountedRequestMapper
+{
+       private final IRequestHandler handler;
+
+       /**
+        * Construct.
+        * 
+        * @param handler
+        */
+       public UnmountedRequestHandlerAdapter(final IRequestHandler handler)
+       {
+               this.handler = handler;
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.mapper.mount.IMountedRequestMapper#getCompatibilityScore(org.apache.wicket.request.Request)
+        */
+       @Override
+       public int getCompatibilityScore(final Request request)
+       {
+               return 0;
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.mapper.mount.IMountedRequestMapper#mapHandler(org.apache.wicket.request.IRequestHandler)
+        */
+       @Override
+       public Mount mapHandler(final IRequestHandler requestHandler)
+       {
+               if (requestHandler.equals(handler))
+               {
+                       return new Mount(new Url());
+               }
+               return null;
+       }
+
+       /**
+        * @see 
org.apache.wicket.request.mapper.mount.IMountedRequestMapper#mapRequest(org.apache.wicket.request.Request,
+        *      org.apache.wicket.request.mapper.mount.MountParameters)
+        */
+       @Override
+       public IRequestHandler mapRequest(final Request request, final 
MountParameters mountParams)
+       {
+               return handler;
+       }
+}

Reply via email to