use of com.zimbra.cs.dav.property.ResourceTypeProperty 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);
}
}
Aggregations