Author: cziegeler
Date: Mon Oct 17 11:18:58 2016
New Revision: 1765240

URL: http://svn.apache.org/viewvc?rev=1765240&view=rev
Log:
SLING-6161 : Should Path.matches support glob pattern as parameter?

Modified:
    
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java
    
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/package-info.java
    
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java

Modified: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java?rev=1765240&r1=1765239&r2=1765240&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java
 (original)
+++ 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java
 Mon Oct 17 11:18:58 2016
@@ -69,16 +69,24 @@ public class Path implements Comparable<
     }
 
     /**
-     * Check whether the provided path is equal to this path or a sub path of 
it.
-     * @param otherPath Path to check
-     * @return {@code true} If other path is within the sub tree of this path.
+     * If this {@code Path} object holds a path (and not a pattern), this 
method
+     * check whether the provided path is equal to this path or a sub path of 
it.
+     * If this {@code Path} object holds a pattern, it checks whether the
+     * provided path matches the pattern.
+     * If the provided argument is not an absolute path (e.g. if it is a 
relative
+     * path or a pattern), this method returns {@code false}.
+     *
+     * @param otherPath Absolute path to check.
+     * @return {@code true} If other path is within the sub tree of this path
+     *         or matches the pattern.
+     * @see Path#isPattern()
      */
     public boolean matches(final String otherPath) {
-        Path oPath = new Path(otherPath);
         if (isPattern) {
+            final Path oPath = new Path(otherPath);
             return this.regexPattern.equals(oPath.regexPattern) || 
this.regexPattern.matcher(otherPath).matches();
         }
-        return this.path.equals(otherPath) || 
oPath.prefix.startsWith(this.prefix);
+        return this.path.equals(otherPath) || 
otherPath.startsWith(this.prefix);
     }
 
     /**
@@ -89,6 +97,15 @@ public class Path implements Comparable<
         return this.path;
     }
 
+    /**
+     * Returns {code true} if this {@code Path} object is holding a pattern
+     * @return {code true} for a pattern, {@code false} for a path.
+     * @since 1.2.0 (Sling API Bundle 2.15.0)
+     */
+    public boolean isPattern() {
+        return this.isPattern;
+    }
+
     @Override
     public int compareTo(@Nonnull final Path o) {
         return this.getPath().compareTo(o.getPath());

Modified: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/package-info.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/package-info.java?rev=1765240&r1=1765239&r2=1765240&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/package-info.java
 (original)
+++ 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/package-info.java
 Mon Oct 17 11:18:58 2016
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("1.1.1")
+@Version("1.2.0")
 package org.apache.sling.api.resource.path;
 
 import org.osgi.annotation.versioning.Version;

Modified: 
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java?rev=1765240&r1=1765239&r2=1765240&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java
 (original)
+++ 
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java
 Mon Oct 17 11:18:58 2016
@@ -70,8 +70,8 @@ public class PathTest {
 
     @Test public void testPatternRootMatching() {
         final Path path = new Path("/");
-        assertTrue(path.matches("glob:/apps/myproject/components/**/*.html"));
-        assertTrue(path.matches("glob:/apps/**/*.html"));
+        assertFalse(path.matches("glob:/apps/myproject/components/**/*.html"));
+        assertFalse(path.matches("glob:/apps/**/*.html"));
     }
 
     @Test public void testPathMatchingTrailingSlash() {


Reply via email to