Search in sources :

Example 1 with ImportContext

use of org.apache.jackrabbit.server.io.ImportContext in project jackrabbit by apache.

the class DavResourceImpl method addMember.

/**
     * Adds a new member to this resource.
     *
     * @see DavResource#addMember(DavResource, org.apache.jackrabbit.webdav.io.InputContext)
     */
public void addMember(DavResource member, InputContext inputContext) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_CONFLICT);
    }
    if (isLocked(this) || isLocked(member)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    try {
        // item or if the new resource would be filtered out
        if (isFilteredResource(member) || node.getDefinition().isProtected()) {
            log.debug("Forbidden to add member: " + member.getDisplayName());
            throw new DavException(DavServletResponse.SC_FORBIDDEN);
        }
        String memberName = Text.getName(member.getLocator().getRepositoryPath());
        ImportContext ctx = getImportContext(inputContext, memberName);
        if (!config.getIOManager().importContent(ctx, member)) {
            // any changes should have been reverted in the importer
            throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        }
        // persist changes after successful import
        node.save();
    } catch (RepositoryException e) {
        log.error("Error while importing resource: " + e.toString());
        throw new JcrDavException(e);
    } catch (IOException e) {
        log.error("Error while importing resource: " + e.toString());
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ImportContext(org.apache.jackrabbit.server.io.ImportContext) PropertyImportContext(org.apache.jackrabbit.server.io.PropertyImportContext) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 RepositoryException (javax.jcr.RepositoryException)1 ImportContext (org.apache.jackrabbit.server.io.ImportContext)1 PropertyImportContext (org.apache.jackrabbit.server.io.PropertyImportContext)1 DavException (org.apache.jackrabbit.webdav.DavException)1 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)1