]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.acr/src/org/argeo/api/acr/search/BasicSearch.java
1 package org
.argeo
.api
.acr
.search
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Arrays
;
7 import java
.util
.Objects
;
8 import java
.util
.function
.Consumer
;
10 import javax
.xml
.namespace
.QName
;
12 import org
.argeo
.api
.acr
.QNamed
;
15 * A basic search mechanism modelled on WebDav basicsearch.
17 * @see http://www.webdav.org/specs/rfc5323.html
19 public class BasicSearch
{
21 private List
<QName
> select
= new ArrayList
<>();
22 private List
<Scope
> from
= new ArrayList
<>();
24 private ContentFilter
<?
extends Composition
> where
;
26 public BasicSearch
select(QNamed
... attr
) {
28 select
.add(q
.qName());
32 public BasicSearch
select(QName
... attr
) {
33 select
.addAll(Arrays
.asList(attr
));
38 * Convenience method, to search below this absolute path, with depth
39 * {@link Depth#INFINITTY}.
41 public BasicSearch
from(String path
) {
42 return from(URI
.create(path
), Depth
.INFINITTY
);
45 /** Search below this URI, with depth {@link Depth#INFINITTY}. */
46 public BasicSearch
from(URI uri
) {
47 return from(uri
, Depth
.INFINITTY
);
50 /** Search below this URI, with this {@link Depth}. */
51 public BasicSearch
from(URI uri
, Depth depth
) {
52 Objects
.requireNonNull(uri
);
53 Objects
.requireNonNull(depth
);
54 Scope scope
= new Scope(uri
, depth
);
59 public BasicSearch
where(Consumer
<AndFilter
> and
) {
61 // throw new IllegalStateException("A where clause is already set");
62 // AndFilter subFilter = new AndFilter();
63 and
.accept((AndFilter
) getWhere());
68 public List
<QName
> getSelect() {
72 public List
<Scope
> getFrom() {
76 public ContentFilter
<?
extends Composition
> getWhere() {
78 where
= new AndFilter();
82 public static enum Depth
{
86 public static class Scope
{
91 public Scope(URI uri
, Depth depth
) {
100 public Depth
getDepth() {
106 // static void main(String[] args) {
107 // BasicSearch search = new BasicSearch();
108 // search.select(DName.creationdate.qName()) //
109 // .from(URI.create("/test")) //
110 // .where((f) -> f.eq(DName.creationdate.qName(), ""));