Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A69266CB2 for ; Tue, 24 May 2011 12:25:55 +0000 (UTC) Received: (qmail 48609 invoked by uid 500); 24 May 2011 12:25:55 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 48578 invoked by uid 500); 24 May 2011 12:25:55 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 48571 invoked by uid 99); 24 May 2011 12:25:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 May 2011 12:25:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 May 2011 12:25:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D46C923889BF; Tue, 24 May 2011 12:25:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1127002 - in /jackrabbit/branches/2.1: ./ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/ jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/ jackrabbit-spi-commons/src/test... Date: Tue, 24 May 2011 12:25:26 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110524122526.D46C923889BF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Tue May 24 12:25:26 2011 New Revision: 1127002 URL: http://svn.apache.org/viewvc?rev=1127002&view=rev Log: 2.1: Merged revision 1126998 (JCR-2953) Modified: jackrabbit/branches/2.1/ (props changed) jackrabbit/branches/2.1/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java Propchange: jackrabbit/branches/2.1/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue May 24 12:25:26 2011 @@ -1,6 +1,6 @@ /jackrabbit/branches/1.5:794012,794100,794102 -/jackrabbit/branches/2.2:1065610,1067910,1071647,1071665,1071668,1089453 +/jackrabbit/branches/2.2:1065610,1067910,1071647,1071665,1071668,1089453,1126998 /jackrabbit/sandbox/JCR-1456:774917-886178 /jackrabbit/sandbox/JCR-2170:812417-816332 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863 -/jackrabbit/trunk:931121,931479,931483-931484,931504,931609,931613,931838,931919,932318-932319,933144,933197,933203,933213,933216,933554,933646,933694,934405,934412,934849,935557,936668,938099,945528,950440,950680,955222,955229,955307,955852,961487,961626,964362,965539,986682,986686,986715,991144,995411-995412,996810,999298-999299,999965,1000947,1001707,1002065-1002066,1002084,1002101-1002102,1002168,1002170,1002589,1002608,1002657,1002729,1003423,1003470,1003542,1003773,1004182,1004184,1004223-1004224,1004652,1005057,1005112,1036117,1036336-1036337,1038201,1039064,1039423,1040090,1065599,1069831,1071562,1071573,1087304,1089436 +/jackrabbit/trunk:931121,931479,931483-931484,931504,931609,931613,931838,931919,932318-932319,933144,933197,933203,933213,933216,933554,933646,933694,934405,934412,934849,935557,936668,938099,945528,950440,950680,955222,955229,955307,955852,961487,961626,964362,965539,986682,986686,986715,991144,995411-995412,996810,999298-999299,999965,1000947,1001707,1002065-1002066,1002084,1002101-1002102,1002168,1002170,1002589,1002608,1002657,1002729,1003423,1003470,1003542,1003773,1004182,1004184,1004223-1004224,1004652,1005057,1005112,1036117,1036336-1036337,1038201,1039064,1039423,1040090,1065599,1069831,1071562,1071573,1087304,1089436,1104027 Modified: jackrabbit/branches/2.1/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java?rev=1127002&r1=1127001&r2=1127002&view=diff ============================================================================== --- jackrabbit/branches/2.1/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java (original) +++ jackrabbit/branches/2.1/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java Tue May 24 12:25:26 2011 @@ -174,7 +174,7 @@ public class PathParser { /** * Parses the given jcrPath and returns a Path. If * parent is not null, it is prepended to the - * built path before it is returned. If the specifed jcrPath + * built path before it is returned. If the specified jcrPath * is an identifier based absolute path beginning with an identifier segment * the given identifierResolver will be used to resolve it to an * absolute path.

