Search in sources :

Example 1 with AddressbookCollection

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

the class AddressbookMultiget method handle.

@Override
public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_MULTIGET))
        throw new DavException("msg " + query.getName() + " is not addressbook-multiget", HttpServletResponse.SC_BAD_REQUEST, null);
    DavResponse resp = ctxt.getDavResponse();
    DavResource reqResource = ctxt.getRequestedResource();
    if (!(reqResource instanceof AddressbookCollection))
        throw new DavException("requested resource is not an addressbook collection", HttpServletResponse.SC_BAD_REQUEST, null);
    RequestProp reqProp = ctxt.getRequestProp();
    for (Object obj : query.elements(DavElements.E_HREF)) {
        if (obj instanceof Element) {
            String href = ((Element) obj).getText();
            URI uri = URI.create(href);
            String[] fragments = HttpUtil.getPathFragments(uri);
            if (uri.getPath().toLowerCase().endsWith(AddressObject.VCARD_EXTENSION)) {
                // double encode the last fragment
                fragments[fragments.length - 1] = HttpUtil.urlEscapeIncludingSlash(fragments[fragments.length - 1]);
            }
            uri = HttpUtil.getUriFromFragments(fragments, uri.getQuery(), true, false);
            href = uri.getPath();
            DavResource rs = UrlNamespace.getResourceAtUrl(ctxt, href);
            if (rs != null)
                resp.addResource(ctxt, rs, reqProp, false);
        }
    }
}
Also used : AddressbookCollection(com.zimbra.cs.dav.resource.AddressbookCollection) DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) 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) URI(java.net.URI)

Example 2 with AddressbookCollection

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

Aggregations

RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)2 DavException (com.zimbra.cs.dav.DavException)2 AddressObject (com.zimbra.cs.dav.resource.AddressObject)2 AddressbookCollection (com.zimbra.cs.dav.resource.AddressbookCollection)2 DavResource (com.zimbra.cs.dav.resource.DavResource)2 DavResponse (com.zimbra.cs.dav.service.DavResponse)2 Element (org.dom4j.Element)2 Filter (com.zimbra.cs.dav.carddav.Filter)1 URI (java.net.URI)1