Search in sources :

Example 26 with DavException

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

the class VersionControlledItemCollection method update.

/**
 * Perform an update on this resource. Depending on the format of the <code>updateInfo</code>
 * this is translated to one of the following methods defined by the JCR API:
 * <ul>
 * <li>{@link Node#restore(javax.jcr.version.Version, boolean)}</li>
 * <li>{@link Node#restore(javax.jcr.version.Version, String, boolean)}</li>
 * <li>{@link Node#restoreByLabel(String, boolean)}</li>
 * <li>{@link Node#update(String)}</li>
 * </ul>
 * <p>
 * Limitation: note that the <code>MultiStatus</code> returned by this method
 * will not list any nodes that have been removed due to an Uuid conflict.
 *
 * @param updateInfo
 * @return
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)
 */
// TODO: with jcr the node must not be versionable in order to perform Node.update.
@Override
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
    if (updateInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        Node node = (Node) item;
        Element udElem = updateInfo.getUpdateElement();
        boolean removeExisting = DomUtil.hasChildElement(udElem, XML_REMOVEEXISTING, NAMESPACE);
        // register eventListener in order to be able to report the modified resources.
        EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
        registerEventListener(el, node.getPath());
        // perform the update/restore according to the update info
        if (updateInfo.getVersionHref() != null) {
            String[] hrefs = updateInfo.getVersionHref();
            if (hrefs.length != 1) {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body missing version href or containing multiple version hrefs.");
            }
            final String href = normalizeResourceHref(hrefs[0]);
            String versionPath = getLocatorFromHref(href).getRepositoryPath();
            String versionName = getItemName(versionPath);
            String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);
            if (relPath == null) {
                // restore version by name
                node.restore(versionName, removeExisting);
            } else if (node.hasNode(relPath)) {
                Version v = node.getNode(relPath).getVersionHistory().getVersion(versionName);
                node.restore(v, relPath, removeExisting);
            } else {
                Version v = (Version) getRepositorySession().getNode(versionPath);
                node.restore(v, relPath, removeExisting);
            }
        } else if (updateInfo.getLabelName() != null) {
            String[] labels = updateInfo.getLabelName();
            if (labels.length != 1) {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: Multiple labels specified.");
            }
            node.restoreByLabel(labels[0], removeExisting);
        } else if (updateInfo.getWorkspaceHref() != null) {
            String href = normalizeResourceHref(obtainAbsolutePathFromUri(updateInfo.getWorkspaceHref()));
            String workspaceName = getLocatorFromHref(href).getWorkspaceName();
            node.update(workspaceName);
        } else {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body.");
        }
        // unregister the event listener again
        unregisterEventListener(el);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Version(javax.jcr.version.Version) Node(javax.jcr.Node) Element(org.w3c.dom.Element) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) EventListener(javax.jcr.observation.EventListener)

Example 27 with DavException

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

the class VersionControlledItemCollection method getVersionHistory.

/**
 * Returns the {@link VersionHistory} associated with the repository node.
 * If the node is not versionable an exception is thrown.
 *
 * @return the {@link VersionHistoryResource} associated with this resource.
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
 * @see javax.jcr.Node#getVersionHistory()
 */
@Override
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = ((Node) item).getVersionHistory();
        DavResourceLocator loc = getLocatorFromItem(vh);
        return (VersionHistoryResource) createResourceFromLocator(loc);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 28 with DavException

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

the class JcrRemotingServlet method doPost.

