Java源码示例:javax.jcr.version.VersionHistory

示例1
@Override
public List<PageVersion> getPageVersions(final String path) {
    return jcrTemplate.execute(session -> {
        Node rootNode = session.getRootNode();
        Node node = JcrUtils.getNodeIfExists(rootNode, path);
        if (node != null) {
            VersionManager vm = session.getWorkspace().getVersionManager();
            VersionHistory history = vm.getVersionHistory("/" + path);
            List<PageVersion> versions = new ArrayList<>();
            for (VersionIterator it = history.getAllVersions(); it.hasNext(); ) {
                Version version = (Version) it.next();
                if (!"jcr:rootVersion".equals(version.getName())) {
                    versions.add(convertNodeToPageVersion(version));
                }
            }
            return versions;
        } else {
            return null;
        }
    });
}
 
示例2
@Override
public Page getPageByVersion(final String path, final String versionName) {
    return jcrTemplate.execute(session -> {
        Node rootNode = session.getRootNode();
        Node node = JcrUtils.getNodeIfExists(rootNode, path);
        if (node != null) {
            VersionManager vm = session.getWorkspace().getVersionManager();
            VersionHistory history = vm.getVersionHistory("/" + path);
            Version version = history.getVersion(versionName);
            if (version != null) {
                Node frozenNode = version.getFrozenNode();
                return convertNodeToPage(frozenNode);
            } else {
                return null;
            }
        } else {
            return null;
        }
    });
}
 
示例3
@Override
public List<VersionFile> getVersionFiles(String path) throws Exception{
	path = processPath(path);
	Node rootNode=getRootNode();
	if (!rootNode.hasNode(path)) {
		throw new RuleException("File [" + path + "] not exist.");
	}
	List<VersionFile> files = new ArrayList<VersionFile>();
	Node fileNode = rootNode.getNode(path);
	VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());
	VersionIterator iterator = versionHistory.getAllVersions();
	while (iterator.hasNext()) {
		Version version = iterator.nextVersion();
		String versionName = version.getName();
		if (versionName.startsWith("jcr:")) {
			continue; // skip root version
		}
		Node fnode = version.getFrozenNode();
		VersionFile file = new VersionFile();
		file.setName(version.getName());
		file.setPath(fileNode.getPath());
		Property prop = fnode.getProperty(CRATE_USER);
		file.setCreateUser(prop.getString());
		prop = fnode.getProperty(CRATE_DATE);
		file.setCreateDate(prop.getDate().getTime());
		if(fnode.hasProperty(VERSION_COMMENT)){
			prop=fnode.getProperty(VERSION_COMMENT);
			file.setComment(prop.getString());
		}
		files.add(file);
	}
	return files;
}
 
示例4
private InputStream readVersionFile(String path, String version) throws Exception{
	path = processPath(path);
	Node rootNode=getRootNode();
	if (!rootNode.hasNode(path)) {
		throw new RuleException("File [" + path + "] not exist.");
	}
	Node fileNode = rootNode.getNode(path);
	VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());
	Version v = versionHistory.getVersion(version);
	Node fnode = v.getFrozenNode();
	Property property = fnode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	return fileBinary.getStream();
}
 
示例5
public Entity getVersion(String id, String versionName) throws NotFoundException {
	// checkPath(path);

	Node node = getNodeById(id);
	if (!isVersionable(node)) {
		// TODO throws an custom exception
		return null;
	}

	try {
		VersionHistory versionHistory = getSession().getWorkspace().getVersionManager()
				.getVersionHistory(node.getPath());
		Version baseVersion = getSession().getWorkspace().getVersionManager().getBaseVersion(node.getPath());
		Version version = versionHistory.getVersion(versionName);

		Entity entity = getEntity(version.getNodes().nextNode());

		// @todo another way ?
		// hack : otherwise name is "jcr:frozenNode"
		entity.setName(StorageUtil.getName(getEntity(node).getPath()));

		getJcrom().setBaseVersionInfo(entity, baseVersion.getName(), baseVersion.getCreated());

		return entity;
	} catch (RepositoryException e) {
		throw convertJcrAccessException(e);
	}
}
 
示例6
@SuppressWarnings("unused")
private VersionHistory getVersionHistoryItem() throws RepositoryException {
       return null;
   }
 
示例7
@Override
public VersionHistory getVersionHistory() throws UnsupportedRepositoryOperationException, RepositoryException {
    return this.delegate.getVersionHistory();
}
 
示例8
@Override
public VersionHistory getVersionHistory() throws UnsupportedRepositoryOperationException, RepositoryException {
    throw new UnsupportedRepositoryOperationException();
}
 
示例9
public VersionInfo[] getVersionInfos(String id) throws NotFoundException {
	// checkPath(path);

	Node node = getNodeById(id);
	if (!isVersionable(node)) {
		// TODO throws an custom exception
		return new VersionInfo[0];
	}

	List<VersionInfo> versionInfos = new ArrayList<VersionInfo>();
	try {
		VersionHistory versionHistory = getSession().getWorkspace().getVersionManager()
				.getVersionHistory(node.getPath());
		Version baseVersion = getSession().getWorkspace().getVersionManager().getBaseVersion(node.getPath());
		VersionIterator versions = versionHistory.getAllVersions();
		versions.skip(1);
		while (versions.hasNext()) {
			Version version = versions.nextVersion();
			NodeIterator nodes = version.getNodes();
			while (nodes.hasNext()) {
				VersionInfo versionInfo = new VersionInfo();
				versionInfo.setName(version.getName());
				try {
					Entity entity = getEntity(nodes.nextNode());
					// after StorageUpdate20 when com.asf.nextserver package
					// was renamed with ro.nextreports.server
					// all version nodes remained with older className (they
					// cannot be changed because they are protected)
					// so they cannot be accessed anymore!
					if (entity == null) {
						continue;
					}
					String createdBy = entity.getLastUpdatedBy();
					if (createdBy == null) {
						createdBy = entity.getCreatedBy();
					}
					versionInfo.setCreatedBy(createdBy);
					versionInfo.setCreatedDate(version.getCreated().getTime());
					versionInfo.setBaseVersion(baseVersion.getName().equals(version.getName()));
					versionInfos.add(versionInfo);
				} catch (JcrMappingException ex) {
					// getEntity version is not found???
					// @todo why?
				}
			}
		}
	} catch (RepositoryException e) {
		throw convertJcrAccessException(e);
	}

	return versionInfos.toArray(new VersionInfo[versionInfos.size()]);
}