Search in sources :

Example 16 with DavResource

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

Example 17 with DavResource

use of com.zimbra.cs.dav.resource.DavResource 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);
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element)

Example 18 with DavResource

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

Example 19 with DavResource

use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.

the class ExpandProperty method handle.

@Override
public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_EXPAND_PROPERTY))
        throw new DavException("msg " + query.getName() + " is not expand-property", HttpServletResponse.SC_BAD_REQUEST, null);
    DavResource rs = ctxt.getRequestedResource();
    ctxt.setDavCompliance(DavProtocol.getComplianceString(rs.getComplianceList()));
    ctxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    Element resp = ctxt.getDavResponse().getTop(DavElements.E_MULTISTATUS).addElement(DavElements.E_RESPONSE);
    expandProperties(ctxt, rs, query, resp);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element)

Example 20 with DavResource

use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.

the class FreeBusyQuery method handle.

public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_FREE_BUSY_QUERY))
        throw new DavException("msg " + query.getName() + " is not free-busy-query", HttpServletResponse.SC_BAD_REQUEST, null);
    Element trElem = query.element(DavElements.E_TIME_RANGE);
    if (trElem == null)
        throw new DavException("need time-range", HttpServletResponse.SC_BAD_REQUEST, null);
    TimeRange timeRange = new TimeRange(trElem);
    DavResource rs = ctxt.getRequestedResource();
    if (!(rs instanceof CalendarCollection))
        throw new DavException("not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null);
    try {
        String freebusy = ((CalendarCollection) rs).getFreeBusyReport(ctxt, timeRange);
        HttpServletResponse resp = ctxt.getResponse();
        resp.setContentType(MimeConstants.CT_TEXT_CALENDAR);
        resp.getOutputStream().write(freebusy.getBytes("UTF-8"));
        ctxt.responseSent();
    } catch (ServiceException se) {
        throw new DavException("can't get freebusy report", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, se);
    }
}
Also used : TimeRange(com.zimbra.cs.dav.caldav.Range.TimeRange) DavResource(com.zimbra.cs.dav.resource.DavResource) CalendarCollection(com.zimbra.cs.dav.resource.CalendarCollection) ServiceException(com.zimbra.common.service.ServiceException) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

DavResource (com.zimbra.cs.dav.resource.DavResource)25 DavException (com.zimbra.cs.dav.DavException)15 Element (org.dom4j.Element)12 DavResponse (com.zimbra.cs.dav.service.DavResponse)9 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)8 ArrayList (java.util.ArrayList)7 ServiceException (com.zimbra.common.service.ServiceException)3 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)3 Collection (com.zimbra.cs.dav.resource.Collection)3 MailItemResource (com.zimbra.cs.dav.resource.MailItemResource)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Document (org.dom4j.Document)3 Account (com.zimbra.cs.account.Account)2 Provisioning (com.zimbra.cs.account.Provisioning)2 TimeRange (com.zimbra.cs.dav.caldav.Range.TimeRange)2 Ace (com.zimbra.cs.dav.property.Acl.Ace)2 AddressObject (com.zimbra.cs.dav.resource.AddressObject)2 AddressbookCollection (com.zimbra.cs.dav.resource.AddressbookCollection)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2