Search in sources :

Example 21 with DavResource

use of com.zimbra.cs.dav.resource.DavResource 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 22 with DavResource

use of com.zimbra.cs.dav.resource.DavResource 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)

Example 23 with DavResource

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

the class Options method handle.

public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    HttpServletResponse resp = ctxt.getResponse();
    DavServlet.setAllowHeader(resp);
    if (ctxt.isMsft())
        resp.addHeader(DavProtocol.HEADER_MS_AUTHOR_VIA, "DAV");
    resp.setContentLength(0);
    try {
        DavResource rs = ctxt.getRequestedResource();
        ctxt.setDavCompliance(DavProtocol.getComplianceString(rs.getComplianceList()));
    } catch (Exception e) {
    }
    sendResponse(ctxt);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) DavException(com.zimbra.cs.dav.DavException) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException)

Example 24 with DavResource

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

the class PropPatch method handle.

@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    if (!ctxt.hasRequestMessage()) {
        throw new DavException("empty request", HttpServletResponse.SC_BAD_REQUEST);
    }
    Document req = ctxt.getRequestMessage();
    Element top = req.getRootElement();
    if (!top.getName().equals(DavElements.P_PROPERTYUPDATE)) {
        throw new DavException("msg " + top.getName() + " not allowed in PROPPATCH", HttpServletResponse.SC_BAD_REQUEST, null);
    }
    DavResource resource = ctxt.getRequestedResource();
    handlePropertyUpdate(ctxt, top, resource, false, PROPPATCH);
    DavResponse resp = ctxt.getDavResponse();
    resp.addResource(ctxt, resource, ctxt.getResponseProp(), false);
    sendResponse(ctxt);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 25 with DavResource

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

the class DavResponse method addResources.

public void addResources(DavContext ctxt, Collection<DavResource> rss, DavContext.RequestProp props) throws DavException {
    ctxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    boolean first = true;
    for (DavResource rs : rss) {
        if (first)
            ctxt.setDavCompliance(DavProtocol.getComplianceString(rs.getComplianceList()));
        addResourceTo(ctxt, rs, props, false);
        first = false;
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource)

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