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
{
21 public void read() throws IOException
{
22 if (getStory() == null) {
23 throw new IOException("No story to read");
29 MetaData meta
= getStory().getMeta();
31 if (meta
.getTitle() != null) {
32 title
= meta
.getTitle();
35 if (meta
.getAuthor() != null) {
36 author
= "©" + meta
.getAuthor();
37 if (meta
.getDate() != null && !meta
.getDate().isEmpty()) {
38 author
= author
+ " (" + meta
.getDate() + ")";
43 System
.out
.println(title
);
44 System
.out
.println(author
);
45 System
.out
.println("");
47 for (Chapter chap
: getStory()) {
48 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
49 System
.out
.println(Instance
.getTrans().getString(
50 StringId
.CHAPTER_NAMED
, chap
.getNumber(),
53 System
.out
.println(Instance
.getTrans().getString(
54 StringId
.CHAPTER_UNNAMED
, chap
.getNumber()));
59 public void read(int chapter
) throws IOException
{
60 if (getStory() == null) {
61 throw new IOException("No story to read");
64 if (chapter
> getStory().getChapters().size()) {
65 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
67 Chapter chap
= getStory().getChapters().get(chapter
- 1);
68 System
.out
.println("Chapter " + chap
.getNumber() + ": "
71 for (Paragraph para
: chap
) {
72 System
.out
.println(para
.getContent());
73 System
.out
.println("");
78 public void browse(String source
) {
79 List
<MetaData
> stories
;
80 stories
= getLibrary().getListBySource(source
);
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()