From: Niki Roo Date: Wed, 28 Mar 2018 06:46:41 +0000 (+0200) Subject: Fix most irregularities found by conversion tests X-Git-Tag: fanfix-1.7.0~2^2~2 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=9005532ff4a232aab5bb302979457d9da54948b1;p=fanfix.git Fix most irregularities found by conversion tests --- diff --git a/src/be/nikiroo/fanfix/output/Cbz.java b/src/be/nikiroo/fanfix/output/Cbz.java index 490ba8f..3d90082 100644 --- a/src/be/nikiroo/fanfix/output/Cbz.java +++ b/src/be/nikiroo/fanfix/output/Cbz.java @@ -73,7 +73,7 @@ class Cbz extends BasicOutput { new FileOutputStream(new File(dir, "URL")), "UTF-8")); try { if (meta != null) { - writer.write(meta.getUuid()); + writer.write(meta.getUrl()); } } finally { writer.close(); diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index c35ed86..8154a15 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -240,15 +240,6 @@ public abstract class BasicSupport { protected void login() throws IOException { } - /** - * Prepare the support if needed before processing. - * - * @throws IOException - * on I/O error - */ - protected void preprocess() throws IOException { - } - /** * Now that we have processed the {@link Story}, close the resources if any. */ @@ -265,10 +256,9 @@ public abstract class BasicSupport { * @throws IOException * in case of I/O error */ - public Story processMeta() throws IOException { + public final Story processMeta() throws IOException { Story story = null; - preprocess(); try { story = processMeta(false, null); } finally { @@ -330,6 +320,32 @@ public abstract class BasicSupport { return story; } + /** + * Actual processing step, without the calls to other methods. + *

+ * Will convert the story resource into a fully filled {@link Story} object. + * + * @param pg + * the optional progress reporter + * + * @return the {@link Story}, never NULL + * + * @throws IOException + * in case of I/O error + */ + // TODO: add final + public Story process(Progress pg) throws IOException { + setCurrentReferer(source); + login(); + sourceNode = loadDocument(source); + + try { + return doProcess(pg); + } finally { + close(); + } + } + /** * Process the given story resource into a fully filled {@link Story} * object. @@ -342,87 +358,78 @@ public abstract class BasicSupport { * @throws IOException * in case of I/O error */ - public Story process(Progress pg) throws IOException { + public Story doProcess(Progress pg) throws IOException { if (pg == null) { pg = new Progress(); } else { pg.setMinMax(0, 100); } - setCurrentReferer(source); - login(); - sourceNode = loadDocument(source); - pg.setProgress(1); - try { - Progress pgMeta = new Progress(); - pg.addProgress(pgMeta, 10); - preprocess(); - Story story = processMeta(true, pgMeta); - if (!pgMeta.isDone()) { - pgMeta.setProgress(pgMeta.getMax()); // 10% - } + Progress pgMeta = new Progress(); + pg.addProgress(pgMeta, 10); + Story story = processMeta(true, pgMeta); + if (!pgMeta.isDone()) { + pgMeta.setProgress(pgMeta.getMax()); // 10% + } - pg.setName("Retrieving " + story.getMeta().getTitle()); + pg.setName("Retrieving " + story.getMeta().getTitle()); - Progress pgGetChapters = new Progress(); - pg.addProgress(pgGetChapters, 10); - story.setChapters(new ArrayList()); - List> chapters = getChapters(pgGetChapters); - if (!pgGetChapters.isDone()) { - pgGetChapters.setProgress(pgGetChapters.getMax()); // 20% - } + Progress pgGetChapters = new Progress(); + pg.addProgress(pgGetChapters, 10); + story.setChapters(new ArrayList()); + List> chapters = getChapters(pgGetChapters); + if (!pgGetChapters.isDone()) { + pgGetChapters.setProgress(pgGetChapters.getMax()); // 20% + } + + if (chapters != null) { + Progress pgChaps = new Progress("Extracting chapters", 0, + chapters.size() * 300); + pg.addProgress(pgChaps, 80); + + long words = 0; + int i = 1; + for (Entry chap : chapters) { + pgChaps.setName("Extracting chapter " + i); + URL chapUrl = chap.getValue(); + String chapName = chap.getKey(); + if (chapUrl != null) { + setCurrentReferer(chapUrl); + } + + pgChaps.setProgress(i * 100); + Progress pgGetChapterContent = new Progress(); + Progress pgMakeChapter = new Progress(); + pgChaps.addProgress(pgGetChapterContent, 100); + pgChaps.addProgress(pgMakeChapter, 100); + + String content = getChapterContent(chapUrl, i, + pgGetChapterContent); + if (!pgGetChapterContent.isDone()) { + pgGetChapterContent.setProgress(pgGetChapterContent + .getMax()); + } - if (chapters != null) { - Progress pgChaps = new Progress("Extracting chapters", 0, - chapters.size() * 300); - pg.addProgress(pgChaps, 80); - - long words = 0; - int i = 1; - for (Entry chap : chapters) { - pgChaps.setName("Extracting chapter " + i); - URL chapUrl = chap.getValue(); - String chapName = chap.getKey(); - if (chapUrl != null) { - setCurrentReferer(chapUrl); - } - - pgChaps.setProgress(i * 100); - Progress pgGetChapterContent = new Progress(); - Progress pgMakeChapter = new Progress(); - pgChaps.addProgress(pgGetChapterContent, 100); - pgChaps.addProgress(pgMakeChapter, 100); - - String content = getChapterContent(chapUrl, i, - pgGetChapterContent); - if (!pgGetChapterContent.isDone()) { - pgGetChapterContent.setProgress(pgGetChapterContent - .getMax()); - } - - Chapter cc = BasicSupportPara.makeChapter(this, chapUrl, i, - chapName, content, isHtml(), pgMakeChapter); - if (!pgMakeChapter.isDone()) { - pgMakeChapter.setProgress(pgMakeChapter.getMax()); - } - - words += cc.getWords(); - story.getChapters().add(cc); - story.getMeta().setWords(words); - - i++; + Chapter cc = BasicSupportPara.makeChapter(this, chapUrl, i, + chapName, content, isHtml(), pgMakeChapter); + if (!pgMakeChapter.isDone()) { + pgMakeChapter.setProgress(pgMakeChapter.getMax()); } - pgChaps.setName("Extracting chapters"); - } else { - pg.setProgress(80); + words += cc.getWords(); + story.getChapters().add(cc); + story.getMeta().setWords(words); + + i++; } - return story; - } finally { - close(); + pgChaps.setName("Extracting chapters"); + } else { + pg.setProgress(80); } + + return story; } /** diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java index 591ba58..e22724a 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java @@ -75,7 +75,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { throw new RuntimeException("should not be used by legacy code"); } - @Override public Story process(Progress pg) throws IOException { return process(getSource(), pg); } diff --git a/src/be/nikiroo/fanfix/supported/Cbz.java b/src/be/nikiroo/fanfix/supported/Cbz.java index ca0f48d..9d71046 100644 --- a/src/be/nikiroo/fanfix/supported/Cbz.java +++ b/src/be/nikiroo/fanfix/supported/Cbz.java @@ -58,7 +58,7 @@ class Cbz extends Epub { } @Override - public Story process(Progress pg) throws IOException { + public Story doProcess(Progress pg) throws IOException { if (pg == null) { pg = new Progress(); } else { diff --git a/src/be/nikiroo/fanfix/test/ConversionTest.java b/src/be/nikiroo/fanfix/test/ConversionTest.java index 51b6deb..9d9fac3 100644 --- a/src/be/nikiroo/fanfix/test/ConversionTest.java +++ b/src/be/nikiroo/fanfix/test/ConversionTest.java @@ -216,6 +216,17 @@ class ConversionTest extends TestLauncher { .length()); } + if (expectedLines.size() != resultLines.size()) { + System.out.println(); + System.out.println("expected: ["); + for (String line : expectedLines) + System.out.println(line); + System.out.println("]"); + System.out.println("actual: ["); + for (String line : resultLines) + System.out.println(line); + System.out.println("]"); + } testCase.assertEquals(errMess + ": " + name + ": the number of lines is not the same", expectedLines.size(), resultLines.size()); diff --git a/test/expected/cbz.cbz b/test/expected/cbz.cbz index 569c395..28cc25b 100644 Binary files a/test/expected/cbz.cbz and b/test/expected/cbz.cbz differ diff --git a/test/expected/epub.epub b/test/expected/epub.epub index 83d5236..776d05d 100644 Binary files a/test/expected/epub.epub and b/test/expected/epub.epub differ diff --git a/test/expected/html/html.info b/test/expected/html/html.info index 901736e..506e477 100644 --- a/test/expected/html/html.info +++ b/test/expected/html/html.info @@ -5,7 +5,7 @@ SUBJECT="test" SOURCE="text" URL="file:/media/xubuntu/sd32/workspace/fanfix/test/test.story" TAGS="" -UUID="file:/media/xubuntu/sd32/workspace/fanfix/test/test.story" +UUID="/media/xubuntu/sd32/workspace/fanfix/test/test.story" LUID="" LANG="en" IMAGES_DOCUMENT="false" @@ -14,5 +14,5 @@ COVER="" EPUBCREATOR="Fanfix (by Niki)" PUBLISHER="" WORDCOUNT="57" -CREATION_DATE="2018-03-24 09:27:09" +CREATION_DATE="2018-03-28 08:40:18" FAKE_COVER="false" diff --git a/test/expected/info_text.info b/test/expected/info_text.info index 5836ef9..cc522dd 100644 --- a/test/expected/info_text.info +++ b/test/expected/info_text.info @@ -5,7 +5,7 @@ SUBJECT="test" SOURCE="text" URL="file:/media/xubuntu/sd32/workspace/fanfix/test/test.story" TAGS="" -UUID="file:/media/xubuntu/sd32/workspace/fanfix/test/test.story" +UUID="/media/xubuntu/sd32/workspace/fanfix/test/test.story" LUID="" LANG="en" IMAGES_DOCUMENT="false" @@ -14,5 +14,5 @@ COVER="" EPUBCREATOR="Fanfix (by Niki)" PUBLISHER="" WORDCOUNT="57" -CREATION_DATE="2018-03-24 09:27:09" +CREATION_DATE="2018-03-28 08:39:39" FAKE_COVER="false"