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;
}
Aggregations