use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent 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.XWikiRCSNodeContent 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);
}
use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent 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.XWikiRCSNodeContent 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.XWikiRCSNodeContent in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method getVersionXml.
/**
* Return the XML corresponding to a version. If the version node contains just a diff, then restore the complete
* XML by applying all patches from the nearest full version to the requested version.
*
* @param version The version to retrieve.
* @param context The {@link com.xpn.xwiki.XWikiContext context}.
* @return The XML corresponding to the version.
* @throws XWikiException If any exception occured.
*/
public String getVersionXml(Version version, XWikiContext context) throws XWikiException {
Version nearestFullVersion = getNearestFullVersion(version);
List<XWikiRCSNodeContent> lstContent = loadRCSNodeContents(nearestFullVersion, version, context);
List<String> origText = new ArrayList<String>();
for (XWikiRCSNodeContent nodeContent : lstContent) {
nodeContent.getPatch().patch(origText);
}
return ToString.arrayToString(origText.toArray());
}
Aggregations