Search in sources :

Example 1 with DavResourceLocator

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

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

the class CompareBaselineReport method getVersions.

private void getVersions(DavResource collection, List<VersionResource> vList) throws DavException {
    DavResourceIterator it = collection.getMembers();
    while (it.hasNext()) {
        DavResource member = it.nextResource();
        if (member instanceof VersionControlledResource) {
            String href = new HrefProperty(member.getProperty(VersionControlledResource.CHECKED_IN)).getHrefs().get(0);
            DavResourceLocator locator = member.getLocator();
            DavResourceLocator vLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), href);
            DavResource v = member.getFactory().createResource(vLocator, member.getSession());
            if (v instanceof VersionResource) {
                vList.add((VersionResource) v);
            } else {
                log.error("Internal error: DAV:checked-in property must point to a VersionResource.");
            }
        }
        if (member.isCollection()) {
            getVersions(member, vList);
        }
    }
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource) VersionControlledResource(org.apache.jackrabbit.webdav.version.VersionControlledResource) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 3 with DavResourceLocator

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

the class DavResourceImpl method getParentElements.

/**
     * @see org.apache.jackrabbit.webdav.bind.BindableResource#getParentElements()
     */
public Set<ParentElement> getParentElements() {
    try {
        if (node.getDepth() > 0) {
            Set<ParentElement> ps = new HashSet<ParentElement>();
            NodeIterator sharedSetIterator = node.getSharedSet();
            while (sharedSetIterator.hasNext()) {
                Node sharednode = sharedSetIterator.nextNode();
                DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), sharednode.getParent().getPath(), false);
                ps.add(new ParentElement(loc.getHref(true), sharednode.getName()));
            }
            return ps;
        }
    } catch (UnsupportedRepositoryOperationException e) {
        log.debug("unable to calculate parent set", e);
    } catch (RepositoryException e) {
        log.warn("unable to calculate parent set", e);
    }
    return Collections.emptySet();
}
Also used : NodeIterator(javax.jcr.NodeIterator) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) HashSet(java.util.HashSet) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 4 with DavResourceLocator

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

the class VersionHistoryItemCollection method getVersions.

//-----------------------------------< VersionHistoryResource interface >---
/**
     * Return an array of {@link VersionResource}s representing all versions
     * present in the underlying JCR version history.
     *
     * @return array of {@link VersionResource}s representing all versions
     * present in the underlying JCR version history.
     * @throws DavException
     * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
     */
public VersionResource[] getVersions() throws DavException {
    try {
        VersionIterator vIter = ((VersionHistory) item).getAllVersions();
        ArrayList<VersionResource> l = new ArrayList<VersionResource>();
        while (vIter.hasNext()) {
            DavResourceLocator versionLoc = getLocatorFromItem(vIter.nextVersion());
            VersionResource vr = (VersionResource) createResourceFromLocator(versionLoc);
            l.add(vr);
        }
        return l.toArray(new VersionResource[l.size()]);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 5 with DavResourceLocator

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

Aggregations

DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)34 DavException (org.apache.jackrabbit.webdav.DavException)25 RepositoryException (javax.jcr.RepositoryException)20 DavResource (org.apache.jackrabbit.webdav.DavResource)19 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)11 Node (javax.jcr.Node)10 ArrayList (java.util.ArrayList)7 VersionHistory (javax.jcr.version.VersionHistory)7 NodeIterator (javax.jcr.NodeIterator)5 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)5 PathNotFoundException (javax.jcr.PathNotFoundException)4 Item (javax.jcr.Item)3 Session (javax.jcr.Session)3 Version (javax.jcr.version.Version)3 VersionIterator (javax.jcr.version.VersionIterator)3 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)3 Element (org.w3c.dom.Element)3