int fnameIdx = url.getFile().lastIndexOf('/');
int extIdx = url.getFile().lastIndexOf('.');
String fname = url.getFile().substring(fnameIdx + 1);
String ext = extIdx < 0 ? "" : url.getFile().substring(extIdx + 1).toLowerCase();
final WebView view = new WebView();
if (ext.equals("md") || ext.equals("markdown")) {
try (InputStream input = url.openStream()) {
String html = Processor.process(input, Configuration.DEFAULT);
view.getEngine().loadContent(html);
}
} else if (ext.equals("htm") || ext.equals("html")) {
view.getEngine().load(url.toExternalForm());
} else {
try (Reader isr = new InputStreamReader(url.openStream(), cs);
BufferedReader br = new BufferedReader(isr)) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
// msteiger: I suspect that the second parameter is the MIME type
view.getEngine().loadContent(sb.toString(), "text/plain");
}
}
view.getStylesheets().add(BundleUtils.getFXMLUrl("css_webview").toExternalForm());
view.setContextMenuEnabled(false);
final AnchorPane pane = new AnchorPane();
AnchorPane.setBottomAnchor(view, 0.0);
AnchorPane.setTopAnchor(view, 0.0);
pane.getChildren().add(view);