You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/04/15 05:26:58 UTC
svn commit: r528918 -
/incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java
Author: ehillenius
Date: Sat Apr 14 20:26:57 2007
New Revision: 528918
URL: http://svn.apache.org/viewvc?view=rev&rev=528918
Log:
sorted members
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java?view=diff&rev=528918&r1=528917&r2=528918
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/protocol/http/request/WebRequestCodingStrategy.java Sat Apr 14 20:26:57 2007
@@ -48,25 +48,161 @@
IRequestTargetMountsInfo
{
/**
- * map of path mounts for mount encoders on paths.
- * <p>
- * mountsOnPath is sorted by longest paths first to improve resolution of
- * possible path conflicts. <br />
- * For example: <br/> we mount Page1 on /page and Page2 on /page/test <br />
- * Page1 uses a parameters encoder that only encodes parameter values <br />
- * now suppose we want to access Page1 with a single paramter param="test".
- * we have a url collision since both pages can be access with /page/test
- * <br />
- * the sorting by longest path first guarantees that the iterator will
- * return the mount /page/test before it returns mount /page therefore
- * giving deterministic behavior to path resolution by always trying to
- * match the longest possible path first.
- * </p>
+ * Map used to store mount paths and their corresponding url coding
+ * strategies.
+ *
+ * @author ivaynberg
*/
- private final MountsMap mountsOnPath;
+ private static class MountsMap
+ {
+ /** Comparator implementation that sorts longest strings first */
+ private static final Comparator<String> LENGTH_COMPARATOR = new Comparator<String>()
+ {
+ public int compare(String o1, String o2)
+ {
+ if (o1 == o2)
+ {
+ return 0;
+ }
+ else if (o1 == null)
+ {
+ return 1;
+ }
+ else if (o2 == null)
+ {
+ return -1;
+ }
+ else
+ {
+ return o2.compareTo(o1);
+ }
+ }
+ };
- /** cached url prefix. */
- private CharSequence urlPrefix;
+ private static final long serialVersionUID = 1L;
+
+ /** case sensitive flag */
+ private final boolean caseSensitiveMounts;
+
+ /** backing map */
+ private final TreeMap<String, IRequestTargetUrlCodingStrategy> map;
+
+ /**
+ * Constructor
+ *
+ * @param caseSensitiveMounts
+ * whether or not keys of this map are case-sensitive
+ */
+ public MountsMap(boolean caseSensitiveMounts)
+ {
+ map = new TreeMap<String, IRequestTargetUrlCodingStrategy>(LENGTH_COMPARATOR);
+ this.caseSensitiveMounts = caseSensitiveMounts;
+ }
+
+
+ /**
+ * Associates a mount with a coding strategy
+ *
+ * @param mount
+ * @param encoder
+ * @return previous coding strategy associated with the mount, or null
+ * if none
+ */
+ public IRequestTargetUrlCodingStrategy mount(String mount,
+ IRequestTargetUrlCodingStrategy encoder)
+ {
+ if (caseSensitiveMounts == false && mount != null)
+ {
+ mount = mount.toLowerCase();
+ }
+ return map.put(mount, encoder);
+ }
+
+ /**
+ * @return number of mounts in the map
+ */
+ public int size()
+ {
+ return map.size();
+ }
+
+
+ /**
+ * @return collection of coding strategies associated with every mount
+ */
+ public Collection<IRequestTargetUrlCodingStrategy> strategies()
+ {
+ return map.values();
+ }
+
+
+ /**
+ * Gets the coding strategy for the specified mount path
+ *
+ * @param mount
+ * mount paht
+ * @return associated coding strategy or null if none
+ */
+ public IRequestTargetUrlCodingStrategy strategyForMount(String mount)
+ {
+ if (caseSensitiveMounts == false && mount != null)
+ {
+ mount = mount.toLowerCase();
+ }
+
+ return map.get(mount);
+ }
+
+ /**
+ * Checks if the specified path matches any mount, and if so returns the
+ * coding strategy for that mount. Returns null if the path doesnt match
+ * any mounts.
+ *
+ * NOTE: path here is not the mount - it is the full url path
+ *
+ * @param path
+ * non-null url path
+ * @return coding strategy or null
+ */
+ public IRequestTargetUrlCodingStrategy strategyForPath(String path)
+ {
+ if (path == null)
+ {
+ throw new IllegalArgumentException("Argument [[path]] cannot be null");
+ }
+ if (caseSensitiveMounts == false)
+ {
+ path = path.toLowerCase();
+ }
+ for (final Iterator it = map.entrySet().iterator(); it.hasNext();)
+ {
+ final Map.Entry entry = (Entry)it.next();
+ final String key = (String)entry.getKey();
+ if (path.startsWith(key))
+ {
+ return (IRequestTargetUrlCodingStrategy)entry.getValue();
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Removes mount from the map
+ *
+ * @param mount
+ */
+ public void unmount(String mount)
+ {
+ if (caseSensitiveMounts == false && mount != null)
+ {
+ mount = mount.toLowerCase();
+ }
+
+ map.remove(mount);
+ }
+
+ }
/**
* Various settings used to configure this strategy
@@ -79,27 +215,48 @@
private boolean mountsCaseSensitive = true;
/**
- * Sets mountsCaseSensitive.
+ * Gets caseSensitive.
*
- * @param mountsCaseSensitive
- * mountsCaseSensitive
+ * @return caseSensitive
*/
- public void setMountsCaseSensitive(boolean mountsCaseSensitive)
+ public boolean areMountsCaseSensitive()
{
- this.mountsCaseSensitive = mountsCaseSensitive;
+ return mountsCaseSensitive;
}
/**
- * Gets caseSensitive.
+ * Sets mountsCaseSensitive.
*
- * @return caseSensitive
+ * @param mountsCaseSensitive
+ * mountsCaseSensitive
*/
- public boolean areMountsCaseSensitive()
+ public void setMountsCaseSensitive(boolean mountsCaseSensitive)
{
- return mountsCaseSensitive;
+ this.mountsCaseSensitive = mountsCaseSensitive;
}
}
+ /**
+ * map of path mounts for mount encoders on paths.
+ * <p>
+ * mountsOnPath is sorted by longest paths first to improve resolution of
+ * possible path conflicts. <br />
+ * For example: <br/> we mount Page1 on /page and Page2 on /page/test <br />
+ * Page1 uses a parameters encoder that only encodes parameter values <br />
+ * now suppose we want to access Page1 with a single paramter param="test".
+ * we have a url collision since both pages can be access with /page/test
+ * <br />
+ * the sorting by longest path first guarantees that the iterator will
+ * return the mount /page/test before it returns mount /page therefore
+ * giving deterministic behavior to path resolution by always trying to
+ * match the longest possible path first.
+ * </p>
+ */
+ private final MountsMap mountsOnPath;
+
+
+ /** cached url prefix. */
+ private CharSequence urlPrefix;
/**
* Construct.
@@ -191,6 +348,28 @@
}
/**
+ * Gets the mount encoder for the given request target if any.
+ *
+ * @param requestTarget
+ * the request target to match
+ * @return the mount encoder if any
+ */
+ protected IRequestTargetUrlCodingStrategy getMountEncoder(IRequestTarget requestTarget)
+ {
+ // TODO Post 1.2: Performance: Optimize algorithm if possible and/ or
+ // cache lookup results
+ for (IRequestTargetUrlCodingStrategy encoder : mountsOnPath.strategies())
+ {
+ if (encoder.matches(requestTarget))
+ {
+ return encoder;
+ }
+ }
+
+ return null;
+ }
+
+ /**
* @see wicket.request.IRequestTargetMountsInfo#listMounts()
*/
public IRequestTargetUrlCodingStrategy[] listMounts()
@@ -290,28 +469,6 @@
}
/**
- * Gets the mount encoder for the given request target if any.
- *
- * @param requestTarget
- * the request target to match
- * @return the mount encoder if any
- */
- protected IRequestTargetUrlCodingStrategy getMountEncoder(IRequestTarget requestTarget)
- {
- // TODO Post 1.2: Performance: Optimize algorithm if possible and/ or
- // cache lookup results
- for (IRequestTargetUrlCodingStrategy encoder : mountsOnPath.strategies())
- {
- if (encoder.matches(requestTarget))
- {
- return encoder;
- }
- }
-
- return null;
- }
-
- /**
* Gets prefix.
*
* @param requestCycle
@@ -327,162 +484,5 @@
urlPrefix = WebApplication.get().getRootPath();
}
return urlPrefix;
- }
-
- /**
- * Map used to store mount paths and their corresponding url coding
- * strategies.
- *
- * @author ivaynberg
- */
- private static class MountsMap
- {
- private static final long serialVersionUID = 1L;
-
- /** case sensitive flag */
- private final boolean caseSensitiveMounts;
-
- /** backing map */
- private final TreeMap<String, IRequestTargetUrlCodingStrategy> map;
-
- /**
- * Constructor
- *
- * @param caseSensitiveMounts
- * whether or not keys of this map are case-sensitive
- */
- public MountsMap(boolean caseSensitiveMounts)
- {
- map = new TreeMap<String, IRequestTargetUrlCodingStrategy>(LENGTH_COMPARATOR);
- this.caseSensitiveMounts = caseSensitiveMounts;
- }
-
- /**
- * Checks if the specified path matches any mount, and if so returns the
- * coding strategy for that mount. Returns null if the path doesnt match
- * any mounts.
- *
- * NOTE: path here is not the mount - it is the full url path
- *
- * @param path
- * non-null url path
- * @return coding strategy or null
- */
- public IRequestTargetUrlCodingStrategy strategyForPath(String path)
- {
- if (path == null)
- {
- throw new IllegalArgumentException("Argument [[path]] cannot be null");
- }
- if (caseSensitiveMounts == false)
- {
- path = path.toLowerCase();
- }
- for (final Iterator it = map.entrySet().iterator(); it.hasNext();)
- {
- final Map.Entry entry = (Entry)it.next();
- final String key = (String)entry.getKey();
- if (path.startsWith(key))
- {
- return (IRequestTargetUrlCodingStrategy)entry.getValue();
- }
- }
- return null;
- }
-
-
- /**
- * @return number of mounts in the map
- */
- public int size()
- {
- return map.size();
- }
-
- /**
- * @return collection of coding strategies associated with every mount
- */
- public Collection<IRequestTargetUrlCodingStrategy> strategies()
- {
- return map.values();
- }
-
-
- /**
- * Removes mount from the map
- *
- * @param mount
- */
- public void unmount(String mount)
- {
- if (caseSensitiveMounts == false && mount != null)
- {
- mount = mount.toLowerCase();
- }
-
- map.remove(mount);
- }
-
-
- /**
- * Gets the coding strategy for the specified mount path
- *
- * @param mount
- * mount paht
- * @return associated coding strategy or null if none
- */
- public IRequestTargetUrlCodingStrategy strategyForMount(String mount)
- {
- if (caseSensitiveMounts == false && mount != null)
- {
- mount = mount.toLowerCase();
- }
-
- return map.get(mount);
- }
-
- /**
- * Associates a mount with a coding strategy
- *
- * @param mount
- * @param encoder
- * @return previous coding strategy associated with the mount, or null
- * if none
- */
- public IRequestTargetUrlCodingStrategy mount(String mount,
- IRequestTargetUrlCodingStrategy encoder)
- {
- if (caseSensitiveMounts == false && mount != null)
- {
- mount = mount.toLowerCase();
- }
- return map.put(mount, encoder);
- }
-
-
- /** Comparator implementation that sorts longest strings first */
- private static final Comparator<String> LENGTH_COMPARATOR = new Comparator<String>()
- {
- public int compare(String o1, String o2)
- {
- if (o1 == o2)
- {
- return 0;
- }
- else if (o1 == null)
- {
- return 1;
- }
- else if (o2 == null)
- {
- return -1;
- }
- else
- {
- return o2.compareTo(o1);
- }
- }
- };
-
}
}