sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r652786 - in /incubator/sling/trunk: api/src/main/java/org/apache/sling/api/resource/ api/src/test/java/org/apache/sling/api/resource/ jcr/resource/src/main/java/org/apache/sling/jcr/resource/ jcr/resource/src/main/java/org/apache/sling/jcr...
Date Fri, 02 May 2008 07:02:39 GMT
Author: cziegeler
Date: Fri May  2 00:02:38 2008
New Revision: 652786

URL: http://svn.apache.org/viewvc?rev=652786&view=rev
Log:
SLING-410: Add ResourceUtil class to API.

Added:
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
  (with props)
    incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/
    incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
  (with props)
Removed:
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/JcrResourceUtilTest.java
Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
    incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
    incubator/sling/trunk/sling/servlets-get/src/main/java/org/apache/sling/servlets/JsonQueryServlet.java
    incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostProcessor.java
    incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java

Added: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=652786&view=auto
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(added)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Fri May  2 00:02:38 2008
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.api.resource;
+
+
+/**
+ * The <code>ResourceUtil</code> class provides helper methods dealing
+ * with resources.
+ */
+public class ResourceUtil {
+
+    /**
+     * Resolves relative path segments '.' and '..' in the absolute path.
+     * Returns null if not possible (.. points above root) or if path is not
+     * absolute.
+     */
+    public static String normalize(String path) {
+
+        // don't care for empty paths
+        if (path.length() == 0) {
+            return path;
+        }
+
+        // prepare the path buffer with trailing slash (simplifies impl)
+        int absOffset = (path.charAt(0) == '/') ? 0 : 1;
+        char[] buf = new char[path.length() + 1 + absOffset];
+        if (absOffset == 1) {
+            buf[0] = '/';
+        }
+        path.getChars(0, path.length(), buf, absOffset);
+        buf[buf.length - 1] = '/';
+
+        int lastSlash = 0; // last slash in path
+        int numDots = 0; // number of consecutive dots after last slash
+
+        int bufPos = 0;
+        for (int bufIdx = lastSlash; bufIdx < buf.length; bufIdx++) {
+            char c = buf[bufIdx];
+            if (c == '/') {
+                if (numDots == 2) {
+                    if (bufPos == 0) {
+                        return null;
+                    }
+
+                    do {
+                        bufPos--;
+                    } while (bufPos > 0 && buf[bufPos] != '/');
+                }
+
+                lastSlash = bufIdx;
+                numDots = 0;
+            } else if (c == '.' && numDots < 2) {
+                numDots++;
+            } else {
+                // find the next slash
+                int nextSlash = bufIdx + 1;
+                while (nextSlash < buf.length && buf[nextSlash] != '/') {
+                    nextSlash++;
+                }
+
+                // append up to the next slash (or end of path)
+                if (bufPos < lastSlash) {
+                    int segLen = nextSlash - bufIdx + 1;
+                    System.arraycopy(buf, lastSlash, buf, bufPos, segLen);
+                    bufPos += segLen;
+                } else {
+                    bufPos = nextSlash;
+                }
+
+                numDots = 0;
+                lastSlash = nextSlash;
+                bufIdx = nextSlash;
+            }
+        }
+
+        String resolved;
+        if (bufPos == 0 && numDots == 0) {
+            resolved = (absOffset == 0) ? "/" : "";
+        } else if ((bufPos - absOffset) == path.length()) {
+            resolved = path;
+        } else {
+            resolved = new String(buf, absOffset, bufPos - absOffset);
+        }
+
+        return resolved;
+    }
+
+    /**
+     * Utility method returns the parent path of the given <code>path</code>,
+     * which is normalized by {@link #normalize(String)} before resolving the
+     * parent.
+     *
+     * @param path The path whose parent is to be returned.
+     * @return <code>null</code> if <code>path</code> is the root
path (<code>/</code>)
+     *         or if <code>path</code> is a single name containing no slash (<code>/</code>)
+     *         characters.
+     * @throws IllegalArgumentException If the path cannot be normalized by the
+     *             {@link #normalize(String)} method.
+     * @throws NullPointerException If <code>path</code> is <code>null</code>.
+     */
+    public static String getParent(String path) {
+        if ("/".equals(path)) {
+            return null;
+        }
+
+        // normalize path (remove . and ..)
+        path = normalize(path);
+
+        // if normalized to root, there is no parent
+        if (path == null || "/".equals(path)) {
+            return null;
+        }
+
+        // find the last slash, after which to cut off
+        int lastSlash = path.lastIndexOf('/');
+        if (lastSlash < 0) {
+            // no slash in the path
+            return null;
+        } else if (lastSlash == 0) {
+            // parent is root
+            return "/";
+        }
+
+        return path.substring(0, lastSlash);
+    }
+
+    /**
+     * Utility method returns the name of the given <code>path</code>, which
+     * is normalized by {@link #normalize(String)} before resolving the name.
+     *
+     * @param path The path whose name (the last path element) is to be
+     *            returned.
+     * @return The empty string if <code>path</code> is the root path (<code>/</code>)
+     *         or if <code>path</code> is a single name containing no slash (<code>/</code>)
+     *         characters.
+     * @throws IllegalArgumentException If the path cannot be normalized by the
+     *             {@link #normalize(String)} method.
+     * @throws NullPointerException If <code>path</code> is <code>null</code>.
+     */
+    public static String getName(String path) {
+        if ("/".equals(path)) {
+            return "";
+        }
+
+        // normalize path (remove . and ..)
+        path = normalize(path);
+        if ("/".equals(path)) {
+            return "";
+        }
+
+        // find the last slash
+        return path.substring(path.lastIndexOf('/') + 1);
+    }
+
+    /**
+     * Returns <code>true</code> if the resource <code>res</code>
is a
+     * synthetic resource.
+     * <p>
+     * This method checks whether the resource is an instance of the
+     * <code>org.apache.sling.resource.SyntheticResource</code> class.
+     *
+     * @param res The <code>Resource</code> to check whether it is a synthetic
+     *            resource.
+     * @return <code>true</code> if <code>res</code> is a synthetic
+     *         resource. <code>false</code> is returned if <code>res</code>
+     *         is <code>null</code> or not an instance of the
+     *         <code>org.apache.sling.resource.SyntheticResource</code> class.
+     */
+    public static boolean isSyntheticResource(Resource res) {
+        return res instanceof SyntheticResource;
+    }
+
+    /**
+     * Returns <code>true</code> if the resource <code>res</code>
is a "star
+     * resource". A <i>star resource</i> is a resource returned from the
+     * <code>ResourceResolver.resolve(HttpServletRequest)</code> whose path
+     * terminates in a <code>/*</code>. Generally such resource result from
+     * requests to something like <code>/some/path/*</code> or
+     * <code>/some/path/*.html</code> which may be used web applications to
+     * uniformly handle resources to be created.
+     * <p>
+     * This method checks whether the resource path ends with a <code>/*</code>
+     * indicating such a star resource.
+     *
+     * @param res The <code>Resource</code> to check whether it is a star
+     *            resource.
+     * @return <code>true</code> if <code>res</code> is to be considered
a
+     *         star resource.
+     * @throws NullPointerException if <code>res</code> is <code>null</code>.
+     */
+    public static boolean isStarResource(Resource res) {
+        return res.getPath().endsWith("/*");
+    }
+
+    /**
+     * Returns <code>true</code> if the resource <code>res</code>
is a
+     * non-existing resource.
+     * <p>
+     * This method checks the resource type of the resource to match the
+     * well-known resource type <code>sling:nonexisting</code> of the
+     * <code>NonExistingResource</code> class defined in the Sling API.
+     *
+     * @param res The <code>Resource</code> to check whether it is a
+     *            non-existing resource.
+     * @return <code>true</code> if <code>res</code> is to be considered
a
+     *         non-existing resource.
+     * @throws NullPointerException if <code>res</code> is <code>null</code>.
+     */
+    public static boolean isNonExistingResource(Resource res) {
+        return NonExistingResource.RESOURCE_TYPE_NON_EXISTING.equals(res.getResourceType());
+    }
+}

