Search in sources :

Example 1 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiHibernateVersioningStore method getXWikiDocVersions.

@Override
public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException {
    try {
        XWikiDocumentArchive archive = getXWikiDocumentArchive(doc, context);
        if (archive == null) {
            return new Version[0];
        }
        Collection<XWikiRCSNodeInfo> nodes = archive.getNodes();
        Version[] versions = new Version[nodes.size()];
        Iterator<XWikiRCSNodeInfo> it = nodes.iterator();
        for (int i = 0; i < versions.length; i++) {
            XWikiRCSNodeInfo node = it.next();
            versions[versions.length - 1 - i] = node.getId().getVersion();
        }
        return versions;
    } catch (Exception e) {
        Object[] args = { doc.getFullName() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS, "Exception while reading document {0} revisions", e, args);
    }
}
Also used : XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiException(com.xpn.xwiki.XWikiException) HibernateException(org.hibernate.HibernateException) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiHibernateVersioningStore method loadXWikiDocArchive.

@Override
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 = { Long.valueOf(archivedoc.getId()) };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading archive {0}", e, args);
    }
}
Also used : XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiException(com.xpn.xwiki.XWikiException) HibernateException(org.hibernate.HibernateException) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiDocument method getRevisions.

/**
 * Get document versions matching criterias like author, minimum creation date, etc.
 *
 * @param criteria criteria used to match versions
 * @return a list of matching versions
 */
public List<String> getRevisions(RevisionCriteria criteria, XWikiContext context) throws XWikiException {
    List<String> results = new ArrayList<String>();
    Version[] revisions = getRevisions(context);
    XWikiRCSNodeInfo nextNodeinfo = null;
    XWikiRCSNodeInfo nodeinfo;
    for (Version revision : revisions) {
        nodeinfo = nextNodeinfo;
        nextNodeinfo = getRevisionInfo(revision.toString(), context);
        if (nodeinfo == null) {
            continue;
        }
        // Minor/Major version matching
        if (criteria.getIncludeMinorVersions() || !nextNodeinfo.isMinorEdit()) {
            // Author matching
            if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
                // Date range matching
                Date versionDate = nodeinfo.getDate();
                if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
                    results.add(nodeinfo.getVersion().toString());
                }
            }
        }
    }
    nodeinfo = nextNodeinfo;
    if (nodeinfo != null) {
        if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
            // Date range matching
            Date versionDate = nodeinfo.getDate();
            if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
                results.add(nodeinfo.getVersion().toString());
            }
        }
    }
    return criteria.getRange().subList(results);
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) ArrayList(java.util.ArrayList) ToString(org.suigeneris.jrcs.util.ToString) Date(java.util.Date)

Example 4 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo 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);
    }
}
Also used : XWikiRCSArchive(com.xpn.xwiki.doc.rcs.XWikiRCSArchive) XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) Iterator(java.util.Iterator) Collection(java.util.Collection) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Example 5 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo 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);
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)

Aggregations

XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)10 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)5 XWikiException (com.xpn.xwiki.XWikiException)4 Version (org.suigeneris.jrcs.rcs.Version)4 ToString (org.suigeneris.jrcs.util.ToString)3 ArrayList (java.util.ArrayList)2 HibernateException (org.hibernate.HibernateException)2 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)1 XWikiPatch (com.xpn.xwiki.doc.rcs.XWikiPatch)1 XWikiRCSArchive (com.xpn.xwiki.doc.rcs.XWikiRCSArchive)1 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1