Search in sources :

Example 91 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class DavResourceImpl method alterProperties.

public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException {
    if (isLocked(this)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatusResponse msr = new MultiStatusResponse(getHref(), null);
    try {
        Map<? extends PropEntry, ?> failures = config.getPropertyManager().alterProperties(getPropertyImportContext(changeList), isCollection());
        if (failures.isEmpty()) {
            // save all changes together (reverted in case this fails)
            node.save();
        } else {
            // set/remove of at least a single prop failed: undo modifications.
            node.refresh(false);
        }
        /* loop over list of properties/names that were successfully altered
               and them to the multistatus response respecting the result of the
               complete action. in case of failure set the status to 'failed-dependency'
               in order to indicate, that altering those names/properties would
               have succeeded, if no other error occured.*/
        for (PropEntry propEntry : changeList) {
            int statusCode;
            if (failures.containsKey(propEntry)) {
                Object error = failures.get(propEntry);
                statusCode = (error instanceof RepositoryException) ? new JcrDavException((RepositoryException) error).getErrorCode() : DavServletResponse.SC_INTERNAL_SERVER_ERROR;
            } else {
                statusCode = (failures.isEmpty()) ? DavServletResponse.SC_OK : DavServletResponse.SC_FAILED_DEPENDENCY;
            }
            if (propEntry instanceof DavProperty) {
                msr.add(((DavProperty<?>) propEntry).getName(), statusCode);
            } else {
                msr.add((DavPropertyName) propEntry, statusCode);
            }
        }
        return msr;
    } catch (RepositoryException e) {
        // revert any changes made so far an throw exception
        try {
            node.refresh(false);
        } catch (RepositoryException re) {
        // should not happen
        }
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException)

Example 92 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class ResourceFactoryImpl method createResource.

/**
     * Create a new <code>DavResource</code> from the given locator and
     * request.
     *
     * @param locator
     * @param request
     * @param response
     * @return DavResource
     * @throws DavException
     * @see DavResourceFactory#createResource(DavResourceLocator,
     *      DavServletRequest, DavServletResponse)
     */
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
    try {
        Node node = getNode(request.getDavSession(), locator);
        DavResource resource;
        if (node == null) {
            log.debug("Creating resource for non-existing repository node.");
            boolean isCollection = DavMethods.isCreateCollectionRequest(request);
            resource = createNullResource(locator, request.getDavSession(), isCollection);
        } else {
            resource = createResource(node, locator, request.getDavSession());
        }
        resource.addLockManager(lockMgr);
        return resource;
    } catch (RepositoryException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 93 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class RepositoryServiceImpl method addVersionLabel.

@Override
public void addVersionLabel(SessionInfo sessionInfo, NodeId versionHistoryId, NodeId versionId, Name label, boolean moveLabel) throws RepositoryException {
    HttpLabel request = null;
    try {
        String uri = getItemUri(versionId, sessionInfo);
        String strLabel = getNamePathResolver(sessionInfo).getJCRName(label);
        request = new HttpLabel(uri, new LabelInfo(strLabel, moveLabel ? LabelInfo.TYPE_SET : LabelInfo.TYPE_ADD));
        initMethod(request, sessionInfo, !isUnLockMethod(request));
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException ex) {
        throw ExceptionConverter.generate(ex);
    } finally {
        request.releaseConnection();
    }
}
Also used : LabelInfo(org.apache.jackrabbit.webdav.version.LabelInfo) DavException(org.apache.jackrabbit.webdav.DavException) HttpLabel(org.apache.jackrabbit.webdav.client.methods.HttpLabel) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Example 94 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class AclPrincipalReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    super.init(resource, info);
    // build the DAV:responses objects.
    DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL);
    if (!(acl instanceof AclProperty)) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected.");
    }
    DavResourceLocator loc = resource.getLocator();
    Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>();
    List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty) acl).getValue();
    for (AclProperty.Ace ace : list) {
        String href = ace.getPrincipal().getHref();
        if (href == null || respMap.containsKey(href)) {
            // ignore non-href principals and principals that have been listed before
            continue;
        }
        // href-principal that has not been found before
        DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href);
        DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession());
        respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet()));
    }
    this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]);
}
Also used : AclProperty(org.apache.jackrabbit.webdav.security.AclProperty) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) HashMap(java.util.HashMap) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) List(java.util.List) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 95 with DavException

use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.

the class PrincipalMatchReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    super.init(resource, info);
    if (info.containsContentElement(XML_PRINCIPAL_PROPERTY, SecurityConstants.NAMESPACE)) {
        Element pp = info.getContentElement(XML_PRINCIPAL_PROPERTY, SecurityConstants.NAMESPACE);
        principalPropertyName = DavPropertyName.createFromXml(DomUtil.getFirstChildElement(pp));
    } else if (info.containsContentElement(XML_SELF, SecurityConstants.NAMESPACE)) {
        principalPropertyName = SecurityConstants.PRINCIPAL_URL;
    } else {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:self or DAV:principal-property element required within report info.");
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)129 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)51 HttpResponse (org.apache.http.HttpResponse)47 Element (org.w3c.dom.Element)29 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 DavResource (org.apache.jackrabbit.webdav.DavResource)21 ArrayList (java.util.ArrayList)19 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)17 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8 Document (org.w3c.dom.Document)8 Session (javax.jcr.Session)7 Version (javax.jcr.version.Version)7