Search in sources :

Example 1 with ResourceProperty

use of com.zimbra.cs.dav.property.ResourceProperty in project zm-mailbox by Zimbra.

the class DavResource method addResourceType.

protected void addResourceType(QName type) {
    ResourceProperty rtype = getProperty(DavElements.E_RESOURCETYPE);
    rtype.addChild(type);
}
Also used : ResourceProperty(com.zimbra.cs.dav.property.ResourceProperty)

Example 2 with ResourceProperty

use of com.zimbra.cs.dav.property.ResourceProperty in project zm-mailbox by Zimbra.

the class DavResource method setProperty.

protected void setProperty(QName key, String val, boolean isProtected) {
    ResourceProperty prop = mProps.get(key);
    if (prop == null) {
        prop = new ResourceProperty(key);
        mProps.put(key, prop);
    }
    prop.setProtected(isProtected);
    prop.setStringValue(val);
}
Also used : ResourceProperty(com.zimbra.cs.dav.property.ResourceProperty)

Example 3 with ResourceProperty

use of com.zimbra.cs.dav.property.ResourceProperty in project zm-mailbox by Zimbra.

the class PropPatch method processSetsAndRemoves.

/**
     * @param setElems - list of elements under "set" in the request.  Must NOT be null
     * @param removeElems - list of elements under "remove" in the request.  Must NOT be null
     * @return Pair - first is list of elements representing properties to set.  second is names of
     *                properties to remove.
     */
public static Pair<List<Element>, List<QName>> processSetsAndRemoves(DavContext ctxt, DavResource resource, List<Element> setElems, List<Element> removeElems, boolean isCreate) throws DavException, IOException {
    List<Element> set = Lists.newArrayList();
    List<QName> remove = Lists.newArrayList();
    RequestProp rp = new RequestProp(true);
    ctxt.setResponseProp(rp);
    for (Element propElem : setElems) {
        QName propName = propElem.getQName();
        ResourceProperty prop = resource.getProperty(propName);
        if (prop == null || !prop.isProtected()) {
            set.add(propElem);
            rp.addProp(propElem);
        } else if (isCreate && prop.isAllowSetOnCreate()) {
            set.add(propElem);
        } else {
            rp.addPropError(propName, new DavException.CannotModifyProtectedProperty(propName));
        }
    }
    for (Element propElem : removeElems) {
        QName propName = propElem.getQName();
        ResourceProperty prop = resource.getProperty(propName);
        if (prop == null || !prop.isProtected()) {
            remove.add(propName);
            rp.addProp(propElem);
        } else {
            rp.addPropError(propName, new DavException.CannotModifyProtectedProperty(propName));
        }
    }
    return new Pair<List<Element>, List<QName>>(set, remove);
}
Also used : ResourceProperty(com.zimbra.cs.dav.property.ResourceProperty) DavException(com.zimbra.cs.dav.DavException) QName(org.dom4j.QName) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) Pair(com.zimbra.common.util.Pair)

Example 4 with ResourceProperty

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

Example 5 with ResourceProperty

use of com.zimbra.cs.dav.property.ResourceProperty in project zm-mailbox by Zimbra.

the class DavResponse method addResourceTo.

public void addResourceTo(DavContext ctxt, DavResource rs, DavContext.RequestProp props, boolean includeChildren) throws DavException {
    if (!rs.isValid()) {
        addStatus(ctxt, rs.getUri(), HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    Element top = getTop(DavElements.E_MULTISTATUS).addElement(DavElements.E_RESPONSE);
    rs.getProperty(DavElements.E_HREF).toElement(ctxt, top, false);
    Collection<QName> propNames;
    if (props.isAllProp())
        propNames = rs.getAllPropertyNames();
    else
        propNames = props.getProps();
    PropStat propstat = new PropStat();
    Map<QName, DavException> errPropMap = props.getErrProps();
    for (QName name : propNames) {
        ResourceProperty prop = rs.getProperty(name, props);
        if (errPropMap.containsKey(name)) {
            DavException ex = errPropMap.get(name);
            propstat.add(name, null, ex.getStatus());
        } else if (prop == null) {
            if (!ctxt.isBrief())
                propstat.add(name, null, HttpServletResponse.SC_NOT_FOUND);
        } else {
            propstat.add(prop);
        }
    }
    propstat.toResponse(ctxt, top, props.isNameOnly());
}
Also used : ResourceProperty(com.zimbra.cs.dav.property.ResourceProperty) DavException(com.zimbra.cs.dav.DavException) QName(org.dom4j.QName) Element(org.dom4j.Element)

Aggregations

ResourceProperty (com.zimbra.cs.dav.property.ResourceProperty)7 Element (org.dom4j.Element)4 DavException (com.zimbra.cs.dav.DavException)3 QName (org.dom4j.QName)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZAuthToken (com.zimbra.common.auth.ZAuthToken)1 Pair (com.zimbra.common.util.Pair)1 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)1 DavResource (com.zimbra.cs.dav.resource.DavResource)1 PropStat (com.zimbra.cs.dav.service.DavResponse.PropStat)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Iterator (java.util.Iterator)1 OutputFormat (org.dom4j.io.OutputFormat)1 XMLWriter (org.dom4j.io.XMLWriter)1