use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiHibernateVersioningStore method getXWikiDocVersions.
@Override
public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException {
try {
XWikiDocumentArchive archive = getXWikiDocumentArchive(doc, context);
if (archive == null) {
return new Version[0];
}
Collection<XWikiRCSNodeInfo> nodes = archive.getNodes();
Version[] versions = new Version[nodes.size()];
Iterator<XWikiRCSNodeInfo> it = nodes.iterator();
for (int i = 0; i < versions.length; i++) {
XWikiRCSNodeInfo node = it.next();
versions[versions.length - 1 - i] = node.getId().getVersion();
}
return versions;
} catch (Exception e) {
Object[] args = { doc.getFullName() };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS, "Exception while reading document {0} revisions", e, args);
}
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiHibernateVersioningStore method loadXWikiDocArchive.
@Override
public void loadXWikiDocArchive(XWikiDocumentArchive archivedoc, boolean bTransaction, XWikiContext context) throws XWikiException {
try {
List<XWikiRCSNodeInfo> nodes = loadAllRCSNodeInfo(context, archivedoc.getId(), bTransaction);
archivedoc.setNodes(nodes);
} catch (Exception e) {
Object[] args = { Long.valueOf(archivedoc.getId()) };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading archive {0}", e, args);
}
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocument method getRevisions.
/**
* Get document versions matching criterias like author, minimum creation date, etc.
*
* @param criteria criteria used to match versions
* @return a list of matching versions
*/
public List<String> getRevisions(RevisionCriteria criteria, XWikiContext context) throws XWikiException {
List<String> results = new ArrayList<String>();
Version[] revisions = getRevisions(context);
XWikiRCSNodeInfo nextNodeinfo = null;
XWikiRCSNodeInfo nodeinfo;
for (Version revision : revisions) {
nodeinfo = nextNodeinfo;
nextNodeinfo = getRevisionInfo(revision.toString(), context);
if (nodeinfo == null) {
continue;
}
// Minor/Major version matching
if (criteria.getIncludeMinorVersions() || !nextNodeinfo.isMinorEdit()) {
// Author matching
if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
// Date range matching
Date versionDate = nodeinfo.getDate();
if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
results.add(nodeinfo.getVersion().toString());
}
}
}
}
nodeinfo = nextNodeinfo;
if (nodeinfo != null) {
if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
// Date range matching
Date versionDate = nodeinfo.getDate();
if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
results.add(nodeinfo.getVersion().toString());
}
}
}
return criteria.getRange().subList(results);
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method setArchive.
/**
* Deserialize class. Used in {@link com.xpn.xwiki.plugin.packaging.PackagePlugin}.
*
* @param text - archive in JRCS format
* @throws XWikiException if parse error
*/
public void setArchive(String text) throws XWikiException {
try {
XWikiRCSArchive archive = new XWikiRCSArchive(text);
resetArchive();
Collection nodes = archive.getNodes(getId());
for (Iterator it = nodes.iterator(); it.hasNext(); ) {
XWikiRCSNodeInfo nodeInfo = (XWikiRCSNodeInfo) it.next();
XWikiRCSNodeContent nodeContent = (XWikiRCSNodeContent) it.next();
updateNode(nodeInfo);
this.updatedNodeInfos.add(nodeInfo);
this.updatedNodeContents.add(nodeContent);
}
} catch (Exception e) {
Object[] args = { text, Long.valueOf(getId()) };
throw new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_CONTENT_ERROR, "Exception while constructing archive for JRCS string [{0}] for document [{1}]", e, args);
}
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method updateArchive.
/**
* Update history with new document version.
*
* @param doc - document for this version
* @param author - author of version
* @param date - date of version
* @param comment - version comment
* @param version - preferably document version in history
* @param context - used for loading nodes content
* @throws XWikiException in any error
*/
public void updateArchive(XWikiDocument doc, String author, Date date, String comment, Version version, XWikiContext context) throws XWikiException {
Version oldLatestVer = getLatestVersion();
Version newVer = version;
if (newVer == null || oldLatestVer != null && newVer.compareVersions(oldLatestVer) <= 0) {
newVer = createNextVersion(oldLatestVer, doc.isMinorEdit());
}
XWikiRCSNodeInfo newNode = new XWikiRCSNodeInfo(new XWikiRCSNodeId(getId(), newVer));
newNode.setAuthor(author);
newNode.setComment(comment);
newNode.setDate(date);
XWikiRCSNodeContent newContent = makePatch(newNode, doc, context);
updateNode(newNode);
this.updatedNodeInfos.add(newNode);
this.updatedNodeContents.add(newContent);
}
Aggregations