Search in sources :

Example 11 with DavProperty

use of org.apache.jackrabbit.webdav.property.DavProperty in project jackrabbit by apache.

the class VersionControlledItemCollection method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null && isVersionControlled()) {
        Node n = (Node) item;
        // workspace property already set in AbstractResource.initProperties()
        try {
            if (VERSION_HISTORY.equals(name)) {
                // DAV:version-history (computed)
                String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);
                prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
            } else if (CHECKED_OUT.equals(name) && n.isCheckedOut()) {
                // DAV:checked-out property (protected)
                String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
                prop = new HrefProperty(CHECKED_OUT, baseVHref, true);
            } else if (CHECKED_IN.equals(name) && !n.isCheckedOut()) {
                // DAV:checked-in property (protected)
                String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
                prop = new HrefProperty(CHECKED_IN, baseVHref, true);
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
    return prop;
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException)

Example 12 with DavProperty

use of org.apache.jackrabbit.webdav.property.DavProperty in project jackrabbit by apache.

the class AbstractItemResource method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null) {
        if (JCR_DEFINITION.equals(name)) {
            if (exists()) {
                try {
                    // protected 'definition' property revealing the item definition
                    ItemDefinitionImpl val;
                    if (item.isNode()) {
                        val = NodeDefinitionImpl.create(((Node) item).getDefinition());
                    } else {
                        val = PropertyDefinitionImpl.create(((Property) item).getDefinition());
                    }
                    prop = new DefaultDavProperty<ItemDefinitionImpl>(JCR_DEFINITION, val, true);
                } catch (RepositoryException e) {
                    // should not get here
                    log.error("Error while accessing item definition: " + e.getMessage());
                }
            }
        } else if (JCR_ISNEW.equals(name)) {
            // transaction resource additional protected properties
            if (exists() && item.isNew()) {
                prop = new DefaultDavProperty<String>(JCR_ISNEW, null, true);
            }
        } else if (JCR_ISMODIFIED.equals(name)) {
            // transaction resource additional protected properties
            if (exists() && item.isModified()) {
                prop = new DefaultDavProperty<String>(JCR_ISMODIFIED, null, true);
            }
        } else if (ObservationConstants.SUBSCRIPTIONDISCOVERY.equals(name)) {
            // observation resource
            prop = subsMgr.getSubscriptionDiscovery(this);
        }
    }
    return prop;
}
Also used : DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) ItemDefinitionImpl(org.apache.jackrabbit.webdav.jcr.nodetype.ItemDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Example 13 with DavProperty

use of org.apache.jackrabbit.webdav.property.DavProperty in project jackrabbit by apache.

the class DefaultHandler method importProperties.

public Map<? extends PropEntry, ?> importProperties(PropertyImportContext importContext, boolean isCollection) throws RepositoryException {
    if (!canImport(importContext, isCollection)) {
        throw new RepositoryException("PropertyHandler " + getName() + " failed import properties");
    }
    // loop over List and remember all properties and propertyNames
    // that failed to be imported (set or remove).
    Map<PropEntry, RepositoryException> failures = new HashMap<PropEntry, RepositoryException>();
    List<? extends PropEntry> changeList = importContext.getChangeList();
    // for collections the import-root is the target node where properties
    // are altered. in contrast 'non-collections' are with the handler
    // represented by 'file' nodes, that must have a jcr:content child
    // node, which holds all properties except jcr:created.
    // -> see canImport for the corresponding assertions
    Node cn = (Node) importContext.getImportRoot();
    if (!isCollection && cn.hasNode(JcrConstants.JCR_CONTENT)) {
        cn = cn.getNode(JcrConstants.JCR_CONTENT);
    }
    if (changeList != null) {
        for (PropEntry propEntry : changeList) {
            try {
                if (propEntry instanceof DavPropertyName) {
                    // remove
                    DavPropertyName propName = (DavPropertyName) propEntry;
                    removeJcrProperty(propName, cn);
                } else if (propEntry instanceof DavProperty) {
                    // add or modify property
                    DavProperty<?> prop = (DavProperty<?>) propEntry;
                    setJcrProperty(prop, cn);
                } else {
                    // ignore any other entry in the change list
                    log.error("unknown object in change list: " + propEntry.getClass().getName());
                }
            } catch (RepositoryException e) {
                failures.put(propEntry, e);
            }
        }
    }
    if (failures.isEmpty()) {
        setLastModified(cn, IOUtil.UNDEFINED_LENGTH);
    }
    return failures;
}
Also used : PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) HashMap(java.util.HashMap) Node(javax.jcr.Node) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 14 with DavProperty