Propchange: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java?rev=652786&view=auto
==============================================================================
--- incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
(added)
+++ incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Fri May  2 00:02:38 2008
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.api.resource;
+
+import junit.framework.TestCase;
+
+public class ResourceUtilTest extends TestCase {
+
+    public void testResolveRelativeSegments() {
+
+        assertEquals("/", ResourceUtil.normalize("/"));
+        assertEquals("/", ResourceUtil.normalize("///"));
+
+        assertEquals("/a/b/c", ResourceUtil.normalize("/a//b/c"));
+        assertEquals("/a/b/c", ResourceUtil.normalize("/a/b//c"));
+        assertEquals("/a/b/c", ResourceUtil.normalize("/a///b///c"));
+        assertEquals("/a/b/c", ResourceUtil.normalize("/a/b/c/"));
+        assertEquals("/a/b/c", ResourceUtil.normalize("/a/b/c//"));
+        assertEquals("/a/b/c", ResourceUtil.normalize("/a/b/c///"));
+
+        assertEquals("/az/bz/cz", ResourceUtil.normalize("/az//bz/cz"));
+        assertEquals("/az/bz/cz", ResourceUtil.normalize("/az/bz//cz"));
+        assertEquals("/az/bz/cz", ResourceUtil.normalize("/az///bz///cz"));
+        assertEquals("/az/bz/cz", ResourceUtil.normalize("/az/bz/cz/"));
+        assertEquals("/az/bz/cz", ResourceUtil.normalize("/az/bz/cz//"));
+        assertEquals("/az/bz/cz", ResourceUtil.normalize("/az/bz/cz///"));
+
+        assertEquals("/a", ResourceUtil.normalize("/a"));
+        assertEquals("/a", ResourceUtil.normalize("//a"));
+        assertEquals("/a", ResourceUtil.normalize("///a"));
+
+        assertEquals("/az", ResourceUtil.normalize("/az"));
+        assertEquals("/az", ResourceUtil.normalize("//az"));
+        assertEquals("/az", ResourceUtil.normalize("///az"));
+
+        assertEquals("/", ResourceUtil.normalize("/."));
+        assertEquals("/a", ResourceUtil.normalize("/a/."));
+        assertEquals("/a", ResourceUtil.normalize("/./a"));
+        assertEquals("/a/b", ResourceUtil.normalize("/a/./b"));
+        assertEquals("/a/b", ResourceUtil.normalize("/a/b/."));
+        assertEquals("/a/b", ResourceUtil.normalize("/a/./b/."));
+
+        assertEquals("/", ResourceUtil.normalize("/."));
+        assertEquals("/az", ResourceUtil.normalize("/az/."));
+        assertEquals("/az", ResourceUtil.normalize("/./az"));
+        assertEquals("/az/bz", ResourceUtil.normalize("/az/./bz"));
+        assertEquals("/az/bz", ResourceUtil.normalize("/az/bz/."));
+        assertEquals("/az/bz", ResourceUtil.normalize("/az/./bz/."));
+
+        assertNull(ResourceUtil.normalize("/.."));
+        assertNull(ResourceUtil.normalize("/.."));
+        assertEquals("/", ResourceUtil.normalize("/a/.."));
+        assertEquals("/a", ResourceUtil.normalize("/a/b/.."));
+        assertEquals("/", ResourceUtil.normalize("/a/b/../.."));
+        assertNull(ResourceUtil.normalize("/a/b/../../.."));
+
+        assertNull(ResourceUtil.normalize("/.."));
+        assertNull(ResourceUtil.normalize("/.."));
+        assertEquals("/", ResourceUtil.normalize("/az/.."));
+        assertEquals("/az", ResourceUtil.normalize("/az/bz/.."));
+        assertEquals("/", ResourceUtil.normalize("/az/bz/../.."));
+        assertNull(ResourceUtil.normalize("/az/bz/../../.."));
+
+        assertEquals("/b", ResourceUtil.normalize("/a/../b"));
+        assertEquals("/a/c", ResourceUtil.normalize("/a/b/../c"));
+        assertEquals("/c", ResourceUtil.normalize("/a/b/../../c"));
+        assertNull(ResourceUtil.normalize("/a/b/../../../c"));
+
+        assertEquals("/bz", ResourceUtil.normalize("/az/../bz"));
+        assertEquals("/az/cz", ResourceUtil.normalize("/az/bz/../cz"));
+        assertEquals("/cz", ResourceUtil.normalize("/az/bz/../../cz"));
+        assertNull(ResourceUtil.normalize("/az/bz/../../../cz"));
+
+        assertEquals("/...", ResourceUtil.normalize("/..."));
+        assertEquals("/a/...", ResourceUtil.normalize("/a/..."));
+        assertEquals("/a/b/...", ResourceUtil.normalize("/a/b/..."));
+
+        assertEquals("/az/...", ResourceUtil.normalize("/az/..."));
+        assertEquals("/az/bz/...", ResourceUtil.normalize("/az/bz/..."));
+
+        try {
+            ResourceUtil.normalize(null);
+            fail("Resolving null expects NullPointerException");
+        } catch (NullPointerException npe) {
+            // expected
+        }
+    }
+
+    public void testResolveRelativeSegmentsRelative() {
+        assertEquals("a/b", ResourceUtil.normalize("a/b"));
+        assertEquals("a", ResourceUtil.normalize("a/b/.."));
+
+        assertEquals("b", ResourceUtil.normalize("a/../b"));
+        assertEquals("a/c", ResourceUtil.normalize("a/b/../c"));
+        assertEquals("c", ResourceUtil.normalize("a/b/../../c"));
+        assertEquals("", ResourceUtil.normalize("a/b/../.."));
+        assertEquals("a/c/d", ResourceUtil.normalize("a/b/../c/d"));
+        assertNull(ResourceUtil.normalize("a/b/../../../c"));
+
+        assertEquals("a/b/c", ResourceUtil.normalize("a/b/c"));
+        assertEquals("az/bz/cz", ResourceUtil.normalize("az/bz/cz"));
+        assertEquals("", ResourceUtil.normalize(""));
+    }
+
+    public void testGetParent() {
+        assertNull(ResourceUtil.getParent("/"));
+        assertNull(ResourceUtil.getParent("/.."));
+
+        assertEquals("/", ResourceUtil.getParent("/b"));
+        assertEquals("b/c", ResourceUtil.getParent("b/c/d"));
+        assertEquals("/b/c", ResourceUtil.getParent("/b/c/d"));
+
+        assertNull(ResourceUtil.getParent("b"));
+        assertNull(ResourceUtil.getParent("/b/.."));
+    }
+
+    public void testGetName() {
+        assertEquals("", ResourceUtil.getName("/"));
+        assertEquals("", ResourceUtil.getName("/a/.."));
+
+        assertEquals("c", ResourceUtil.getName("c"));
+        assertEquals("c", ResourceUtil.getName("/c"));
+
+        assertEquals("c", ResourceUtil.getName("b/c"));
+        assertEquals("c", ResourceUtil.getName("/b/c"));
+
+        assertEquals("c", ResourceUtil.getName("b/c/"));
+        assertEquals("c", ResourceUtil.getName("/b/c/"));
+
+        assertEquals("b", ResourceUtil.getName("b/c/.."));
+        assertEquals("b", ResourceUtil.getName("/b/c/.."));
+        assertEquals("", ResourceUtil.getName("/b/c/../.."));
+    }
+}

