X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FCliReader.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FCliReader.java;h=0000000000000000000000000000000000000000;hb=89cb07a69f3ee217f9ea6a4284bec0df94ef77fa;hp=52a5ea4321f7ef6aa8a1607605b09e39f7708b77;hpb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/CliReader.java b/src/be/nikiroo/fanfix/reader/CliReader.java deleted file mode 100644 index 52a5ea4..0000000 --- a/src/be/nikiroo/fanfix/reader/CliReader.java +++ /dev/null @@ -1,146 +0,0 @@ -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. - *

- * Will output stories to the console. - * - * @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()); - - } - } - - /** - * 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.getAuthor() != null) { - author = "©" + meta.getAuthor(); - if (meta.getDate() != null && !meta.getDate().isEmpty()) { - author = author + " (" + meta.getDate() + ")"; - } - } - } - - System.out.println(title); - System.out.println(author); - System.out.println(""); - - for (Chapter chap : story) { - if (chap.getName() != null && !chap.getName().isEmpty()) { - System.out.println(Instance.getTrans().getString( - StringId.CHAPTER_NAMED, chap.getNumber(), - chap.getName())); - } else { - System.out.println(Instance.getTrans().getString( - StringId.CHAPTER_UNNAMED, chap.getNumber())); - } - } - } - - /** - * Read the selected chapter (starting at 1). - * - * @param chapter - * the chapter - */ - public void read(int chapter) { - if (chapter > story.getChapters().size()) { - System.err.println("Chapter " + chapter + ": no such chapter"); - } else { - Chapter chap = story.getChapters().get(chapter - 1); - System.out.println("Chapter " + chap.getNumber() + ": " - + chap.getName()); - - for (Paragraph para : chap) { - System.out.println(para.getContent()); - System.out.println(""); - } - } - } - - /** - * 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) { - List stories; - stories = Instance.getLibrary().getList(type); - - for (MetaData story : stories) { - String author = ""; - if (story.getAuthor() != null && !story.getAuthor().isEmpty()) { - author = " (" + story.getAuthor() + ")"; - } - - System.out.println(story.getLuid() + ": " + story.getTitle() - + author); - } - } -}