You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by je...@apache.org on 2018/07/31 14:26:18 UTC
[sling-org-apache-sling-resource-filter] branch master updated:
Added String encoding support
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 ab314bb Added String encoding support
ab314bb is described below
commit ab314bb515cc24a7a4546711cc539c8fed85a18b
Author: Jason E Bailey <je...@apache.org>
AuthorDate: Tue Jul 31 10:25:34 2018 -0400
Added String encoding support
---
.../sling/resource/filter/ResourceFilter.java | 18 ++++++++++-
.../resource/filter/ResourceFilterStream.java | 36 ++++++++++++++++++++--
2 files changed, 51 insertions(+), 3 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 52f9a7d..a4b8045 100644
--- a/src/main/java/org/apache/sling/resource/filter/ResourceFilter.java
+++ b/src/main/java/org/apache/sling/resource/filter/ResourceFilter.java
@@ -40,7 +40,8 @@ public class ResourceFilter implements Predicate<Resource> {
* Creates a {@link Predicate<Resource>} using the input String as the basis of
* the selection
*
- * @param matchDefinition Script used to define the matching requirements for the Predicate
+ * @param matchDefinition
+ * Script used to define the matching requirements for the Predicate
* @throws ParseException
*/
public ResourceFilter(String matchDefinition) throws ParseException {
@@ -48,6 +49,21 @@ public class ResourceFilter implements Predicate<Resource> {
this.parsedPredicate = rootNode.accept(getContext().getLogicVisitor());
}
+ /**
+ * Creates a {@link Predicate<Resource>} using the input String as the basis of
+ * the selection
+ *
+ * @param matchDefinition
+ * Script used to define the matching requirements for the Predicate
+ * @param charEncoding
+ * char encoding of the matchDefinition
+ * @throws ParseException
+ */
+ public ResourceFilter(String matchDefinition, String charEncoding) throws ParseException {
+ Node rootNode = new FilterParser(new ByteArrayInputStream(matchDefinition.getBytes()), charEncoding).parse();
+ this.parsedPredicate = rootNode.accept(getContext().getLogicVisitor());
+ }
+
@Override
public boolean test(Resource resource) {
return parsedPredicate.test(resource);
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 eafa4f1..0c06c7c 100644
--- a/src/main/java/org/apache/sling/resource/filter/ResourceFilterStream.java
+++ b/src/main/java/org/apache/sling/resource/filter/ResourceFilterStream.java
@@ -39,18 +39,50 @@ public class ResourceFilterStream extends ResourceStream {
public Stream<Resource> stream(String branchSelector) throws ParseException {
return stream(new ResourceFilter(branchSelector));
}
-
+
+ /**
+ * Creates a Stream<Resource> using the branchSelector to create the traversal
+ * predicate to select the appropriate child resources
+ *
+ * @param branchSelector
+ * resourceFilter script for traversal control
+ * @param charEncoding
+ * char encoding of the branch selector String
+ * @return ResourceStream
+ * @throws ParseException
+ */
+ public Stream<Resource> stream(String branchSelector, String charEncoding) throws ParseException {
+ return stream(new ResourceFilter(branchSelector, charEncoding));
+ }
+
/**
* Provides a stream of the child resources of the base resource. The predicate
* is a filter to determine which of the children are returned
*
* @param childSelector
* @return
- * @throws ParseException
+ * @throws ParseException
*/
public Stream<Resource> listChildren(String childSelector) throws ParseException {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(resource.listChildren(),
Spliterator.ORDERED | Spliterator.IMMUTABLE), false).filter(new ResourceFilter(childSelector));
}
+ /**
+ * Provides a stream of the child resources of the base resource. The predicate
+ * is a filter to determine which of the children are returned
+ *
+ * @param childSelector
+ * @param charEncoding
+ * char encoding of the branch selector String
+ * @return
+ * @throws ParseException
+ */
+ public Stream<Resource> listChildren(String childSelector, String charEncoding) throws ParseException {
+ return StreamSupport
+ .stream(Spliterators.spliteratorUnknownSize(resource.listChildren(),
+ Spliterator.ORDERED | Spliterator.IMMUTABLE), false)
+ .filter(new ResourceFilter(childSelector, charEncoding));
+ }
+
}
\ No newline at end of file