Author: thomas.heute(a)jboss.com
Date: 2007-08-15 18:53:02 -0400 (Wed, 15 Aug 2007)
New Revision: 7942
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectPath.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectPathTestCase.java
Log:
JBPORTAL-1614: Allow '.' in username, and portal object names.
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectPath.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectPath.java 2007-08-15
22:48:19 UTC (rev 7941)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectPath.java 2007-08-15
22:53:02 UTC (rev 7942)
@@ -365,7 +365,10 @@
{
break;
}
- length++;
+ if (next > 0 && value.charAt(next-1) != '\\')
+ {
+ length++;
+ }
previous = next + 1;
}
@@ -373,17 +376,26 @@
String[] names = new String[length];
length = 0;
previous = 1;
+ int next = 1;
while (true)
{
- int next = value.indexOf(PATH_SEPARATOR, previous);
+ next = value.indexOf(PATH_SEPARATOR, next);
if (next == -1)
{
break;
}
- names[length++] = value.substring(previous, next);
- previous = next + 1;
+ if (next > 0 && value.charAt(next-1) != '\\')
+ {
+ String name = value.substring(previous, next);
+ name = decodeName(name);
+ names[length++] = name;
+ previous = next + 1;
+ }
+ next++;
}
- names[length] = value.substring(previous);
+ String name = value.substring(previous);
+ name = decodeName(name);
+ names[length] = name;
//
return names;
@@ -406,11 +418,23 @@
{
throw new IllegalArgumentException("No null name expected in the
name string array");
}
+ name = encodeName(name);
tmp.append(PATH_SEPARATOR).append(name);
}
return tmp.toString();
}
}
+
+ protected String decodeName(String name)
+ {
+ return name.replace("\\/", "/");
+ }
+
+ protected String encodeName(String name)
+ {
+ return name.replace("/", "\\/");
+ }
+
}
;
@@ -438,18 +462,25 @@
int length = 1;
for (int next = value.indexOf('.'); next != -1; next =
value.indexOf('.', next + 1))
{
- length++;
+ if (next > 0 && value.charAt(next-1) != '\\')
+ {
+ length++;
+ }
}
//
String[] names = new String[length];
length = 0;
int previous = 0;
- for (int next = value.indexOf('.'); next != -1; previous = next + 1,
next = value.indexOf('.', next + 1))
+ for (int next = value.indexOf('.'); next != -1; next =
value.indexOf('.', next + 1))
{
- String name = value.substring(previous, next);
- name = decodeName(name);
- names[length++] = name;
+ if (next > 0 && value.charAt(next-1) != '\\')
+ {
+ String name = value.substring(previous, next);
+ name = decodeName(name);
+ names[length++] = name;
+ previous = next + 1;
+ }
}
String name = value.substring(previous);
name = decodeName(name);
@@ -490,12 +521,12 @@
protected String decodeName(String name)
{
- return name;
+ return name.replace("\\.", ".");
}
protected String encodeName(String name)
{
- return name;
+ return name.replace(".", "\\.");
}
}
Modified:
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectPathTestCase.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectPathTestCase.java 2007-08-15
22:48:19 UTC (rev 7941)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectPathTestCase.java 2007-08-15
22:53:02 UTC (rev 7942)
@@ -141,6 +141,10 @@
assertEquals(new PortalObjectPath(new String[]{}),
PortalObjectPath.parse("/", PortalObjectPath.CANONICAL_FORMAT));
assertEquals(new PortalObjectPath(new String[]{"a"}),
PortalObjectPath.parse("/a", PortalObjectPath.CANONICAL_FORMAT));
assertEquals(new PortalObjectPath(new String[]{"a","b"}),
PortalObjectPath.parse("/a/b", PortalObjectPath.CANONICAL_FORMAT));
+ assertEquals(new PortalObjectPath(new String[]{"a.b", "c"}),
PortalObjectPath.parse(new PortalObjectPath(new String[]{"a.b",
"c"}).toString(PortalObjectPath.CANONICAL_FORMAT),
PortalObjectPath.CANONICAL_FORMAT));
+ assertEquals(new PortalObjectPath(new String[]{".a.b", "c"}),
PortalObjectPath.parse(new PortalObjectPath(new String[]{".a.b",
"c"}).toString(PortalObjectPath.CANONICAL_FORMAT),
PortalObjectPath.CANONICAL_FORMAT));
+ assertEquals(new PortalObjectPath(new String[]{"\\.a.b/",
"\\c"}), PortalObjectPath.parse(new PortalObjectPath(new
String[]{"\\.a.b/",
"\\c"}).toString(PortalObjectPath.CANONICAL_FORMAT),
PortalObjectPath.CANONICAL_FORMAT));
+ assertEquals(new PortalObjectPath(new String[]{"/"}),
PortalObjectPath.parse(new PortalObjectPath(new
String[]{"/"}).toString(PortalObjectPath.CANONICAL_FORMAT),
PortalObjectPath.CANONICAL_FORMAT));
//
try
@@ -166,6 +170,11 @@
assertEquals(new PortalObjectPath(new String[]{}),
PortalObjectPath.parse("", PortalObjectPath.LEGACY_FORMAT));
assertEquals(new PortalObjectPath(new String[]{"a"}),
PortalObjectPath.parse("a", PortalObjectPath.LEGACY_FORMAT));
assertEquals(new PortalObjectPath(new String[]{"a","b"}),
PortalObjectPath.parse("a.b", PortalObjectPath.LEGACY_FORMAT));
+
+
+ assertEquals(new PortalObjectPath(new String[]{"a.b", "c"}),
PortalObjectPath.parse(new PortalObjectPath(new String[]{"a.b",
"c"}).toString(PortalObjectPath.LEGACY_FORMAT),
PortalObjectPath.LEGACY_FORMAT));
+ assertEquals(new PortalObjectPath(new String[]{".a.b", "c"}),
PortalObjectPath.parse(new PortalObjectPath(new String[]{".a.b",
"c"}).toString(PortalObjectPath.LEGACY_FORMAT),
PortalObjectPath.LEGACY_FORMAT));
+ assertEquals(new PortalObjectPath(new String[]{"\\.a.b/",
"\\c"}), PortalObjectPath.parse(new PortalObjectPath(new
String[]{"\\.a.b/", "\\c"}).toString(PortalObjectPath.LEGACY_FORMAT),
PortalObjectPath.LEGACY_FORMAT));
}
public void testEquals()