use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method loadRCSNodeContents.
/**
* @return List of {@link XWikiRCSNodeContent} where vfrom<=version<=vto order by version
* @param vfrom - start version
* @param vto - end version
* @param context - used everywhere
* @throws XWikiException if any error
*/
private List<XWikiRCSNodeContent> loadRCSNodeContents(Version vfrom, Version vto, XWikiContext context) throws XWikiException {
List<XWikiRCSNodeContent> result = new ArrayList<XWikiRCSNodeContent>();
for (XWikiRCSNodeInfo nodeInfo : getNodes(vfrom, vto)) {
XWikiRCSNodeContent nodeContent = nodeInfo.getContent(context);
result.add(nodeContent);
}
return result;
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method makePatch.
/**
* Make a patch. It is store only modified nodes(latest). New nodes need be saved after.
*
* @param newnode - new node information
* @param doc - document for that patch created
* @param context - used for loading node contents and generating xml
* @return node content for newnode
* @throws XWikiException if exception while loading content
*/
protected XWikiRCSNodeContent makePatch(XWikiRCSNodeInfo newnode, XWikiDocument doc, XWikiContext context) throws XWikiException {
XWikiRCSNodeContent result = new XWikiRCSNodeContent();
result.setPatch(new XWikiPatch().setFullVersion(doc, context));
newnode.setContent(result);
XWikiRCSNodeInfo latestNode = getLatestNode();
if (latestNode != null) {
int nodesCount = getNodes().size();
int nodesPerFull = context.getWiki() == null ? 5 : Integer.parseInt(context.getWiki().getConfig().getProperty("xwiki.store.rcs.nodesPerFull", "5"));
if (nodesPerFull <= 0 || (nodesCount % nodesPerFull) != 0) {
XWikiRCSNodeContent latestContent = latestNode.getContent(context);
latestContent.getPatch().setDiffVersion(latestContent.getPatch().getContent(), doc, context);
latestNode.setContent(latestContent);
updateNode(latestNode);
getUpdatedNodeContents().add(latestContent);
}
}
return result;
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method removeVersions.
/**
* Remove document versions from vfrom to vto, inclusive.
*
* @param newerVersion - start version
* @param olderVersion - end version
* @param context - used for loading nodes content
* @throws XWikiException if any error
*/
public void removeVersions(Version newerVersion, Version olderVersion, XWikiContext context) throws XWikiException {
Version upperBound = newerVersion;
Version lowerBound = olderVersion;
if (upperBound.compareVersions(lowerBound) < 0) {
Version tmp = upperBound;
upperBound = lowerBound;
lowerBound = tmp;
}
Version firstVersionAfter = getNextVersion(upperBound);
Version firstVersionBefore = getPrevVersion(lowerBound);
if (firstVersionAfter == null && firstVersionBefore == null) {
resetArchive();
return;
}
if (firstVersionAfter == null) {
// Deleting the most recent version.
// Store full version in firstVersionBefore
String xmlBefore = getVersionXml(firstVersionBefore, context);
XWikiRCSNodeInfo niBefore = getNode(firstVersionBefore);
XWikiRCSNodeContent ncBefore = niBefore.getContent(context);
ncBefore.getPatch().setFullVersion(xmlBefore);
niBefore.setContent(ncBefore);
updateNode(niBefore);
getUpdatedNodeContents().add(ncBefore);
} else if (firstVersionBefore != null) {
// We're not deleting from the first version, so we must make a new diff jumping over
// the deleted versions.
String xmlAfter = getVersionXml(firstVersionAfter, context);
String xmlBefore = getVersionXml(firstVersionBefore, context);
XWikiRCSNodeInfo niBefore = getNode(firstVersionBefore);
XWikiRCSNodeContent ncBefore = niBefore.getContent(context);
ncBefore.getPatch().setDiffVersion(xmlBefore, xmlAfter, "");
niBefore.setContent(ncBefore);
updateNode(niBefore);
getUpdatedNodeContents().add(ncBefore);
}
// if (firstVersionBefore == null) => nothing else to do, except delete
for (Iterator<XWikiRCSNodeInfo> it = getNodes(upperBound, lowerBound).iterator(); it.hasNext(); ) {
XWikiRCSNodeInfo ni = it.next();
this.fullVersions.remove(ni.getId().getVersion());
this.deletedNodes.add(ni);
it.remove();
}
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method loadDocument.
/**
* @return selected version of document, null if version is not found.
* @param version - which version to load
* @param context - used for loading
* @throws XWikiException if any error
*/
public XWikiDocument loadDocument(Version version, XWikiContext context) throws XWikiException {
XWikiRCSNodeInfo nodeInfo = getNode(version);
if (nodeInfo == null) {
return null;
}
try {
String content = getVersionXml(version, context);
XWikiDocument doc = new XWikiDocument();
doc.fromXML(content);
doc.setRCSVersion(version);
doc.setComment(nodeInfo.getComment());
doc.setAuthor(nodeInfo.getAuthor());
doc.setMinorEdit(nodeInfo.isMinorEdit());
doc.setMostRecent(version.equals(getLatestVersion()));
// A document coming from the archive should never be considered new.
doc.setNew(false);
return doc;
} catch (Exception e) {
Object[] args = { version.toString(), Long.valueOf(getId()) };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_READING_REVISIONS, "Exception while reading version [{0}] for document id [{1,number}]", e, args);
}
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method setNodes.
/**
* @param versions - collection of XWikiRCSNodeInfo
*/
public void setNodes(Collection<XWikiRCSNodeInfo> versions) {
resetArchive();
for (XWikiRCSNodeInfo node : versions) {
updateNode(node);
}
if (getNodes().size() > 0) {
// ensure latest version is full
getLatestNode().setDiff(false);
updateNode(getLatestNode());
}
}
Aggregations