Propchange: incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
Fri May  2 00:02:38 2008
@@ -27,14 +27,9 @@
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
-import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.SyntheticResource;
 import org.apache.sling.jcr.resource.internal.helper.LazyInputStream;
-import org.apache.sling.jcr.resource.internal.helper.starresource.StarResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * The <code>JcrResourceUtil</code> class provides helper methods used
@@ -42,9 +37,6 @@
  */
 public class JcrResourceUtil {
 
-    /** default log */
-    private static final Logger log = LoggerFactory.getLogger(JcrResourceUtil.class);
-
     /** Helper method to execute a JCR query */
     public static QueryResult query(Session session, String query,
             String language) throws RepositoryException {
@@ -101,90 +93,10 @@
     }
 
     /**
-     * Resolves relative path segments '.' and '..' in the absolute path.
-     * Returns null if not possible (.. points above root) or if path is not
-     * absolute.
-     */
-    public static String normalize(String path) {
-
-        // don't care for empty paths
-        if (path.length() == 0) {
-            log.error("normalize: Not modifying empty path");
-            return path;
-        }
-
-        // prepare the path buffer with trailing slash (simplifies impl)
-        int absOffset = (path.charAt(0) == '/') ? 0 : 1;
-        char[] buf = new char[path.length() + 1 + absOffset];
-        if (absOffset == 1) {
-            buf[0] = '/';
-        }
-        path.getChars(0, path.length(), buf, absOffset);
-        buf[buf.length - 1] = '/';
-
-        int lastSlash = 0; // last slash in path
-        int numDots = 0; // number of consecutive dots after last slash
-
-        int bufPos = 0;
-        for (int bufIdx = lastSlash; bufIdx < buf.length; bufIdx++) {
-            char c = buf[bufIdx];
-            if (c == '/') {
-                if (numDots == 2) {
-                    if (bufPos == 0) {
-                        log.error("normalize: Path '{}' cannot be resolved",
-                            path);
-                        return null;
-                    }
-
-                    do {
-                        bufPos--;
-                    } while (bufPos > 0 && buf[bufPos] != '/');
-                }
-
-                lastSlash = bufIdx;
-                numDots = 0;
-            } else if (c == '.' && numDots < 2) {
-                numDots++;
-            } else {
-                // find the next slash
-                int nextSlash = bufIdx + 1;
-                while (nextSlash < buf.length && buf[nextSlash] != '/') {
-                    nextSlash++;
-                }
-
-                // append up to the next slash (or end of path)
-                if (bufPos < lastSlash) {
-                    int segLen = nextSlash - bufIdx + 1;
-                    System.arraycopy(buf, lastSlash, buf, bufPos, segLen);
-                    bufPos += segLen;
-                } else {
-                    bufPos = nextSlash;
-                }
-
-                numDots = 0;
-                lastSlash = nextSlash;
-                bufIdx = nextSlash;
-            }
-        }
-
-        String resolved;
-        if (bufPos == 0 && numDots == 0) {
-            resolved = (absOffset == 0) ? "/" : "";
-        } else if ((bufPos - absOffset) == path.length()) {
-            resolved = path;
-        } else {
-            resolved = new String(buf, absOffset, bufPos - absOffset);
-        }
-
-        log.debug("normalize: Resolving '{}' to '{}'", path, resolved);
-        return resolved;
-    }
-
-    /**
      * Helper method, which returns the given resource type as returned from the
      * {@link org.apache.sling.api.resource.Resource#getResourceType()} as a
      * relative path.
-     * 
+     *
      * @param type The resource type to be converted into a path
      * @return The resource type as a path.
      */
@@ -193,80 +105,13 @@
     }
 
     /**
-     * Utility method returns the parent path of the given <code>path</code>,
-     * which is normalized by {@link #normalize(String)} before resolving the
-     * parent.
-     * 
-     * @param path The path whose parent is to be returned.
-     * @return <code>null</code> if <code>path</code> is the root
path (<code>/</code>)
-     *         or if <code>path</code> is a single name containing no slash (<code>/</code>)
-     *         characters.
-     * @throws IllegalArgumentException If the path cannot be normalized by the
-     *             {@link #normalize(String)} method.
-     * @throws NullPointerException If <code>path</code> is <code>null</code>.
-     */
-    public static String getParent(String path) {
-        if ("/".equals(path)) {
-            return null;
-        }
-
-        // normalize path (remove . and ..)
-        path = normalize(path);
-
-        // if normalized to root, there is no parent
-        if (path == null || "/".equals(path)) {
-            return null;
-        }
-
-        // find the last slash, after which to cut off
-        int lastSlash = path.lastIndexOf('/');
-        if (lastSlash < 0) {
-            // no slash in the path
-            return null;
-        } else if (lastSlash == 0) {
-            // parent is root
-            return "/";
-        }
-
-        return path.substring(0, lastSlash);
-    }
-
-    /**
-     * Utility method returns the name of the given <code>path</code>, which
-     * is normalized by {@link #normalize(String)} before resolving the name.
-     * 
-     * @param path The path whose name (the last path element) is to be
-     *            returned.
-     * @return The empty string if <code>path</code> is the root path (<code>/</code>)
-     *         or if <code>path</code> is a single name containing no slash (<code>/</code>)
-     *         characters.
-     * @throws IllegalArgumentException If the path cannot be normalized by the
-     *             {@link #normalize(String)} method.
-     * @throws NullPointerException If <code>path</code> is <code>null</code>.
-     */
-    public static String getName(String path) {
-        if ("/".equals(path)) {
-            return "";
-        }
-
-        // normalize path (remove . and ..)
-        path = normalize(path);
-        if ("/".equals(path)) {
-            return "";
-        }
-
-        // find the last slash
-        return path.substring(path.lastIndexOf('/') + 1);
-    }
-
-    /**
      * Returns the super type of the given resource type. This is the result of
      * calling the <code>getResourceSuperType()</code> method on the
      * <code>Resource</code> addressed by the <code>resourceType</code>.
If
      * the resource type does not address a resource or if the addressed
      * resource has no resource super type, this method returns
      * <code>null</code>.
-     * 
+     *
      * @param resourceResolver The <code>ResourceResolver</code> used to
      *            access the resource whose path (relative or absolute) is given
      *            by the <code>resourceType</code> parameter.
@@ -289,62 +134,4 @@
         // get the resource super type from the resource
         return (rtResource != null) ? rtResource.getResourceSuperType() : null;
     }
-
-    /**
-     * Returns <code>true</code> if the resource <code>res</code>
is a
-     * synthetic resource.
-     * <p>
-     * This method checks whether the resource is an instance of the
-     * <code>org.apache.sling.resource.SyntheticResource</code> class.
-     * 
-     * @param res The <code>Resource</code> to check whether it is a synthetic
-     *            resource.
-     * @return <code>true</code> if <code>res</code> is a synthetic
-     *         resource. <code>false</code> is returned if <code>res</code>
-     *         is <code>null</code> or not an instance of the
-     *         <code>org.apache.sling.resource.SyntheticResource</code> class.
-     */
-    public static boolean isSyntheticResource(Resource res) {
-        return res instanceof SyntheticResource;
-    }
-
-    /**
-     * Returns <code>true</code> if the resource <code>res</code>
is a "star
-     * resource". A <i>star resource</i> is a resource returned from the
-     * <code>ResourceResolver.resolve(HttpServletRequest)</code> whose path
-     * terminates in a <code>/*</code>. Generally such resource result from
-     * requests to something like <code>/some/path/*</code> or
-     * <code>/some/path/*.html</code> which may be used web applications to
-     * uniformly handle resources to be created.
-     * <p>
-     * This method checks whether the resource path ends with a <code>/*</code>
-     * indicating such a star resource.
-     * 
-     * @param res The <code>Resource</code> to check whether it is a star
-     *            resource.
-     * @return <code>true</code> if <code>res</code> is to be considered
a
-     *         star resource.
-     * @throws NullPointerException if <code>res</code> is <code>null</code>.
-     */
-    public static boolean isStarResource(Resource res) {
-        return StarResource.isStarResource(res);
-    }
-
-    /**
-     * Returns <code>true</code> if the resource <code>res</code>
is a
-     * non-existing resource.
-     * <p>
-     * This method checks the resource type of the resource to match the
-     * well-known resource type <code>sling:nonexisting</code> of the
-     * <code>NonExistingResource</code> class defined in the Sling API.
-     * 
-     * @param res The <code>Resource</code> to check whether it is a
-     *            non-existing resource.
-     * @return <code>true</code> if <code>res</code> is to be considered
a
-     *         non-existing resource.
-     * @throws NullPointerException if <code>res</code> is <code>null</code>.
-     */
-    public static boolean isNonExistingResource(Resource res) {
-        return NonExistingResource.RESOURCE_TYPE_NON_EXISTING.equals(res.getResourceType());
-    }
 }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
