import be.nikiroo.fanfix.searchable.BasicSearchable;
import be.nikiroo.fanfix.searchable.SearchableTag;
import be.nikiroo.fanfix.supported.SupportType;
+import be.nikiroo.utils.StringUtils;
/**
* Command line {@link Story} reader.
+ author);
}
}
-
+
@Override
- public void search(SupportType searchOn, String keywords, int page, int item) throws IOException {
-
+ public void search(SupportType searchOn, String keywords, int page, int item)
+ throws IOException {
+
}
-
+
@Override
- public void searchTag(SupportType searchOn, int page, int item, String... tags) throws IOException {
+ public void searchTag(SupportType searchOn, int page, int item,
+ Integer... tags) throws IOException {
BasicSearchable search = BasicSearchable.getSearchable(searchOn);
List<SearchableTag> stags = search.getTags();
-
-
+ String fqnTag = "";
+
SearchableTag stag = null;
- for (String tag : tags) {
- stag = null;
- for (int i = 0 ; i < stags.size() ; i++) {
- if (stags.get(i).getName().equalsIgnoreCase(tag)) {
- stag = stags.get(i);
- break;
- }
+ for (Integer tagIndex : tags) {
+ // ! 1-based index !
+ if (tagIndex == null || tagIndex <= 0 | tagIndex > stags.size()) {
+ throw new IOException("Index out of bounds: " + tagIndex);
}
-
+
+ stag = stags.get(tagIndex - 1);
if (stag != null) {
search.fillTag(stag);
stags = stag.getChildren();
+ if (!fqnTag.isEmpty()) {
+ fqnTag += " / ";
+ }
+ fqnTag += stag.getName();
} else {
stags = new ArrayList<SearchableTag>();
break;
if (stag != null) {
if (page <= 0) {
if (stag.isLeaf()) {
+ search.search(stag, 1);
System.out.println(stag.getPages());
} else {
System.out.println(stag.getCount());
List<MetaData> metas = null;
List<SearchableTag> subtags = null;
int count;
-
+
if (stag.isLeaf()) {
metas = search.search(stag, page);
count = metas.size();
subtags = stag.getChildren();
count = subtags.size();
}
-
+
if (item > 0) {
if (item <= count) {
if (metas != null) {
MetaData meta = metas.get(item - 1);
- System.out.println(item + ": " + meta.getTitle());
+ System.out.println(page + "/" + item + ": "
+ + meta.getTitle());
+ System.out.println();
System.out.println(meta.getUrl());
System.out.println();
System.out.println("Tags: " + meta.getTags());
}
} else {
SearchableTag subtag = subtags.get(item - 1);
- // TODO: display fixed info, not debug
- System.out.println(subtag);
+
+ // TODO: i18n
+ String stories = "stories";
+ String num = StringUtils.formatNumber(subtag
+ .getCount());
+ System.out.println(String.format("%s (%s), %s %s",
+ subtag.getName(), fqnTag, num, stories));
}
} else {
- System.out.println("Invalid item: only " + count + " items found");
+ System.out.println("Invalid item: only " + count
+ + " items found");
}
} else {
if (metas != null) {
- int i = 0;
+ // TODO i18n
+ System.out.println(String.format("Content of %s: ",
+ fqnTag));
+ int i = 1;
for (MetaData meta : metas) {
- System.out.println((i + 1) + ": " + meta.getTitle());
+ System.out.println(i + ": " + meta.getTitle());
i++;
}
} else {
+ // TODO i18n
+ System.out.println(String.format("Subtags of %s: ",
+ fqnTag));
+ int i = 1;
for (SearchableTag subtag : subtags) {
+ String total = "";
if (subtag.getCount() > 0) {
- System.out.println(subtag.getName() + " (" + subtag.getCount() + ")");
+ total = StringUtils.formatNumber(subtag
+ .getCount());
+ }
+
+ if (total.isEmpty()) {
+ System.out.println(String.format("%d: %s", i,
+ subtag.getName()));
} else {
- System.out.println(subtag.getName());
+ System.out.println(String.format("%d: %s (%s)",
+ i, subtag.getName(), total));
}
+
+ i++;
}
}
}
}
} else {
+ // TODO i18n
+ System.out.println("Known tags: ");
+ int i = 1;
for (SearchableTag s : stags) {
- System.out.println(s.getName());
+ System.out.println(String.format("%d: %s", i, s.getName()));
+ i++;
}
}
}