Search in sources :

Example 6 with ToString

use of org.suigeneris.jrcs.util.ToString in project xwiki-platform by xwiki.

the class XWikiRCSArchive method getNodes.

/**
 * @return Collection of pairs [{@link XWikiRCSNodeInfo}, {@link XWikiRCSNodeContent}]
 * @param docId - docId which will be wrote in {@link XWikiRCSNodeId#setDocId(long)}
 * @throws PatchFailedException
 * @throws InvalidFileFormatException
 * @throws NodeNotFoundException
 */
public Collection getNodes(long docId) throws NodeNotFoundException, InvalidFileFormatException, PatchFailedException {
    Collection result = new ArrayList(this.nodes.values().size());
    for (Iterator it = this.nodes.values().iterator(); it.hasNext(); ) {
        XWikiJRCSNode node = new XWikiJRCSNode((Node) it.next());
        XWikiRCSNodeInfo nodeInfo = new XWikiRCSNodeInfo();
        nodeInfo.setId(new XWikiRCSNodeId(docId, node.getVersion()));
        nodeInfo.setDiff(node.isDiff());
        if (!node.hasOldFormat()) {
            nodeInfo.setAuthor(node.getAuthor1());
            nodeInfo.setComment(node.getLog());
            nodeInfo.setDate(node.getDate());
        } else {
            // ones from a XWikiDocment object that we construct using the archive content.
            try {
                String xml = getRevisionAsString(node.getVersion());
                XWikiDocument doc = new XWikiDocument();
                doc.fromXML(xml);
                // set this fields from old document
                nodeInfo.setAuthor(doc.getAuthor());
                nodeInfo.setComment(doc.getComment());
                nodeInfo.setDate(doc.getDate());
            } catch (Exception e) {
                // 3 potential known errors:
                // 1) Revision 1.1 doesn't exist. Some time in the past there was a bug in XWiki where version
                // were starting at 1.2. When this happens the returned xml has a value of "\n".
                // 2) A Class property with an invalid XML name was created.
                // See https://jira.xwiki.org/browse/XWIKI-1855
                // 3) Cannot get the revision as a string from a node version. Not sure why this
                // is happening though... See https://jira.xwiki.org/browse/XWIKI-2076
                LOGGER.warn("Error in revision [" + node.getVersion().toString() + "]: [" + e.getMessage() + "]. Ignoring non-fatal error, the Author, Comment and Date are not set.");
            }
        }
        XWikiRCSNodeContent content = new XWikiRCSNodeContent(nodeInfo.getId());
        content.setPatch(new XWikiPatch(node.getTextString(), node.isDiff()));
        nodeInfo.setContent(content);
        result.add(nodeInfo);
        result.add(content);
    }
    // Ensure that the latest revision is set set to have the full content and not a diff.
    if (result.size() > 0) {
        ((XWikiRCSNodeInfo) ((ArrayList) result).get(0)).setDiff(false);
        ((XWikiRCSNodeContent) ((ArrayList) result).get(1)).getPatch().setDiff(false);
    }
    return result;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) ToString(org.suigeneris.jrcs.util.ToString) XWikiException(com.xpn.xwiki.XWikiException) InvalidTrunkVersionNumberException(org.suigeneris.jrcs.rcs.InvalidTrunkVersionNumberException) PatchFailedException(org.suigeneris.jrcs.diff.PatchFailedException) InvalidFileFormatException(org.suigeneris.jrcs.rcs.InvalidFileFormatException) ParseException(org.suigeneris.jrcs.rcs.parse.ParseException) DecoderException(org.apache.commons.codec.DecoderException) NodeNotFoundException(org.suigeneris.jrcs.rcs.impl.NodeNotFoundException)

Aggregations

ToString (org.suigeneris.jrcs.util.ToString)6 XWikiException (com.xpn.xwiki.XWikiException)3 ArrayList (java.util.ArrayList)3 Version (org.suigeneris.jrcs.rcs.Version)3 DifferentiationFailedException (org.suigeneris.jrcs.diff.DifferentiationFailedException)2 PatchFailedException (org.suigeneris.jrcs.diff.PatchFailedException)2 InvalidFileFormatException (org.suigeneris.jrcs.rcs.InvalidFileFormatException)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 StringTokenizer (java.util.StringTokenizer)1 DecoderException (org.apache.commons.codec.DecoderException)1 Revision (org.suigeneris.jrcs.diff.Revision)1 AddDelta (org.suigeneris.jrcs.diff.delta.AddDelta)1 Chunk (org.suigeneris.jrcs.diff.delta.Chunk)1