Search in sources :

Example 6 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class LocateCorrespondingNodeReport method init.

/**
 * @see Report#init(DavResource, ReportInfo)
 */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    // general validation checks
    super.init(resource, info);
    // specific for this report: a workspace href must be provided
    Element workspace = info.getContentElement(DeltaVConstants.WORKSPACE.getName(), DeltaVConstants.WORKSPACE.getNamespace());
    String workspaceHref = normalizeResourceHref(DomUtil.getChildTextTrim(workspace, DavConstants.XML_HREF, DavConstants.NAMESPACE));
    if (workspaceHref == null || "".equals(workspaceHref)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Request body must define the href of a source workspace");
    }
    // retrieve href of the corresponding resource in the other workspace
    try {
        this.correspHref = getCorrespondingResourceHref(resource, getRepositorySession(), workspaceHref);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException)

Example 7 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class DavResourceImpl method alterProperty.

private void alterProperty(PropEntry prop) throws DavException {
    if (isLocked(this)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        List<? extends PropEntry> list = Collections.singletonList(prop);
        alterProperties(list);
        Map<? extends PropEntry, ?> failure = config.getPropertyManager().alterProperties(getPropertyImportContext(list), isCollection());
        if (failure.isEmpty()) {
            node.save();
        } else {
            node.refresh(false);
            // TODO: retrieve specific error from failure-map
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        // revert any changes made so far
        JcrDavException je = new JcrDavException(e);
        try {
            node.refresh(false);
        } catch (RepositoryException re) {
        // should not happen...
        }
        throw je;
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException)

Example 8 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class VersionControlledResourceImpl method checkin.

/**
 * Calls {@link javax.jcr.Node#checkin()} on the underlying repository node.
 *
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkin()
 */
public String checkin() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
    }
    try {
        Version v = getNode().checkin();
        String versionHref = getLocatorFromNode(v).getHref(false);
        return versionHref;
    } catch (RepositoryException e) {
        // UnsupportedRepositoryException should not occur
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException)

Example 9 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException 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 10 with JcrDavException

use of org.apache.jackrabbit.webdav.jcr.JcrDavException in project jackrabbit by apache.

the class JcrRemotingServlet method doGet.

@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
    if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
        // return json representation of the requested resource
        DavResourceLocator locator = davResource.getLocator();
        String path = locator.getRepositoryPath();
        Session session = getRepositorySession(webdavRequest);
        try {
            Node node = session.getNode(path);
            int depth = ((WrappingLocator) locator).getDepth();
            webdavResponse.setContentType("text/plain;charset=utf-8");
            webdavResponse.setStatus(DavServletResponse.SC_OK);
            JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
            String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
            if (includes == null) {
                if (depth < BatchReadConfig.DEPTH_INFINITE) {
                    NodeType type = node.getPrimaryNodeType();
                    depth = brConfig.getDepth(type.getName());
                }
                writer.write(node, depth);
            } else {
                writeMultiple(writer, node, includes, depth);
            }
        } catch (PathNotFoundException e) {
            // properties cannot be requested as json object.
            throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
        } catch (RepositoryException e) {
            // should only get here if the item does not exist.
            log.debug(e.getMessage());
            throw new JcrDavException(e);
        }
    } else {
        super.doGet(webdavRequest, webdavResponse, davResource);
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) NodeType(javax.jcr.nodetype.NodeType) PathNotFoundException(javax.jcr.PathNotFoundException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)24 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)24 DavException (org.apache.jackrabbit.webdav.DavException)17 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)8 Node (javax.jcr.Node)6 Session (javax.jcr.Session)6 VersionHistory (javax.jcr.version.VersionHistory)6 JcrDavSession (org.apache.jackrabbit.webdav.jcr.JcrDavSession)5 DavResource (org.apache.jackrabbit.webdav.DavResource)4 DavSession (org.apache.jackrabbit.webdav.DavSession)3 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)3 ArrayList (java.util.ArrayList)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 Map (java.util.Map)1 Item (javax.jcr.Item)1