X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FCliReader.java;h=2f0b8cee32910ffae7e31374b807a3cd2d65f32c;hb=211f7ddb50f68aa8a999023ef6d63d5756bdace6;hp=52a5ea4321f7ef6aa8a1607605b09e39f7708b77;hpb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/CliReader.java b/src/be/nikiroo/fanfix/reader/CliReader.java index 52a5ea4..2f0b8ce 100644 --- a/src/be/nikiroo/fanfix/reader/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/CliReader.java @@ -1,19 +1,14 @@ package be.nikiroo.fanfix.reader; import java.io.IOException; -import java.net.URL; import java.util.List; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.Library; import be.nikiroo.fanfix.bundles.StringId; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.output.BasicOutput.OutputType; -import be.nikiroo.fanfix.supported.BasicSupport; -import be.nikiroo.fanfix.supported.BasicSupport.SupportType; /** * Command line {@link Story} reader. @@ -22,66 +17,26 @@ import be.nikiroo.fanfix.supported.BasicSupport.SupportType; * * @author niki */ -public class CliReader { - private Story story; - - /** - * Create a new {@link CliReader} for a {@link Story} in the {@link Library} - * . - * - * @param luid - * the {@link Story} ID - * @throws IOException - * in case of I/O error - */ - public CliReader(String luid) throws IOException { - story = Instance.getLibrary().getStory(luid); - if (story == null) { - throw new IOException("Cannot retrieve story from library: " + luid); - } - } - - /** - * Create a new {@link CliReader} for an external {@link Story}. - * - * @param source - * the {@link Story} {@link URL} - * @throws IOException - * in case of I/O error - */ - public CliReader(URL source) throws IOException { - BasicSupport support = BasicSupport.getSupport(source); - if (support == null) { - throw new IOException("URL not supported: " + source.toString()); - } - - story = support.process(source); - if (story == null) { - throw new IOException( - "Cannot retrieve story from external source: " - + source.toString()); +class CliReader extends BasicReader { + @Override + public void read() throws IOException { + MetaData meta = getMeta(); + if (meta == null) { + throw new IOException("No story to read"); } - } - /** - * Read the information about the {@link Story}. - */ - public void read() { String title = ""; String author = ""; - MetaData meta = story.getMeta(); - if (meta != null) { - if (meta.getTitle() != null) { - title = meta.getTitle(); - } + if (meta.getTitle() != null) { + title = meta.getTitle(); + } - if (meta.getAuthor() != null) { - author = "©" + meta.getAuthor(); - if (meta.getDate() != null && !meta.getDate().isEmpty()) { - author = author + " (" + meta.getDate() + ")"; - } + if (meta.getAuthor() != null) { + author = "©" + meta.getAuthor(); + if (meta.getDate() != null && !meta.getDate().isEmpty()) { + author = author + " (" + meta.getDate() + ")"; } } @@ -89,7 +44,8 @@ public class CliReader { System.out.println(author); System.out.println(""); - for (Chapter chap : story) { + // TODO: progress? + for (Chapter chap : getStory(null)) { if (chap.getName() != null && !chap.getName().isEmpty()) { System.out.println(Instance.getTrans().getString( StringId.CHAPTER_NAMED, chap.getNumber(), @@ -101,17 +57,18 @@ public class CliReader { } } - /** - * Read the selected chapter (starting at 1). - * - * @param chapter - * the chapter - */ - public void read(int chapter) { - if (chapter > story.getChapters().size()) { + public void read(int chapter) throws IOException { + MetaData meta = getMeta(); + + if (meta == null) { + throw new IOException("No story to read"); + } + + // TODO: progress? + if (chapter > getStory(null).getChapters().size()) { System.err.println("Chapter " + chapter + ": no such chapter"); } else { - Chapter chap = story.getChapters().get(chapter - 1); + Chapter chap = getStory(null).getChapters().get(chapter - 1); System.out.println("Chapter " + chap.getNumber() + ": " + chap.getName()); @@ -122,16 +79,10 @@ public class CliReader { } } - /** - * List all the stories available in the {@link Library} by - * {@link OutputType} (or all of them if the given type is NULL) - * - * @param type - * the {@link OutputType} or NULL for all stories - */ - public static void list(SupportType type) { + @Override + public void browse(String source) { List stories; - stories = Instance.getLibrary().getList(type); + stories = getLibrary().getListBySource(source); for (MetaData story : stories) { String author = "";