jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r154876 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/Path.java java/org/apache/jackrabbit/core/util/ValueHelper.java test/org/apache/jackrabbit/core/PathTest.java
Date Tue, 22 Feb 2005 17:12:43 GMT
Author: stefan
Date: Tue Feb 22 09:12:41 2005
New Revision: 154876

URL: http://svn.apache.org/viewcvs?view=rev&rev=154876
Log:
fixing Path testcase

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ValueHelper.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/PathTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java?view=diff&r1=154875&r2=154876
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Path.java Tue Feb 22 09:12:41
2005
@@ -151,7 +151,7 @@
         this.normalized = isNormalized;
     }
 
-    //----------------------------------------------------< factory methods >---
+    //------------------------------------------------------< factory methods >
     /**
      * Creates a new <code>Path</code> from the given <code>jcrPath</code>
      * string. If <code>normalize</code> is <code>true</code>, the
returned
@@ -283,6 +283,135 @@
         return new Path(new PathElement[]{elem}, !elem.equals(CURRENT_ELEMENT));
     }
 
+    //-------------------------------------------------------< implementation >
+    /**
+     * Parses the give string an d returns an array of path elements. if
+     * <code>master</code> is not <code>null</code>, it is prepended
to the
+     * returned list. If <code>resolver</code> is <code>null</code>,
this
+     * method only checks the format of the string and returns <code>null</code>.
+     *
+     * @param jcrPath
+     * @param master
+     * @param resolver
+     * @return
+     * @throws MalformedPathException
+     */
+    private static Path parse(String jcrPath, Path master, NamespaceResolver resolver)
+            throws MalformedPathException {
+        // shortcut
+        if ("/".equals(jcrPath)) {
+            return ROOT;
+        }
+
+        // split path into path elements
+        String[] elems = Text.explode(jcrPath, '/', true);
+        if (elems.length == 0) {
+            throw new MalformedPathException("empty path");
+        }
+
+        ArrayList list = new ArrayList();
+        boolean isNormalized = true;
+        boolean leadingParent = true;
+        if (master != null) {
+            isNormalized = master.normalized;
+            // a master path was specified; the 'path' argument is assumed
+            // to be a relative path
+            for (int i = 0; i < master.elements.length; i++) {
+                list.add(master.elements[i]);
+                leadingParent &= master.elements[i].denotesParent();
+            }
+        }
+
+        for (int i = 0; i < elems.length; i++) {
+            // validate & parse path element
+            String prefix;
+            String localName;
+            int index;
+
+            String elem = elems[i];
+            if (i == 0 && elem.length() == 0) {
+                // path is absolute, i.e. the first element is the root element
+                if (!list.isEmpty()) {
+                    throw new MalformedPathException("'" + jcrPath + "' is not a relative
path");
+                }
+                list.add(ROOT_ELEMENT);
+                leadingParent = false;
+                continue;
+            }
+            Matcher matcher = PATH_ELEMENT_PATTERN.matcher(elem);
+            if (matcher.matches()) {
+                if (resolver == null) {
+                    // check only
+                    continue;
+                }
+
+                if (matcher.group(1) != null) {
+                    // group 1 is .
+                    list.add(CURRENT_ELEMENT);
+                    leadingParent = false;
+                    isNormalized = false;
+                } else if (matcher.group(2) != null) {
+                    // group 2 is ..
+                    list.add(PARENT_ELEMENT);
+                    isNormalized &= leadingParent;
+                } else {
+                    // element is a name
+
+                    // check for prefix (group 3)
+                    if (matcher.group(3) != null) {
+                        // prefix specified
+                        // group 4 is namespace prefix excl. delimiter (colon)
+                        prefix = matcher.group(4);
+                        // check if the prefix is a valid XML prefix
+                        if (!XMLChar.isValidNCName(prefix)) {
+                            // illegal syntax for prefix
+                            throw new MalformedPathException("'" + jcrPath + "' is not a
valid path: '" + elem + "' specifies an illegal namespace prefix");
+                        }
+                    } else {
+                        // no prefix specified
+                        prefix = "";
+                    }
+
+                    // group 5 is localName
+                    localName = matcher.group(5);
+
+                    // check for index (group 6)
+                    if (matcher.group(6) != null) {
+                        // index specified
+                        // group 7 is index excl. brackets
+                        index = Integer.parseInt(matcher.group(7));
+                    } else {
+                        // no index specified
+                        index = 0;
+                    }
+
+                    String nsURI;
+                    try {
+                        nsURI = resolver.getURI(prefix);
+                    } catch (NamespaceException nse) {
+                        // unknown prefix
+                        throw new MalformedPathException("'" + jcrPath + "' is not a valid
path: '" + elem + "' specifies an unmapped namespace prefix");
+                    }
+
+                    PathElement element;
+                    if (index == 0) {
+                        element = new PathElement(nsURI, localName);
+                    } else {
+                        element = new PathElement(nsURI, localName, index);
+                    }
+                    list.add(element);
+                    leadingParent = false;
+                }
+            } else {
+                // illegal syntax for path element
+                throw new MalformedPathException("'" + jcrPath + "' is not a valid path:
'" + elem + "' is not a legal path element");
+            }
+        }
+        return resolver == null
+                ? null
+                : new Path((PathElement[]) list.toArray(new PathElement[list.size()]), isNormalized);
+    }
+
     //------------------------------------------------------< utility methods >
     /**
      * Checks if <code>jcrPath</code> is a valid JCR-style absolute or relative
@@ -1147,135 +1276,4 @@
             return false;
         }
     }
-
-    //-------------------------------------------------------< implementation >
-
-    /**
-     * parses the give string an d returns an array of path elements. if
-     * <code>master</code> is not <code>null</code>, it is prepended
to the
-     * returned list. If <code>resolver</code> is <code>null</code>,
this
-     * method only checks the format of the string and returns <code>null</code>.
-     *
-     * @param jcrPath
-     * @param master
-     * @param resolver
-     * @return
-     * @throws MalformedPathException
-     */
-    private static Path parse(String jcrPath, Path master, NamespaceResolver resolver)
-            throws MalformedPathException {
-        // shortcut
-        if (jcrPath.equals("/")) {
-            return ROOT;
-        }
-
-        // split path into path elements
-        String[] elems = Text.explode(jcrPath, '/', true);
-        if (elems.length == 0) {
-            throw new MalformedPathException("empty path");
-        }
-
-        ArrayList list = new ArrayList();
-        boolean isNormalized = true;
-        boolean leadingParent = true;
-        if (master != null) {
-            isNormalized = master.normalized;
-            // a master path was specified; the 'path' argument is assumed
-            // to be a relative path
-            for (int i = 0; i < master.elements.length; i++) {
-                list.add(master.elements[i]);
-                leadingParent &= master.elements[i].denotesParent();
-            }
-        }
-
-        for (int i = 0; i < elems.length; i++) {
-            // validate & parse path element
-            String prefix;
-            String localName;
-            int index;
-
-            String elem = elems[i];
-            if (i == 0 && elem.length() == 0) {
-                // path is absolute, i.e. the first element is the root element
-                if (!list.isEmpty()) {
-                    throw new MalformedPathException("'" + jcrPath + "' is not a relative
path");
-                }
-                list.add(ROOT_ELEMENT);
-                leadingParent = false;
-                continue;
-            }
-            Matcher matcher = PATH_ELEMENT_PATTERN.matcher(elem);
-            if (matcher.matches()) {
-                if (resolver == null) {
-                    // check only
-                    continue;
-                }
-
-                if (matcher.group(1) != null) {
-                    // group 1 is .
-                    list.add(CURRENT_ELEMENT);
-                    leadingParent = false;
-                    isNormalized = false;
-                } else if (matcher.group(2) != null) {
-                    // group 2 is ..
-                    list.add(PARENT_ELEMENT);
-                    isNormalized &= leadingParent;
-                } else {
-                    // element is a name
-
-                    // check for prefix (group 3)
-                    if (matcher.group(3) != null) {
-                        // prefix specified
-                        // group 4 is namespace prefix excl. delimiter (colon)
-                        prefix = matcher.group(4);
-                        // check if the prefix is a valid XML prefix
-                        if (!XMLChar.isValidNCName(prefix)) {
-                            // illegal syntax for prefix
-                            throw new MalformedPathException("'" + jcrPath + "' is not a
valid path: '" + elem + "' specifies an illegal namespace prefix");
-                        }
-                    } else {
-                        // no prefix specified
-                        prefix = "";
-                    }
-
-                    // group 5 is localName
-                    localName = matcher.group(5);
-
-                    // check for index (group 6)
-                    if (matcher.group(6) != null) {
-                        // index specified
-                        // group 7 is index excl. brackets
-                        index = Integer.parseInt(matcher.group(7));
-                    } else {
-                        // no index specified
-                        index = 0;
-                    }
-
-                    String nsURI;
-                    try {
-                        nsURI = resolver.getURI(prefix);
-                    } catch (NamespaceException nse) {
-                        // unknown prefix
-                        throw new MalformedPathException("'" + jcrPath + "' is not a valid
path: '" + elem + "' specifies an unmapped namespace prefix");
-                    }
-
-                    PathElement element;
-                    if (index == 0) {
-                        element = new PathElement(nsURI, localName);
-                    } else {
-                        element = new PathElement(nsURI, localName, index);
-                    }
-                    list.add(element);
-                    leadingParent = false;
-                }
-            } else {
-                // illegal syntax for path element
-                throw new MalformedPathException("'" + jcrPath + "' is not a valid path:
'" + elem + "' is not a legal path element");
-            }
-        }
-        return resolver == null
-                ? null
-                : new Path((PathElement[]) list.toArray(new PathElement[list.size()]), isNormalized);
-    }
-
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ValueHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ValueHelper.java?view=diff&r1=154875&r2=154876
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ValueHelper.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ValueHelper.java Tue
Feb 22 09:12:41 2005
@@ -58,7 +58,7 @@
      */
     public static Value convert(Value srcValue, int targetType)
             throws ValueFormatException, IllegalStateException, IllegalArgumentException
{
-        Value val = null;
+        Value val;
         int srcType = srcValue.getType();
 
         if (srcType == targetType) {

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/PathTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/PathTest.java?view=diff&r1=154875&r2=154876
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/PathTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/PathTest.java Tue Feb 22
09:12:41 2005
@@ -212,11 +212,27 @@
         }
         for (int i=0; i<elems.length; i++) {
             int pos = elems[i].indexOf('[');
+            String elem;
+            QName name;
+            int index;
             if (pos<0) {
-                builder.addLast(QName.fromJCRName(elems[i], resolver));
+                elem = elems[i];
+                index = -1;
             } else {
-                int index = Integer.parseInt(elems[i].substring(pos+1, elems[i].length()-1));
-                builder.addLast(QName.fromJCRName(elems[i].substring(0, pos), resolver),
index);
+                index = Integer.parseInt(elems[i].substring(pos+1, elems[i].length()-1));
+                elem = elems[i].substring(0, pos);
+            }
+            if (".".equals(elem)) {
+                name = new QName("", ".");
+            } else if ("..".equals(elems[i])) {
+                name = new QName("", "..");
+            } else {
+                name = QName.fromJCRName(elem, resolver);
+            }
+            if (index < 0) {
+                builder.addLast(name);
+            } else {
+                builder.addLast(name, index);
             }
         }
         return normalize ? builder.getPath().getNormalizedPath() : builder.getPath();
@@ -228,11 +244,27 @@
         String[] elems = Text.explode(path, '/', false);
         for (int i=elems.length-1; i>=0; i--) {
             int pos = elems[i].indexOf('[');
+            String elem;
+            QName name;
+            int index;
             if (pos<0) {
-                builder.addFirst(QName.fromJCRName(elems[i], resolver));
+                elem = elems[i];
+                index = -1;
+            } else {
+                index = Integer.parseInt(elems[i].substring(pos+1, elems[i].length()-1));
+                elem = elems[i].substring(0, pos);
+            }
+            if (".".equals(elem)) {
+                name = new QName("", ".");
+            } else if ("..".equals(elems[i])) {
+                name = new QName("", "..");
+            } else {
+                name = QName.fromJCRName(elem, resolver);
+            }
+            if (index < 0) {
+                builder.addFirst(name);
             } else {
-                int index = Integer.parseInt(elems[i].substring(pos+1, elems[i].length()-1));
-                builder.addFirst(QName.fromJCRName(elems[i].substring(0, pos), resolver),
index);
+                builder.addFirst(name, index);
             }
         }
         if (path.startsWith("/")) {



Mime
View raw message