This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resource-filter.git


The following commit(s) were added to refs/heads/master by this push:
     new 99c1e5c  minor changes for OSGi
99c1e5c is described below

commit 99c1e5c510a7a622b29049d2f183ac1577c8dc53
Author: JE Bailey <[email protected]>
AuthorDate: Mon Aug 6 14:00:32 2018 -0400

    minor changes for OSGi
---
 .../sling/resource/filter/ResourceFilter.java      |   5 +-
 .../resource/filter/ResourceFilterException.java   |   3 -
 .../resource/filter/ResourceFilterStream.java      |  82 ++++++++++-------
 .../filter/impl/ResourceFilterAdapter.java         |   7 +-
 .../filter/impl/ResourceFilterStreamImpl.java      | 101 ---------------------
 .../resource/filter/ResourceFilterArgTest.java     |   3 +-
 6 files changed, 59 insertions(+), 142 deletions(-)

diff --git a/src/main/java/org/apache/sling/resource/filter/ResourceFilter.java 
b/src/main/java/org/apache/sling/resource/filter/ResourceFilter.java
index 1bfc71e..a204ec5 100644
--- a/src/main/java/org/apache/sling/resource/filter/ResourceFilter.java
+++ b/src/main/java/org/apache/sling/resource/filter/ResourceFilter.java
@@ -31,7 +31,7 @@ public interface ResourceFilter {
 
     /**
      * Add a series of key - value pairs that can then be evaluated as part of 
the
-     * ScriptFilter
+     * filter creation
      * 
      * @param params
      * @return
@@ -39,7 +39,8 @@ public interface ResourceFilter {
     public abstract ResourceFilter addParams(Map<String, Object> params);
 
     /**
-     * Add a key - value pair that can then be evaluated as part of the Script
+     * Add a key - value pair that can then be evaluated as part of the filter
+     * creation
      * 
      * @param params
      * @return
diff --git 
a/src/main/java/org/apache/sling/resource/filter/ResourceFilterException.java 
b/src/main/java/org/apache/sling/resource/filter/ResourceFilterException.java
index cc36917..e06e2cd 100644
--- 
a/src/main/java/org/apache/sling/resource/filter/ResourceFilterException.java
+++ 
b/src/main/java/org/apache/sling/resource/filter/ResourceFilterException.java
@@ -24,9 +24,6 @@ public class ResourceFilterException extends Exception {
         super(cause);
     }
 
-    /**
-     * 
-     */
     private static final long serialVersionUID = 5893818236312416308L;
 
 
diff --git 
a/src/main/java/org/apache/sling/resource/filter/ResourceFilterStream.java 
b/src/main/java/org/apache/sling/resource/filter/ResourceFilterStream.java
index b40cebc..ae86dd4 100644
--- a/src/main/java/org/apache/sling/resource/filter/ResourceFilterStream.java
+++ b/src/main/java/org/apache/sling/resource/filter/ResourceFilterStream.java
@@ -1,33 +1,38 @@
 /*
- * 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
+ * Licensed 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
+ * 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.
+ * 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.resource.filter;
 
 import java.util.Map;
+import java.util.function.Predicate;
 import java.util.stream.Stream;
 
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.resource.filter.ResourceFilterStream;
 import org.apache.sling.resource.filter.impl.script.ParseException;
 
-public abstract class ResourceFilterStream extends ResourceStream {
+/**
+ * Creates a {@link Predicate} of type {@link Resource} to identify matching
+ * Resource objects
+ *
+ */
+public class ResourceFilterStream extends ResourceStream {
 
-    public ResourceFilterStream(Resource resource) {
+    private ResourceFilter resourceFilter;
+
+    public ResourceFilterStream(Resource resource, ResourceFilter filter) {
         super(resource);
+        this.resourceFilter = filter;
     }
 
     /**
@@ -39,7 +44,9 @@ public abstract class ResourceFilterStream extends 
ResourceStream {
      * @return ResourceStream
      * @throws ParseException
      */
-    public abstract Stream<Resource> stream(String branchSelector) throws 
ResourceFilterException;
+    public Stream<Resource> stream(String branchSelector) throws 
ResourceFilterException {
+        return stream(resourceFilter.parse(branchSelector));
+    }
 
     /**
      * Creates a Stream<Resource> using the branchSelector to create the 
traversal
@@ -52,44 +59,57 @@ public abstract class ResourceFilterStream extends 
ResourceStream {
      * @return ResourceStream
      * @throws ParseException
      */
-    public abstract Stream<Resource> stream(String text, String charEncoding) 
throws ResourceFilterException;
-    
+    public Stream<Resource> stream(String branchSelector, String charEncoding) 
throws ResourceFilterException {
+        return stream(resourceFilter.parse(branchSelector, charEncoding));
+    }
 
     /**
      * Provides a stream of the child resources filtered by the child selector
      * 
      * @param childSelector
      * @return
-     * @throws ResourceFilterException 
+     * @throws ResourceFilterException
      * @throws ParseException
      */
-    public abstract Stream<Resource> listChildren(String text) throws 
ResourceFilterException;
+    public Stream<Resource> listChildren(String childSelector) throws 
ResourceFilterException {
+        return listChildren(resourceFilter.parse(childSelector));
+    }
 
     /**
      * Provides a stream of the child resources filtered by the child selector
      * 
-     * @param childSelector text based definition of the Predicate to use
+     * @param childSelector
+     *            text based definition of the Predicate to use
      * @param charEncoding
      *            char encoding of the branch selector String
      * @return
-     * @throws ResourceFilterException 
+     * @throws ResourceFilterException
      * @throws ParseException
      */
-    public abstract Stream<Resource> listChildren(String text, String 
charEncoding) throws ResourceFilterException;
-    
+    public Stream<Resource> listChildren(String childSelector, String 
charEncoding) throws ResourceFilterException {
+        return listChildren(resourceFilter.parse(childSelector, charEncoding));
+    }
+
     /**
-     * Add a series of key - value pairs that can then be evaluated as part of 
the ScriptFilter
+     * Add a key - value pair that can then be evaluated as part of the Script
      * 
      * @param params
      * @return
      */
-    public abstract ResourceFilterStream addParams(Map<String,Object> params);
-    
+    public ResourceFilterStream addParam(String key, Object value) {
+        resourceFilter.addParam(key, value);
+        return this;
+    }
+
     /**
-     * Add a key - value pair that can then be evaluated as part of the Script
+     * Add a series of key - value pairs that can then be evaluated as part of 
the
+     * ScriptFilter
      * 
      * @param params
      * @return
      */
-    public abstract ResourceFilterStream addParam(String key, Object value);
-}
\ No newline at end of file
+    public ResourceFilterStream addParams(Map<String, Object> params) {
+        resourceFilter.addParams(params);
+        return this;
+    }
+}
diff --git 
a/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterAdapter.java
 
b/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterAdapter.java
index 829a4fa..9f490fa 100644
--- 
a/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterAdapter.java
+++ 
b/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterAdapter.java
@@ -20,7 +20,8 @@ package org.apache.sling.resource.filter.impl;
 
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.resource.filter.ResourceFilter;
+import org.apache.sling.resource.filter.ResourceFilterProvider;
+import org.apache.sling.resource.filter.ResourceFilterStream;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 
@@ -29,13 +30,13 @@ import org.osgi.service.component.annotations.Reference;
 public class ResourceFilterAdapter implements AdapterFactory {
     
     @Reference
-    private volatile ResourceFilter filter;
+    private volatile ResourceFilterProvider filter;
 
     @SuppressWarnings("unchecked")
     @Override
     public <T> T getAdapter(Object adaptable, Class<T> type) {
         if (adaptable instanceof Resource) {
-            return (T) new ResourceFilterStreamImpl((Resource)adaptable, 
filter);
+            return (T) new ResourceFilterStream((Resource)adaptable, 
filter.getResourceFilter());
         }
         return null;
     }
diff --git 
a/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterStreamImpl.java
 
b/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterStreamImpl.java
deleted file mode 100644
index 51d945a..0000000
--- 
a/src/main/java/org/apache/sling/resource/filter/impl/ResourceFilterStreamImpl.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed 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.resource.filter.impl;
-
-import java.util.Map;
-import java.util.function.Predicate;
-import java.util.stream.Stream;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.resource.filter.ResourceFilter;
-import org.apache.sling.resource.filter.ResourceFilterException;
-import org.apache.sling.resource.filter.ResourceFilterStream;
-import org.apache.sling.resource.filter.impl.script.ParseException;
-
-/**
- * Creates a {@link Predicate} of type {@link Resource} to identify matching
- * Resource objects
- *
- */
-public class ResourceFilterStreamImpl extends ResourceFilterStream {
-
-    private ResourceFilter resourceFilter;
-
-    public ResourceFilterStreamImpl(Resource resource, ResourceFilter filter) {
-        super(resource);
-        this.resourceFilter = filter;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * 
org.apache.sling.resource.filter.ResourceFilterStream#addArgument(java.lang.
-     * String, java.lang.Object)
-     */
-    public ResourceFilterStream addArgument(String key, Object value) {
-        resourceFilter.addParam(key, value);
-        return this;
-    }
-
-    @Override
-    public Stream<Resource> stream(String branchSelector) throws 
ResourceFilterException {
-        return stream(resourceFilter.parse(branchSelector));
-    }
-
-    @Override
-    public Stream<Resource> stream(String branchSelector, String charEncoding) 
throws ResourceFilterException {
-        return stream(resourceFilter.parse(branchSelector, charEncoding));
-    }
-
-    @Override
-    public ResourceFilterStream addParams(Map<String, Object> params) {
-        resourceFilter.addParams(params);
-        return this;
-    }
-
-    /**
-     * Provides a stream of the child resources filtered by the child selector
-     * 
-     * @param childSelector
-     * @return
-     * @throws ResourceFilterException
-     * @throws ParseException
-     */
-    public Stream<Resource> listChildren(String childSelector) throws 
ResourceFilterException {
-        return listChildren(resourceFilter.parse(childSelector));
-    }
-
-    /**
-     * Provides a stream of the child resources filtered by the child selector
-     * 
-     * @param childSelector
-     *            text based definition of the Predicate to use
-     * @param charEncoding
-     *            char encoding of the branch selector String
-     * @return
-     * @throws ResourceFilterException
-     * @throws ParseException
-     */
-    public Stream<Resource> listChildren(String childSelector, String 
charEncoding) throws ResourceFilterException {
-        return listChildren(resourceFilter.parse(childSelector,charEncoding));
-    }
-
-    @Override
-    public ResourceFilterStream addParam(String key, Object value) {
-        resourceFilter.addParam(key, value);
-        return this;
-    }
-
-}
diff --git 
a/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java 
b/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java
index 996d16e..3d7efee 100644
--- a/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java
+++ b/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java
@@ -25,7 +25,6 @@ import java.util.stream.Collectors;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.resource.filter.impl.ResourceFilterImpl;
 import org.apache.sling.resource.filter.impl.ResourceFilterProviderImpl;
-import org.apache.sling.resource.filter.impl.ResourceFilterStreamImpl;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
 import org.junit.Before;
 import org.junit.Rule;
@@ -46,7 +45,7 @@ public class ResourceFilterArgTest {
         context.load().json("/data.json", "/content/sample/en");
         context.registerService(new ResourceFilterProviderImpl());
         resource = context.resourceResolver().getResource(START_PATH);
-        context.registerAdapter(Resource.class, ResourceFilterStream.class, 
new ResourceFilterStreamImpl(resource,new ResourceFilterImpl()));
+        context.registerAdapter(Resource.class, ResourceFilterStream.class, 
new ResourceFilterStream(resource,new ResourceFilterImpl()));
     }
 
     @Test

Reply via email to