@Override
protected void doPost(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
    if (canHandle(DavMethods.DAV_POST, webdavRequest, davResource)) {
        // special remoting request: the defined parameters are exclusive
        // and cannot be combined.
        Session session = getRepositorySession(webdavRequest);
        RequestData data = new RequestData(webdavRequest, getTempDirectory(getServletContext()));
        String loc = null;
        try {
            String[] pValues;
            // multi-read over POST
            String[] includes = null;
            if ((pValues = data.getParameterValues(PARAM_CLONE)) != null) {
                loc = clone(session, pValues, davResource.getLocator());
            } else if ((pValues = data.getParameterValues(PARAM_COPY)) != null) {
                loc = copy(session, pValues, davResource.getLocator());
            } else if (data.getParameterValues(PARAM_DIFF) != null) {
                String targetPath = davResource.getLocator().getRepositoryPath();
                processDiff(session, targetPath, data, protectedRemoveManager);
            } else if ((pValues = data.getParameterValues(PARAM_INCLUDE)) != null && canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
                includes = pValues;
            } else {
                String targetPath = davResource.getLocator().getRepositoryPath();
                loc = modifyContent(session, targetPath, data, protectedRemoveManager);
            }
            // TODO: append entity
            if (loc == null) {
                webdavResponse.setStatus(HttpServletResponse.SC_OK);
                if (includes != null) {
                    webdavResponse.setContentType("text/plain;charset=utf-8");
                    JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
                    DavResourceLocator locator = davResource.getLocator();
                    String path = locator.getRepositoryPath();
                    Node node = session.getNode(path);
                    int depth = ((WrappingLocator) locator).getDepth();
                    writeMultiple(writer, node, includes, depth);
                }
            } else {
                webdavResponse.setHeader(DeltaVConstants.HEADER_LOCATION, loc);
                webdavResponse.setStatus(HttpServletResponse.SC_CREATED);
            }
        } catch (RepositoryException e) {
            log.warn(e.getMessage(), e);
            throw new JcrDavException(e);
        } catch (DiffException e) {
            log.warn(e.getMessage());
            Throwable cause = e.getCause();
            if (cause instanceof RepositoryException) {
                throw new JcrDavException((RepositoryException) cause);
            } else {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid diff format.");
            }
        } finally {
            data.dispose();
        }
    } else {
        super.doPost(webdavRequest, webdavResponse, davResource);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RequestData(org.apache.jackrabbit.server.util.RequestData) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 29 with DavException

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

the class DefaultItemResource method internalSetProperty.

/**
 * Internal method that performs the setting or adding of properties
 *
 * @param property
 * @throws DavException
 * @see #setProperty(DavProperty)
 * @see #alterProperties(List)
 */
private void internalSetProperty(DavProperty<?> property) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        Property prop = (Property) item;
        int defaultType = prop.getType();
        ValueFactory vfact = getRepositorySession().getValueFactory();
        ValuesProperty vp = new ValuesProperty(property, defaultType, vfact);
        if (property.getName().equals(JCR_VALUE)) {
            prop.setValue(vp.getJcrValue(vp.getValueType(), vfact));
        } else if (property.getName().equals(JCR_VALUES)) {
            prop.setValue(vp.getJcrValues());
        } else {
            throw new DavException(DavServletResponse.SC_CONFLICT);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) LengthsProperty(org.apache.jackrabbit.webdav.jcr.property.LengthsProperty) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) ValuesProperty(org.apache.jackrabbit.webdav.jcr.property.ValuesProperty)

Example 30 with DavException

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

the class AbstractWebdavServlet method doAcl.

/**
 * The ACL method
 *
 * @param request
 * @param response
 * @param resource
 * @throws DavException
 * @throws IOException
 */
protected void doAcl(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException {
    if (!(resource instanceof AclResource)) {
        response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }
    Document doc = request.getRequestDocument();
    if (doc == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body.");
    }
    AclProperty acl = AclProperty.createFromXml(doc.getDocumentElement());
    ((AclResource) resource).alterAcl(acl);
}
Also used : AclProperty(org.apache.jackrabbit.webdav.security.AclProperty) AclResource(org.apache.jackrabbit.webdav.security.AclResource) DavException(org.apache.jackrabbit.webdav.DavException) Document(org.w3c.dom.Document)

Aggregations

DavException (org.apache.jackrabbit.webdav.DavException)157 RepositoryException (javax.jcr.RepositoryException)89 IOException (java.io.IOException)61 HttpResponse (org.apache.http.HttpResponse)47 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavResource (org.apache.jackrabbit.webdav.DavResource)30 Element (org.w3c.dom.Element)29 ArrayList (java.util.ArrayList)25 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)25 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)18 Node (javax.jcr.Node)16 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)15 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)14 ItemNotFoundException (javax.jcr.ItemNotFoundException)13 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)12 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)12 Path (java.nio.file.Path)11 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)10 Test (org.junit.Test)9 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)8