1 package be
.nikiroo
.fanfix
.reader
.cli
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
7 import be
.nikiroo
.fanfix
.Instance
;
8 import be
.nikiroo
.fanfix
.bundles
.StringId
;
9 import be
.nikiroo
.fanfix
.data
.Chapter
;
10 import be
.nikiroo
.fanfix
.data
.MetaData
;
11 import be
.nikiroo
.fanfix
.data
.Paragraph
;
12 import be
.nikiroo
.fanfix
.data
.Story
;
13 import be
.nikiroo
.fanfix
.reader
.BasicReader
;
14 import be
.nikiroo
.fanfix
.searchable
.BasicSearchable
;
15 import be
.nikiroo
.fanfix
.searchable
.SearchableTag
;
16 import be
.nikiroo
.fanfix
.supported
.SupportType
;
19 * Command line {@link Story} reader.
21 * Will output stories to the console.
25 class CliReader
extends BasicReader
{
27 public void read(boolean sync
) throws IOException
{
28 MetaData meta
= getMeta();
31 throw new IOException("No story to read");
37 if (meta
.getTitle() != null) {
38 title
= meta
.getTitle();
41 if (meta
.getAuthor() != null) {
42 author
= "©" + meta
.getAuthor();
43 if (meta
.getDate() != null && !meta
.getDate().isEmpty()) {
44 author
= author
+ " (" + meta
.getDate() + ")";
48 System
.out
.println(title
);
49 System
.out
.println(author
);
50 System
.out
.println("");
53 for (Chapter chap
: getStory(null)) {
54 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
55 System
.out
.println(Instance
.getTrans().getString(
56 StringId
.CHAPTER_NAMED
, chap
.getNumber(),
59 System
.out
.println(Instance
.getTrans().getString(
60 StringId
.CHAPTER_UNNAMED
, chap
.getNumber()));
65 public void read(int chapter
) throws IOException
{
66 MetaData meta
= getMeta();
69 throw new IOException("No story to read");
73 if (chapter
> getStory(null).getChapters().size()) {
74 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
76 Chapter chap
= getStory(null).getChapters().get(chapter
- 1);
77 System
.out
.println("Chapter " + chap
.getNumber() + ": "
80 for (Paragraph para
: chap
) {
81 System
.out
.println(para
.getContent());
82 System
.out
.println("");
88 public void browse(String source
) {
89 List
<MetaData
> stories
;
90 stories
= getLibrary().getListBySource(source
);
92 for (MetaData story
: stories
) {
94 if (story
.getAuthor() != null && !story
.getAuthor().isEmpty()) {
95 author
= " (" + story
.getAuthor() + ")";
98 System
.out
.println(story
.getLuid() + ": " + story
.getTitle()
104 public void search(SupportType searchOn
, String keywords
, int page
, int item
)
110 public void searchTag(SupportType searchOn
, int page
, int item
,
111 String
... tags
) throws IOException
{
112 BasicSearchable search
= BasicSearchable
.getSearchable(searchOn
);
113 List
<SearchableTag
> stags
= search
.getTags();
115 SearchableTag stag
= null;
116 for (String tag
: tags
) {
118 for (int i
= 0; i
< stags
.size(); i
++) {
119 if (stags
.get(i
).getName().equalsIgnoreCase(tag
)) {
126 search
.fillTag(stag
);
127 stags
= stag
.getChildren();
129 stags
= new ArrayList
<SearchableTag
>();
137 search
.search(stag
, 1);
138 System
.out
.println(stag
.getPages());
140 System
.out
.println(stag
.getCount());
143 List
<MetaData
> metas
= null;
144 List
<SearchableTag
> subtags
= null;
148 metas
= search
.search(stag
, page
);
149 count
= metas
.size();
151 subtags
= stag
.getChildren();
152 count
= subtags
.size();
158 MetaData meta
= metas
.get(item
- 1);
159 System
.out
.println(page
+ "/" + item
+ ": "
161 System
.out
.println();
162 System
.out
.println(meta
.getUrl());
163 System
.out
.println();
164 System
.out
.println("Tags: " + meta
.getTags());
165 System
.out
.println();
166 for (Paragraph para
: meta
.getResume()) {
167 System
.out
.println(para
.getContent());
168 System
.out
.println("");
171 SearchableTag subtag
= subtags
.get(item
- 1);
174 if (subtag
.getParent() != null) {
175 List
<String
> parents
= new ArrayList
<String
>();
176 for (SearchableTag parent
= subtag
.getParent(); parent
!= null; parent
= parent
178 parents
.add(parent
.getName());
180 for (String parent
: parents
) {
190 System
.out
.println(String
.format(
191 "%d/%d: %s, %d %s", page
, item
,
192 subtag
.getName(), subtag
.getCount(),
195 System
.out
.println(String
.format(
196 "%d/%d: %s (%s), %d %s", page
, item
,
197 subtag
.getName(), sp
,
198 subtag
.getCount(), "stories"));
202 System
.out
.println("Invalid item: only " + count
208 for (MetaData meta
: metas
) {
210 .println((i
+ 1) + ": " + meta
.getTitle());
215 for (SearchableTag subtag
: subtags
) {
217 if (subtag
.getCount() > 0) {
218 // TODO: use StringUtils fromNumber
219 total
= " (" + subtag
.getCount() + ")";
221 System
.out
.println(i
+ ": " + subtag
.getName()
229 for (SearchableTag s
: stags
) {
230 System
.out
.println(s
.getName());