Commit | Line | Data |
---|---|---|
3727aae2 | 1 | package be.nikiroo.fanfix.reader; |
08fe2e33 NR |
2 | |
3 | import java.io.IOException; | |
08fe2e33 NR |
4 | import java.util.List; |
5 | ||
6 | import be.nikiroo.fanfix.Instance; | |
08fe2e33 NR |
7 | import be.nikiroo.fanfix.bundles.StringId; |
8 | import be.nikiroo.fanfix.data.Chapter; | |
9 | import be.nikiroo.fanfix.data.MetaData; | |
10 | import be.nikiroo.fanfix.data.Paragraph; | |
11 | import be.nikiroo.fanfix.data.Story; | |
08fe2e33 NR |
12 | import be.nikiroo.fanfix.supported.BasicSupport.SupportType; |
13 | ||
14 | /** | |
15 | * Command line {@link Story} reader. | |
16 | * <p> | |
17 | * Will output stories to the console. | |
18 | * | |
19 | * @author niki | |
20 | */ | |
3727aae2 NR |
21 | class CliReader extends BasicReader { |
22 | @Override | |
89cb07a6 NR |
23 | public void read() throws IOException { |
24 | if (getStory() == null) { | |
25 | throw new IOException("No story to read"); | |
08fe2e33 | 26 | } |
08fe2e33 | 27 | |
08fe2e33 NR |
28 | String title = ""; |
29 | String author = ""; | |
30 | ||
89cb07a6 | 31 | MetaData meta = getStory().getMeta(); |
08fe2e33 NR |
32 | if (meta != null) { |
33 | if (meta.getTitle() != null) { | |
34 | title = meta.getTitle(); | |
35 | } | |
36 | ||
37 | if (meta.getAuthor() != null) { | |
38 | author = "©" + meta.getAuthor(); | |
39 | if (meta.getDate() != null && !meta.getDate().isEmpty()) { | |
40 | author = author + " (" + meta.getDate() + ")"; | |
41 | } | |
42 | } | |
43 | } | |
44 | ||
45 | System.out.println(title); | |
46 | System.out.println(author); | |
47 | System.out.println(""); | |
48 | ||
89cb07a6 | 49 | for (Chapter chap : getStory()) { |
08fe2e33 NR |
50 | if (chap.getName() != null && !chap.getName().isEmpty()) { |
51 | System.out.println(Instance.getTrans().getString( | |
52 | StringId.CHAPTER_NAMED, chap.getNumber(), | |
53 | chap.getName())); | |
54 | } else { | |
55 | System.out.println(Instance.getTrans().getString( | |
56 | StringId.CHAPTER_UNNAMED, chap.getNumber())); | |
57 | } | |
58 | } | |
59 | } | |
60 | ||
3727aae2 | 61 | @Override |
08fe2e33 | 62 | public void read(int chapter) { |
89cb07a6 | 63 | if (chapter > getStory().getChapters().size()) { |
08fe2e33 NR |
64 | System.err.println("Chapter " + chapter + ": no such chapter"); |
65 | } else { | |
89cb07a6 | 66 | Chapter chap = getStory().getChapters().get(chapter - 1); |
08fe2e33 NR |
67 | System.out.println("Chapter " + chap.getNumber() + ": " |
68 | + chap.getName()); | |
69 | ||
70 | for (Paragraph para : chap) { | |
71 | System.out.println(para.getContent()); | |
72 | System.out.println(""); | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
89cb07a6 NR |
77 | @Override |
78 | public void start(SupportType type) { | |
08fe2e33 NR |
79 | List<MetaData> stories; |
80 | stories = Instance.getLibrary().getList(type); | |
81 | ||
82 | for (MetaData story : stories) { | |
83 | String author = ""; | |
84 | if (story.getAuthor() != null && !story.getAuthor().isEmpty()) { | |
85 | author = " (" + story.getAuthor() + ")"; | |
86 | } | |
87 | ||
88 | System.out.println(story.getLuid() + ": " + story.getTitle() | |
89 | + author); | |
90 | } | |
91 | } | |
92 | } |