use of org.freeplane.features.url.IMapInputStreamConverter in project freeplane by freeplane.
the class MFileManager method loadTreeImpl.
private NodeModel loadTreeImpl(final MapModel map, final File f) throws FileNotFoundException, IOException, XMLException, MapConversionException {
final BufferedInputStream file = new BufferedInputStream(new FileInputStream(f));
int versionInfoLength = 1000;
final byte[] buffer = new byte[versionInfoLength];
final int readCount = file.read(buffer);
final String mapStart = new String(buffer, FileUtils.defaultCharset().name());
final ByteArrayInputStream readBytes = new ByteArrayInputStream(buffer, 0, readCount);
final InputStream sequencedInput = new SequenceInputStream(readBytes, file);
Reader reader = null;
MapVersionInterpreter versionInterpreter = MapVersionInterpreter.getVersionInterpreter(mapStart);
map.addExtension(versionInterpreter);
if (versionInterpreter.anotherDialect) {
String message = versionInterpreter.getDialectInfo(f.getAbsolutePath());
UITools.showMessage(message, JOptionPane.WARNING_MESSAGE);
}
if (versionInterpreter.needsConversion) {
final int showResult = OptionalDontShowMeAgainDialog.show("really_convert_to_current_version", "confirmation", MMapController.RESOURCES_CONVERT_TO_CURRENT_VERSION, OptionalDontShowMeAgainDialog.ONLY_OK_SELECTION_IS_STORED);
IMapInputStreamConverter isConverter = versionInterpreter.getMapInputStreamConverter();
if (showResult != JOptionPane.OK_OPTION || isConverter == null) {
reader = new InputStreamReader(sequencedInput, FileUtils.defaultCharset());
} else {
sequencedInput.close();
// reader = UrlManager.getUpdateReader(f, FREEPLANE_VERSION_UPDATER_XSLT);
reader = isConverter.getConvertedStream(f);
}
} else {
reader = new InputStreamReader(sequencedInput, FileUtils.defaultCharset());
}
try {
return Controller.getCurrentModeController().getMapController().getMapReader().createNodeTreeFromXml(map, reader, Mode.FILE);
} finally {
FileUtils.silentlyClose(reader);
}
}
Aggregations