Search in sources :

Example 21 with JcrDavException

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

the class LocateByUuidReport 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:locate-by-uuid element must at least contain a single DAV:href child.");
    }
    // immediately build the final multistatus element
    try {
        Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
        String uuid = DomUtil.getTextTrim(hrefElem);
        DavResourceLocator resourceLoc = resource.getLocator();
        Node n = getRepositorySession().getNodeByUUID(uuid);
        DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath(), false);
        DavResource locatedResource = resource.getFactory().createResource(loc, resource.getSession());
        ms = new MultiStatus();
        ms.addResourceProperties(locatedResource, info.getPropertyNameSet(), info.getDepth());
    } 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) Element(org.w3c.dom.Element) Node(javax.jcr.Node) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 22 with JcrDavException

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

Example 23 with JcrDavException

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

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

the class VersionResourceImpl method getVersionHistory.

/**
 * Returns the {@link VersionHistory} associated with the repository version.
 * Note: in contrast to a versionable node, the version history of a version
 * item is always represented by its nearest ancestor.
 *
 * @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
 * @see javax.jcr.Item#getParent()
 */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = getVersionHistoryItem();
        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)

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