Author: stefanegli
Date: Wed Nov 2 16:35:09 2016
New Revision: 1767723
URL: http://svn.apache.org/viewvc?rev=1767723&view=rev
Log:
OAK-5021 related : moving glob path to regex conversion to separate helper for
reuse - plus more testcases added for the same
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelper.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelperTest.java
(with props)
Removed:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/observation/OakEventFilterImplTest.java
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/OakEventFilterImpl.java
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelper.java?rev=1767723&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelper.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelper.java
Wed Nov 2 16:35:09 2016
@@ -0,0 +1,54 @@
+/*
+ * 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.jackrabbit.oak.plugins.observation.filter;
+
+public class GlobbingPathHelper {
+
+ public static String globAsRegex(String patternWithGlobs) {
+ if (patternWithGlobs == null) {
+ return null;
+ } else if (!patternWithGlobs.contains("*")) {
+ return patternWithGlobs;
+ }
+ String[] starStarParts = patternWithGlobs.split("\\*\\*", -1);
+ StringBuffer sb = new StringBuffer();
+ sb.append("\\Q");
+ for (int i = 0; i < starStarParts.length; i++) {
+ if (i > 0) {
+ // the '**' regexp equivalent:
+ // - anything not including '/'
+ // - followed by ('/' plus anything not including '/') repeated
+ sb.append("\\E[^/]*(/[^/]*)*\\Q");
+ }
+ String part = starStarParts[i];
+ if (!part.equals("/")) {
+ if (starStarParts.length > 1 && part.startsWith("/")) {
+ part = part.substring(1);
+ }
+ if (i < starStarParts.length -1 && part.endsWith("/")) {
+ part = part.substring(0, part.length() - 1);
+ }
+ sb.append(part.replace("*", "\\E[^/]*\\Q"));
+ }
+ }
+ sb.append("\\E");
+ return sb.toString();
+ }
+
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelperTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelperTest.java?rev=1767723&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelperTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelperTest.java
Wed Nov 2 16:35:09 2016
@@ -0,0 +1,93 @@
+/*
+ * 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.jackrabbit.oak.plugins.observation.filter;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+public class GlobbingPathHelperTest {
+
+ @Test
+ public void globSubPath1() throws Exception {
+ assertMatches("foo", "foo");
+ assertMatches("**", "foo");
+ assertMatches("**/bar", "bar");
+ assertMatches("**/bar", "foo/bar");
+ assertMatches("**/bar", "foo/zoo/bar");
+ assertMatches("**/bar/**", "bar");
+ assertMatches("**/bar/**", "/bar");
+ assertMatches("**/bar/**", "foo/bar");
+ assertMatches("**/bar/**", "/foo/bar");
+ assertMatches("**/bar/**", "foo/bar/zoo");
+ assertMatches("**/bar/**", "/foo/bar/zoo");
+ assertMatches("**/bar/**", "bar/foo");
+ assertMatches("**/bar/**", "/bar/foo");
+ assertMatches("**/bar/**", "bar/foo/zoo");
+ assertMatches("**/bar/**", "/bar/foo/zoo");
+ }
+
+ @Test
+ public void globSubPath2() throws Exception {
+ assertMatches("foo", "foo");
+ assertDoesntMatch("foo", "/foo");
+ assertMatches("**", "foo");
+ assertMatches("**", "/foo");
+ assertMatches("**", "foo/bar");
+ assertMatches("**", "foo/bar/zoo");
+ assertMatches("*.html", "foo.html");
+ assertDoesntMatch("*.html", "/foo.html");
+ assertMatches("**/*.html", "foo.html");
+ assertMatches("**/*.html", "/foo.html");
+ assertMatches("**/*.html", "bar/foo.html");
+ assertMatches("**/*.html", "/bar/foo.html");
+ assertMatches("**/*.html", "bar/zoo/foo.html");
+ assertMatches("**/*.html", "/bar/zoo/foo.html");
+ }
+
+ @Test
+ public void globPath() throws Exception {
+ assertMatches("/**", "foo");
+ assertMatches("/**", "/foo");
+ assertMatches("/**", "foo/bar");
+ assertMatches("/**", "/foo/bar");
+ assertMatches("/**", "foo/bar/zoo");
+ assertMatches("/**", "/foo/bar/zoo");
+ assertMatches("/**/*.html", "foo.html");
+ assertMatches("/**/*.html", "/foo.html");
+ assertMatches("/**/*.html", "bar/foo.html");
+ assertMatches("/**/*.html", "/bar/foo.html");
+ assertMatches("/**/*.html", "bar/zoo/foo.html");
+ assertMatches("/**/*.html", "/bar/zoo/foo.html");
+ assertDoesntMatch("/*.html", "foo.html");
+ assertMatches("/*.html", "/foo.html");
+ }
+
+ private void assertMatches(String globPath, String path) {
+ Pattern p = Pattern.compile(GlobbingPathHelper.globAsRegex(globPath));
+ assertTrue("'"+globPath+"' does not match '"+path+"'",
p.matcher(path).matches());
+ }
+
+ private void assertDoesntMatch(String globPath, String path) {
+ Pattern p = Pattern.compile(GlobbingPathHelper.globAsRegex(globPath));
+ assertFalse("'"+globPath+"' does match '"+path+"'",
p.matcher(path).matches());
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/OakEventFilterImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/OakEventFilterImpl.java?rev=1767723&r1=1767722&r2=1767723&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/OakEventFilterImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/OakEventFilterImpl.java
Wed Nov 2 16:35:09 2016
@@ -44,6 +44,7 @@ import org.apache.jackrabbit.oak.plugins
import
org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder.Condition;
import org.apache.jackrabbit.oak.plugins.observation.filter.Filters;
import org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathFilter;
+import org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathHelper;
import
org.apache.jackrabbit.oak.plugins.observation.filter.PermissionProviderFactory;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -502,7 +503,7 @@ public class OakEventFilterImpl extends
public OakEventFilter withNodeTypeAggregate(String[] nodeTypes, String[]
relativeGlobPaths) {
final Pattern[] relativePathPatterns = new
Pattern[relativeGlobPaths.length];
for (int i = 0; i < relativePathPatterns.length; i++) {
- relativePathPatterns[i] =
Pattern.compile(globAsRegex(relativeGlobPaths[i]));
+ relativePathPatterns[i] =
Pattern.compile(GlobbingPathHelper.globAsRegex(relativeGlobPaths[i]));
}
aggregator(new NodeTypeAggregator(nodeTypes, relativePathPatterns));
@@ -511,29 +512,4 @@ public class OakEventFilterImpl extends
return this;
}
- static String globAsRegex(String patternWithGlobs) {
- if (patternWithGlobs == null) {
- return null;
- }
- String[] starStarParts = patternWithGlobs.split("\\*\\*", -1);
- StringBuffer sb = new StringBuffer();
- sb.append("\\Q");
- for (int i = 0; i < starStarParts.length; i++) {
- if (i > 0) {
- // the '**' regexp equivalent
- sb.append("\\E.*\\Q");
- }
- String part = starStarParts[i];
- if (part.startsWith("/")) {
- part = part.substring(1);
- }
- if (part.endsWith("/")) {
- part = part.substring(0, part.length() - 1);
- }
- sb.append(part.replace("*", "\\E[^/]*\\Q"));
- }
- sb.append("\\E");
- return sb.toString();
- }
-
}