Search in sources :

Example 21 with FilterBase

use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.

the class SimpleFilterParser method and.

private FilterBase and(final String name, final FilterBase af, final FilterBase f) {
    final FilterBase res;
    if (af == null) {
        res = f;
    } else {
        if (af instanceof AndFilter) {
            res = af;
        } else {
            res = new AndFilter();
            res.addChild(af);
        }
        res.addChild(f);
    }
    if (name != null) {
        res.setName(name);
    }
    return res;
}
Also used : AndFilter(org.bedework.caldav.util.filter.AndFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 22 with FilterBase

use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.

the class SimpleFilterParser method doPropertyComparison.

private boolean doPropertyComparison() throws ParseFailed {
    final List<PropertyInfo> pis = getProperty(nextToken("getProperty()"));
    final Operator oper = nextOperator();
    final FilterBase pfilter = makePropFilter(pis, oper.op);
    if (pfilter == null) {
        error(new CalFacadeException(CalFacadeException.filterBadProperty, listProps(pis) + " source: " + source));
        throw parseResult.fail("Bad property: " + listProps(pis) + " source: " + source);
    }
    /* If there is a logical operator on the stack top (and/or) then we create
     * an anded or ored filter and push that.
     *
     * Otherwise we just push
     *
     * WRONG - should be done by doFactor
     */
    // if (!topLOp()) {
    filterStack.push(pfilter);
    return true;
}
Also used : BwIcalPropertyInfo(org.bedework.calfacade.ical.BwIcalPropertyInfo) FilterBase(org.bedework.caldav.util.filter.FilterBase) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 23 with FilterBase

use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.

the class SimpleFilterParser method parse.

/**
 * Parse the given expression into a filter. The explicitSelection
 * flag determines whether or not we skip certain collections. For
 * example, we normally skip collections with display off or the
 * inbox. If we explicitly selct thos e items however, we want to
 * see them.
 *
 * @param expr the expression
 * @param explicitSelection true if we are explicitly selecting a
 *                          path or paths
 * @param source            Where the expression came from - for errors
 * @return ParseResult
 */
public ParseResult parse(final String expr, final boolean explicitSelection, final String source) {
    this.explicitSelection = explicitSelection;
    this.source = source;
    parseResult.ok = true;
    try {
        if (debug) {
            debug("About to parse filter expression: " + expr + " from " + source);
        }
        currentExpr = expr;
        tokenizer = new SfpTokenizer(new StringReader(expr));
        doExpr();
        if (topLOp()) {
            pop();
        }
        if (!stackEmpty()) {
            throw parseResult.fail("Filter syntax: " + "source: " + source);
        }
        if (filterStack.size() != 1) {
            throw parseResult.fail("Filter syntax: " + " source: " + source);
        }
        final FilterBase f = popFilters();
        if (debug) {
            debug(f.toString());
        }
        parseResult.SetFilter(f);
    } catch (final ParseFailed ignored) {
    // Result set
    }
    return parseResult;
}
Also used : StringReader(java.io.StringReader) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 24 with FilterBase

use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.

the class FilterBuilder method makeColFilter.

/* Create a filter for the supplied collection object.
   *
   * explicitSelection is true if we have a single path and it refers directly
   * to the given collection, e.g. /user/xxx/Inbox
   *
   * This allows us to see the contents of the inbox for example, but not to
   * include it when given paths like /user/xxx
   *
   * pathElement is used to detect loops in the actual path. We fail with an
   * exception if we discover a repeated URI in the list.
   */
private CalFilter makeColFilter(final BwCalendar cal, final boolean applyFilter, final boolean explicitSelection, final ArrayList<String> pathElements) throws CalFacadeException {
    /* Result of parsing any filter attached to this entity. */
    FilterBase fltr = null;
    if (applyFilter && (cal.getFilterExpr() != null)) {
        fltr = parseExpr(cal);
    }
    if (cal.getCalType() == BwCalendar.calTypeEventList) {
        OrCalFilter ocf = new OrCalFilter();
        for (EventListEntry ele : cal.getEventList()) {
            HrefFilter hf = new HrefFilter();
            hf.href = ele.getHref();
            ocf.terms.add(hf);
        }
        return ocf;
    }
    /* This covers most - calendar collection, inbox, outbox, external alias etc */
    if (cal.getCollectionInfo().onlyCalEntities) {
        // Leaf node
        if (!explicitSelection && (cal.getCalType() != BwCalendar.calTypeCalendarCollection) && (cal.getCalType() != BwCalendar.calTypeExtSub)) {
            return null;
        }
        EntityCalFilter ecalFilter = new EntityCalFilter();
        ecalFilter.cal = cal;
        ecalFilter.filter = fltr;
        // filterCache.put(calPath, ecalFilter);
        return ecalFilter;
    }
    if (cal.getInternalAlias()) {
        BwCalendar target = parser.resolveAlias(cal, false);
        if (target == null) {
            return null;
        }
        String path = target.getPath();
        if (pathElements.contains(path)) {
            throw new CalFacadeSubscriptionLoopException();
        }
        pathElements.add(path);
        return anded(fltr, makeColFilter(target, true, false, pathElements));
    }
    if (cal.getCalType() == BwCalendar.calTypeFolder) {
        return anded(fltr, makeFolderFilter(cal, pathElements));
    }
    return null;
}
Also used : EventListEntry(org.bedework.calfacade.BwCalendar.EventListEntry) CalFacadeSubscriptionLoopException(org.bedework.calfacade.exc.CalFacadeSubscriptionLoopException) BwCalendar(org.bedework.calfacade.BwCalendar) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 25 with FilterBase

use of org.bedework.caldav.util.filter.FilterBase in project bw-calendar-engine by Bedework.

the class FilterBuilder method dumpChildren.

private void dumpChildren(final Iterator<FilterBase> it, final String curLine) {
    if (!it.hasNext()) {
        return;
    }
    FilterBase f = it.next();
    if (it.hasNext()) {
        dumpChildren(it, curLine + "   |   ");
    }
    dump(f, curLine);
}
Also used : FilterBase(org.bedework.caldav.util.filter.FilterBase)

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