use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwObjectFilter method match.
/* ====================================================================
* matching methods
* ==================================================================== */
@Override
public boolean match(final Object o, final String userHref) throws WebdavException {
ObjectFilter of = getEntity();
Object ent = of.getEntity();
boolean not = of.getNot();
String val = null;
Integer ival = null;
if (ent instanceof BwCalendar) {
val = ((BwCalendar) ent).getPath();
} else if (ent instanceof String) {
val = (String) ent;
} else if (ent instanceof Integer) {
ival = (Integer) ent;
} else {
throw new WebdavException("Unmatchable filter");
}
BwEvent ev = null;
if (o instanceof BwEvent) {
ev = (BwEvent) o;
}
if (of instanceof EntityTypeFilter) {
if (ev == null) {
return false;
}
if (not) {
return ev.getEntityType() != ival;
}
return ev.getEntityType() == ival;
}
PropertyInfoIndex pii = of.getPropertyIndex();
BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pii);
if (pi.getParam()) {
pii = of.getParentPropertyIndex();
}
switch(pii) {
case CLASS:
if (ev.getClassification() == null) {
return false;
}
return stringMatch(ev.getClassification(), val);
case CREATED:
return stringMatch(ev.getCreated(), val);
case DESCRIPTION:
for (BwLongString ls : ev.getDescriptions()) {
if (stringMatch(ls.getValue(), val)) {
return true;
}
}
return false;
case DTSTAMP:
return stringMatch(ev.getDtstamp(), val);
case DTEND:
/* Event only */
case DUE:
/* Todo only */
return matchDateTime(pi, ev.getDtend(), val);
case DTSTART:
return matchDateTime(pi, ev.getDtstart(), val);
case DURATION:
return stringMatch(ev.getDuration(), val);
case GEO:
if (ev.getGeo() == null) {
return false;
}
return stringMatch(ev.getGeo().toString(), val);
case LAST_MODIFIED:
return stringMatch(ev.getLastmod(), val);
case LOCATION:
if (ev.getLocation() == null) {
return false;
}
return stringMatch(ev.getLocation().getAddress().getValue(), val);
case ORGANIZER:
if (ev.getOrganizer() == null) {
return false;
}
return stringMatch(ev.getOrganizer().getOrganizerUri(), val);
case PRIORITY:
if (ev.getPriority() == null) {
return false;
}
return stringMatch(String.valueOf(ev.getPriority()), val);
case RECURRENCE_ID:
if (ev.getRecurrenceId() == null) {
return false;
}
return stringMatch(ev.getRecurrenceId(), val);
case SEQUENCE:
return stringMatch(String.valueOf(ev.getSequence()), val);
case STATUS:
if (ev.getStatus() == null) {
return false;
}
return stringMatch(ev.getStatus(), val);
case SUMMARY:
for (BwString s : ev.getSummaries()) {
if (stringMatch(s.getValue(), val)) {
return true;
}
}
return false;
case UID:
return stringMatch(ev.getUid(), val);
case URL:
if (ev.getLink() == null) {
return false;
}
return stringMatch(ev.getLink(), val);
case TRANSP:
try {
if (ev.getPeruserTransparency(userHref) == null) {
return false;
}
return stringMatch(ev.getPeruserTransparency(userHref), val);
} catch (Throwable t) {
throw new WebdavException(t);
}
case COMPLETED:
if (ev.getCompleted() == null) {
return false;
}
return stringMatch(ev.getCompleted(), val);
case PERCENT_COMPLETE:
if (ev.getPercentComplete() == null) {
return false;
}
return stringMatch(String.valueOf(ev.getPercentComplete()), val);
case ATTACH:
break;
case ATTENDEE:
break;
case CATEGORIES:
for (BwCategory cat : ev.getCategories()) {
if (stringMatch(cat.getWordVal(), val)) {
return true;
}
}
return false;
case COMMENT:
for (BwString s : ev.getComments()) {
if (stringMatch(s.getValue(), val)) {
return true;
}
}
return false;
case CONTACT:
for (BwContact c : ev.getContacts()) {
if (stringMatch(c.getCn().getValue(), val)) {
return true;
}
}
return false;
case EXDATE:
for (BwDateTime dt : ev.getExdates()) {
if (stringMatch(dt.getDtval(), val)) {
return true;
}
}
return false;
case EXRULE:
for (String s : ev.getExrules()) {
if (stringMatch(s, val)) {
return true;
}
}
return false;
case REQUEST_STATUS:
for (BwRequestStatus rs : ev.getRequestStatuses()) {
if (stringMatch(rs.getCode(), val)) {
return true;
}
}
return false;
case RELATED_TO:
if (ev.getRelatedTo() == null) {
return false;
}
return stringMatch(ev.getRelatedTo().getValue(), val);
case RESOURCES:
for (BwString s : ev.getResources()) {
if (stringMatch(s.getValue(), val)) {
return true;
}
}
return false;
case RDATE:
for (BwDateTime dt : ev.getRdates()) {
if (stringMatch(dt.getDtval(), val)) {
return true;
}
}
return false;
case RRULE:
for (String s : ev.getRrules()) {
if (stringMatch(s, val)) {
return true;
}
}
return false;
case FREEBUSY:
break;
case TZID:
break;
case TZNAME:
break;
case TZOFFSETFROM:
break;
case TZOFFSETTO:
break;
case TZURL:
break;
case ACTION:
break;
case REPEAT:
break;
case TRIGGER:
break;
case COLLECTION:
return stringMatch(ev.getColPath(), val);
case CREATOR:
return stringMatch(ev.getCreatorHref(), val);
case OWNER:
return stringMatch(ev.getOwnerHref(), val);
case ENTITY_TYPE:
break;
}
return false;
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwCalDAVEvent method generatePropertyValue.
@Override
public boolean generatePropertyValue(final QName tag, final XmlEmit xml) throws WebdavException {
try {
BwEvent ev = getEv();
if (tag.equals(CaldavTags.scheduleTag)) {
if (!ev.getOrganizerSchedulingObject() && !ev.getAttendeeSchedulingObject()) {
return false;
}
xml.property(tag, ev.getStag());
return true;
}
if (tag.equals(CaldavTags.originator)) {
if (ev.getOriginator() != null) {
xml.openTag(tag);
xml.property(WebdavTags.href, ev.getOriginator());
xml.closeTag(tag);
}
return true;
}
if (tag.equals(CaldavTags.recipient)) {
Collection<String> r = ev.getRecipients();
if ((r == null) || (r.isEmpty())) {
return true;
}
xml.openTag(tag);
for (String recip : r) {
xml.property(WebdavTags.href, recip);
}
xml.closeTag(tag);
return true;
}
if (tag.equals(AppleServerTags.scheduleChanges)) {
List<BwXproperty> xps = ev.getXproperties(BwXproperty.bedeworkChanges);
if (Util.isEmpty(xps)) {
return true;
}
BwXproperty xp = xps.get(0);
String[] vals = xp.getValue().split(";");
xml.openTag(tag);
xml.property(AppleServerTags.dtstamp, vals[0]);
xml.openTag(AppleServerTags.action);
QName actionTag;
if ("CANCEL".equals(vals[1])) {
actionTag = AppleServerTags.cancel;
} else if ("CREATE".equals(vals[1])) {
actionTag = AppleServerTags.create;
} else if ("REPLY".equals(vals[1])) {
actionTag = AppleServerTags.reply;
} else {
// "UPDATE"
actionTag = AppleServerTags.update;
}
xml.openTag(actionTag);
int i = 2;
while (i < vals.length) {
/* Next is master or rid */
xml.openTag(AppleServerTags.recurrence);
String val = vals[i];
if ("MASTER".equals(val)) {
xml.emptyTag(AppleServerTags.master);
i++;
}
if (val.startsWith("RID=")) {
xml.openTagNoNewline(AppleServerTags.recurrenceid);
xml.value(val);
xml.closeTag(AppleServerTags.recurrenceid);
i++;
}
if ((i < vals.length) && "CHANGES".equals(vals[i])) {
i++;
xml.openTag(AppleServerTags.changes);
while (i < vals.length) {
val = vals[i];
if ("MASTER".equals(val) || "CHANGES".equals(val) || val.startsWith("RID=")) {
break;
}
xml.startTag(AppleServerTags.changedProperty);
xml.attribute("name", val);
xml.endEmptyTag();
i++;
}
xml.closeTag(AppleServerTags.changes);
}
xml.closeTag(AppleServerTags.recurrence);
}
xml.closeTag(actionTag);
xml.closeTag(AppleServerTags.action);
xml.closeTag(tag);
return true;
}
if (tag.equals(ICalTags.action)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.attach)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.attendee)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.categories)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags._class)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.comment)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.completed)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.contact)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.created)) {
xml.property(tag, ev.getCreated());
return true;
}
if (tag.equals(ICalTags.description)) {
if (ev.getDescription() != null) {
xml.property(tag, ev.getDescription());
}
return true;
}
if (tag.equals(ICalTags.dtend)) {
xml.property(tag, ev.getDtend().getDate());
return true;
}
if (tag.equals(ICalTags.dtstamp)) {
xml.property(tag, ev.getDtstamp());
return true;
}
if (tag.equals(ICalTags.dtstart)) {
xml.property(tag, ev.getDtstart().getDate());
return true;
}
if (tag.equals(ICalTags.duration)) {
xml.property(tag, ev.getDuration());
return true;
}
if (tag.equals(ICalTags.exdate)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.exrule)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.freebusy)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.geo)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.lastModified)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.lastModified)) {
xml.property(tag, ev.getLastmod());
return true;
}
if (tag.equals(ICalTags.location)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.organizer)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.organizer)) {
if (ev.getOrganizer() != null) {
xml.property(tag, ev.getOrganizer().getOrganizerUri());
}
return true;
}
if (tag.equals(ICalTags.percentComplete)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.priority)) {
Integer val = ev.getPriority();
if ((val != null) && (val != 0)) {
xml.property(tag, String.valueOf(val));
}
return true;
}
if (tag.equals(ICalTags.rdate)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.recurrenceId)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.recurrenceId)) {
if (ev.getRecurrenceId() != null) {
xml.property(tag, ev.getRecurrenceId());
}
return true;
}
if (tag.equals(ICalTags.relatedTo)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.repeat)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.resources)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.requestStatus)) {
/*
if (ev.getRequestStatus() != null) {
xml.property(tag, ev.getRequestStatus().strVal());
}
*/
return true;
}
if (tag.equals(ICalTags.rrule)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.sequence)) {
xml.property(tag, String.valueOf(ev.getSequence()));
return true;
}
if (tag.equals(ICalTags.status)) {
xml.property(tag, ev.getStatus());
return true;
}
if (tag.equals(ICalTags.summary)) {
xml.property(tag, ev.getSummary());
return true;
}
if (tag.equals(ICalTags.transp)) {
xml.property(tag, ev.getPeruserTransparency(intf.getPrincipal().getPrincipalRef()));
return true;
}
if (tag.equals(ICalTags.trigger)) {
// PROPTODO
return true;
}
if (tag.equals(ICalTags.uid)) {
xml.property(tag, ev.getUid());
return true;
}
if (tag.equals(ICalTags.url)) {
if (ev.getLink() != null) {
xml.property(tag, ev.getLink());
}
return true;
}
if (tag.equals(ICalTags.version)) {
// PROPTODO
return true;
}
return false;
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method updateQuota.
boolean updateQuota(final AccessPrincipal principal, final long inc) throws WebdavException {
try {
BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
if (p == null) {
// No quota - fail
return false;
}
if (p.getKind() != WhoDefs.whoTypeUser) {
// No quota - fail
return false;
}
BwPreferences prefs = getPrefs();
long used = prefs.getQuotaUsed() + inc;
prefs.setQuotaUsed(used);
getSvci().getUsersHandler().update(p);
return // Decreasing usage - let it pass
(inc < 0) || (used <= p.getQuota());
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.webdav.servlet.shared.WebdavException 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.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getCalPrincipalInfo.
@Override
public CalPrincipalInfo getCalPrincipalInfo(final AccessPrincipal principal) throws WebdavException {
try {
if (principal == null) {
return null;
}
final boolean thisPrincipal = principal.equals(getSvci().getPrincipal());
if (thisPrincipal && (principalInfo != null)) {
return principalInfo;
}
final BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
if (p == null) {
return null;
}
if (p.getKind() != WhoDefs.whoTypeUser) {
// XXX Cannot handle this yet
return null;
}
// SCHEDULE - just get home path and get default cal from user prefs.
final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(p));
final String defaultCalendarPath = Util.buildPath(true, userHomePath + basicSysProperties.getUserDefaultCalendar());
final String inboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserInbox());
;
final String outboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserOutbox());
final String notificationsPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getDefaultNotificationsName());
final CalPrincipalInfo pi = new CalPrincipalInfo(p, null, null, userHomePath, defaultCalendarPath, inboxPath, outboxPath, notificationsPath, p.getQuota());
if (thisPrincipal) {
principalInfo = pi;
}
return pi;
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
Aggregations