Search in sources :

Example 1 with FilterBase

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);
}
Also used : FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 2 with FilterBase

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;
}
Also used : ArrayList(java.util.ArrayList) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 3 with FilterBase

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());
    }
}
Also used : AndFilter(org.bedework.caldav.util.filter.AndFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) BwCalendar(org.bedework.calfacade.BwCalendar) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 4 with FilterBase

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;
}
Also used : FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 5 with FilterBase

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;
}
Also used : ToString(org.bedework.util.misc.ToString) FilterBase(org.bedework.caldav.util.filter.FilterBase) BwView(org.bedework.calfacade.svc.BwView)

Aggregations

FilterBase (org.bedework.caldav.util.filter.FilterBase)25 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)9 ArrayList (java.util.ArrayList)8 OrFilter (org.bedework.caldav.util.filter.OrFilter)8 BwCalendar (org.bedework.calfacade.BwCalendar)8 AndFilter (org.bedework.caldav.util.filter.AndFilter)7 EntityTimeRangeFilter (org.bedework.caldav.util.filter.EntityTimeRangeFilter)5 PresenceFilter (org.bedework.caldav.util.filter.PresenceFilter)5 TimeRangeFilter (org.bedework.caldav.util.filter.TimeRangeFilter)5 BwObjectFilter (org.bedework.calfacade.filter.BwObjectFilter)5 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)4 PropertyFilter (org.bedework.caldav.util.filter.PropertyFilter)4 BwCategoryFilter (org.bedework.calfacade.filter.BwCategoryFilter)4 EventInfo (org.bedework.calfacade.svc.EventInfo)4 TreeSet (java.util.TreeSet)3 BwCategory (org.bedework.calfacade.BwCategory)3 BwEvent (org.bedework.calfacade.BwEvent)3 BwHrefFilter (org.bedework.calfacade.filter.BwHrefFilter)3 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)3 ToString (org.bedework.util.misc.ToString)3