]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.api.acr/src/org/argeo/api/acr/search/BasicSearch.java
Prepare next development cycle
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / search / BasicSearch.java
index 8028f5d2033e8d5138bf23aaca90a029b2e2f4ce..7aae8cca07721df4cc8a40b819e75eab2d743995 100644 (file)
@@ -9,9 +9,13 @@ import java.util.function.Consumer;
 
 import javax.xml.namespace.QName;
 
-import org.argeo.api.acr.DName;
 import org.argeo.api.acr.QNamed;
 
+/**
+ * A basic search mechanism modelled on WebDav basicsearch.
+ * 
+ * @see http://www.webdav.org/specs/rfc5323.html
+ */
 public class BasicSearch {
 
        private List<QName> select = new ArrayList<>();
@@ -30,10 +34,20 @@ public class BasicSearch {
                return this;
        }
 
+       /**
+        * Convenience method, to search below this absolute path, with depth
+        * {@link Depth#INFINITTY}.
+        */
+       public BasicSearch from(String path) {
+               return from(URI.create(path), Depth.INFINITTY);
+       }
+
+       /** Search below this URI, with depth {@link Depth#INFINITTY}. */
        public BasicSearch from(URI uri) {
                return from(uri, Depth.INFINITTY);
        }
 
+       /** Search below this URI, with this {@link Depth}. */
        public BasicSearch from(URI uri, Depth depth) {
                Objects.requireNonNull(uri);
                Objects.requireNonNull(depth);
@@ -43,11 +57,11 @@ public class BasicSearch {
        }
 
        public BasicSearch where(Consumer<AndFilter> and) {
-               if (where != null)
-                       throw new IllegalStateException("A where clause is already set");
-               AndFilter subFilter = new AndFilter();
-               and.accept(subFilter);
-               where = subFilter;
+//             if (where != null)
+//                     throw new IllegalStateException("A where clause is already set");
+//             AndFilter subFilter = new AndFilter();
+               and.accept((AndFilter) getWhere());
+//             where = subFilter;
                return this;
        }
 
@@ -60,6 +74,8 @@ public class BasicSearch {
        }
 
        public ContentFilter<? extends Composition> getWhere() {
+               if (where == null)
+                       where = new AndFilter();
                return where;
        }
 
@@ -87,10 +103,10 @@ public class BasicSearch {
 
        }
 
-       static void main(String[] args) {
-               BasicSearch search = new BasicSearch();
-               search.select(DName.creationdate.qName()) //
-                               .from(URI.create("/test")) //
-                               .where((f) -> f.eq(DName.creationdate.qName(), ""));
-       }
+//     static void main(String[] args) {
+//             BasicSearch search = new BasicSearch();
+//             search.select(DName.creationdate.qName()) //
+//                             .from(URI.create("/test")) //
+//                             .where((f) -> f.eq(DName.creationdate.qName(), ""));
+//     }
 }