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
;
14 * Command line {@link Story} reader.
16 * Will output stories to the console.
20 class CliReader
extends BasicReader
{
22 public void read() throws IOException
{
23 if (getStory() == null) {
24 throw new IOException("No story to read");
30 MetaData meta
= getStory().getMeta();
32 if (meta
.getTitle() != null) {
33 title
= meta
.getTitle();
36 if (meta
.getAuthor() != null) {
37 author
= "©" + meta
.getAuthor();
38 if (meta
.getDate() != null && !meta
.getDate().isEmpty()) {
39 author
= author
+ " (" + meta
.getDate() + ")";
44 System
.out
.println(title
);
45 System
.out
.println(author
);
46 System
.out
.println("");
48 for (Chapter chap
: getStory()) {
49 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
50 System
.out
.println(Instance
.getTrans().getString(
51 StringId
.CHAPTER_NAMED
, chap
.getNumber(),
54 System
.out
.println(Instance
.getTrans().getString(
55 StringId
.CHAPTER_UNNAMED
, chap
.getNumber()));
61 public void read(int chapter
) throws IOException
{
62 if (getStory() == null) {
63 throw new IOException("No story to read");
66 if (chapter
> getStory().getChapters().size()) {
67 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
69 Chapter chap
= getStory().getChapters().get(chapter
- 1);
70 System
.out
.println("Chapter " + chap
.getNumber() + ": "
73 for (Paragraph para
: chap
) {
74 System
.out
.println(para
.getContent());
75 System
.out
.println("");
81 public void start(String type
) {
82 List
<MetaData
> stories
;
83 stories
= Instance
.getLibrary().getListByType(type
);
85 for (MetaData story
: stories
) {
87 if (story
.getAuthor() != null && !story
.getAuthor().isEmpty()) {
88 author
= " (" + story
.getAuthor() + ")";
91 System
.out
.println(story
.getLuid() + ": " + story
.getTitle()