+
+ /**
+ * Change the default {@link Library} to open with the {@link BasicReader}s.
+ *
+ * @param lib
+ * the new {@link Library}
+ */
+ public static void setDefaultLibrary(Library lib) {
+ BasicReader.defaultLibrary = lib;
+ }
+
+ /**
+ * Return an {@link URL} from this {@link String}, be it a file path or an
+ * actual {@link URL}.
+ *
+ * @param sourceString
+ * the source
+ *
+ * @return the corresponding {@link URL}
+ *
+ * @throws MalformedURLException
+ * if this is neither a file nor a conventional {@link URL}
+ */
+ public static URL getUrl(String sourceString) throws MalformedURLException {
+ if (sourceString == null || sourceString.isEmpty()) {
+ throw new MalformedURLException("Empty url");
+ }
+
+ URL source = null;
+ try {
+ source = new URL(sourceString);
+ } catch (MalformedURLException e) {
+ File sourceFile = new File(sourceString);
+ source = sourceFile.toURI().toURL();
+ }
+
+ return source;
+ }
+
+ // open with external player the related file
+ public static void open(Library lib, String luid) throws IOException {
+ MetaData meta = lib.getInfo(luid);
+ File target = lib.getFile(luid);
+
+ open(meta, target);
+ }
+
+ // open with external player the related file
+ protected static void open(MetaData meta, File target) throws IOException {
+ String program = null;
+ if (meta.isImageDocument()) {
+ program = Instance.getUiConfig().getString(
+ UiConfig.IMAGES_DOCUMENT_READER);
+ } else {
+ program = Instance.getUiConfig().getString(
+ UiConfig.NON_IMAGES_DOCUMENT_READER);
+ }
+
+ if (program != null && program.trim().isEmpty()) {
+ program = null;
+ }
+
+ if (program == null) {
+ try {
+ Desktop.getDesktop().browse(target.toURI());
+ } catch (UnsupportedOperationException e) {
+ Runtime.getRuntime().exec(
+ new String[] { "xdg-open", target.getAbsolutePath() });
+
+ }
+ } else {
+ Runtime.getRuntime().exec(
+ new String[] { program, target.getAbsolutePath() });
+ }
+ }