X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupport.java;h=ff9ecaf9be3cc80666d964ee48da375d1307bae6;hp=900bcf9d5c2f59cb34b6879416b0e52565db769b;hb=ee8686f095023b8cde2fc33488a58c291acfc50a;hpb=55d4513cabcb14396c5500613e94dee93415c7d9 diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index 900bcf9..ff9ecaf 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Scanner; import java.util.Map.Entry; +import org.json.JSONException; import org.json.JSONObject; import org.jsoup.helper.DataUtil; import org.jsoup.nodes.Document; @@ -271,9 +272,18 @@ public abstract class BasicSupport { pg.setProgress(30); Story story = new Story(); + MetaData meta = getMeta(); - if (meta.getCreationDate() == null || meta.getCreationDate().isEmpty()) { - meta.setCreationDate(StringUtils.fromTime(new Date().getTime())); + meta.setType(getType().toString()); + meta.setSource(getType().getSourceName()); + if (meta.getPublisher() == null) { + meta.setPublisher(getType().getSourceName()); + } + + if (meta.getCreationDate() == null + || meta.getCreationDate().trim().isEmpty()) { + meta.setCreationDate(bsHelper + .formatDate(StringUtils.fromTime(new Date().getTime()))); } story.setMeta(meta); pg.put("meta", meta); @@ -345,6 +355,8 @@ public abstract class BasicSupport { scan.useDelimiter("\0"); try { return new JSONObject(scan.next()); + } catch (JSONException e) { + throw new IOException(e); } finally { scan.close(); } @@ -372,7 +384,25 @@ public abstract class BasicSupport { sourceNode = loadDocument(source); try { - return doProcess(pg); + Story story = doProcess(pg); + + // Check for "no chapters" stories + if (story.getChapters().isEmpty() + && story.getMeta().getResume() != null + && !story.getMeta().getResume().getParagraphs().isEmpty()) { + Chapter resume = story.getMeta().getResume(); + resume.setName(""); + resume.setNumber(1); + story.getChapters().add(resume); + story.getMeta().setWords(resume.getWords()); + + String descChapterName = Instance.getInstance().getTrans() + .getString(StringId.DESCRIPTION); + resume = new Chapter(0, descChapterName); + story.getMeta().setResume(resume); + } + + return story; } finally { close(); } @@ -412,7 +442,7 @@ public abstract class BasicSupport { story.setChapters(new ArrayList()); List> chapters = getChapters(pgGetChapters); pgGetChapters.done(); // 20% - + if (chapters != null) { Progress pgChaps = new Progress("Extracting chapters", 0, chapters.size() * 300); @@ -443,10 +473,11 @@ public abstract class BasicSupport { words += cc.getWords(); story.getChapters().add(cc); - story.getMeta().setWords(words); i++; } + + story.getMeta().setWords(words); pgChaps.setName("Extracting chapters"); pgChaps.done(); @@ -469,7 +500,8 @@ public abstract class BasicSupport { * the chapter name * @param content * the content of the chapter - * @return the {@link Chapter} + * + * @return the {@link Chapter}, never NULL * * @throws IOException * in case of I/O error