Search in sources :

Example 1 with DavPropertyName

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

the class DefaultHandler method setJcrProperty.

/**
     * @param property dav property
     * @param contentNode the content node
     * @throws RepositoryException if an error during repository access occurs.
     */
private void setJcrProperty(DavProperty<?> property, Node contentNode) throws RepositoryException {
    // Retrieve the property value. Note, that a 'null' value is replaced
    // by empty string, since setting a jcr property value to 'null'
    // would be equivalent to its removal.
    String value = "";
    if (property.getValue() != null) {
        value = property.getValue().toString();
    }
    DavPropertyName davName = property.getName();
    if (DavPropertyName.GETCONTENTTYPE.equals(davName)) {
        String mimeType = IOUtil.getMimeType(value);
        String encoding = IOUtil.getEncoding(value);
        contentNode.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
        contentNode.setProperty(JcrConstants.JCR_ENCODING, encoding);
    } else {
        contentNode.setProperty(getJcrName(davName, contentNode.getSession()), value);
    }
}
Also used : DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 2 with DavPropertyName

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

the class DefaultHandler method exportProperties.

public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException {
    if (!canExport(exportContext, isCollection)) {
        throw new RepositoryException("PropertyHandler " + getName() + " failed to export properties.");
    }
    Node cn = getContentNode(exportContext, isCollection);
    try {
        // export the properties common with normal I/O handling
        exportProperties(exportContext, isCollection, cn);
        // export all other properties as well
        PropertyIterator it = cn.getProperties();
        while (it.hasNext()) {
            Property p = it.nextProperty();
            String name = p.getName();
            PropertyDefinition def = p.getDefinition();
            if (def.isMultiple() || isDefinedByFilteredNodeType(def)) {
                log.debug("Skip property '" + name + "': not added to webdav property set.");
                continue;
            }
            if (JcrConstants.JCR_DATA.equals(name) || JcrConstants.JCR_MIMETYPE.equals(name) || JcrConstants.JCR_ENCODING.equals(name) || JcrConstants.JCR_LASTMODIFIED.equals(name)) {
                continue;
            }
            DavPropertyName davName = getDavName(name, p.getSession());
            exportContext.setProperty(davName, p.getValue().getString());
        }
        return true;
    } catch (IOException e) {
        // should not occur (log output see 'exportProperties')
        return false;
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Property(javax.jcr.Property) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 3 with DavPropertyName

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

the class ExpandPropertyReport method getResponse.

/**
     * Builds a <code>MultiStatusResponse</code> for the given resource respecting
     * the properties specified. Any property that represents a {@link HrefProperty}
     * is expanded: It's name equals the name of a valid {@link HrefProperty}.
     * However the value of that given property (consisting of one or multiple DAV:href elements)
     * is replaced by the Xml representation of a separate
     * {@link MultiStatusResponse multistatus responses} for the
     * resource referenced by the given DAV:href elements. The responses may
     * themselves have properties, which are defined by the separate list.
     *
     * @param res
     * @param propertyElements
     * @return <code>MultiStatusResponse</code> for the given resource.
     * @see ExpandProperty
     */
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
    MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
    while (propertyElements.hasNext()) {
        Element propertyElem = propertyElements.next();
        // retrieve the localName present in the "name" attribute
        String nameAttr = propertyElem.getAttribute(ATTR_NAME);
        if (nameAttr == null || "".equals(nameAttr)) {
            // NOTE: this is not valid according to the DTD
            continue;
        }
        // retrieve the namespace present in the "namespace" attribute
        // NOTE: if this attribute is missing the DAV: namespace represents the default.
        String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
        Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
        DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
        DavProperty<?> p = res.getProperty(propName);
        if (p != null) {
            if (p instanceof HrefProperty && res instanceof DeltaVResource) {
                ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
                resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
            } else {
                resp.add(p);
            }
        } else {
            resp.add(propName, DavServletResponse.SC_NOT_FOUND);
        }
    }
    return resp;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DeltaVResource(org.apache.jackrabbit.webdav.version.DeltaVResource) Namespace(org.apache.jackrabbit.webdav.xml.Namespace) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 4 with DavPropertyName

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

the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.

private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new PathNotFoundException("Unable to retrieve privileges definitions.");
        }
        DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
        DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
        if (p == null) {
            return new PrivilegeDefinition[0];
        } else {
            // build PrivilegeDefinition(s) from the supported-privileges dav property
            Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
            fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
            List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
            for (Name privilegeName : spMap.keySet()) {
                SupportedPrivilege sp = spMap.get(privilegeName);
                Set<Name> aggrnames = null;
                SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
                if (aggregates != null && aggregates.length > 0) {
                    aggrnames = new HashSet<Name>();
                    for (SupportedPrivilege aggregate : aggregates) {
                        Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
                        aggrnames.add(aggregateName);
                    }
                }
                PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
                pDefs.add(def);
            }
            return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) SupportedPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty) PathNotFoundException(javax.jcr.PathNotFoundException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege)

Example 5 with DavPropertyName

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

the class DefaultItemCollection method alterProperties.

/**
     * Loops over the given <code>List</code>s and alters the properties accordingly.
     * Changes are persisted at the end according to the rules defined with
     * the {@link AbstractItemResource#complete()} method.<p>
     * Please note: since there is only a single property
     * ({@link ItemResourceConstants#JCR_MIXINNODETYPES}
     * that can be set or removed with PROPPATCH, this method either succeeds
     * or throws an exception, even if this violates RFC 2518. Thus no property
     * specific multistatus will be created in case of an error.
     *
     * @param changeList
     * @return
     * @throws DavException
     */
@Override
public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
    for (PropEntry propEntry : changeList) {
        if (propEntry instanceof DavPropertyName) {
            // use the internal remove method in order to prevent premature 'save'
            DavPropertyName propName = (DavPropertyName) propEntry;
            internalRemoveProperty(propName);
        } else if (propEntry instanceof DavProperty) {
            // use the internal set method in order to prevent premature 'save'
            DavProperty<?> prop = (DavProperty<?>) propEntry;
            internalSetProperty(prop);
        } else {
            throw new IllegalArgumentException("unknown object in change list: " + propEntry.getClass().getName());
        }
    }
    // TODO: missing undo of successful set/remove if subsequent operation fails
    // NOTE, that this is relevant with transactions only.
    // success: save all changes together if no error occurred
    complete();
    return new MultiStatusResponse(getHref(), DavServletResponse.SC_OK);
}
Also used : PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Aggregations

DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)11 RepositoryException (javax.jcr.RepositoryException)6 Node (javax.jcr.Node)4 DavException (org.apache.jackrabbit.webdav.DavException)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)4 IOException (java.io.IOException)3 PropEntry (org.apache.jackrabbit.webdav.property.PropEntry)3 HashMap (java.util.HashMap)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 HttpResponse (org.apache.http.HttpResponse)2 Name (org.apache.jackrabbit.spi.Name)2 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)2 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)2 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)2 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)2 SupportedPrivilege (org.apache.jackrabbit.webdav.security.SupportedPrivilege)2 Namespace (org.apache.jackrabbit.webdav.xml.Namespace)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1