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
.BasicReader
;
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 MetaData meta
= getMeta();
27 throw new IOException("No story to read");
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() + ")";
44 System
.out
.println(title
);
45 System
.out
.println(author
);
46 System
.out
.println("");
49 for (Chapter chap
: getStory(null)) {
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()));
61 public void read(int chapter
) throws IOException
{
62 MetaData meta
= getMeta();
65 throw new IOException("No story to read");
69 if (chapter
> getStory(null).getChapters().size()) {
70 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
72 Chapter chap
= getStory(null).getChapters().get(chapter
- 1);
73 System
.out
.println("Chapter " + chap
.getNumber() + ": "
76 for (Paragraph para
: chap
) {
77 System
.out
.println(para
.getContent());
78 System
.out
.println("");
84 public void browse(String source
) {
85 List
<MetaData
> stories
;
86 stories
= getLibrary().getListBySource(source
);
88 for (MetaData story
: stories
) {
90 if (story
.getAuthor() != null && !story
.getAuthor().isEmpty()) {
91 author
= " (" + story
.getAuthor() + ")";
94 System
.out
.println(story
.getLuid() + ": " + story
.getTitle()