Fri May  2 00:02:38 2008
@@ -36,6 +36,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.jcr.resource.internal.helper.Mapping;
 import org.apache.sling.jcr.resource.internal.helper.ResourcePathIterator;
@@ -147,7 +148,7 @@
 
         // if the path is absolute, normalize . and .. segements and get res
         if (path.startsWith("/")) {
-            path = JcrResourceUtil.normalize(path);
+            path = ResourceUtil.normalize(path);
             return (path != null) ? getResourceInternal(path) : null;
         }
 

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Fri May  2 00:02:38 2008
@@ -37,9 +37,9 @@
 import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.jcr.resource.internal.helper.Mapping;
 import org.apache.sling.jcr.resource.internal.helper.starresource.StarResource;
 
@@ -167,7 +167,7 @@
                 Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
         }
     }
-    
+
     public void testGetRemovesExtensionInResolution() throws Exception {
         final String path = rootPath + ".whatever";
         final Resource res = resResolver.resolve(new ResourceResolverTestRequest(
@@ -185,7 +185,7 @@
         testStarResourceHelper(path, "PUT");
         testStarResourceHelper(path, "DELETE");
     }
-    
+
     public void testStarResourceExtension() throws Exception {
         final String path = rootPath + "/" + System.currentTimeMillis() + "/*.html";
         testStarResourceHelper(path, "GET");
@@ -193,7 +193,7 @@
         testStarResourceHelper(path, "PUT");
         testStarResourceHelper(path, "DELETE");
     }
-    
+
     public void testStarResourceSelectorExtension() throws Exception {
         final String path = rootPath + "/" + System.currentTimeMillis() + "/*.print.a4.html";
         testStarResourceHelper(path, "GET");
@@ -205,11 +205,11 @@
     private void testStarResourceHelper(final String path, final String method) {
         final Resource res = resResolver.resolve(new ResourceResolverTestRequest(path, method));
         assertNotNull(res);
-        assertTrue(JcrResourceUtil.isStarResource(res));
+        assertTrue(ResourceUtil.isStarResource(res));
         assertEquals(StarResource.class.getName(), res.getClass().getName());
         assertEquals(StarResource.DEFAULT_RESOURCE_TYPE, res.getResourceType());
     }
-    
+
     private static class ResourceResolverTestRequest implements
             HttpServletRequest {
 

Modified: incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
(original)
+++ incubator/sling/trunk/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
Fri May  2 00:02:38 2008
@@ -29,8 +29,8 @@
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.request.RequestDispatcherOptions;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.resource.SyntheticResource;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.scripting.jsp.util.JspSlingHttpServletResponseWrapper;
 import org.apache.sling.scripting.jsp.util.TagUtil;
 import org.slf4j.Logger;
@@ -61,7 +61,7 @@
 
     /**
      * Called after the body has been processed.
-     * 
+     *
      * @return whether additional evaluations of the body are desired
      */
     public int doEndTag() throws JspException {
@@ -81,9 +81,9 @@
             if (!path.startsWith("/")) {
                 path = request.getResource().getPath() + "/" + path;
             }
-            path = JcrResourceUtil.normalize(path);
+            path = ResourceUtil.normalize(path);
         }
-        
+
         // check the resource
         if (resource == null) {
             if (path == null) {
@@ -106,7 +106,7 @@
                 // might throw an IOException of course
                 pageContext.getOut().flush();
             }
-            
+
             // create a dispatcher for the resource or path
             RequestDispatcher dispatcher;
             if (resource != null) {
@@ -114,7 +114,7 @@
             } else {
                 dispatcher = request.getRequestDispatcher(path, opts);
             }
-            
+
             if (dispatcher != null) {
                 SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(
                     pageContext);

Modified: incubator/sling/trunk/sling/servlets-get/src/main/java/org/apache/sling/servlets/JsonQueryServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlets-get/src/main/java/org/apache/sling/servlets/JsonQueryServlet.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlets-get/src/main/java/org/apache/sling/servlets/JsonQueryServlet.java
(original)
+++ incubator/sling/trunk/sling/servlets-get/src/main/java/org/apache/sling/servlets/JsonQueryServlet.java
Fri May  2 00:02:38 2008
@@ -34,6 +34,7 @@
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
@@ -43,7 +44,7 @@
 
 /**
  * A SlingSafeMethodsServlet that renders the search results as JSON data
- * 
+ *
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.component immediate="true" metatype="false"
  * @scr.property name="service.description" value="Default Query Servlet"
@@ -87,7 +88,7 @@
 
     /**
      * Dumps the result as JSON object.
-     * 
+     *
      * @param req request
      * @param resp response
      * @throws IOException in case the search will unexpectedly fail
@@ -143,7 +144,7 @@
                 String path = row.get("jcr:path").toString();
 
                 w.key("name");
-                w.value(JcrResourceUtil.getName(path));
+                w.value(ResourceUtil.getName(path));
 
                 // dump columns
                 for (String colName : row.keySet()) {
@@ -163,7 +164,7 @@
                     Resource nodeRes = resolver.getResource(path);
                     dumpProperties(w, nodeRes, properties);
                 }
-                
+
                 w.endObject();
                 count--;
             }
@@ -175,13 +176,13 @@
 
     private void dumpProperties(JSONWriter w, Resource nodeRes,
             List<String> properties) throws JSONException {
-        
+
         // nothing to do if there is no resource
         if (nodeRes == null) {
             return;
         }
-        
-        
+
+
         ResourceResolver resolver = nodeRes.getResourceResolver();
         for (String property : properties) {
             Resource prop = resolver.getResource(nodeRes, property);
@@ -211,7 +212,7 @@
         }
         return "";
     }
-    
+
     private String formatValue(Object value) {
         String strValue;
         if (value instanceof InputStream) {

Modified: incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostProcessor.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostProcessor.java
(original)
+++ incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostProcessor.java
Fri May  2 00:02:38 2008
@@ -22,10 +22,10 @@
 import javax.jcr.NamespaceException;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -33,9 +33,9 @@
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.request.RequestParameter;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.servlets.HtmlResponse;
 import org.apache.sling.api.wrappers.SlingRequestPaths;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -128,7 +128,7 @@
         StringBuffer rootPathBuf = new StringBuffer();
         String suffix;
         Resource currentResource = request.getResource();
-        if (JcrResourceUtil.isSyntheticResource(currentResource)) {
+        if (ResourceUtil.isSyntheticResource(currentResource)) {
 
             // no resource, treat the missing resource path as suffix
             suffix = currentResource.getPath();

Modified: incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java?rev=652786&r1=652785&r2=652786&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
(original)
+++ incubator/sling/trunk/sling/servlets-post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
Fri May  2 00:02:38 2008
@@ -24,9 +24,9 @@
 
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.api.servlets.HtmlResponse;
 import org.apache.sling.api.servlets.SlingAllMethodsServlet;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -249,7 +249,7 @@
                 }
 
                 // append the name of the manipulated node
-                buf.append(JcrResourceUtil.getName(ctx.getPath()));
+                buf.append(ResourceUtil.getName(ctx.getPath()));
 
                 // anything after the star
                 if (star < result.length() - 1) {



Mime
View raw message