Search in sources :

Example 1 with VersionHistoryResource

use of org.apache.jackrabbit.webdav.version.VersionHistoryResource in project jackrabbit by apache.

the class LatestActivityVersionReport method init.

/**
     * Check all the preconditions for this report.
     *
     * @throws DavException if a precondition is not met.
     * @see Report#init(DavResource, ReportInfo)
     */
public void init(DavResource resource, ReportInfo info) throws DavException {
    // validate info
    if (!getType().isRequestedReportType(info)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version element expected.");
    }
    // make sure the report is applied to a vh-resource
    if (resource != null && (resource instanceof VersionHistoryResource)) {
        vhResource = (VersionHistoryResource) resource;
    } else {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version report can only be created for a version history resource.");
    }
    // make sure the DAV:href element inside the request body points to
    // an activity resource (precondition for this report).
    String activityHref = DomUtil.getText(info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE));
    DavResourceLocator vhLocator = resource.getLocator();
    DavResourceLocator activityLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), activityHref);
    activity = resource.getFactory().createResource(activityLocator, resource.getSession());
    if (!(activity instanceof ActivityResource)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:latest-activity-version report: The DAV:href in the request body MUST identify an activity.");
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ActivityResource(org.apache.jackrabbit.webdav.version.ActivityResource) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 2 with VersionHistoryResource

use of org.apache.jackrabbit.webdav.version.VersionHistoryResource in project jackrabbit by apache.

the class VersionItemCollection 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 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 = getLocatorFromItem(vh);
        return (VersionHistoryResource) createResourceFromLocator(loc);
    } 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) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 3 with VersionHistoryResource

use of org.apache.jackrabbit.webdav.version.VersionHistoryResource 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 4 with VersionHistoryResource

use of org.apache.jackrabbit.webdav.version.VersionHistoryResource 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 5 with VersionHistoryResource

use of org.apache.jackrabbit.webdav.version.VersionHistoryResource 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

DavException (org.apache.jackrabbit.webdav.DavException)5 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)5 RepositoryException (javax.jcr.RepositoryException)4 VersionHistory (javax.jcr.version.VersionHistory)4 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 DavResource (org.apache.jackrabbit.webdav.DavResource)2 Node (javax.jcr.Node)1 ActivityResource (org.apache.jackrabbit.webdav.version.ActivityResource)1