Search in sources :

Example 1 with PropStat

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);
}
Also used : ResourceProperty(com.zimbra.cs.dav.property.ResourceProperty) DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) PropStat(com.zimbra.cs.dav.service.DavResponse.PropStat) Element(org.dom4j.Element) Iterator(java.util.Iterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

DavException (com.zimbra.cs.dav.DavException)1 ResourceProperty (com.zimbra.cs.dav.property.ResourceProperty)1 DavResource (com.zimbra.cs.dav.resource.DavResource)1 PropStat (com.zimbra.cs.dav.service.DavResponse.PropStat)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Iterator (java.util.Iterator)1 Element (org.dom4j.Element)1