use of com.zimbra.cs.dav.resource.Collection in project zm-mailbox by Zimbra.
the class DavContext method getDestinationCollection.
public Collection getDestinationCollection() throws DavException {
String destinationUrl = getDestinationUrl();
if (!destinationUrl.endsWith("/")) {
int slash = destinationUrl.lastIndexOf('/');
destinationUrl = destinationUrl.substring(0, slash + 1);
}
try {
destinationUrl = HttpUtil.urlUnescape(destinationUrl);
destinationUrl = getInternalDestinationUrl(destinationUrl);
DavResource r = UrlNamespace.getResourceAtUrl(this, destinationUrl);
if (r instanceof Collection)
return ((Collection) r);
return UrlNamespace.getCollectionAtUrl(this, destinationUrl);
} catch (Exception e) {
throw new DavException("can't get destination collection", DavProtocol.STATUS_FAILED_DEPENDENCY);
}
}
use of com.zimbra.cs.dav.resource.Collection in project zm-mailbox by Zimbra.
the class MkAddressbook 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_FORBIDDEN, null);
Element top = null;
if (ctxt.hasRequestMessage()) {
Document doc = ctxt.getRequestMessage();
top = doc.getRootElement();
if (!top.getName().equals(DavElements.P_MKADDRESSBOOK))
throw new DavException("msg " + top.getName() + " not allowed in MKADDRESSBOOK", HttpServletResponse.SC_BAD_REQUEST, null);
}
Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
Collection newone = col.mkCol(ctxt, name, MailItem.Type.CONTACT);
boolean success = false;
try {
PropPatch.handlePropertyUpdate(ctxt, top, newone, true, MKADDRESSBOOK);
success = true;
} finally {
if (!success)
newone.delete(ctxt);
}
ctxt.setStatus(HttpServletResponse.SC_CREATED);
ctxt.getResponse().addHeader(DavProtocol.HEADER_CACHE_CONTROL, DavProtocol.NO_CACHE);
}
use of com.zimbra.cs.dav.resource.Collection in project zm-mailbox by Zimbra.
the class MkCalendar method handle.
// valid return codes:
// 201 Created, 207 Multi-Status (403, 409, 423, 424, 507),
// 403 Forbidden, 409 Conflict, 415 Unsupported Media Type,
// 507 Insufficient Storage
@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_FORBIDDEN, null);
Element top = null;
if (ctxt.hasRequestMessage()) {
Document doc = ctxt.getRequestMessage();
top = doc.getRootElement();
if (!top.getName().equals(DavElements.P_MKCALENDAR))
throw new DavException("msg " + top.getName() + " not allowed in MKCALENDAR", HttpServletResponse.SC_BAD_REQUEST, null);
}
Collection col = UrlNamespace.getCollectionAtUrl(ctxt, ctxt.getPath());
if (col instanceof CalendarCollection)
throw new DavException("can't create calendar under another calendar", HttpServletResponse.SC_FORBIDDEN, null);
Collection newone = col.mkCol(ctxt, name, MailItem.Type.APPOINTMENT);
boolean success = false;
try {
PropPatch.handlePropertyUpdate(ctxt, top, newone, true, MKCALENDAR);
success = true;
} finally {
if (!success)
newone.delete(ctxt);
}
ctxt.setStatus(HttpServletResponse.SC_CREATED);
ctxt.getResponse().addHeader(DavProtocol.HEADER_CACHE_CONTROL, DavProtocol.NO_CACHE);
}
use of com.zimbra.cs.dav.resource.Collection in project zm-mailbox by Zimbra.
the class MkCol 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());
Pair<List<Element>, List<Element>> elemPair = null;
if (ctxt.hasRequestMessage()) {
Document req = ctxt.getRequestMessage();
Element top = req.getRootElement();
if (!top.getName().equals(DavElements.P_MKCOL)) {
throw new DavException("body " + top.getName() + " not allowed in MKCOL", HttpServletResponse.SC_BAD_REQUEST, null);
}
elemPair = PropPatch.getSetsAndRemoves(top, true, MKCOL);
}
if (elemPair == null) {
col.mkCol(ctxt, name);
ctxt.setStatus(HttpServletResponse.SC_CREATED);
} else {
Element resourcetypeElem = null;
MailItem.Type view = null;
List<Element> set = elemPair.getFirst();
Iterator<Element> setIter = set.iterator();
while (setIter.hasNext()) {
Element elem = setIter.next();
String propName = elem.getName();
if (propName.equals(DavElements.P_RESOURCETYPE)) {
ResourceTypeProperty prop = new ResourceTypeProperty(elem);
if (prop.isAddressBook()) {
view = MailItem.Type.CONTACT;
} else if (prop.isCalendar()) {
view = MailItem.Type.APPOINTMENT;
} else if (!prop.isCollection()) {
throw new DavException("resourcetype must include collection for MKCOL", HttpServletResponse.SC_BAD_REQUEST, null);
}
resourcetypeElem = elem;
setIter.remove();
break;
}
}
col = col.mkCol(ctxt, name, view);
Pair<List<Element>, List<QName>> pair = PropPatch.processSetsAndRemoves(ctxt, col, elemPair.getFirst(), elemPair.getSecond(), true);
col.patchProperties(ctxt, pair.getFirst(), pair.getSecond());
ctxt.getResponseProp().addProp(resourcetypeElem);
ctxt.setStatus(HttpServletResponse.SC_CREATED);
DavResponse resp = ctxt.getDavResponse();
resp.addResource(ctxt, col, ctxt.getResponseProp(), false);
sendResponse(ctxt);
}
}
use of com.zimbra.cs.dav.resource.Collection 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);
}
}
Aggregations