Search in sources :

Example 6 with DavResponse

use of com.zimbra.cs.dav.service.DavResponse in project zm-mailbox by Zimbra.

the class CalendarQuery method handleCalendarItem.

private void handleCalendarItem(QueryContext ctxt, DavResource calItem) {
    if (!(calItem instanceof CalendarObject))
        return;
    try {
        CalendarObject calobj = (CalendarObject) calItem;
        if (!calobj.match(ctxt.componentFilter)) {
            return;
        }
        DavResponse resp = ctxt.davCtxt.getDavResponse();
        if (ctxt.expandRange != null) {
            calobj.expand(ctxt.expandRange);
        }
        resp.addResource(ctxt.davCtxt, calItem, ctxt.props, false);
    } catch (DavException de) {
        ZimbraLog.dav.error("can't get calendar item data", de);
    }
}
Also used : DavResponse(com.zimbra.cs.dav.service.DavResponse) DavException(com.zimbra.cs.dav.DavException) CalendarObject(com.zimbra.cs.dav.resource.CalendarObject)

Example 7 with DavResponse

use of com.zimbra.cs.dav.service.DavResponse 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 8 with DavResponse

use of com.zimbra.cs.dav.service.DavResponse 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 9 with DavResponse

use of com.zimbra.cs.dav.service.DavResponse in project zm-mailbox by Zimbra.

the class AddressbookQuery method handle.

public void handle(DavContext ctxt) throws DavException, ServiceException {
    DavResource rsc = ctxt.getRequestedResource();
    if (!(rsc instanceof AddressbookCollection))
        throw new DavException("not an addressbook resource", HttpServletResponse.SC_BAD_REQUEST, null);
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_QUERY))
        throw new DavException("msg " + query.getName() + " is not addressbook-query", HttpServletResponse.SC_BAD_REQUEST, null);
    Element f = query.element(DavElements.CardDav.E_FILTER);
    if (f == null)
        throw new DavException("msg " + query.getName() + " is missing filter", HttpServletResponse.SC_BAD_REQUEST, null);
    Filter filter = new Filter.PropFilter((Element) f.elementIterator().next());
    Collection<AddressObject> contacts = filter.match(ctxt, ((AddressbookCollection) rsc));
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    resp.createResponse(ctxt);
    for (AddressObject c : contacts) {
        resp.addResource(ctxt, c, reqProp, false);
    }
}
Also used : AddressbookCollection(com.zimbra.cs.dav.resource.AddressbookCollection) DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) Filter(com.zimbra.cs.dav.carddav.Filter) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) AddressObject(com.zimbra.cs.dav.resource.AddressObject)

Example 10 with DavResponse

use of com.zimbra.cs.dav.service.DavResponse in project zm-mailbox by Zimbra.

the class CalendarMultiget method handle.

public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.E_CALENDAR_MULTIGET))
        throw new DavException("msg " + query.getName() + " is not calendar-multiget", HttpServletResponse.SC_BAD_REQUEST, null);
    DavResponse resp = ctxt.getDavResponse();
    ArrayList<String> hrefs = new ArrayList<String>();
    for (Object obj : query.elements(DavElements.E_HREF)) if (obj instanceof Element)
        hrefs.add(((Element) obj).getText());
    long ts = System.currentTimeMillis();
    DavResource reqResource = ctxt.getRequestedResource();
    if (!(reqResource instanceof CalendarCollection))
        throw new DavException("requested resource is not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null);
    CalendarCollection calResource = (CalendarCollection) reqResource;
    long now = System.currentTimeMillis();
    ZimbraLog.dav.debug("GetRequestedResource: " + (now - ts) + "ms");
    RequestProp reqProp = ctxt.getRequestProp();
    for (DavResource rs : calResource.getAppointmentsByUids(ctxt, hrefs)) resp.addResource(ctxt, rs, reqProp, false);
    ts = now;
    now = System.currentTimeMillis();
    ZimbraLog.dav.debug("multiget: " + (now - ts) + "ms");
}
Also used : 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) ArrayList(java.util.ArrayList)

Aggregations

DavResponse (com.zimbra.cs.dav.service.DavResponse)11 DavResource (com.zimbra.cs.dav.resource.DavResource)9 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)8 DavException (com.zimbra.cs.dav.DavException)8 Element (org.dom4j.Element)8 Document (org.dom4j.Document)3 AddressObject (com.zimbra.cs.dav.resource.AddressObject)2 AddressbookCollection (com.zimbra.cs.dav.resource.AddressbookCollection)2 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)2 ArrayList (java.util.ArrayList)2 TimeRange (com.zimbra.cs.dav.caldav.Range.TimeRange)1 Filter (com.zimbra.cs.dav.carddav.Filter)1 ResourceTypeProperty (com.zimbra.cs.dav.property.ResourceTypeProperty)1 CalendarObject (com.zimbra.cs.dav.resource.CalendarObject)1 Collection (com.zimbra.cs.dav.resource.Collection)1 MailItem (com.zimbra.cs.mailbox.MailItem)1 URI (java.net.URI)1 List (java.util.List)1