X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fcli%2FCliReader.java;h=33578be668818e9974d26db122e29cbe1904cafe;hb=b31a0db030e164bc1d9a8620e71b595dad31adb6;hp=6d9841830982533247e20dfcc8c5f2b9461a61af;hpb=e39e560faae7c7bf3cf6fb098be5c4b209ac29e3;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/cli/CliReader.java b/src/be/nikiroo/fanfix/reader/cli/CliReader.java index 6d98418..33578be 100644 --- a/src/be/nikiroo/fanfix/reader/cli/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/cli/CliReader.java @@ -1,7 +1,6 @@ package be.nikiroo.fanfix.reader.cli; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import be.nikiroo.fanfix.Instance; @@ -102,40 +101,56 @@ class CliReader extends BasicReader { } @Override - public void search(SupportType searchOn, String keywords, int page, int item) - throws IOException { - + public void search(boolean sync) throws IOException { + for (SupportType type : SupportType.values()) { + if (BasicSearchable.getSearchable(type) != null) { + System.out.println(type); + } + } } @Override - public void searchTag(SupportType searchOn, int page, int item, - Integer... tags) throws IOException { + public void search(SupportType searchOn, String keywords, int page, + int item, boolean sync) throws IOException { BasicSearchable search = BasicSearchable.getSearchable(searchOn); - List stags = search.getTags(); - String fqnTag = ""; - - SearchableTag stag = null; - 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(); + if (page == 0) { + System.out.println(search.searchPages(keywords)); + } else { + List metas = search.search(keywords, page); + + if (item == 0) { + System.out.println("Page " + page + " of stories for: " + + keywords); + displayStories(metas); } else { - stags = new ArrayList(); - break; + // ! 1-based index ! + if (item <= 0 || item > metas.size()) { + throw new IOException("Index out of bounds: " + item); + } + + MetaData meta = metas.get(item - 1); + displayStory(meta); } } + } + + @Override + public void searchTag(SupportType searchOn, int page, int item, + boolean sync, Integer... tags) throws IOException { + + BasicSearchable search = BasicSearchable.getSearchable(searchOn); + SearchableTag stag = search.getTag(tags); - if (stag != null) { + if (stag == null) { + // TODO i18n + System.out.println("Known tags: "); + int i = 1; + for (SearchableTag s : search.getTags()) { + System.out.println(String.format("%d: %s", i, s.getName())); + i++; + } + } else { if (page <= 0) { if (stag.isLeaf()) { search.search(stag, 1); @@ -160,26 +175,10 @@ class CliReader extends BasicReader { if (item <= count) { if (metas != null) { MetaData meta = metas.get(item - 1); - System.out.println(page + "/" + item + ": " - + meta.getTitle()); - System.out.println(); - System.out.println(meta.getUrl()); - System.out.println(); - System.out.println("Tags: " + meta.getTags()); - System.out.println(); - for (Paragraph para : meta.getResume()) { - System.out.println(para.getContent()); - System.out.println(""); - } + displayStory(meta); } else { SearchableTag subtag = subtags.get(item - 1); - - // 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)); + displayTag(subtag); } } else { System.out.println("Invalid item: only " + count @@ -189,45 +188,65 @@ class CliReader extends BasicReader { if (metas != null) { // TODO i18n System.out.println(String.format("Content of %s: ", - fqnTag)); - int i = 1; - for (MetaData meta : metas) { - System.out.println(i + ": " + meta.getTitle()); - i++; - } + stag.getFqName())); + displayStories(metas); } 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) { - total = StringUtils.formatNumber(subtag - .getCount()); - } - - if (total.isEmpty()) { - System.out.println(String.format("%d: %s", i, - subtag.getName())); - } else { - System.out.println(String.format("%d: %s (%s)", - i, subtag.getName(), total)); - } - - i++; - } + stag.getFqName())); + displayTags(subtags); } } } - } else { - // TODO i18n - System.out.println("Known tags: "); - int i = 1; - for (SearchableTag s : stags) { - System.out.println(String.format("%d: %s", i, s.getName())); - i++; + } + } + + private void displayTag(SearchableTag subtag) { + // TODO: i18n + String stories = "stories"; + String num = StringUtils.formatNumber(subtag.getCount()); + System.out.println(String.format("%s (%s), %s %s", subtag.getName(), + subtag.getFqName(), num, stories)); + } + + private void displayStory(MetaData meta) { + System.out.println(meta.getTitle()); + System.out.println(); + System.out.println(meta.getUrl()); + System.out.println(); + System.out.println("Tags: " + meta.getTags()); + System.out.println(); + for (Paragraph para : meta.getResume()) { + System.out.println(para.getContent()); + System.out.println(""); + } + } + + private void displayTags(List subtags) { + int i = 1; + for (SearchableTag subtag : subtags) { + String total = ""; + if (subtag.getCount() > 0) { + total = StringUtils.formatNumber(subtag.getCount()); } + + if (total.isEmpty()) { + System.out + .println(String.format("%d: %s", i, subtag.getName())); + } else { + System.out.println(String.format("%d: %s (%s)", i, + subtag.getName(), total)); + } + + i++; + } + } + + private void displayStories(List metas) { + int i = 1; + for (MetaData meta : metas) { + System.out.println(i + ": " + meta.getTitle()); + i++; } } }