X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FBasicReader.java;h=ae1c8d4c6eb32162c65421e0959da5bb6fc00e31;hb=edd4628984f5f06e955606651fc828ac839f7f43;hp=bc3bf72f2ab7f3c576daddac33b39d4a2bfa8052;hpb=92fb0719f84f5b6734b51e528332546d78e9ccec;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/BasicReader.java b/src/be/nikiroo/fanfix/reader/BasicReader.java index bc3bf72..ae1c8d4 100644 --- a/src/be/nikiroo/fanfix/reader/BasicReader.java +++ b/src/be/nikiroo/fanfix/reader/BasicReader.java @@ -1,6 +1,8 @@ package be.nikiroo.fanfix.reader; +import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import be.nikiroo.fanfix.Instance; @@ -8,7 +10,7 @@ import be.nikiroo.fanfix.Library; import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.supported.BasicSupport; -import be.nikiroo.utils.ui.Progress; +import be.nikiroo.utils.Progress; /** * The class that handles the different {@link Story} readers you can use. @@ -132,8 +134,12 @@ public abstract class BasicReader { * * @param chapter * the chapter + * + * @throws IOException + * in case of I/O error or if the {@link Story} was not + * previously set */ - public abstract void read(int chapter); + public abstract void read(int chapter) throws IOException; /** * Start the reader in browse mode for the given type (or pass NULL for all @@ -190,4 +196,32 @@ public abstract class BasicReader { public static void setDefaultReaderType(ReaderType defaultType) { BasicReader.defaultType = defaultType; } + + /** + * 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; + } }