use of com.zimbra.cs.dav.service.DavResponse 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.service.DavResponse in project zm-mailbox by Zimbra.
the class AclReports method handlePrincipalPropertySearch.
/**
* http://tools.ietf.org/html/rfc3744#section-9.4. DAV:principal-property-search REPORT
* Preconditions: None
* Postconditions: DAV:number-of-matches-within-limits
*/
private void handlePrincipalPropertySearch(DavContext ctxt, Element query) throws DavException, ServiceException {
RequestProp reqProp = ctxt.getRequestProp();
DavResponse resp = ctxt.getDavResponse();
// http://tools.ietf.org/html/rfc3744#section-9.4
// The response body for a successful request MUST be a DAV:multistatus XML element. In the case where there
// are no response elements, the returned multistatus XML element is empty.
resp.getTop(DavElements.E_MULTISTATUS);
for (DavResource rs : getMatchingResources(ctxt, query)) {
resp.addResource(ctxt, rs, reqProp, false);
}
}
use of com.zimbra.cs.dav.service.DavResponse in project zm-mailbox by Zimbra.
the class AclReports method handlePrincipalMatch.
/**
* http://tools.ietf.org/html/rfc3744#section-9.3. DAV:principal-match REPORT
* This report is only defined when the Depth header has value "0";
* other values result in a 400 (Bad Request) error response.
*/
private void handlePrincipalMatch(DavContext ctxt, Element query) throws DavException, ServiceException {
if (ctxt.getDepth() != Depth.zero) {
throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
}
ArrayList<DavResource> ret = new ArrayList<DavResource>();
RequestProp reqProp = ctxt.getRequestProp();
DavResponse resp = ctxt.getDavResponse();
// The response body for a successful request MUST be a DAV:multistatus XML element. In the case where there
// are no response elements, the returned multistatus XML element is empty.
resp.getTop(DavElements.E_MULTISTATUS);
Element principalProp = query.element(DavElements.E_PRINCIPAL_PROPERTY);
if (principalProp == null) {
// request must be to the principals path
String path = ctxt.getUri();
if (path.startsWith(UrlNamespace.PRINCIPALS_PATH))
ret.add(UrlNamespace.getPrincipal(ctxt, ctxt.getAuthAccount()));
} else {
// we know of only <owner/> element
Element owner = principalProp.element(DavElements.E_OWNER);
if (owner != null) {
// return the all the members of the collection.
DavResource rs = ctxt.getRequestedResource();
if (rs.isCollection())
ret.addAll(rs.getChildren(ctxt));
}
}
for (DavResource rs : ret) resp.addResource(ctxt, rs, reqProp, false);
}
use of com.zimbra.cs.dav.service.DavResponse in project zm-mailbox by Zimbra.
the class PropFind method handle.
@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
if (ctxt.hasRequestMessage()) {
Document req = ctxt.getRequestMessage();
Element top = req.getRootElement();
if (!top.getName().equals(DavElements.P_PROPFIND)) {
throw new DavException("msg " + top.getName() + " not allowed in PROPFIND", HttpServletResponse.SC_BAD_REQUEST, null);
}
}
RequestProp reqProp = ctxt.getRequestProp();
DavResponse resp = ctxt.getDavResponse();
if (ctxt.getDepth() == Depth.one) {
resp.addResources(ctxt, ctxt.getAllRequestedResources(), reqProp);
} else {
DavResource resource = ctxt.getRequestedResource();
resp.addResource(ctxt, resource, reqProp, false);
}
sendResponse(ctxt);
}
use of com.zimbra.cs.dav.service.DavResponse in project zm-mailbox by Zimbra.
the class AclReports method handleAclPrincipalPropSet.
/**
* http://tools.ietf.org/html/rfc3744#section-9.2 DAV:acl-principal-prop-set REPORT
* Postconditions:
* (DAV:number-of-matches-within-limits): The number of matching principals must fall within
* server-specific, predefined limits. For example, this condition might be triggered if a search
* specification would cause the return of an extremely large number of responses.
*/
private void handleAclPrincipalPropSet(DavContext ctxt, Element query) throws DavException, ServiceException {
/* From rfc3744#section-9.2 DAV:acl-principal-prop-set REPORT
* This report is only defined when the Depth header has value "0"; other values result in a
* 400 (Bad Request) error response. Note that [RFC3253], Section 3.6, states that if the Depth header is
* not present, it defaults to a value of "0".
*/
if (ctxt.getDepth() != Depth.zero) {
throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
}
RequestProp reqProp = ctxt.getRequestProp();
DavResponse resp = ctxt.getDavResponse();
// The response body for a successful request MUST be a DAV:multistatus XML element. In the case where there
// are no response elements, the returned multistatus XML element is empty.
resp.getTop(DavElements.E_MULTISTATUS);
for (DavResource rs : getAclPrincipals(ctxt)) resp.addResource(ctxt, rs, reqProp, false);
}
Aggregations