Search in sources :

Example 1 with NodeNotFoundException

use of org.suigeneris.jrcs.rcs.impl.NodeNotFoundException 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

XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 DecoderException (org.apache.commons.codec.DecoderException)1 PatchFailedException (org.suigeneris.jrcs.diff.PatchFailedException)1 InvalidFileFormatException (org.suigeneris.jrcs.rcs.InvalidFileFormatException)1 InvalidTrunkVersionNumberException (org.suigeneris.jrcs.rcs.InvalidTrunkVersionNumberException)1 NodeNotFoundException (org.suigeneris.jrcs.rcs.impl.NodeNotFoundException)1 ParseException (org.suigeneris.jrcs.rcs.parse.ParseException)1 ToString (org.suigeneris.jrcs.util.ToString)1