- /**
- * 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}
- */
- private static URL getUrl(String sourceString) throws MalformedURLException {
- if (sourceString == null || sourceString.isEmpty()) {
- throw new MalformedURLException("Empty url");
+ if (exitCode != 255) {
+ switch (action) {
+ case IMPORT:
+ exitCode = imprt(urlString, pg);
+ updates.ok(); // we consider it read
+ break;
+ case EXPORT:
+ exitCode = export(luid, sourceString, target, pg);
+ updates.ok(); // we consider it read
+ break;
+ case CONVERT:
+ exitCode = convert(urlString, sourceString, target,
+ plusInfo == null ? false : plusInfo, pg);
+ updates.ok(); // we consider it read
+ break;
+ case LIST:
+ if (BasicReader.getReader() == null) {
+ Instance.syserr(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ exitCode = list(sourceString);
+ break;
+ case READ:
+ if (BasicReader.getReader() == null) {
+ Instance.syserr(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ exitCode = read(luid, chapString, true);
+ break;
+ case READ_URL:
+ if (BasicReader.getReader() == null) {
+ Instance.syserr(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ exitCode = read(urlString, chapString, false);
+ break;
+ case HELP:
+ syntax(true);
+ exitCode = 0;
+ break;
+ case SET_READER:
+ exitCode = 255;
+ break;
+ case VERSION:
+ System.out
+ .println(String.format("Fanfix version %s"
+ + "\nhttps://github.com/nikiroo/fanfix/"
+ + "\n\tWritten by Nikiroo",
+ Version.getCurrentVersion()));
+ updates.ok(); // we consider it read
+ break;
+ case START:
+ if (BasicReader.getReader() == null) {
+ Instance.syserr(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ BasicReader.getReader().browse(null);
+ break;
+ case SERVER:
+ if (port == null) {
+ exitCode = 255;
+ break;
+ }
+ try {
+ Server server = new RemoteLibraryServer(port);
+ server.start();
+ System.out.println("Remote server started on: " + port);
+ } catch (IOException e) {
+ Instance.syserr(e);
+ }
+ return;
+ case REMOTE:
+ exitCode = 255; // should not be reachable (REMOTE -> START)
+ break;
+ }