use of com.zimbra.cs.dav.service.DavResponse.PropStat in project zm-mailbox by Zimbra.
the class ExpandProperty method expandProperties.
/**
* @param rs - the requested resource
* @param elem - specification of what should be expanded - either the top level {@code <DAV:expand-property>}
* element or a descendant {@code <DAV:property>} element
* @param resp - the target {@code <DAV:response>} element
*/
private void expandProperties(DavContext ctxt, DavResource rs, Element elem, Element resp) {
rs.getProperty(DavElements.E_HREF).toElement(ctxt, resp, false);
@SuppressWarnings("rawtypes") Iterator iter = elem.elementIterator(DavElements.E_PROPERTY);
PropStat propstat = new PropStat();
while (iter.hasNext()) {
Element property = (Element) iter.next();
Prop p = new Prop(property);
ResourceProperty rp = rs.getProperty(p.getQName());
if (rp == null) {
if (!ctxt.isBrief())
propstat.add(p.getQName(), null, HttpServletResponse.SC_NOT_FOUND);
} else {
@SuppressWarnings("rawtypes") Iterator subProps = property.elementIterator();
if (subProps.hasNext()) {
PropStat sub = new PropStat();
sub.add(rp);
Element subElem = DocumentHelper.createElement(DavElements.E_RESPONSE);
sub.toResponse(ctxt, subElem, false);
@SuppressWarnings("rawtypes") Iterator subPropstats = subElem.elementIterator(DavElements.E_PROPSTAT);
while (subPropstats.hasNext()) {
Element subPropstat = (Element) subPropstats.next();
Element status = subPropstat.element(DavElements.E_STATUS);
if (!status.getText().equals(DavResponse.sStatusTextMap.get(HttpServletResponse.SC_OK)))
continue;
Element prop = subPropstat.element(DavElements.E_PROP);
if (prop == null)
continue;
prop = prop.element(p.getQName());
if (prop == null)
continue;
@SuppressWarnings("rawtypes") Iterator hrefs = prop.elementIterator(DavElements.E_HREF);
if (!hrefs.hasNext()) {
// need to say which property, even if the list is empty
propstat.add(rp);
} else {
while (hrefs.hasNext()) {
Element href = (Element) hrefs.next();
String url = href.getText();
if (url == null)
continue;
try {
url = URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
ZimbraLog.dav.warn("can't decode url %s", url, e);
}
try {
DavResource target = UrlNamespace.getResourceAtUrl(ctxt, url);
Element targetElem = DocumentHelper.createElement(DavElements.E_RESPONSE);
expandProperties(ctxt, target, property, targetElem);
propstat.add(rp.getName(), targetElem);
} catch (DavException e) {
ZimbraLog.dav.warn("can't find resource for " + url, e);
}
}
}
}
} else {
propstat.add(rp);
}
}
}
propstat.toResponse(ctxt, resp, false);
}
Aggregations