Search in sources :

Example 1 with VersionResource

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

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

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

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

the class CompareBaselineReport method toXml.

/**
 * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
 */
public Element toXml(Document document) {
    Element el = DomUtil.createElement(document, XML_COMPARE_BASELINE_REPORT, DeltaVConstants.NAMESPACE);
    try {
        // TODO: check if correct
        List<VersionResource> requestVs = new ArrayList<VersionResource>();
        getVersions(requestBaseline.getBaselineCollection(), requestVs);
        List<VersionResource> compareVs = new ArrayList<VersionResource>();
        getVersions(compareBaseline.getBaselineCollection(), compareVs);
        for (VersionResource requestV : requestVs) {
            if (!compareVs.remove(requestV)) {
                // check if another version of the same vh is present (change)
                VersionResource changedV = findChangedVersion(requestV, compareVs);
                if (changedV != null) {
                    // found a 'changed-version' entry
                    Element cv = DomUtil.addChildElement(el, XML_CHANGED_VERSION, DeltaVConstants.NAMESPACE);
                    cv.appendChild(DomUtil.hrefToXml(requestV.getHref(), document));
                    cv.appendChild(DomUtil.hrefToXml(changedV.getHref(), document));
                } else {
                    // no corresponding version => 'deleted-version'
                    Element cv = DomUtil.addChildElement(el, XML_DELETED_VERSION, DeltaVConstants.NAMESPACE);
                    cv.appendChild(DomUtil.hrefToXml(requestV.getHref(), document));
                }
            }
        // else: both baseline contain a vc-resource with the same checked-in version
        }
        // to be added-versions.
        for (VersionResource addedV : compareVs) {
            Element cv = DomUtil.addChildElement(el, XML_ADDED_VERSION, DeltaVConstants.NAMESPACE);
            cv.appendChild(DomUtil.hrefToXml(addedV.getHref(), document));
        }
    } catch (DavException e) {
        log.error("Internal error while building report", e);
    }
    return el;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource)

Aggregations

VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)4 ArrayList (java.util.ArrayList)3 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 RepositoryException (javax.jcr.RepositoryException)2 VersionHistory (javax.jcr.version.VersionHistory)2 VersionIterator (javax.jcr.version.VersionIterator)2 DavException (org.apache.jackrabbit.webdav.DavException)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)2 DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)1 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)1 VersionControlledResource (org.apache.jackrabbit.webdav.version.VersionControlledResource)1 Element (org.w3c.dom.Element)1