use of org.bedework.calfacade.BwResourceContent 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.BwResourceContent in project bw-calendar-engine by Bedework.
the class EntityDAO method getResourceContent.
public void getResourceContent(final BwResource val) throws CalFacadeException {
final HibSession sess = getSess();
sess.createQuery(getResourceContentQuery);
sess.setString("path", val.getColPath());
sess.setString("name", val.getName());
sess.cacheableQuery();
final BwResourceContent rc = (BwResourceContent) sess.getUnique();
if (rc == null) {
throw new CalFacadeException(CalFacadeException.missingResourceContent);
}
val.setContent(rc);
}
use of org.bedework.calfacade.BwResourceContent in project bw-calendar-engine by Bedework.
the class BwCalDAVResource method getBinaryStream.
private InputStream getBinaryStream() throws WebdavException {
if (rsrc == null) {
return null;
}
if (rsrc.getContent() == null) {
intf.getFileContent(this);
}
BwResourceContent bwrc = rsrc.getContent();
if (bwrc == null) {
return null;
}
Blob b = bwrc.getValue();
if (b == null) {
return null;
}
try {
return b.getBinaryStream();
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
use of org.bedework.calfacade.BwResourceContent 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);
}
}
use of org.bedework.calfacade.BwResourceContent in project bw-calendar-engine by Bedework.
the class Notifications method makeNotification.
private NotificationType makeNotification(final BwResource rsrc) throws CalFacadeException {
getSvc().getResourcesHandler().getContent(rsrc);
final BwResourceContent bwrc = rsrc.getContent();
if (bwrc == null) {
return null;
}
final Blob b = bwrc.getValue();
if (b == null) {
return null;
}
try {
final InputStream is = b.getBinaryStream();
final NotificationType note = Parser.fromXml(is);
if (note != null) {
note.setName(rsrc.getName());
note.getNotification().setEncoding(rsrc.getEncoding());
}
return note;
} catch (final Throwable t) {
if (debug) {
error(t);
}
error("Unable to parse notification " + rsrc.getColPath() + " " + rsrc.getName());
return null;
}
}
Aggregations