package be.nikiroo.fanfix.reader;
-import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
}
@Override
- public MetaData getMeta() {
+ public synchronized MetaData getMeta() {
return meta;
}
throw new IOException("URL not supported: " + source.toString());
}
- story = support.process(source, pg);
+ story = support.process(pg);
if (story == null) {
throw new IOException(
"Cannot retrieve story from external source: "
.getTypeName());
}
} catch (Exception e) {
- Instance.syserr(new Exception("Cannot create a reader of type: "
- + defaultType + " (Not compiled in?)", e));
+ Instance.getTraceHandler().error(
+ new Exception("Cannot create a reader of type: "
+ + defaultType + " (Not compiled in?)", e));
}
return null;
* @throws IOException
* in case of I/O error
*/
- public static void openExternal(BasicLibrary lib, String luid)
- throws IOException {
+ @Override
+ public void openExternal(BasicLibrary lib, String luid) throws IOException {
MetaData meta = lib.getInfo(luid);
File target = lib.getFile(luid, null);
* @throws IOException
* in case of I/O error
*/
- protected static void openExternal(MetaData meta, File target)
- throws IOException {
+ protected void openExternal(MetaData meta, File target) throws IOException {
String program = null;
if (meta.isImageDocument()) {
program = Instance.getUiConfig().getString(
program = null;
}
- if (program == null) {
- try {
- Desktop.getDesktop().browse(target.toURI());
- } catch (UnsupportedOperationException e) {
- Runtime.getRuntime().exec(
- new String[] { "xdg-open", target.getAbsolutePath() });
+ start(target, program);
+ }
+ /**
+ * Start a file and open it with the given program if given or the first
+ * default system starter we can find.
+ *
+ * @param target
+ * the target to open
+ * @param program
+ * the program to use or NULL for the default system starter
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ protected void start(File target, String program) throws IOException {
+ if (program == null) {
+ boolean ok = false;
+ for (String starter : new String[] { "xdg-open", "open", "see",
+ "start", "run" }) {
+ try {
+ Instance.getTraceHandler().trace(
+ "starting external program");
+ Runtime.getRuntime().exec(
+ new String[] { starter, target.getAbsolutePath() });
+ ok = true;
+ break;
+ } catch (IOException e) {
+ }
+ }
+ if (!ok) {
+ throw new IOException("Cannot find a program to start the file");
}
} else {
+ Instance.getTraceHandler().trace("starting external program");
Runtime.getRuntime().exec(
new String[] { program, target.getAbsolutePath() });
}