use of com.zimbra.cs.dav.DavContext.RequestProp 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);
}
}
}
use of com.zimbra.cs.dav.DavContext.RequestProp 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);
}
}
use of com.zimbra.cs.dav.DavContext.RequestProp 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);
}
}
use of com.zimbra.cs.dav.DavContext.RequestProp 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");
}
Aggregations