Search in sources :

Example 81 with DavException

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

the class JcrPrivilegeReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    // delegate basic validation to super class
    super.init(resource, info);
    // make also sure, the info contains a DAV:href child element
    if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:privileges element must at least contain a single DAV:href child.");
    }
    // immediately build the final multistatus element
    Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
    String href = DomUtil.getTextTrim(hrefElem);
    // TODO: we should check whether the authority component matches
    href = obtainAbsolutePathFromUri(href);
    DavResourceLocator resourceLoc = resource.getLocator();
    DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), href);
    // immediately build the final multistatus element
    addResponses(loc);
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 82 with DavException

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

the class DavResourceImpl method getCollection.

/**
     * @see DavResource#getCollection()
     */
public DavResource getCollection() {
    DavResource parent = null;
    if (getResourcePath() != null && !getResourcePath().equals("/")) {
        String parentPath = Text.getRelativeParent(getResourcePath(), 1);
        if (parentPath.equals("")) {
            parentPath = "/";
        }
        DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), parentPath);
        try {
            parent = factory.createResource(parentloc, session);
        } catch (DavException e) {
        // should not occur
        }
    }
    return parent;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 83 with DavException

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

the class DavSessionProviderImpl method attachSession.

/**
     * Acquires a DavSession. Upon success, the WebdavRequest will
     * reference that session.
     *
     * A session will not be available if an exception is thrown.
     *
     * @param request
     * @throws org.apache.jackrabbit.webdav.DavException if a problem occurred while obtaining the session
     * @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
     */
public boolean attachSession(WebdavRequest request) throws DavException {
    try {
        // retrieve the workspace name
        String workspaceName = request.getRequestLocator().getWorkspaceName();
        // empty workspaceName rather means default -> must be 'null'
        if (workspaceName != null && "".equals(workspaceName)) {
            workspaceName = null;
        }
        // login to repository
        Session repSession = sesProvider.getSession(request, repository, workspaceName);
        if (repSession == null) {
            log.debug("Could not to retrieve a repository session.");
            return false;
        }
        DavSession ds = new DavSessionImpl(repSession);
        log.debug("Attaching session '" + ds + "' to request '" + request + "'");
        request.setDavSession(ds);
        return true;
    } catch (NoSuchWorkspaceException e) {
        // which seems not appropriate here
        throw new JcrDavException(e, DavServletResponse.SC_NOT_FOUND);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    } catch (ServletException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ServletException(javax.servlet.ServletException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) RepositoryException(javax.jcr.RepositoryException) DavSession(org.apache.jackrabbit.webdav.DavSession) Session(javax.jcr.Session) DavSession(org.apache.jackrabbit.webdav.DavSession)

Example 84 with DavException

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

the class VersionControlledResourceImpl method getVersionHistory.

/**
     * Returns the {@link javax.jcr.version.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()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        VersionHistory vh = getNode().getVersionHistory();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 85 with DavException

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

the class VersionControlledResourceImpl method addVersionControl.

//------------------------------------------< VersionControlledResource >---
/**
     * Adds version control to this resource. If the resource is already under
     * version control, this method has no effect. If this resource is a Collection
     * resource this method fails with {@link DavServletResponse#SC_METHOD_NOT_ALLOWED}.
     *
     * @throws org.apache.jackrabbit.webdav.DavException if this resource does not
     * exist yet, is a collection or if an error occurs while making the
     * underlying node versionable.
     * @see org.apache.jackrabbit.webdav.version.VersionableResource#addVersionControl()
     */
public void addVersionControl() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (isCollection()) {
        // the underlying node was / could be made jcr versionable.
        throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
    }
    if (!isVersionControlled()) {
        Node item = getNode();
        try {
            item.addMixin(JcrConstants.MIX_VERSIONABLE);
            item.save();
        } catch (RepositoryException e) {
            throw new JcrDavException(e);
        }
    }
// else: is already version controlled -> ignore
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

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