jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r756405 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/conversion/ test/java/org/apache/jackrabbit/spi/commons/conversion/ test/java/org/apache/jackrabbit/spi/commons/name/
Date Fri, 20 Mar 2009 10:29:34 GMT
Author: angela
Date: Fri Mar 20 10:29:28 2009
New Revision: 756405

URL: http://svn.apache.org/viewvc?rev=756405&view=rev
Log:
JCR-1712: JCR Names (jsr 283)

- NameParser#checkFormat(String) failed for expanded names (missing check)
- some more tests

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/JcrName.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java?rev=756405&r1=756404&r2=756405&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/NameParser.java
Fri Mar 20 10:29:28 2009
@@ -67,6 +67,7 @@
         int nameStart = 0;
         int state = STATE_PREFIX_START;
         boolean trailingSpaces = false;
+        boolean checkFormat = (resolver == null);
 
         for (int i = 0; i < len; i++) {
             char c = jcrName.charAt(i);
@@ -122,7 +123,9 @@
                         // make sure the uri is a known namespace uri
                         // TODO: since namespace registration does not validate
                         //       the URI format validation is omitted here
-                        resolver.getPrefix(tmp);
+                        if (!checkFormat) {
+                            resolver.getPrefix(tmp);
+                        }
                         uri = tmp;
                         state = STATE_NAME_START;
                     } catch (NamespaceException e) {
@@ -170,7 +173,7 @@
 
         // if namespace is null, this is just a check for format. this can only
         // happen if invoked internally
-        if (resolver == null) {
+        if (checkFormat) {
             return null;
         }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java?rev=756405&r1=756404&r2=756405&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
Fri Mar 20 10:29:28 2009
@@ -172,6 +172,80 @@
         }
     }
 
+    public void testCheckFormatOfExpandedNames() throws NamespaceException, IllegalNameException
{
+        NamespaceResolver resolver = new TestNamespaceResolver();
+
+        List valid = new ArrayList();
+        // valid qualified jcr-names:
+        // String-array consisting of { jcrName , uri , localName }
+        valid.add(new String[] {"abc:{c}", "abc", "{c}"});
+        valid.add(new String[] {"abc:}c", "abc", "}c"});
+        valid.add(new String[] {"abc:c}", "abc", "c}"});
+        valid.add(new String[] {"{ab", "", "{ab"});
+        valid.add(new String[] {"ab}", "", "ab}"});
+        valid.add(new String[] {"a}bc", "", "a}bc"});
+        valid.add(new String[] {"{", "", "{"});
+        valid.add(new String[] {"}", "", "}"});
+        valid.add(new String[] {"abc", "", "abc"});
+        valid.add(new String[] {"abc{abc}", "", "abc{abc}"});
+        valid.add(new String[] {"{{abc}", "", "{{abc}"});
+        valid.add(new String[] {"{abc{abc}", "", "{abc{abc}"});
+        valid.add(new String[] {"abc {", "", "abc {"});
+        valid.add(new String[] {"abc { }", "", "abc { }"});
+        valid.add(new String[] {"{ }abc", "", "{ }abc"});
+        // unknown uri -> but valid non-prefixed jcr-name
+        valid.add(new String[] {"{test}abc", "", "{test}abc"});
+
+        // valid expanded jcr-names:
+        // String-array consisting of { jcrName , uri , localName }
+        valid.add(new String[] {"{http://jackrabbit.apache.org}abc", "http://jackrabbit.apache.org",
"abc"});
+        valid.add(new String[] {"{http://jackrabbit.apache.org:80}abc", "http://jackrabbit.apache.org:80",
"abc"});
+        valid.add(new String[] {"{http://jackrabbit.apache.org/info}abc", "http://jackrabbit.apache.org/info",
"abc"});
+        valid.add(new String[] {"{jcr:jackrabbit}abc", "jcr:jackrabbit", "abc"});
+        valid.add(new String[] {"{/jackrabbit/a/b/c}abc", "/jackrabbit/a/b/c", "abc"});
+        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();
+            try {
+                NameParser.checkFormat(strs[0]);
+            } catch (Exception e) {
+                fail(e.getMessage() + " -> " + strs[0]);
+            }
+        }
+
+        // invalid jcr-names (neither expanded nor qualified form)
+        List invalid = new ArrayList();
+        // invalid prefix
+        invalid.add("{a:b");
+        invalid.add("}a:b");
+        invalid.add("a{b:c");
+        invalid.add("a}b:c");
+        // invalid local name containing '/'
+        invalid.add("{http://jackrabbit.apache.org}abc/dfg");
+        // invalid local name containing ':'
+        invalid.add("{http://jackrabbit.apache.org}abc:dfg");
+        // invalid local name containing ':' and '/'
+        invalid.add("{{http://jackrabbit.apache.org}abc:dfg}");
+        // invalid local name containing '/'
+        invalid.add("/a/b/c");
+        // known uri but local name missing -> must fail.
+        invalid.add("{abc}");
+        invalid.add("{http://jackrabbit.apache.org}");
+        invalid.add("{}");
+
+        for (Iterator it = invalid.iterator(); it.hasNext();) {
+            String jcrName = (String) it.next();
+            try {
+                NameParser.checkFormat(jcrName);
+                fail("Checking format of '" + jcrName + "' should fail. Not a valid jcr name.");
+            } catch (IllegalNameException e) {
+                //ok
+            }
+        }
+    }
+    
     /**
      * Dummy NamespaceResolver that only knows the empty namespace and
      * namespaces containing either 'jackrabbit' or 'abc'. Used to test

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/JcrName.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/JcrName.java?rev=756405&r1=756404&r2=756405&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/JcrName.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/JcrName.java
Fri Mar 20 10:29:28 2009
@@ -39,6 +39,15 @@
         list.add(new JcrName("...", "", "..."));
         list.add(new JcrName(".a.", "", ".a."));
 
+        // expanded names
+        list.add(new JcrName("{}a", "", "a"));
+        list.add(new JcrName("{}name", "", "name"));
+        list.add(new JcrName("{}na me", "", "na me"));
+        list.add(new JcrName("{prefix}name", "prefix", "name"));
+        list.add(new JcrName("{prefix}na me", "prefix", "na me"));        
+        list.add(new JcrName("{}...", "", "..."));
+        list.add(new JcrName("{}.a.", "", ".a."));
+
         // invalid names
         list.add(new JcrName(":name"));
         list.add(new JcrName("."));



Mime
View raw message