final String uriString = uri.toString();
if (uriString.startsWith("#")) {
final String target = uri.getFragment();
try {
final ModeController modeController = Controller.getCurrentModeController();
final MapController mapController = modeController.getMapController();
final NodeModel node = mapController.getNodeFromID(target);
if (node != null) {
mapController.select(node);
}
}
catch (final Exception e) {
LogUtils.warn("link " + target + " not found", e);
UITools.errorMessage(TextUtils.format("link_not_found", target));
}
return;
}
try {
final String extension = FileUtils.getExtension(uri.getRawPath());
if(! uri.isAbsolute()){
URI absoluteUri = getAbsoluteUri(uri);
if (absoluteUri == null) {
final MapModel map = Controller.getCurrentController().getMap();
if (map.getURL() == null)
UITools.errorMessage(TextUtils.getText("map_not_saved"));
else
UITools.errorMessage(TextUtils.format("link_not_found", String.valueOf(uri)));
return;
}
uri = absoluteUri;
}
//DOCEAR: mindmaps can be linked in a mindmap --> therefore project-relative-paths are possible
if(! asList(FILE_SCHEME, SMB_SCHEME, FREEPLANE_SCHEME).contains(uri.getScheme())) {
try {
uri = uri.toURL().openConnection().getURL().toURI().normalize();
}
catch (Exception e) {
LogUtils.warn("link " + uri + " not found", e);
UITools.errorMessage(TextUtils.format("link_not_found", uri.toString()));
}
}
try {
if ((extension != null)
&& extension.equals(UrlManager.FREEPLANE_FILE_EXTENSION_WITHOUT_DOT)) {
FreeplaneUriConverter freeplaneUriConverter = new FreeplaneUriConverter();
final URL url = freeplaneUriConverter.freeplaneUrl(uri);
final ModeController modeController = Controller.getCurrentModeController();
modeController.getMapController().newMap(url);
final String ref = uri.getFragment();
if (ref != null) {
final ModeController newModeController = Controller.getCurrentModeController();
final MapController newMapController = newModeController.getMapController();
newMapController.select(newMapController.getNodeFromID(ref));
}
return;
}
Controller.getCurrentController().getViewController().openDocument(uri);
}