Search in sources :

Example 6 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class VersionHistoryItemCollection method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null) {
        // required, protected version-set property for version-history resource
        try {
            if (ROOT_VERSION.equals(name)) {
                // required root-version property for version-history resource
                String rootVersionHref = getLocatorFromItem(((VersionHistory) item).getRootVersion()).getHref(true);
                prop = new HrefProperty(ROOT_VERSION, rootVersionHref, true);
            } else if (VERSION_SET.equals(name)) {
                VersionIterator vIter = ((VersionHistory) item).getAllVersions();
                prop = getHrefProperty(VERSION_SET, vIter, true);
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
    return prop;
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 7 with VersionIterator

use of javax.jcr.version.VersionIterator 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 8 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class VersionHistoryResourceImpl method getMembers.

//--------------------------------------------------------< DavResource >---
/**
     * Show all versions of this history as members.
     *
     * @return
     * @see DavResource#getMembers()
     */
@Override
public DavResourceIterator getMembers() {
    ArrayList<DavResource> list = new ArrayList<DavResource>();
    if (exists() && isCollection()) {
        try {
            // only display versions as members of the vh. the jcr:versionLabels
            // node is an internal structure.
            VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
            while (it.hasNext()) {
                // omit item filter here. if the version history is visible
                // its versions should be visible as well.
                Version v = it.nextVersion();
                DavResourceLocator vhLocator = getLocator();
                DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
                DavResource childRes = getFactory().createResource(resourceLocator, getSession());
                list.add(childRes);
            }
        } catch (RepositoryException e) {
            // should not occur
            log.error("Unexpected error", e);
        } catch (DavException e) {
            // should not occur
            log.error("Unexpected error", e);
        }
    }
    return new DavResourceIteratorImpl(list);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResourceIteratorImpl(org.apache.jackrabbit.webdav.DavResourceIteratorImpl) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 9 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class VersionHistoryResourceImpl method getVersions.

//---------------------------------------------< VersionHistoryResource >---
/**
     * Return an array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
     * present in the underlying JCR version history.
     *
     * @return array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
     * present in the underlying JCR version history.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
     */
public VersionResource[] getVersions() throws DavException {
    try {
        VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
        ArrayList<VersionResource> l = new ArrayList<VersionResource>();
        while (vIter.hasNext()) {
            DavResourceLocator versionLoc = getLocatorFromNode(vIter.nextVersion());
            DavResource vr = createResourceFromLocator(versionLoc);
            if (vr instanceof VersionResource) {
                l.add((VersionResource) vr);
            } else {
                // severe error since resource factory doesn't behave correctly.
                throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
        }
        return l.toArray(new VersionResource[l.size()]);
    } 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) 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 10 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class RestoreTest method testLinearVersionsJcr2_3.

/**
     * Tests if restore on simple versioning creates a new version that is
     * in the correct linear order.
     */
public void testLinearVersionsJcr2_3() throws Exception {
    // first get all linear versions
    VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer expected = new StringBuffer();
    while (iter.hasNext()) {
        expected.append(iter.nextVersion().getName()).append(",");
    }
    // restore version
    versionManager.restore(versionableNode.getPath(), version.getName(), true);
    // append new base version
    expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
    // get the version names again
    iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer actual = new StringBuffer();
    while (iter.hasNext()) {
        actual.append(iter.nextVersion().getName()).append(",");
    }
    assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
Also used : VersionIterator(javax.jcr.version.VersionIterator)

Aggregations

VersionIterator (javax.jcr.version.VersionIterator)29 Version (javax.jcr.version.Version)16 VersionHistory (javax.jcr.version.VersionHistory)12 Node (javax.jcr.Node)9 ArrayList (java.util.ArrayList)8 RepositoryException (javax.jcr.RepositoryException)6 VersionException (javax.jcr.version.VersionException)5 VersionManager (javax.jcr.version.VersionManager)4 Test (org.junit.Test)4 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 HashMap (java.util.HashMap)2 Session (javax.jcr.Session)2 DavException (org.apache.jackrabbit.webdav.DavException)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)2 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1