Package javax.jcr.version

Examples of javax.jcr.version.VersionHistory


        List<JCRNodeWrapper> childEntries = new ArrayList<JCRNodeWrapper>();
        while (ni1.hasNext()) {
            JCRNodeWrapper child = (JCRNodeWrapper) ni1.next();
            try {
                if (child.isNodeType(Constants.NT_VERSIONEDCHILD)) {
                    VersionHistory vh = (VersionHistory) getSession().getProviderSession(provider).getNodeByIdentifier(child.getProperty(
                            "jcr:childVersionHistory").getValue().getString());
                    Version closestVersion = null;
                    if (versionLabel != null) {
                        closestVersion = JCRVersionService.findVersionByLabel(vh, versionLabel);
                    }
View Full Code Here


                    child = ((JCRFrozenNodeAsRegular) current).superGetNode(next);
                } else {
                    child = current.getNode(next);
                }
                if (child.isNodeType(Constants.NT_VERSIONEDCHILD)) {
                    VersionHistory vh = (VersionHistory) getSession().getProviderSession(provider).getNodeByIdentifier(child.getProperty(
                            "jcr:childVersionHistory").getValue().getString());
                    Version closestVersion = null;
                    if (versionLabel != null) {
                        closestVersion = JCRVersionService.findVersionByLabel(vh, versionLabel);
                    }
View Full Code Here

    @Override
    protected Node getI18N(Locale locale, boolean fallback) throws RepositoryException {
        Node node1 = super.getI18N(locale, fallback);
        if (node1.hasProperty("jcr:childVersionHistory")) {
            VersionHistory versionHistory = (VersionHistory) getSession().getProviderSession(provider).getNodeByIdentifier(node1.getProperty(
                    "jcr:childVersionHistory").getValue().getString());
            Version v = null;
            if (versionLabel != null) {
                v = JCRVersionService.findVersionByLabel(versionHistory, versionLabel);
            }
            if (v == null && versionDate != null) {
                v = JCRVersionService.findClosestVersion(versionHistory, versionDate);
            }
            if (v == null) {
                return null;
            }
            node1 = v.getNode(Constants.JCR_FROZENNODE);
        } else if (node1.hasProperty("jcr:versionHistory")) {
            VersionHistory versionHistory = (VersionHistory) getSession().getProviderSession(provider).getNodeByIdentifier(node1.getProperty(
                    "jcr:versionHistory").getValue().getString());
            Version v = null;
            if (versionLabel != null) {
                v = JCRVersionService.findVersionByLabel(versionHistory, versionLabel);
            }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public JCRNodeWrapper getFrozenVersionAsRegular(Node objectNode, JCRStoreProvider provider) throws RepositoryException {
        try {
            VersionHistory vh =
                    objectNode.getSession().getWorkspace().getVersionManager().getVersionHistory(objectNode.getPath());

            Version v = null;
            if (versionLabel != null) {
                v = JCRVersionService.findVersionByLabel(vh, versionLabel);
View Full Code Here

    private void displayVersions(JCRSessionWrapper editSession, JCRNodeWrapper subPageEditNode,
                                 JCRSessionWrapper liveSession) throws RepositoryException {
        // Display versions
        VersionManager versionManager;
        VersionHistory versionHistory;
        versionManager = editSession.getWorkspace().getVersionManager();
        logger.info("Versions of " + subPageEditNode.getPath() + " in edit ws :");
        try {
            logger.info("Base version in edit ws is : " + versionManager.getBaseVersion(
                    subPageEditNode.getPath()).getName());
            logger.info("Base version in live ws is : " + liveSession.getWorkspace().getVersionManager().getBaseVersion(
                    subPageEditNode.getPath()).getName());
        } catch (RepositoryException e) {
            logger.debug(e.getMessage(), e);
        }
        try {
            versionHistory = versionManager.getVersionHistory(subPageEditNode.getPath());
            VersionIterator allVersions = versionHistory.getAllVersions();
            while (allVersions.hasNext()) {
                Version version = allVersions.nextVersion();
                StringBuilder builder = new StringBuilder();

                builder.append(version.getName());
                String[] strings = versionHistory.getVersionLabels(version);
                if (strings != null && strings.length > 0) {
                    builder.append(" ").append(Arrays.deepToString(strings));
                }
                Version[] versions = version.getPredecessors();
                for (Version version1 : versions) {
                    builder.append(" <- ").append(version1.getName());
                    strings = versionHistory.getVersionLabels(version1);
                    if (strings != null && strings.length > 0) {
                        builder.append(" ").append(Arrays.deepToString(strings));
                    }
                }
                logger.info(builder.toString());
View Full Code Here

            EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
            registerEventListener(el, node.getPath());

            // perform the update/restore according to the update info
            if (updateInfo.getVersionHref() != null) {
                VersionHistory vh = node.getVersionHistory();
                String[] hrefs = updateInfo.getVersionHref();
                Version[] versions = new Version[hrefs.length];
                for (int  i = 0; i < hrefs.length; i++) {
                    String itemPath = getLocatorFromHref(hrefs[i]).getRepositoryPath();
                    versions[i] = vh.getVersion(getItemName(itemPath));
                }
                if (versions.length == 1) {
                    String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);
                    if (relPath == null) {
                        node.restore(versions[0], removeExisting);
                    } else {
                        node.restore(versions[0], relPath, removeExisting);
                    }
                } else {
                    getRepositorySession().getWorkspace().restore(versions, removeExisting);
                }
            } else if (updateInfo.getLabelName() != null) {
                String[] labels = updateInfo.getLabelName();
                if (labels.length == 1) {
                    node.restoreByLabel(labels[0], removeExisting);
                } else {
                    Version[] vs = new Version[labels.length];
                    VersionHistory vh = node.getVersionHistory();
                    for (int  i = 0; i < labels.length; i++) {
                        vs[i] = vh.getVersionByLabel(labels[i]);
                    }
                    getRepositorySession().getWorkspace().restore(vs, removeExisting);
                }
            } else if (updateInfo.getWorkspaceHref() != null) {
                String workspaceName = getLocatorFromHref(updateInfo.getWorkspaceHref()).getWorkspaceName();
View Full Code Here

        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);
        }
View Full Code Here

        // add all versions to map of versions to restore
        final HashMap toRestore = new HashMap();
        for (int i = 0; i < versions.length; i++) {
            VersionImpl v = (VersionImpl) versions[i];
            VersionHistory vh = v.getContainingHistory();
            // check for collision
            if (toRestore.containsKey(vh.getUUID())) {
                throw new VersionException("Unable to restore. Two or more versions have same version history.");
            }
            toRestore.put(vh.getUUID(), v);
        }

        // create a version selector to the set of versions
        VersionSelector vsel = new VersionSelector() {
            public Version select(VersionHistory versionHistory) throws RepositoryException {
View Full Code Here

        if (relQPath == null) {
            /* restore target already exists. */
            // target must be versionable
            targetNode.checkIsVersionable();

            VersionHistory vH = targetNode.getVersionHistory();
            // version must be a version of the target node
            if (!vH.isSame(version.getContainingHistory())) {
                throw new VersionException("Version " + version + " does not correspond to the restore target.");
            }
            // version must not be the root version
            if (vH.getRootVersion().isSame(version)) {
                throw new VersionException("Attempt to restore root version.");
            }
            targetNode.checkIsWritable();
            targetNode.checkIsLocked();
        } else {
View Full Code Here

                    restoredChild.restoreFrozenState(f, vsel, restored, removeExisting);
                }

            } else if (child instanceof InternalFrozenVersionHistory) {
                InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
                VersionHistory history = (VersionHistory) session.getNodeById(f.getVersionHistoryId());
                NodeId nodeId = NodeId.valueOf(history.getVersionableUUID());
                String oldVersion = "jcr:dummy";

                // check if representing versionable already exists somewhere
                if (itemMgr.itemExists(nodeId)) {
                    NodeImpl n = session.getNodeById(nodeId);
                    if (removeExisting) {
                        String dstPath = getPath() + "/" + n.getName();
                        if (!n.getPath().equals(dstPath)) {
                            session.move(n.getPath(), dstPath);
                        }
                        oldVersion = n.getBaseVersion().getName();
                    } else if (n.getParent().isSame(this)) {
                        n.internalRemove(true);
                    } else {
                        // since we delete the OPV=Copy children beforehand, all
                        // found nodes must be outside of this tree
                        throw new ItemExistsException(
                                "Unable to restore node, item already exists"
                                        + " outside of restored tree: " + n);
                    }
                }
                // get desired version from version selector
                VersionImpl v = (VersionImpl) vsel.select(history);

                // check existing version of item exists
                if (!itemMgr.itemExists(nodeId)) {
                    if (v == null) {
                        // if version selector was unable to select version,
                        // choose the initial one
                        Version[] vs = history.getRootVersion().getSuccessors();
                        if (vs.length == 0) {
                            String msg = "Unable to select appropariate version for "
                                    + child.getName() + " using " + vsel;
                            log.error(msg);
                            throw new VersionException(msg);
                        }
                        v = (VersionImpl) vs[0];
                    }
                    restoredChild = addNode(child.getName(), v.getInternalFrozenNode());
                } else {
                    restoredChild = session.getNodeById(nodeId);
                    if (v == null || oldVersion == null || v.getName().equals(oldVersion)) {
                        v = null;
                    }
                }
                if (v != null) {
                    try {
                        restoredChild.internalRestore(v, vsel, removeExisting);
                    } catch (RepositoryException e) {
                        log.error("Error while restoring node: " + e);
                        log.error("  child path: " + restoredChild);
                        log.error("  selected version: " + v.getName());
                        StringBuffer avail = new StringBuffer();
                        VersionIterator vi = history.getAllVersions();
                        while (vi.hasNext()) {
                            avail.append(vi.nextVersion().getName());
                            if (vi.hasNext()) {
                                avail.append(", ");
                            }
View Full Code Here

TOP

Related Classes of javax.jcr.version.VersionHistory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.