use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class Notifications method find.
@Override
public NotificationType find(final String name) throws CalFacadeException {
final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return null;
}
final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", name));
if (noteRsrc == null) {
return null;
}
return makeNotification(noteRsrc);
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class Notifications method update.
@Override
public boolean update(final NotificationType val) throws CalFacadeException {
if ((val == null) || (val.getNotification() == null) || (val.getNotification().getElementName() == null)) {
return false;
}
try {
final String xml = val.toXml(true);
if (xml == null) {
return false;
}
final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
if (ncol == null) {
return false;
}
final BwResource noteRsrc = getSvc().getResourcesHandler().get(Util.buildPath(false, ncol.getPath(), "/", val.getName()));
if (noteRsrc == null) {
return false;
}
BwResourceContent rc = noteRsrc.getContent();
if (rc == null) {
rc = new BwResourceContent();
noteRsrc.setContent(rc);
}
final byte[] xmlData = xml.getBytes();
rc.setValue(getSvc().getBlob(xmlData));
noteRsrc.setContentLength(xmlData.length);
noteRsrc.setContentType(val.getContentType());
getSvc().getResourcesHandler().update(noteRsrc, true);
getNoteClient().informNotifier(getPrincipalHref(), noteRsrc.getName());
return true;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class EntityDAO method getResource.
public BwResource getResource(final String name, final BwCalendar coll, final int desiredAccess) throws CalFacadeException {
final HibSession sess = getSess();
sess.createQuery(getResourceQuery);
sess.setString("name", name);
sess.setString("path", coll.getPath());
sess.setString("tsenc", BwResource.tombstoned);
sess.cacheableQuery();
return (BwResource) sess.getUnique();
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class Dumpling method dumpCollection.
private void dumpCollection(final Iterator<T> it) throws Throwable {
while (it.hasNext()) {
final DumpEntity d = unwrap(it.next());
globals.counts[countIndex]++;
if ((globals.counts[countIndex] % 100) == 0) {
info(" ... " + globals.counts[countIndex]);
}
if (d instanceof BwResource) {
dumpResource((BwResource) d);
continue;
}
if (d instanceof BwCalendar) {
dumpCollection((BwCalendar) d);
continue;
}
if (d instanceof BwEvent) {
dumpEvent((BwEvent) d);
continue;
}
/* Just dump any remaining classes - no special treatment */
d.dump(xml);
}
}
use of org.bedework.calfacade.BwResource in project bw-calendar-engine by Bedework.
the class BwCalDAVResource method setBinaryContent.
@Override
public void setBinaryContent(final InputStream val) throws WebdavException {
BwResource r = getRsrc();
BwResourceContent rc = r.getContent();
if (rc == null) {
if (!isNew()) {
intf.getFileContent(this);
rc = r.getContent();
}
if (rc == null) {
rc = new BwResourceContent();
r.setContent(rc);
}
}
try {
/* If this is a notification we need to unprefix the data */
final InputStream str;
if (!isNotification()) {
str = val;
} else {
final NotificationType note = Parser.fromXml(val);
note.getNotification().unprefixHrefs(intf.getUrlHandler());
str = new ByteArrayInputStream(note.toXml(true).getBytes());
}
final ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
byte[] inBuffer = new byte[1000];
long clen = 0;
int chunkSize;
int maxSize = intf.getAuthProperties().getMaxUserEntitySize();
long oldSize = r.getContentLength();
while (clen <= maxSize) {
chunkSize = str.read(inBuffer);
if (chunkSize < 0) {
break;
}
outBuff.write(inBuffer, 0, chunkSize);
clen += chunkSize;
}
if (clen > maxSize) {
throw new WebdavForbidden(CaldavTags.maxResourceSize);
}
rc.setValue(intf.getBlob(outBuff.toByteArray()));
r.setContentLength(clen);
if (!intf.updateQuota(getOwner(), clen - oldSize)) {
throw new WebdavForbidden(WebdavTags.quotaNotExceeded);
}
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
Aggregations