use of org.apache.jackrabbit.webdav.property.DavProperty in project jackrabbit by apache.

the class WebdavRequestImpl method parsePropPatchRequest.

/**
     * Parse the PROPPATCH request body.
     */
private void parsePropPatchRequest() throws DavException {
    proppatchSet = new DavPropertySet();
    proppatchList = new ArrayList<PropEntry>();
    Document requestDocument = getRequestDocument();
    if (requestDocument == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid request body.");
    }
    Element root = requestDocument.getDocumentElement();
    if (!DomUtil.matches(root, XML_PROPERTYUPDATE, NAMESPACE)) {
        log.warn("PropPatch-Request has no <DAV:propertyupdate> tag.");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropPatch-Request has no <propertyupdate> tag.");
    }
    ElementIterator it = DomUtil.getChildren(root);
    while (it.hasNext()) {
        Element el = it.nextElement();
        if (DomUtil.matches(el, XML_SET, NAMESPACE)) {
            Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);
            if (propEl != null) {
                ElementIterator properties = DomUtil.getChildren(propEl);
                while (properties.hasNext()) {
                    DavProperty<?> davProp = DefaultDavProperty.createFromXml(properties.nextElement());
                    proppatchSet.add(davProp);
                    proppatchList.add(davProp);
                }
            }
        } else if (DomUtil.matches(el, XML_REMOVE, NAMESPACE)) {
            Element propEl = DomUtil.getChildElement(el, XML_PROP, NAMESPACE);
            if (propEl != null) {
                ElementIterator properties = DomUtil.getChildren(propEl);
                while (properties.hasNext()) {
                    DavProperty<?> davProp = DefaultDavProperty.createFromXml(properties.nextElement());
                    proppatchSet.add(davProp);
                    proppatchList.add(davProp.getName());
                }
            }
        } else {
            log.debug("Unknown element in DAV:propertyupdate: " + el.getNodeName());
        // unknown child elements are ignored
        }
    }
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) Element(org.w3c.dom.Element) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) Document(org.w3c.dom.Document)

Example 15 with DavProperty

use of org.apache.jackrabbit.webdav.property.DavProperty in project jackrabbit by apache.

the class BindTest method getParentSet.

private DavProperty getParentSet(String uri) throws IOException, DavException, URISyntaxException {
    DavPropertyNameSet names = new DavPropertyNameSet();
    names.add(BindConstants.PARENTSET);
    HttpPropfind propfind = new HttpPropfind(uri, names, 0);
    HttpResponse response = this.client.execute(propfind, this.context);
    int status = response.getStatusLine().getStatusCode();
    assertEquals(207, status);
    MultiStatus multistatus = propfind.getResponseBodyAsMultiStatus(response);
    MultiStatusResponse[] responses = multistatus.getResponses();
    assertEquals(1, responses.length);
    DavProperty parentset = responses[0].getProperties(200).get(BindConstants.PARENTSET);
    assertNotNull(parentset);
    return parentset;
}
Also used : HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus)

Aggregations

DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)16 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)13 RepositoryException (javax.jcr.RepositoryException)11 Node (javax.jcr.Node)6 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)6 PropEntry (org.apache.jackrabbit.webdav.property.PropEntry)5 Property (javax.jcr.Property)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 DavException (org.apache.jackrabbit.webdav.DavException)3 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)3 Session (javax.jcr.Session)2 Version (javax.jcr.version.Version)2 HttpResponse (org.apache.http.HttpResponse)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)2 LengthsProperty (org.apache.jackrabbit.webdav.jcr.property.LengthsProperty)2 ValuesProperty (org.apache.jackrabbit.webdav.jcr.property.ValuesProperty)2 JcrSupportedPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrSupportedPrivilegesProperty)2 JcrUserPrivilegesProperty (org.apache.jackrabbit.webdav.jcr.security.JcrUserPrivilegesProperty)2 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)2