/** * {@inheritDoc} */ 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 = {new Long(archivedoc.getId())}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading archive {0}", e, args); } }
/** * 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); updatedNodeInfos.add(nodeInfo); updatedNodeContents.add(nodeContent); } } catch (Exception e) { Object[] args = {text, new Long(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); } }
/** * 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); }
/** * @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); } }