use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.
the class FilterBuilder method makeBwFilter.
private FilterBase makeBwFilter(final CalFilter val) {
boolean conjunction = val instanceof AndCalFilter;
if (val instanceof CalFilterTerms) {
CalFilterTerms cft = (CalFilterTerms) val;
if (cft.terms.size() == 0) {
// No valid matches
return BooleanFilter.falseFilter;
}
if (cft.terms.size() == 1) {
return makeBwFilter(cft.terms.iterator().next());
}
FilterBase res = null;
for (CalFilter cf : cft.terms) {
FilterBase f = makeBwFilter(cf);
if (f != null) {
if (conjunction) {
res = FilterBase.addAndChild(res, f);
} else {
res = FilterBase.addOrChild(res, f);
}
}
}
return res;
}
if (val instanceof HrefFilter) {
BwHrefFilter hf = new BwHrefFilter(null, PropertyInfoIndex.HREF);
hf.setEntity(((HrefFilter) val).href);
return hf;
}
EntityCalFilter ecf = (EntityCalFilter) val;
if (ecf.cal == null) {
return ecf.filter;
}
FilterBase f = new BwCollectionFilter(null, ecf.cal);
return FilterBase.addAndChild(f, ecf.filter);
}
use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.
the class FilterBuilder method buildFilter.
/**
* Build a filter from the given path. The applyFilter flag only
* applies to the root of the tree. The filter may already have been
* processed by the caller.
*
* @param path
* @param applyFilter applies only to root of tree
* @return FilterBase or null
*/
public FilterBase buildFilter(final String path, final boolean applyFilter, final boolean explicitSelection) {
if (path == null) {
return BooleanFilter.falseFilter;
}
BwCalendar col = colCache.get(path);
if (col == null) {
try {
col = parser.getCollection(path);
} catch (CalFacadeException cfe) {
error(cfe);
return BooleanFilter.falseFilter;
}
colCache.put(path, col);
}
final ArrayList<String> pathElements = new ArrayList<>();
pathElements.add(path);
final CalFilter calFilter;
try {
calFilter = makeColFilter(col, applyFilter, explicitSelection, pathElements);
} catch (CalFacadeException cfe) {
error(cfe);
return BooleanFilter.falseFilter;
}
if (calFilter == null) {
// No valid matches
return BooleanFilter.falseFilter;
}
/* if we have any OrCalFilters it's because they refer to different
* calendar collections.
*
* Re-express this as BwFilters
*/
final FilterBase f = makeBwFilter(calFilter);
if (debug) {
debug(" --------- FilterBuilder result ---------------");
dump(f, "");
debug(" --------- end of FilterBuilder result ---------------");
}
return f;
}
use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.
the class FilterBuilder method dump.
private void dump(final FilterBase f, final String curLine) {
if (f instanceof OrFilter) {
debug(curLine + " OR ");
Iterator<FilterBase> it = f.getChildren().iterator();
dumpChildren(it, curLine);
return;
}
if (f instanceof AndFilter) {
debug(curLine + " AND ");
Iterator<FilterBase> it = f.getChildren().iterator();
dumpChildren(it, curLine);
return;
}
if (f instanceof ObjectFilter) {
ObjectFilter of = (ObjectFilter) f;
if (of.getEntity() instanceof BwCalendar) {
final StringBuilder sb = new StringBuilder(curLine);
sb.append(curLine);
sb.append(" cal=");
sb.append(((BwCalendar) of.getEntity()).getPath());
debug(sb.toString());
} else {
debug(curLine + f.toString());
}
} else {
debug(curLine + f.toString());
}
}
use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.
the class SimpleFilterParser method doFactor.
private boolean doFactor() throws ParseFailed {
if (debug) {
debug("doFactor: " + tokenizer.toString());
}
final int tkn = nextToken("doFactor(1)");
if (tkn == StreamTokenizer.TT_EOF) {
return false;
}
if (tkn == '(') {
push(openParen);
doExpr();
if (nextToken("doFactor(2)") != ')') {
throw parseResult.fail("Expected close paren: " + " source: " + source);
}
popOpenParen();
} else {
tokenizer.pushBack();
if (!doPropertyComparison()) {
return false;
}
}
if (!topLOp()) {
return true;
}
final FilterBase filter = popFilters();
final FilterBase topFilter = popFilters();
if (anding()) {
filterStack.push(FilterBase.addAndChild(topFilter, filter));
} else {
filterStack.push(FilterBase.addOrChild(topFilter, filter));
}
// The operator
pop();
return true;
}
use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.
the class SimpleFilterParser method viewFilter.
private FilterBase viewFilter(final String val) throws ParseFailed {
final BwView view = callGetView(val);
if (view == null) {
throw parseResult.fail("Unknown view: " + val + " source: " + source);
}
FilterBase filter = view.getFilter();
if (filter != null) {
return filter;
}
for (final String vpath : view.getCollectionPaths()) {
final FilterBase vpf = resolveVpath(vpath);
filter = or(filter, vpf);
}
final BwViewFilter vf = new BwViewFilter(null);
vf.setEntity(view);
vf.setFilter(filter);
view.setFilter(filter);
return vf;
}
Aggregations