Search in sources :

Example 1 with Collection

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);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) Collection(com.zimbra.cs.dav.resource.Collection) ZMountpoint(com.zimbra.client.ZMountpoint) ServiceException(com.zimbra.common.service.ServiceException) XmlParseException(com.zimbra.common.soap.XmlParseException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with Collection

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);
}
Also used : DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) Collection(com.zimbra.cs.dav.resource.Collection) Document(org.dom4j.Document)

Example 3 with Collection

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);
}
Also used : CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) Collection(com.zimbra.cs.dav.resource.Collection) Document(org.dom4j.Document)

Example 4 with Collection

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);
    }
}
Also used : DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) Document(org.dom4j.Document) MailItem(com.zimbra.cs.mailbox.MailItem) DavResponse(com.zimbra.cs.dav.service.DavResponse) Collection(com.zimbra.cs.dav.resource.Collection) List(java.util.List) ResourceTypeProperty(com.zimbra.cs.dav.property.ResourceTypeProperty)

Example 5 with Collection

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);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) MailItemResource(com.zimbra.cs.dav.resource.MailItemResource) DavException(com.zimbra.cs.dav.DavException) Collection(com.zimbra.cs.dav.resource.Collection)

Aggregations

Collection (com.zimbra.cs.dav.resource.Collection)6 DavException (com.zimbra.cs.dav.DavException)5 DavResource (com.zimbra.cs.dav.resource.DavResource)3 Document (org.dom4j.Document)3 Element (org.dom4j.Element)3 ZMountpoint (com.zimbra.client.ZMountpoint)1 ServiceException (com.zimbra.common.service.ServiceException)1 XmlParseException (com.zimbra.common.soap.XmlParseException)1 ResourceTypeProperty (com.zimbra.cs.dav.property.ResourceTypeProperty)1 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)1 MailItemResource (com.zimbra.cs.dav.resource.MailItemResource)1 DavResponse (com.zimbra.cs.dav.service.DavResponse)1 MailItem (com.zimbra.cs.mailbox.MailItem)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1