use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class ProcessUpdate method updateCollection.
private boolean updateCollection() {
try {
open();
final BwCalendar col = getCal();
if (col == null) {
warn("No path or no calendar");
return true;
}
while (true) {
final String upname = word();
if (upname == null) {
break;
}
assertToken('=');
switch(upname) {
case "topicalArea":
{
final Boolean val = boolFor(upname);
if (val == null) {
return true;
}
col.setIsTopicalArea(val);
break;
}
case "summary":
{
final String val = qstringFor(upname);
if (val == null) {
return true;
}
col.setSummary(val);
break;
}
}
}
getSvci().getCalendarsHandler().update(col);
return true;
} catch (final Throwable t) {
error(t);
return false;
} finally {
close();
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getSyncToken.
@Override
public String getSyncToken(final CalDAVCollection col) throws WebdavException {
try {
BwCalendar bwcol = ((BwCalDAVCollection) col).getCol();
String path = col.getPath();
if (bwcol.getInternalAlias()) {
path = bwcol.getAliasTarget().getPath();
}
return "data:," + getSvci().getCalendarsHandler().getSyncToken(path);
} catch (CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
} catch (Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method copyMove.
/* (non-Javadoc)
* @see org.bedework.caldav.server.SysIntf#copyMove(org.bedework.caldav.server.CalDAVCollection, org.bedework.caldav.server.CalDAVCollection, boolean, boolean)
*/
@Override
public void copyMove(final CalDAVCollection from, final CalDAVCollection to, final boolean copy, final boolean overwrite) throws WebdavException {
try {
BwCalendar bwFrom = unwrap(from);
BwCalendar bwTo = unwrap(to);
if (!copy) {
/* Move the from collection to the new location "to".
* If the parent calendar is the same in both cases, this is just a rename.
*/
if ((bwFrom.getColPath() == null) || (bwTo.getColPath() == null)) {
throw new WebdavForbidden("Cannot move root");
}
if (bwFrom.getColPath().equals(bwTo.getColPath())) {
// Rename
getSvci().getCalendarsHandler().rename(bwFrom, to.getName());
return;
}
}
} catch (CalFacadeAccessException cfae) {
throw new WebdavForbidden();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
} catch (Throwable t) {
throw new WebdavException(t);
}
throw new WebdavException("unimplemented");
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method fromIcal.
/* (non-Javadoc)
* @see org.bedework.caldav.server.sysinterface.SysIntf#fromIcal(org.bedework.caldav.server.CalDAVCollection, java.io.Reader, java.lang.String, org.bedework.caldav.server.sysinterface.SysIntf.IcalResultType, boolean)
*/
@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final Reader rdr, final String contentType, final IcalResultType rtype, final boolean mergeAttendees) throws WebdavException {
// Ensure open
getSvci();
boolean rollback = true;
/* (CALDAV:supported-calendar-data) */
if ((contentType == null) || (!contentType.equals("text/calendar") && !contentType.equals("application/calendar+json"))) {
if (debug) {
debug("Bad content type: " + contentType);
}
throw new WebdavForbidden(CaldavTags.supportedCalendarData, "Bad content type: " + contentType);
}
try {
BwCalendar bwcol = null;
if (col != null) {
bwcol = unwrap(col);
}
final Icalendar ic = trans.fromIcal(bwcol, new SysIntfReader(rdr), contentType, // diff the contents
true, mergeAttendees);
if (rtype == IcalResultType.OneComponent) {
if (ic.getComponents().size() != 1) {
throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
}
if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
}
} else if (rtype == IcalResultType.TimeZone) {
if (ic.getTimeZones().size() != 1) {
throw new WebdavForbidden("Expected one timezone");
}
}
final SysiIcalendar sic = new MySysiIcalendar(this, ic);
rollback = false;
return sic;
} catch (final IcalMalformedException ime) {
throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
} catch (final CalFacadeException cfe) {
if (CalFacadeException.unknownTimezone.equals(cfe.getDetailMessage())) {
throw new WebdavForbidden(CaldavTags.validTimezone, cfe.getMessage());
}
throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, cfe.getMessage());
} catch (final WebdavException wde) {
throw wde;
} catch (final Throwable t) {
if (debug) {
error(t);
}
// Assume bad data in some way
throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, t.getMessage());
} finally {
if (rollback) {
try {
getSvci().rollbackTransaction();
} catch (final Throwable ignored) {
}
}
}
}
use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method allowsSyncReport.
@Override
public boolean allowsSyncReport(final WdCollection col) throws WebdavException {
if (col == null) {
return false;
}
/* This - or any target if an alias - cannot be filtered at the moment. */
final BwCalendar bwcol = ((BwCalDAVCollection) col).getCol();
if (bwcol.getFilterExpr() != null) {
return false;
}
BwCalendar leaf = bwcol;
while (leaf.getInternalAlias()) {
leaf = resolveAlias(leaf, false);
if (// bad alias
(leaf == null) || (leaf.getFilterExpr() != null)) {
return false;
}
}
/* This must be a collection which is either a user home or below. */
String uhome = basicSysProperties.getUserCalendarRoot();
if (uhome.endsWith("/")) {
uhome = uhome.substring(0, uhome.length() - 1);
}
if (uhome.startsWith("/")) {
uhome = uhome.substring(1);
}
final String[] els = bwcol.getPath().split("/");
if ((els.length < 3) || (!"".equals(els[0])) || (els[1] == null) || (els[2] == null) || (els[2].length() == 0)) {
return false;
}
return els[1].equals(uhome);
}
Aggregations