@@ -406,8 +406,14 @@ public class PathParser { throw new MalformedPathException("'" + jcrPath + "' is not a valid path. '" + c + "' not a valid name character."); } case '{': - if (state == STATE_PREFIX_START) { + if (state == STATE_PREFIX_START && lastPos == pos-1) { + // '{' marks the start of a uri enclosed in an expanded name + // instead of the usual namespace prefix, if it is + // located at the beginning of a new segment. state = STATE_URI; + } else if (state == STATE_NAME_START || state == STATE_DOT || state == STATE_DOTDOT) { + // otherwise it's part of the local name + state = STATE_NAME; } break; Modified: jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java?rev=1127002&r1=1127001&r2=1127002&view=diff ============================================================================== --- jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java (original) +++ jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java Tue May 24 12:25:26 2011 @@ -42,10 +42,9 @@ public class NameParserTest extends Test public void testParse() throws Exception { - for (int i=0; i1) { - System.out.println("testCreate():\t" + t + "\t" + (t2-t1) + "\tms"); + if (NUM_TESTS > 1) { + System.out.println("testCreate():\t" + t + "\t" + (t2 - t1) + "\tms"); } } } public void testCheckFormat() throws Exception { - for (int i=0; i1) { - System.out.println("testCheckFormat():\t" + t + "\t" + (t2-t1) + "\tms"); + if (NUM_TESTS > 1) { + System.out.println("testCheckFormat():\t" + t + "\t" + (t2 - t1) + "\tms"); } } } @@ -94,7 +92,7 @@ public class NameParserTest extends Test public void testExpandedJcrNames() throws NamespaceException, IllegalNameException { NamespaceResolver resolver = new TestNamespaceResolver(); - List valid = new ArrayList(); + List valid = new ArrayList(); // valid qualified jcr-names: // String-array consisting of { jcrName , uri , localName } valid.add(new String[] {"abc:{c}", "abc", "{c}"}); @@ -116,6 +114,7 @@ public class NameParserTest extends Test // unknown uri -> but valid non-prefixed jcr-name valid.add(new String[] {"{test}abc", "", "{test}abc"}); valid.add(new String[] {"{ab}", "", "{ab}"}); + valid.add(new String[] {".{.}", "", ".{.}"}); // valid expanded jcr-names: // String-array consisting of { jcrName , uri , localName } @@ -126,8 +125,8 @@ public class NameParserTest extends Test valid.add(new String[] {"{abc:}def", "abc:", "def"}); valid.add(new String[] {"{}abc", "", "abc"}); - for (Iterator it = valid.iterator(); it.hasNext();) { - String[] strs = (String[]) it.next(); + for (Object aValid : valid) { + String[] strs = (String[]) aValid; try { Name n = NameParser.parse(strs[0], resolver, factory); assertEquals("URI mismatch", strs[1], n.getNamespaceURI()); @@ -138,7 +137,7 @@ public class NameParserTest extends Test } // invalid jcr-names (neither expanded nor qualified form) - List invalid = new ArrayList(); + List invalid = new ArrayList(); // invalid prefix invalid.add("{a:b"); invalid.add("}a:b"); @@ -159,8 +158,8 @@ public class NameParserTest extends Test invalid.add("{http://jackrabbit.apache.org}"); invalid.add("{}"); - for (Iterator it = invalid.iterator(); it.hasNext();) { - String jcrName = (String) it.next(); + for (Object anInvalid : invalid) { + String jcrName = (String) anInvalid; try { NameParser.parse(jcrName, resolver, factory); fail("Parsing '" + jcrName + "' should fail. Not a valid jcr name."); @@ -171,9 +170,7 @@ public class NameParserTest extends Test } public void testCheckFormatOfExpandedNames() throws NamespaceException, IllegalNameException { - NamespaceResolver resolver = new TestNamespaceResolver(); - - List valid = new ArrayList(); + List valid = new ArrayList(); // valid qualified jcr-names: // String-array consisting of { jcrName , uri , localName } valid.add(new String[] {"abc:{c}", "abc", "{c}"}); @@ -203,8 +200,8 @@ public class NameParserTest extends Test valid.add(new String[] {"{abc}def", "abc", "def"}); valid.add(new String[] {"{}abc", "", "abc"}); - for (Iterator it = valid.iterator(); it.hasNext();) { - String[] strs = (String[]) it.next(); + for (Object aValid : valid) { + String[] strs = (String[]) aValid; try { NameParser.checkFormat(strs[0]); } catch (Exception e) { @@ -213,7 +210,7 @@ public class NameParserTest extends Test } // invalid jcr-names (neither expanded nor qualified form) - List invalid = new ArrayList(); + List invalid = new ArrayList(); // invalid prefix invalid.add("{a:b"); invalid.add("}a:b"); @@ -234,8 +231,8 @@ public class NameParserTest extends Test invalid.add("{/jackrabbit/a/b/c}abc"); - for (Iterator it = invalid.iterator(); it.hasNext();) { - String jcrName = (String) it.next(); + for (Object anInvalid : invalid) { + String jcrName = (String) anInvalid; try { NameParser.checkFormat(jcrName); fail("Checking format of '" + jcrName + "' should fail. Not a valid jcr name."); @@ -273,4 +270,4 @@ public class NameParserTest extends Test } } } -} \ No newline at end of file +} Modified: jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java?rev=1127002&r1=1127001&r2=1127002&view=diff ============================================================================== --- jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java (original) +++ jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java Tue May 24 12:25:26 2011 @@ -19,15 +19,19 @@ package org.apache.jackrabbit.spi.common import junit.framework.TestCase; import java.util.ArrayList; -import java.util.Iterator; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.apache.jackrabbit.spi.Name; import org.apache.jackrabbit.spi.commons.name.JcrPath; import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl; import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl; import org.apache.jackrabbit.spi.Path; import org.apache.jackrabbit.spi.PathFactory; +import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver; +import javax.jcr.NamespaceException; import javax.jcr.RepositoryException; /** @@ -49,17 +53,16 @@ public class PathParserTest extends Test } public void testParse() throws Exception { - for (int i=0; i1) { - System.out.println("testCreate():\t" + t + "\t" + (t2-t1) + "\tms"); + if (NUM_TESTS > 1) { + System.out.println("testCreate():\t" + t + "\t" + (t2 - t1) + "\tms"); } } } public void testCheckFormat() throws Exception { - for (int i=0; i1) { - System.out.println("testCheckFormat():\t" + t + "\t" + (t2-t1) + "\tms"); + if (NUM_TESTS > 1) { + System.out.println("testCheckFormat():\t" + t + "\t" + (t2 - t1) + "\tms"); } } } public void testNormalizedPaths() throws Exception { - List paths = new ArrayList(); + List paths = new ArrayList(); // normalized paths paths.add(PathParser.parse("/", resolver, factory)); paths.add(PathParser.parse("/foo", resolver, factory)); @@ -120,8 +122,7 @@ public class PathParserTest extends Test paths.add(PathParser.parse("..", resolver, factory)); paths.add(PathParser.parse(".", resolver, factory)); - for (Iterator it = paths.iterator(); it.hasNext(); ) { - Path path = (Path) it.next(); + for (Path path : paths) { assertTrue("path is not normalized: " + path, path.isNormalized()); } @@ -137,14 +138,13 @@ public class PathParserTest extends Test paths.add(PathParser.parse("../foo/..", resolver, factory)); paths.add(PathParser.parse("../foo/.", resolver, factory)); - for (Iterator it = paths.iterator(); it.hasNext(); ) { - Path path = (Path) it.next(); + for (Path path : paths) { assertFalse("path is normalized: " + path, path.isNormalized()); } } public void testAbsolutePaths() throws Exception { - List paths = new ArrayList(); + List paths = new ArrayList(); // absolute paths paths.add(PathParser.parse("/", resolver, factory)); @@ -155,8 +155,7 @@ public class PathParserTest extends Test paths.add(PathParser.parse("/foo/./bar", resolver, factory)); paths.add(PathParser.parse("/foo/.././bar/./foo", resolver, factory)); - for (Iterator it = paths.iterator(); it.hasNext(); ) { - Path path = (Path) it.next(); + for (Path path : paths) { assertTrue("path is not absolute: " + path, path.isAbsolute()); } @@ -173,22 +172,113 @@ public class PathParserTest extends Test paths.add(PathParser.parse("../foo/..", resolver, factory)); paths.add(PathParser.parse("../foo/.", resolver, factory)); - for (Iterator it = paths.iterator(); it.hasNext(); ) { - Path path = (Path) it.next(); + for (Path path : paths) { assertFalse("path is absolute: " + path, path.isAbsolute()); } } + public void testExpandedPaths() throws Exception { + Map paths = new HashMap(); + + NameResolver ns = new ParsingNameResolver(NameFactoryImpl.getInstance(), new TestNamespaceResolver()); + PathResolver ps = new ParsingPathResolver(factory, ns); + + // expanded paths + paths.put("/",PathParser.parse("/", ns, factory)); + paths.put("/foo",PathParser.parse("/{}foo", ns, factory)); + paths.put("/a:foo/a:bar",PathParser.parse("/{http://jackrabbit.apache.org}foo/{http://jackrabbit.apache.org}bar", ns, factory)); + paths.put("/a:foo/../a:bar",PathParser.parse("/{http://jackrabbit.apache.org}foo/../{http://jackrabbit.apache.org}bar", ns, factory)); + paths.put("/foo/..",PathParser.parse("/{}foo/..", ns, factory)); + paths.put("/a:foo/./a:bar",PathParser.parse("/{http://jackrabbit.apache.org}foo/./{http://jackrabbit.apache.org}bar", ns, factory)); + paths.put("/a:foo/.././a:bar/./a:foo",PathParser.parse("/{http://jackrabbit.apache.org}foo/.././{http://jackrabbit.apache.org}bar/./{http://jackrabbit.apache.org}foo", resolver, factory)); + paths.put("/foo/.{a}/a:b",PathParser.parse("/{}foo/{}.{a}/{http://jackrabbit.apache.org}b", ns, factory)); + paths.put("/foo/.{.}/a:c",PathParser.parse("/{}foo/{}.{.}/{http://jackrabbit.apache.org}c", ns, factory)); + paths.put("foo/.{.}/a:c",PathParser.parse("{}foo/{}.{.}/{http://jackrabbit.apache.org}c", ns, factory)); + + for (String key : paths.keySet()) { + Path path = paths.get(key); + assertEquals(key, ps.getJCRPath(path)); + } + } + + public void testJCRPaths() throws Exception { + Map paths = new HashMap(); + paths.put("/",PathParser.parse("/", resolver, factory)); + paths.put("/foo",PathParser.parse("/foo", resolver, factory)); + paths.put("/a:foo/a:bar",PathParser.parse("/a:foo/a:bar", resolver, factory)); + paths.put("/a:foo/../a:bar",PathParser.parse("/a:foo/../a:bar", resolver, factory)); + paths.put("/a:foo/..",PathParser.parse("/a:foo/..", resolver, factory)); + paths.put("/a:foo/./a:bar",PathParser.parse("/a:foo/./a:bar", resolver, factory)); + paths.put("/a:foo/.././a:bar/./a:foo",PathParser.parse("/a:foo/.././a:bar/./a:foo", resolver, factory)); + paths.put("foo/..",PathParser.parse("foo/..", resolver, factory)); + paths.put("foo/.",PathParser.parse("foo/.", resolver, factory)); + paths.put("foo/../bar",PathParser.parse("foo/../bar", resolver, factory)); + paths.put("foo/./bar",PathParser.parse("foo/./bar", resolver, factory)); + paths.put("./foo",PathParser.parse("./foo", resolver, factory)); + paths.put(".",PathParser.parse(".", resolver, factory)); + paths.put("foo/..",PathParser.parse("foo/..", resolver, factory)); + paths.put("../foo/..",PathParser.parse("../foo/..", resolver, factory)); + paths.put("../foo/.",PathParser.parse("../foo/.", resolver, factory)); + paths.put("/foo/.{a}/a:b",PathParser.parse("/foo/.{a}/a:b", resolver, factory)); + paths.put("/a:foo/.{.}/a:c",PathParser.parse("/a:foo/.{.}/a:c", resolver, factory)); + paths.put("/a:foo/{.}/a:c",PathParser.parse("/a:foo/{.}/a:c", resolver, factory)); + paths.put("/a:foo/{..}/a:c",PathParser.parse("/a:foo/{..}/a:c", resolver, factory)); + paths.put("/a:foo/{...}/a:c",PathParser.parse("/a:foo/{...}/a:c", resolver, factory)); + paths.put("/a:foo/.{.}/a:c",PathParser.parse("/a:foo/.{.}/a:c", resolver, factory)); + paths.put("/a:foo/.{.}/a:c",PathParser.parse("/a:foo/.{.}/a:c", resolver, factory)); + paths.put(".{a}",PathParser.parse(".{a}", resolver, factory)); + paths.put(".{.}",PathParser.parse(".{.}", resolver, factory)); + paths.put("..{.}",PathParser.parse("..{.}", resolver, factory)); + paths.put("..{..}",PathParser.parse("..{..}", resolver, factory)); + paths.put(".{...}",PathParser.parse(".{...}", resolver, factory)); + paths.put("{...}",PathParser.parse("{...}", resolver, factory)); + paths.put("...",PathParser.parse("...", resolver, factory)); + paths.put("a:.{.}",PathParser.parse("a:.{.}", resolver, factory)); + paths.put("..{a}",PathParser.parse("..{a}", resolver, factory)); + paths.put(".{..}",PathParser.parse(".{..}", resolver, factory)); + paths.put("a:..{.}",PathParser.parse("a:..{.}", resolver, factory)); + paths.put("a:.{..}",PathParser.parse("a:.{..}", resolver, factory)); + paths.put("a:..{..}",PathParser.parse("a:..{..}", resolver, factory)); + paths.put(".a",PathParser.parse(".a", resolver, factory)); + paths.put("..a",PathParser.parse("..a", resolver, factory)); + + for (String key : paths.keySet()) { + Path path = paths.get(key); + assertEquals(key, pathResolver.getJCRPath(path)); + } + } + + public void testInvalidJCRPaths() throws Exception { + List paths = new ArrayList(); + paths.add("/a:.."); + paths.add("/a:."); + paths.add("/a::"); + paths.add("/a:{:a}"); + paths.add("/.{:a}"); + paths.add("/.{a:a}"); + paths.add("/:"); + paths.add("/*"); + paths.add("//"); + + for (String jcrPath : paths) { + try { + PathParser.parse(jcrPath, resolver, factory); + fail(jcrPath + " isn't a valid jcr path"); + } catch (MalformedPathException e) { + // ok. + } + } + } + public void testCanonicalPaths() throws Exception { - List paths = new ArrayList(); + List paths = new ArrayList(); // canonical paths paths.add(PathParser.parse("/", resolver, factory)); paths.add(PathParser.parse("/foo", resolver, factory)); paths.add(PathParser.parse("/foo/bar", resolver, factory)); - for (Iterator it = paths.iterator(); it.hasNext(); ) { - Path path = (Path) it.next(); + for (Path path : paths) { assertTrue("path is not canonical: " + path, path.isCanonical()); } @@ -204,18 +294,17 @@ public class PathParserTest extends Test paths.add(PathParser.parse("/foo/..", resolver, factory)); paths.add(PathParser.parse("/../foo/.", resolver, factory)); - for (Iterator it = paths.iterator(); it.hasNext(); ) { - Path path = (Path) it.next(); + for (Path path : paths) { assertFalse("path is canonical: " + path, path.isCanonical()); } } public void testIdentifierParse() throws RepositoryException { DummyIdentifierResolver idResolver = new DummyIdentifierResolver(); - List valid = idResolver.getValidIdentifiers(); - for (Iterator it = valid.iterator(); it.hasNext();) { - String jcrPath = "[" + it.next() + "]"; - try { + List valid = idResolver.getValidIdentifiers(); + for (String id : valid) { + String jcrPath = "[" + id + "]"; + try { PathParser.parse(jcrPath, resolver, factory); fail("Parsing an identifier-based jcr path needs a IdentifierResolver"); } catch (MalformedPathException e) { @@ -250,20 +339,46 @@ public class PathParserTest extends Test } } + public void testIdentifierParseWithTrailingString() throws RepositoryException { + List suffix = new ArrayList(); + suffix.add("/"); // additional path delimiter + suffix.add("/property"); // additional path segment + suffix.add("suffix"); // trailing string + suffix.add("[1]"); // an index + + DummyIdentifierResolver idResolver = new DummyIdentifierResolver(); + List valid = idResolver.getValidIdentifiers(); + for (String id : valid) { + for (String s : suffix) { + String jcrPath = "[" + id + "]" + s; + try { + PathParser.parse(jcrPath, resolver, idResolver, factory, true); + } catch (MalformedPathException e) { + // success + } + + try { + PathParser.parse(jcrPath, resolver, idResolver, factory, false); + } catch (MalformedPathException e) { + // success + } + } + } + } + public void testInvalidIdentifierParse() throws RepositoryException { DummyIdentifierResolver idResolver = new DummyIdentifierResolver(); - List invalid = idResolver.getInvalidIdentifierPaths(); - for (Iterator it = invalid.iterator(); it.hasNext();) { - String jcrPath = it.next().toString(); + List invalid = idResolver.getInvalidIdentifierPaths(); + for (String jcrPath : invalid) { try { - Path p = PathParser.parse(jcrPath, resolver, idResolver, factory, true); + PathParser.parse(jcrPath, resolver, idResolver, factory, true); fail("Invalid identifier based path"); } catch (MalformedPathException e) { // ok } try { - Path p = PathParser.parse(jcrPath, resolver, idResolver, factory, false); + PathParser.parse(jcrPath, resolver, idResolver, factory, false); fail("Invalid identifier based path"); } catch (MalformedPathException e) { // ok @@ -273,15 +388,14 @@ public class PathParserTest extends Test public void testIdentifierCheckFormat() throws RepositoryException { DummyIdentifierResolver idResolver = new DummyIdentifierResolver(); - List valid = idResolver.getValidIdentifiers(); - for (Iterator it = valid.iterator(); it.hasNext();) { - String jcrPath = "[" + it.next() + "]"; + List valid = idResolver.getValidIdentifiers(); + for (String id : valid) { + String jcrPath = "[" + id + "]"; PathParser.checkFormat(jcrPath); } - List invalid = idResolver.getInvalidIdentifierFormats(); - for (Iterator it = invalid.iterator(); it.hasNext();) { - String jcrPath = it.next().toString(); + List invalid = idResolver.getInvalidIdentifierFormats(); + for (String jcrPath : invalid) { try { // passing null-nameResolver -> executes check-format only PathParser.checkFormat(jcrPath); @@ -291,4 +405,34 @@ public class PathParserTest extends Test } } } + + + /** + * Dummy NamespaceResolver that only knows the empty namespace and + * namespaces containing either 'jackrabbit' or 'abc'. Used to test + * the parsing of the expanded jcr names, which should treat a jcr name with + * unknown namespace uri qualified jcr names. + */ + private class TestNamespaceResolver implements NamespaceResolver { + + public String getURI(String prefix) throws NamespaceException { + if (Name.NS_EMPTY_PREFIX.equals(prefix)) { + return Name.NS_DEFAULT_URI; + } else if ("a".equals(prefix)) { + return "http://jackrabbit.apache.org"; + } else { + throw new NamespaceException("Unknown namespace prefix " + prefix); + } + } + + public String getPrefix(String uri) throws NamespaceException { + if (Name.NS_DEFAULT_URI.equals(uri)) { + return Name.NS_EMPTY_PREFIX; + } else if ("http://jackrabbit.apache.org".equals(uri)) { + return "a"; + } else { + throw new NamespaceException("Unknown namespace prefix " + uri); + } + } + } } Modified: jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java?rev=1127002&r1=1127001&r2=1127002&view=diff ============================================================================== --- jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java (original) +++ jackrabbit/branches/2.1/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java Tue May 24 12:25:26 2011 @@ -61,11 +61,10 @@ public class PathTest extends TestCase { } public void testGetAncestor() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path); if (p.getNormalizedPath().denotesRoot()) { continue; } @@ -78,11 +77,8 @@ public class PathTest extends TestCase { } public void testGetAncestorOfRelativePath() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - int degree = 5; - for (int i = 0; i < tests.length; i++) { - JcrPath test = tests[i]; + for (JcrPath test : tests) { if (test.isValid() && !test.isAbsolute()) { Path p = resolver.getQPath(test.path); @@ -97,10 +93,8 @@ public class PathTest extends TestCase { } public void testGetAncestorAtDegreeDepth() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - JcrPath test = tests[i]; + for (JcrPath test : tests) { if (test.isValid() && test.isAbsolute()) { Path p = resolver.getQPath(test.path); @@ -113,11 +107,10 @@ public class PathTest extends TestCase { } public void testGetAncestorIsAncestor() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path); while (!p.getNormalizedPath().denotesRoot()) { Path ancestor = p.getAncestor(1); assertTrue(ancestor.isAncestorOf(p)); @@ -128,8 +121,8 @@ public class PathTest extends TestCase { } public void testGetAncestorOfRelativePath2() throws RepositoryException { - for (Iterator it = JcrPathAndAncestor.list.iterator(); it.hasNext();) { - JcrPathAndAncestor tp = (JcrPathAndAncestor) it.next(); + for (Object aList : JcrPathAndAncestor.list) { + JcrPathAndAncestor tp = (JcrPathAndAncestor) aList; Path ancestor = resolver.getQPath(tp.ancestor).getNormalizedPath(); Path p = resolver.getQPath(tp.path); @@ -139,19 +132,15 @@ public class PathTest extends TestCase { } public void testGetAncestorReturnsNormalized() throws RepositoryException { - List tests = JcrPathAndAncestor.list; - for (Iterator it = tests.iterator(); it.hasNext();) { - JcrPathAndAncestor test = (JcrPathAndAncestor) it.next(); - + List tests = JcrPathAndAncestor.list; + for (JcrPathAndAncestor test : tests) { Path p = resolver.getQPath(test.path); assertTrue(p.getAncestor(test.degree).isNormalized()); } } public void testIsAncestorOfRelativePath() throws RepositoryException { - for (Iterator it = JcrPathAndAncestor.list.iterator(); it.hasNext();) { - JcrPathAndAncestor tp = (JcrPathAndAncestor) it.next(); - + for (JcrPathAndAncestor tp : JcrPathAndAncestor.list) { Path ancestor = resolver.getQPath(tp.ancestor); Path p = resolver.getQPath(tp.path); @@ -168,11 +157,11 @@ public class PathTest extends TestCase { public void testAbsolutePathIsDescendantOfRoot() throws RepositoryException { Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path).getNormalizedPath(); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path).getNormalizedPath(); if (!p.equals(root)) { - assertTrue(tests[i].path + " must be decendant of the root path.",p.isDescendantOf(root)); + assertTrue(test.path + " must be decendant of the root path.", p.isDescendantOf(root)); } } } @@ -181,9 +170,9 @@ public class PathTest extends TestCase { public void testRootIsAncestorOfAbsolutePath() throws RepositoryException { Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path).getNormalizedPath(); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path).getNormalizedPath(); if (!p.equals(root)) { assertFalse(p.isAncestorOf(root)); } @@ -193,17 +182,16 @@ public class PathTest extends TestCase { public void testIsEquivalentToSelf() throws RepositoryException { JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid()) { + Path p = resolver.getQPath(test.path); assertTrue(p.isEquivalentTo(p)); } } } public void testIsEquivalentTo() throws IllegalArgumentException, RepositoryException { - for (Iterator it = Equivalent.list.iterator(); it.hasNext();) { - Equivalent tp = (Equivalent) it.next(); + for (Equivalent tp : Equivalent.list) { Path path = resolver.getQPath(tp.path); Path other = resolver.getQPath(tp.other); @@ -222,10 +210,10 @@ public class PathTest extends TestCase { Path absPath = factory.getRootPath(); Path relPath = factory.create(NameConstants.JCR_DATA); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid()) { - Path p = resolver.getQPath(tests[i].path).getNormalizedPath(); - if (tests[i].isAbsolute()) { + for (JcrPath test : tests) { + if (test.isValid()) { + Path p = resolver.getQPath(test.path).getNormalizedPath(); + if (test.isAbsolute()) { if (absPath.isAncestorOf(p)) { assertTrue(p.isDescendantOf(absPath)); } else { @@ -265,9 +253,9 @@ public class PathTest extends TestCase { Path rel = factory.create(NameConstants.JCR_DATA); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path).getNormalizedPath(); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path).getNormalizedPath(); try { if (p.isAbsolute()) { p.isDescendantOf(rel); @@ -303,9 +291,9 @@ public class PathTest extends TestCase { Path rel = factory.create(NameConstants.JCR_DATA); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path).getNormalizedPath(); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path).getNormalizedPath(); try { if (p.isAbsolute()) { p.isAncestorOf(rel); @@ -321,55 +309,50 @@ public class PathTest extends TestCase { } public void testAbsolutePaths() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); - assertTrue("Path must be absolute " + tests[i].path, p.isAbsolute()); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path); + assertTrue("Path must be absolute " + test.path, p.isAbsolute()); } } } public void testNotAbsolutePaths() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && !tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); - assertFalse("Path must not be absolute " + tests[i].path, p.isAbsolute()); + for (JcrPath test : tests) { + if (test.isValid() && !test.isAbsolute()) { + Path p = resolver.getQPath(test.path); + assertFalse("Path must not be absolute " + test.path, p.isAbsolute()); } } } public void testCanonicalPaths() throws Exception { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path);; - if (!tests[i].isNormalized()) { + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path); + if (!test.isNormalized()) { p = p.getNormalizedPath(); } - assertTrue("Path must be canonical " + tests[i].path, p.isCanonical()); + assertTrue("Path must be canonical " + test.path, p.isCanonical()); } } } public void testNotCanonicalPaths() throws Exception { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && (!tests[i].isNormalized() || !tests[i].isAbsolute())) { - Path p = resolver.getQPath(tests[i].path); - assertFalse("Path must not be canonical " + tests[i].path, p.isCanonical()); + for (JcrPath test : tests) { + if (test.isValid() && (!test.isNormalized() || !test.isAbsolute())) { + Path p = resolver.getQPath(test.path); + assertFalse("Path must not be canonical " + test.path, p.isCanonical()); } } } public void testIsNotAncestor() throws RepositoryException { - for (Iterator it = NotAncestor.list.iterator(); it.hasNext();) { - NotAncestor test = (NotAncestor) it.next(); + for (NotAncestor test : NotAncestor.list) { Path p = resolver.getQPath(test.path); Path ancestor = resolver.getQPath(test.notAncestor); assertFalse(test.notAncestor + " isn't an ancestor of " + test.path, @@ -378,35 +361,33 @@ public class PathTest extends TestCase { } public void testDepth() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); - String normJcrPath = (tests[i].normalizedPath == null) ? tests[i].path : tests[i].normalizedPath; + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path); + String normJcrPath = (test.normalizedPath == null) ? test.path : test.normalizedPath; int depth = Text.explode(normJcrPath, '/').length; - assertTrue("Depth of " + tests[i].path + " must be " + depth, depth == p.getDepth()); + assertTrue("Depth of " + test.path + " must be " + depth, depth == p.getDepth()); } } } public void testDepthOfRelativePath() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && !tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid() && !test.isAbsolute()) { + Path p = resolver.getQPath(test.path); int depth = Path.ROOT_DEPTH; Path.Element[] elements = p.getNormalizedPath().getElements(); - for (int j = 0; j < elements.length; j++) { - if (elements[j].denotesParent()) { + for (Path.Element element : elements) { + if (element.denotesParent()) { depth--; - } else if (elements[j].denotesName()) { + } else if (element.denotesName()) { depth++; } } //System.out.println("Depth of " + tests[i].path + " = " + depth); - assertTrue("Depth of " + tests[i].path + " must be " + depth, depth == p.getDepth()); + assertTrue("Depth of " + test.path + " must be " + depth, depth == p.getDepth()); } } } @@ -430,22 +411,20 @@ public class PathTest extends TestCase { } public void testAncestorCount() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid() && test.isAbsolute()) { + Path p = resolver.getQPath(test.path); assertTrue("Ancestor count must be same a depth", p.getDepth() == p.getAncestorCount()); } } } public void testAncestorCountOfRelativePath() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && !tests[i].isAbsolute()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid() && !test.isAbsolute()) { + Path p = resolver.getQPath(test.path); assertTrue("Ancestor count or a relative path must be -1", -1 == p.getAncestorCount()); } } @@ -469,69 +448,65 @@ public class PathTest extends TestCase { } public void testLength() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid()) { - int length = Text.explode(tests[i].path, '/').length; - if (tests[i].isAbsolute()) { + for (JcrPath test : tests) { + if (test.isValid()) { + int length = Text.explode(test.path, '/').length; + if (test.isAbsolute()) { length++; } - Path p = resolver.getQPath(tests[i].path); + Path p = resolver.getQPath(test.path); //System.out.println("Length of " + tests[i].path + " = " + length); - assertEquals("Length of " + tests[i].path + " must reflect " + + assertEquals("Length of " + test.path + " must reflect " + "number of elements.", new Integer(length), new Integer(p.getLength())); } } } public void testIsNormalized() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid()) { - Path p = resolver.getQPath(tests[i].path); - if (tests[i].isNormalized()) { - assertTrue("Path " + tests[i].path + " must be normalized.", p.isNormalized()); + for (JcrPath test : tests) { + if (test.isValid()) { + Path p = resolver.getQPath(test.path); + if (test.isNormalized()) { + assertTrue("Path " + test.path + " must be normalized.", p.isNormalized()); } else { - assertFalse("Path " + tests[i].path + " must not be normalized.", p.isNormalized()); + assertFalse("Path " + test.path + " must not be normalized.", p.isNormalized()); } } } } public void testGetNameElement() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid()) { + Path p = resolver.getQPath(test.path); Path.Element nameEl = p.getNameElement(); Path.Element[] all = p.getElements(); - assertEquals(all[all.length-1], nameEl); + assertEquals(all[all.length - 1], nameEl); } } } public void testSubPath() throws RepositoryException { - Path root = factory.getRootPath(); JcrPath[] tests = JcrPath.getTests(); - for (int i = 0; i < tests.length; i++) { - if (tests[i].isValid() && tests[i].isNormalized()) { - Path p = resolver.getQPath(tests[i].path); + for (JcrPath test : tests) { + if (test.isValid() && test.isNormalized()) { + Path p = resolver.getQPath(test.path); // subpath between 0 and length -> equal path assertEquals(p, p.subPath(0, p.getLength())); // subpath a single element if (p.getLength() > 2) { - Path expected = factory.create(new Path.Element[] {p.getElements()[1]}); - assertEquals(expected, p.subPath(1,2)); + Path expected = factory.create(new Path.Element[]{p.getElements()[1]}); + assertEquals(expected, p.subPath(1, 2)); } // subpath name element if (p.getLength() > 2) { Path expected = factory.create(new Path.Element[] {p.getNameElement()}); - assertEquals(expected, p.subPath(p.getLength()-1, p.getLength())); + assertEquals(expected, p.subPath(p.getLength() - 1, p.getLength())); } } } @@ -595,7 +570,7 @@ public class PathTest extends TestCase { this.degree = degree; } - private static List list = new ArrayList(); + private static List list = new ArrayList(); static { // normalized list.add(new JcrPathAndAncestor("abc/def", "abc", 1)); @@ -648,7 +623,7 @@ public class PathTest extends TestCase { this.notAncestor = notAncestor; } - private static List list = new ArrayList(); + private static List list = new ArrayList(); static { // false if same path list.add(new NotAncestor("/", "/")); @@ -720,7 +695,7 @@ public class PathTest extends TestCase { this.isEquivalent = isEquivalent; } - private static List list = new ArrayList(); + private static List list = new ArrayList(); static { list.add(new Equivalent(".", "a/b", false)); list.add(new Equivalent(".", "a/..", true));