/** * @return full copy of this archive with specified docId * @param docId - new {@link #getId()} * @param context - used for loading content * @throws XWikiException if any error */ public XWikiDocumentArchive clone(long docId, XWikiContext context) throws XWikiException { XWikiDocumentArchive result = new XWikiDocumentArchive(docId); result.setArchive(getArchive(context)); return result; } }
public Object doInHibernate(Session session) throws HibernateException { for (XWikiRCSNodeInfo ni : archivedoc.getDeletedNodeInfo()) { session.delete(ni); } archivedoc.getDeletedNodeInfo().clear(); for (XWikiRCSNodeInfo ni : archivedoc.getUpdatedNodeInfos()) { session.saveOrUpdate(ni); } archivedoc.getUpdatedNodeInfos().clear(); for (XWikiRCSNodeContent nc : archivedoc.getUpdatedNodeContents()) { session.update(nc); } archivedoc.getUpdatedNodeContents().clear(); return null; } });
/** * 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); } }
/** @return latest node in history for document. null if none. */ public XWikiRCSNodeInfo getLatestNode() { return getNode(getLatestVersion()); }
/** @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()); } }
Version firstVersionAfter = getNextVersion(upperBound); Version firstVersionBefore = getPrevVersion(lowerBound); if (firstVersionAfter == null && firstVersionBefore == null) { resetArchive(); return; 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) { 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); for (Iterator<XWikiRCSNodeInfo> it = getNodes(upperBound, lowerBound).iterator(); it.hasNext();) { XWikiRCSNodeInfo ni = it.next(); fullVersions.remove(ni.getId().getVersion());
/** * 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); } }
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() doc, context); latestNode.setContent(latestContent); updateNode(latestNode); getUpdatedNodeContents().add(latestContent);
/** * @return the archive of the document in a string format. */ public String getArchive() throws XWikiException { return this.doc.getDocumentArchive(getXWikiContext()).getArchive(getXWikiContext()); }
archive.removeVersions(v1, v2, context); context.getWiki().getVersioningStore().saveXWikiDocArchive(archive, true, context); 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);
public void setDocumentArchive(String sarch) throws XWikiException { XWikiDocumentArchive xda = new XWikiDocumentArchive(getId()); xda.setArchive(sarch); setDocumentArchive(xda); }
/** * {@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); } }
/** * 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()); }
public Object doInHibernate(Session session) throws HibernateException, XWikiException { XWikiDocumentArchive archive = getXWikiDocumentArchive(doc, context); archive.resetArchive(); archive.getDeletedNodeInfo().clear(); doc.setMinorEdit(false); deleteArchive(doc, false, context); updateXWikiDocArchive(doc, false, context); return null; } });
/** * {@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); } }
/** * @since 2.2M1 */ public XWikiDocument copyDocument(DocumentReference newDocumentReference, XWikiContext context) throws XWikiException { loadAttachments(context); loadArchive(context); XWikiDocument newdoc = duplicate(newDocumentReference); newdoc.setOriginalDocument(null); newdoc.setContentDirty(true); newdoc.getXClass().setDocumentReference(newDocumentReference); XWikiDocumentArchive archive = newdoc.getDocumentArchive(); if (archive != null) { newdoc.setDocumentArchive(archive.clone(newdoc.getId(), context)); } return newdoc; }
context.setDatabase(doc.getDatabase()); archiveDoc = new XWikiDocumentArchive(doc.getId()); loadXWikiDocArchive(archiveDoc, true, context); doc.setDocumentArchive(archiveDoc);
try { localeParameters.put(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, document.getDocumentArchive(xcontext).getArchive(xcontext)); } catch (XWikiException e) { this.logger.error("Document [{}] has malformed history", document.getDocumentReference(), e);
XWikiDocumentArchive docArchive = new XWikiDocumentArchive(docId); try { docArchive.setArchive(sArchive); } catch (XWikiException e) { LOG.warn("The RCS archive for [" + rs.getString(3)