String currentVersion = parseFormatVersion(currentXml);
ArrayList<String> warnings = new ArrayList<String>();
// Avoid upgrades getting stuck in an infinite loop.
int tries = 0;
if (currentVersion.equals("0.9")) {
throw new LoadException(file, "This is a NodeBox 2 file. Download NodeBox 2 from http://beta.nodebox.net/");
}
while (!currentVersion.equals(targetVersion) && tries < 100) {
Method upgradeMethod = upgradeMap.get(currentVersion);
if (upgradeMethod == null) {
throw new LoadException(file, "Unsupported version " + currentVersion + ": this file is too new. Try downloading a new version of NodeBox from http://nodebox.net/download/");
}
try {
UpgradeStringResult result = (UpgradeStringResult) upgradeMethod.invoke(null, currentXml);
warnings.addAll(result.warnings);
currentXml = result.xml;
} catch (Exception e) {
throw new LoadException(file, "Upgrading to " + currentVersion + " failed.", e);
}
currentVersion = parseFormatVersion(currentXml);
tries++;
}
if (tries >= 100) {
throw new LoadException(file, "Got stuck in an infinite loop when trying to upgrade from " + currentVersion);
}
return new UpgradeResult(file, currentXml, warnings);
}