use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class Move method checkPrecondition.
@Override
public void checkPrecondition(DavContext ctxt) throws DavException, ServiceException {
super.checkPrecondition(ctxt);
DavResource rs = ctxt.getRequestedResource();
if (!(rs instanceof MailItemResource))
throw new DavException("cannot move", HttpServletResponse.SC_BAD_REQUEST, null);
col = ctxt.getDestinationCollection();
mir = (MailItemResource) rs;
if (!mir.isCollection()) {
Collection srcCollection = ctxt.getRequestedParentCollection();
if (srcCollection.getDefaultView() != MailItem.Type.UNKNOWN && srcCollection.getDefaultView() != col.getDefaultView())
throw new DavException("cannot move to incompatible collection", HttpServletResponse.SC_FORBIDDEN, null);
} else {
// allow moving of collections of type document or unknown only.
if (!(((Collection) mir).getDefaultView() == MailItem.Type.DOCUMENT || ((Collection) mir).getDefaultView() == MailItem.Type.UNKNOWN))
throw new DavException("cannot move non-document collection", HttpServletResponse.SC_FORBIDDEN, null);
// do not allow moving of collection if destination type is not document or unknown.
if (!(col.getDefaultView() == MailItem.Type.UNKNOWN || col.getDefaultView() == MailItem.Type.DOCUMENT))
throw new DavException("cannot move to incompatible collection", HttpServletResponse.SC_FORBIDDEN, null);
}
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class Put method handle.
@Override
public void handle(DavContext ctxt) throws DavException, IOException {
String user = ctxt.getUser();
String name = ctxt.getItem();
if (user == null || name == null)
throw new DavException("invalid uri", HttpServletResponse.SC_NOT_ACCEPTABLE, null);
Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
DavResource rs = col.createItem(ctxt, name);
if (rs.isNewlyCreated())
ctxt.setStatus(HttpServletResponse.SC_CREATED);
else
ctxt.setStatus(HttpServletResponse.SC_NO_CONTENT);
if (rs.hasEtag()) {
ctxt.getResponse().setHeader(DavProtocol.HEADER_ETAG, rs.getEtag());
ctxt.getResponse().setHeader(ETagHeaderFilter.ZIMBRA_ETAG_HEADER, rs.getEtag());
}
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class Report method handle.
@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
if (!ctxt.hasRequestMessage()) {
throw new DavException("empty request body", HttpServletResponse.SC_BAD_REQUEST, null);
}
Document req = ctxt.getRequestMessage();
Element top = req.getRootElement();
if (top == null) {
throw new DavException("empty request body", HttpServletResponse.SC_BAD_REQUEST, null);
}
QName topName = top.getQName();
DavMethod report = sReports.get(topName);
if (report == null) {
throw new DavException.UnsupportedReport(topName);
}
disableJettyTimeout(ctxt);
if (ctxt.getDepth() != DavContext.Depth.zero) {
ctxt.getDavResponse().createResponse(ctxt);
}
report.handle(ctxt);
sendResponse(ctxt);
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class CalendarQuery method handle.
@Override
public void handle(DavContext ctxt) throws DavException, ServiceException {
Element query = ctxt.getRequestMessage().getRootElement();
if (!query.getQName().equals(DavElements.E_CALENDAR_QUERY)) {
throw new DavException("msg " + query.getName() + " is not calendar-query", HttpServletResponse.SC_BAD_REQUEST, null);
}
RequestProp reqProp = ctxt.getRequestProp();
QueryContext qctxt = new QueryContext(ctxt, query, reqProp);
if (qctxt.componentFilter == null) {
throw new DavException("missing filter element in the request", HttpServletResponse.SC_BAD_REQUEST, null);
}
DavResource rsc = ctxt.getRequestedResource();
if (!(rsc instanceof CalendarCollection)) {
throw new DavException("not a calendar resource", HttpServletResponse.SC_BAD_REQUEST, null);
}
CalendarCollection cal = (CalendarCollection) rsc;
TimeRange tr = qctxt.componentFilter.getTimeRange();
if (tr == null) {
tr = new TimeRange(rsc.getOwner());
}
/**
* Even if there are no matching items, we should return a DAV:multistatus report
* http://tools.ietf.org/html/rfc4791#section-7.8 CALDAV:calendar-query REPORT
* The response body for a successful request MUST be a DAV:multistatus XML element (i.e., the response uses
* the same format as the response for PROPFIND). In the case where there are no response elements, the
* returned DAV:multistatus XML element is empty.
*/
qctxt.davCtxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
DavResponse resp = qctxt.davCtxt.getDavResponse();
resp.getTop(DavElements.E_MULTISTATUS);
for (DavResource calItem : cal.getChildren(ctxt, tr)) {
handleCalendarItem(qctxt, calItem);
}
}
use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.
the class Delete method handle.
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
DavResource rsc = ctxt.getRequestedResource();
if (rsc == null)
throw new DavException("cannot find the resource", HttpServletResponse.SC_NOT_FOUND, null);
rsc.delete(ctxt);
ctxt.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Aggregations