1 package be
.nikiroo
.fanfix
.reader
;
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
.supported
.BasicSupport
.SupportType
;
15 * Command line {@link Story} reader.
17 * Will output stories to the console.
21 class CliReader
extends BasicReader
{
23 public void read() throws IOException
{
24 if (getStory() == null) {
25 throw new IOException("No story to read");
31 MetaData meta
= getStory().getMeta();
33 if (meta
.getTitle() != null) {
34 title
= meta
.getTitle();
37 if (meta
.getAuthor() != null) {
38 author
= "©" + meta
.getAuthor();
39 if (meta
.getDate() != null && !meta
.getDate().isEmpty()) {
40 author
= author
+ " (" + meta
.getDate() + ")";
45 System
.out
.println(title
);
46 System
.out
.println(author
);
47 System
.out
.println("");
49 for (Chapter chap
: getStory()) {
50 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
51 System
.out
.println(Instance
.getTrans().getString(
52 StringId
.CHAPTER_NAMED
, chap
.getNumber(),
55 System
.out
.println(Instance
.getTrans().getString(
56 StringId
.CHAPTER_UNNAMED
, chap
.getNumber()));
62 public void read(int chapter
) {
63 if (chapter
> getStory().getChapters().size()) {
64 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
66 Chapter chap
= getStory().getChapters().get(chapter
- 1);
67 System
.out
.println("Chapter " + chap
.getNumber() + ": "
70 for (Paragraph para
: chap
) {
71 System
.out
.println(para
.getContent());
72 System
.out
.println("");
78 public void start(SupportType type
) {
79 List
<MetaData
> stories
;
80 stories
= Instance
.getLibrary().getList(type
);
82 for (MetaData story
: stories
) {
84 if (story
.getAuthor() != null && !story
.getAuthor().isEmpty()) {
85 author
= " (" + story
.getAuthor() + ")";
88 System
.out
.println(story
.getLuid() + ": " + story
.getTitle()