1 package be
.nikiroo
.fanfix
.reader
.cli
;
3 import java
.io
.IOException
;
6 import be
.nikiroo
.fanfix
.Instance
;
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
;
12 import be
.nikiroo
.fanfix
.reader
.FanfixReader
;
13 import be
.nikiroo
.fanfix
.supported
.BasicSupport
.SupportType
;
16 * Command line {@link Story} reader.
18 * Will output stories to the console.
22 public class CliReader
extends FanfixReader
{
24 * Start the {@link Story} Reading.
27 * in case of I/O error or if the {@link Story} was not
30 public void read() throws IOException
{
31 if (getStory() == null) {
32 throw new IOException("No story to read");
38 MetaData meta
= getStory().getMeta();
40 if (meta
.getTitle() != null) {
41 title
= meta
.getTitle();
44 if (meta
.getAuthor() != null) {
45 author
= "©" + meta
.getAuthor();
46 if (meta
.getDate() != null && !meta
.getDate().isEmpty()) {
47 author
= author
+ " (" + meta
.getDate() + ")";
52 System
.out
.println(title
);
53 System
.out
.println(author
);
54 System
.out
.println("");
56 for (Chapter chap
: getStory()) {
57 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
58 System
.out
.println(Instance
.getTrans().getString(
59 StringId
.CHAPTER_NAMED
, chap
.getNumber(),
62 System
.out
.println(Instance
.getTrans().getString(
63 StringId
.CHAPTER_UNNAMED
, chap
.getNumber()));
69 * Read the selected chapter (starting at 1).
74 public void read(int chapter
) {
75 if (chapter
> getStory().getChapters().size()) {
76 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
78 Chapter chap
= getStory().getChapters().get(chapter
- 1);
79 System
.out
.println("Chapter " + chap
.getNumber() + ": "
82 for (Paragraph para
: chap
) {
83 System
.out
.println(para
.getContent());
84 System
.out
.println("");
90 public void start(SupportType type
) {
91 List
<MetaData
> stories
;
92 stories
= Instance
.getLibrary().getList(type
);
94 for (MetaData story
: stories
) {
96 if (story
.getAuthor() != null && !story
.getAuthor().isEmpty()) {
97 author
= " (" + story
.getAuthor() + ")";
100 System
.out
.println(story
.getLuid() + ": " + story
.getTitle()