/** @return latest node in history for document. null if none. */ public XWikiRCSNodeInfo getLatestNode() { return getNode(getLatestVersion()); }
/** * 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); updatedNodeInfos.add(newNode); updatedNodeContents.add(newContent); }
/** * {@inheritDoc} */ public void updateXWikiDocArchive(XWikiDocument doc, boolean bTransaction, XWikiContext context) throws XWikiException { try { XWikiDocumentArchive archiveDoc = getXWikiDocumentArchive(doc, context); archiveDoc.updateArchive(doc, doc.getAuthor(), doc.getDate(), doc.getComment(), doc.getRCSVersion(), context); doc.setRCSVersion(archiveDoc.getLatestVersion()); saveXWikiDocArchive(archiveDoc, bTransaction, context); } catch (Exception e) { Object[] args = {doc.getFullName()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT, "Exception while updating archive {0}", e, args); } }
tdoc.setDocumentArchive(archive); if (archive.getLatestVersion() == null) { if (StringUtils.isEmpty(language) || language.equals(doc.getDefaultLanguage())) { context.getWiki().deleteAllDocuments(doc, context); if (!tdoc.getRCSVersion().equals(archive.getLatestVersion())) { XWikiDocument newdoc = archive.loadDocument(archive.getLatestVersion(), context);
/** * @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())); return doc; } catch (Exception e) { Object[] args = {version.toString(), new Long(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); } }