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