[jboss-cvs] JBossAS SVN: r77319 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 21 09:47:49 EDT 2008
Author: alesj
Date: 2008-08-21 09:47:49 -0400 (Thu, 21 Aug 2008)
New Revision: 77319
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextFactory.java
Log:
Extract root url check.
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextFactory.java 2008-08-21 13:40:05 UTC (rev 77318)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextFactory.java 2008-08-21 13:47:49 UTC (rev 77319)
@@ -87,8 +87,20 @@
MemoryContext context = registry.get(host);
return context != null ? context.getVFS() : null;
}
-
+
/**
+ * Is url valid root url.
+ *
+ * @param url the url to check
+ * @return true if url is root url
+ */
+ protected static boolean isValidRootURL(URL url)
+ {
+ String path = url.getPath();
+ return path == null || path.length() == 0 || "/".equals(path);
+ }
+
+ /**
* Creates a new root MemoryContext, or returns an already exixting one of one already
* exists for the name
* @param url The url of the root, we use the 'host' part of the name for indexing the context
@@ -99,9 +111,8 @@
{
try
{
- String urlPath = url.getPath();
- if (urlPath != null && urlPath.length() > 0)
- throw new IllegalArgumentException("Root url cannot contain path - " + urlPath);
+ if (isValidRootURL(url) == false)
+ throw new IllegalArgumentException("Root url cannot contain path - " + url);
String rootName = url.getHost();
MemoryContext ctx = registry.get(rootName);
@@ -164,9 +175,8 @@
*/
public boolean deleteRoot(URL url)
{
- String path = url.getPath();
- if (path != null && path.length() > 0)
- throw new IllegalArgumentException("Root can not contain '/' - " + path);
+ if (isValidRootURL(url) == false)
+ throw new IllegalArgumentException("Root cannot contain path - " + url);
String rootName = url.getHost();
return (registry.remove(rootName) != null);
More information about the jboss-cvs-commits
mailing list