X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FText.java;h=2dd052470278886f30b715f541ca571d7967ae50;hp=f1ee71c1195d6337461dc35e6d9fdbfdde7a3ef2;hb=333f0e7b5e333e8f6222881ce35398f403fc4121;hpb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d diff --git a/src/be/nikiroo/fanfix/supported/Text.java b/src/be/nikiroo/fanfix/supported/Text.java index f1ee71c..2dd0524 100644 --- a/src/be/nikiroo/fanfix/supported/Text.java +++ b/src/be/nikiroo/fanfix/supported/Text.java @@ -1,5 +1,6 @@ package be.nikiroo.fanfix.supported; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -12,6 +13,7 @@ import java.util.Scanner; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; +import be.nikiroo.fanfix.data.MetaData; /** * Support class for local stories encoded in textual format, with a few rules: @@ -42,13 +44,28 @@ class Text extends BasicSupport { } @Override - protected String getPublisher(URL source, InputStream in) - throws IOException { - return ""; + protected MetaData getMeta(URL source, InputStream in) throws IOException { + MetaData meta = new MetaData(); + + meta.setTitle(getTitle(reset(in))); + meta.setAuthor(getAuthor(reset(in))); + meta.setDate(getDate(reset(in))); + meta.setTags(new ArrayList()); + meta.setSource(getSourceName()); + meta.setUrl(source.toString()); + meta.setPublisher(""); + meta.setUuid(source.toString()); + meta.setLuid(""); + meta.setLang(getLang(source, reset(in))); // default is EN + meta.setSubject(getSubject(source)); + meta.setType(getType().toString()); + meta.setImageDocument(false); + meta.setCover(getCover(source)); + + return meta; } - @Override - protected String getSubject(URL source, InputStream in) throws IOException { + private String getSubject(URL source) throws IOException { try { File file = new File(source.toURI()); return file.getParentFile().getName(); @@ -59,8 +76,7 @@ class Text extends BasicSupport { } - @Override - protected String getLang(URL source, InputStream in) throws IOException { + private String getLang(URL source, InputStream in) throws IOException { @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); scan.useDelimiter("\\n"); @@ -73,7 +89,7 @@ class Text extends BasicSupport { String lang = detectChapter(chapter0); if (lang == null) { - lang = super.getLang(source, in); + lang = "EN"; } else { lang = lang.toUpperCase(); } @@ -81,16 +97,14 @@ class Text extends BasicSupport { return lang; } - @Override - protected String getTitle(URL source, InputStream in) throws IOException { + private String getTitle(InputStream in) throws IOException { @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); scan.useDelimiter("\\n"); return scan.next(); } - @Override - protected String getAuthor(URL source, InputStream in) throws IOException { + private String getAuthor(InputStream in) throws IOException { @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); scan.useDelimiter("\\n"); @@ -103,11 +117,10 @@ class Text extends BasicSupport { author = authorDate.substring(0, pos); } - return author; + return fixAuthor(author); } - @Override - protected String getDate(URL source, InputStream in) throws IOException { + private String getDate(InputStream in) throws IOException { @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); scan.useDelimiter("\\n"); @@ -128,12 +141,11 @@ class Text extends BasicSupport { } @Override - protected String getDesc(URL source, InputStream in) { + protected String getDesc(URL source, InputStream in) throws IOException { return getChapterContent(source, in, 0); } - @Override - protected URL getCover(URL source, InputStream in) { + private BufferedImage getCover(URL source) throws IOException { String path; try { path = new File(source.toURI()).getPath(); @@ -148,11 +160,12 @@ class Text extends BasicSupport { } } - return getImage(source, path); + return getImage(this, source, path); } @Override - protected List> getChapters(URL source, InputStream in) { + protected List> getChapters(URL source, InputStream in) + throws IOException { List> chaps = new ArrayList>(); @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); @@ -195,29 +208,23 @@ class Text extends BasicSupport { } @Override - protected String getChapterContent(URL source, InputStream in, int number) { + protected String getChapterContent(URL source, InputStream in, int number) + throws IOException { StringBuilder builder = new StringBuilder(); @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); scan.useDelimiter("\\n"); boolean inChap = false; - boolean prevLineEmpty = false; while (scan.hasNext()) { String line = scan.next(); - if (prevLineEmpty) { - if (detectChapter(line, number) != null) { - inChap = true; - } else if (inChap) { - if (prevLineEmpty && detectChapter(line) != null) { - break; - } - - builder.append(line); - builder.append("\n"); - } + if (detectChapter(line, number) != null) { + inChap = true; + } else if (inChap && detectChapter(line) != null) { + break; + } else if (inChap) { + builder.append(line); + builder.append("\n"); } - - prevLineEmpty = line.trim().isEmpty(); } return builder.toString();