89eb3ac034b0ef1c9e5d338d6528a7050a200eac
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
;
17 import be
.nikiroo
.utils
.StringUtils
;
20 * Command line {@link Story} reader.
22 * Will output stories to the console.
26 class CliReader
extends BasicReader
{
28 public void read(boolean sync
) throws IOException
{
29 MetaData meta
= getMeta();
32 throw new IOException("No story to read");
38 if (meta
.getTitle() != null) {
39 title
= meta
.getTitle();
42 if (meta
.getAuthor() != null) {
43 author
= "©" + meta
.getAuthor();
44 if (meta
.getDate() != null && !meta
.getDate().isEmpty()) {
45 author
= author
+ " (" + meta
.getDate() + ")";
49 System
.out
.println(title
);
50 System
.out
.println(author
);
51 System
.out
.println("");
54 for (Chapter chap
: getStory(null)) {
55 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
56 System
.out
.println(Instance
.getTrans().getString(
57 StringId
.CHAPTER_NAMED
, chap
.getNumber(),
60 System
.out
.println(Instance
.getTrans().getString(
61 StringId
.CHAPTER_UNNAMED
, chap
.getNumber()));
66 public void read(int chapter
) throws IOException
{
67 MetaData meta
= getMeta();
70 throw new IOException("No story to read");
74 if (chapter
> getStory(null).getChapters().size()) {
75 System
.err
.println("Chapter " + chapter
+ ": no such chapter");
77 Chapter chap
= getStory(null).getChapters().get(chapter
- 1);
78 System
.out
.println("Chapter " + chap
.getNumber() + ": "
81 for (Paragraph para
: chap
) {
82 System
.out
.println(para
.getContent());
83 System
.out
.println("");
89 public void browse(String source
) {
90 List
<MetaData
> stories
;
91 stories
= getLibrary().getListBySource(source
);
93 for (MetaData story
: stories
) {
95 if (story
.getAuthor() != null && !story
.getAuthor().isEmpty()) {
96 author
= " (" + story
.getAuthor() + ")";
99 System
.out
.println(story
.getLuid() + ": " + story
.getTitle()
105 public void search(SupportType searchOn
, String keywords
, int page
, int item
)
111 public void searchTag(SupportType searchOn
, int page
, int item
,
112 String
... tags
) throws IOException
{
113 BasicSearchable search
= BasicSearchable
.getSearchable(searchOn
);
114 List
<SearchableTag
> stags
= search
.getTags();
116 SearchableTag stag
= null;
117 for (String tag
: tags
) {
119 for (int i
= 0; i
< stags
.size(); i
++) {
120 if (stags
.get(i
).getName().equalsIgnoreCase(tag
)) {
127 search
.fillTag(stag
);
128 stags
= stag
.getChildren();
130 stags
= new ArrayList
<SearchableTag
>();
138 search
.search(stag
, 1);
139 System
.out
.println(stag
.getPages());
141 System
.out
.println(stag
.getCount());
144 List
<MetaData
> metas
= null;
145 List
<SearchableTag
> subtags
= null;
149 metas
= search
.search(stag
, page
);
150 count
= metas
.size();
152 subtags
= stag
.getChildren();
153 count
= subtags
.size();
159 MetaData meta
= metas
.get(item
- 1);
160 System
.out
.println(page
+ "/" + item
+ ": "
162 System
.out
.println();
163 System
.out
.println(meta
.getUrl());
164 System
.out
.println();
165 System
.out
.println("Tags: " + meta
.getTags());
166 System
.out
.println();
167 for (Paragraph para
: meta
.getResume()) {
168 System
.out
.println(para
.getContent());
169 System
.out
.println("");
172 SearchableTag subtag
= subtags
.get(item
- 1);
175 if (subtag
.getParent() != null) {
176 List
<String
> parents
= new ArrayList
<String
>();
177 for (SearchableTag parent
= subtag
.getParent(); parent
!= null; parent
= parent
179 parents
.add(parent
.getName());
181 for (String parent
: parents
) {
191 System
.out
.println(String
.format(
192 "%d/%d: %s, %d %s", page
, item
,
193 subtag
.getName(), subtag
.getCount(),
196 System
.out
.println(String
.format(
197 "%d/%d: %s (%s), %d %s", page
, item
,
198 subtag
.getName(), sp
,
199 subtag
.getCount(), "stories"));
203 System
.out
.println("Invalid item: only " + count
209 for (MetaData meta
: metas
) {
211 .println((i
+ 1) + ": " + meta
.getTitle());
216 for (SearchableTag subtag
: subtags
) {
218 if (subtag
.getCount() > 0) {
219 total
= StringUtils
.formatNumber(subtag
223 if (total
.isEmpty()) {
224 System
.out
.println(String
.format("%d: %s", i
,
227 System
.out
.println(String
.format("%d: %s (%s)",
228 i
, subtag
.getName(), total
));
237 for (SearchableTag s
: stags
) {
238 System
.out
.println(s
.getName());