use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.
the class FilterBuilder method parseExpr.
private FilterBase parseExpr(final BwCalendar col) throws CalFacadeException {
SimpleFilterParser sfp = parser.getParser();
ParseResult pr = sfp.parse(col.getFilterExpr(), false, col.getPath());
if (!pr.ok) {
throw pr.cfe;
}
return pr.filter;
}
use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.
the class Filters method parse.
@Override
public ParseResult parse(final BwFilterDef val) {
final String def = val.getDefinition();
if ((def.length() > 5) && (def.startsWith("<?xml"))) {
// Assume xml filter
final ParseResult pr = new ParseResult();
try {
final FilterType f = org.bedework.caldav.util.filter.parse.Filters.parse(def);
final EventQuery eq = org.bedework.caldav.util.filter.parse.Filters.getQuery(f);
val.setFilters(eq.filter);
pr.ok = true;
} catch (final Throwable t) {
pr.ok = false;
pr.message = t.getMessage();
pr.cfe = new CalFacadeException(t);
}
return pr;
}
// Assume simple expression filter
final String source = "BwFilterDef:" + val.getOwnerHref() + ":" + val.getName();
final ParseResult pr = getSvc().getFilterParser().parse(def, false, source);
if (pr.ok) {
val.setFilters(pr.filter);
}
return pr;
}
use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getEvents.
@Override
public Collection<CalDAVEvent> getEvents(final CalDAVCollection col, final FilterBase filter, final List<String> retrieveList, final RetrievalMode recurRetrieval) throws WebdavException {
try {
/* Limit the results to just this collection by adding an ANDed filter */
final SimpleFilterParser sfp = getSvci().getFilterParser();
final String expr = "(colPath='" + SfpTokenizer.escapeQuotes(col.getPath()) + "')";
final ParseResult pr = sfp.parse(expr, true, null);
if (!pr.ok) {
throw new WebdavBadRequest("Failed to reference collection " + col.getPath() + ": message was " + pr.message);
}
final FilterBase f = FilterBase.addAndChild(filter, pr.filter);
final Collection<EventInfo> bwevs = // Collection
getSvci().getEventsHandler().getEvents(// Collection
null, f, // start
null, // end
null, RetrieveList.getRetrieveList(retrieveList), DeletedState.noDeleted, getRrm(recurRetrieval));
if (bwevs == null) {
return null;
}
final Collection<CalDAVEvent> evs = new ArrayList<>();
for (final EventInfo ei : bwevs) {
if (recurRetrieval != null) {
ei.getEvent().setForceUTC(recurRetrieval.getExpand() != null);
}
evs.add(new BwCalDAVEvent(this, ei));
}
return evs;
} catch (final CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (final CalFacadeException cfe) {
if (CalFacadeException.unknownProperty.equals(cfe.getMessage())) {
throw new WebdavBadRequest("Unknown property " + cfe.getExtra());
}
throw new WebdavException(cfe);
} catch (final WebdavException wde) {
throw wde;
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.calfacade.filter.SimpleFilterParser.ParseResult in project bw-calendar-engine by Bedework.
the class Events method get.
@Override
public EventInfo get(final BwCalendar col, final String name, final String recurrenceId, final List<String> retrieveList) throws CalFacadeException {
if ((col == null) || (name == null)) {
throw new CalFacadeException(CalFacadeException.badRequest);
}
if (col.getInternalAlias()) {
final String expr = "(vpath='" + SfpTokenizer.escapeQuotes(col.getPath()) + "') and (name='" + SfpTokenizer.escapeQuotes(name) + "')";
final SimpleFilterParser sfp = getSvc().getFilterParser();
final ParseResult pr = sfp.parse(expr, true, null);
if (!pr.ok) {
throw new CalFacadeException("Failed to parse " + expr + ": message was " + pr.message);
}
final Collection<EventInfo> evs = getEvents(null, pr.filter, // start
null, // end
null, RetrieveList.getRetrieveList(retrieveList), DeletedState.noDeleted, RecurringRetrievalMode.overrides);
if (evs.size() == 0) {
return null;
}
if (evs.size() == 1) {
return evs.iterator().next();
}
throw new CalFacadeException("Multiple results");
}
String path = col.getPath();
if (col.getCalType() == BwCalendar.calTypeEventList) {
/* Find the event in the list using the name */
final SortedSet<EventListEntry> eles = col.getEventList();
findHref: {
for (final EventListEntry ele : eles) {
if (ele.getName().equals(name)) {
path = ele.getPath();
break findHref;
}
}
// Not in list
return null;
}
// findHref
}
return get(path, name, null);
}
Aggregations