Fix most irregularities found by conversion tests
authorNiki Roo <niki@nikiroo.be>
Wed, 28 Mar 2018 06:46:41 +0000 (08:46 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 28 Mar 2018 06:46:41 +0000 (08:46 +0200)
src/be/nikiroo/fanfix/output/Cbz.java
src/be/nikiroo/fanfix/supported/BasicSupport.java
src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java
src/be/nikiroo/fanfix/supported/Cbz.java
src/be/nikiroo/fanfix/test/ConversionTest.java
test/expected/cbz.cbz
test/expected/epub.epub
test/expected/html/html.info
test/expected/info_text.info

index 490ba8f04fe936e8f25417f7e829a5ed075045c9..3d9008299052451539d1e99db77c426d8e1bebd0 100644 (file)
@@ -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();
index c35ed86b65b564d4e905c9c635ded5804bd038e4..8154a15e600564e3bfb1da2d9211030512efc72b 100644 (file)
@@ -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.
+        * <p>
+        * 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<Chapter>());
-                       List<Entry<String, URL>> chapters = getChapters(pgGetChapters);
-                       if (!pgGetChapters.isDone()) {
-                               pgGetChapters.setProgress(pgGetChapters.getMax()); // 20%
-                       }
+               Progress pgGetChapters = new Progress();
+               pg.addProgress(pgGetChapters, 10);
+               story.setChapters(new ArrayList<Chapter>());
+               List<Entry<String, URL>> 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<String, URL> 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<String, URL> 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;
        }
 
        /**
index 591ba58d1f630727283762de72f9c27a0e4df664..e22724a20aad5634fb38523dac7d9ddc231cf25f 100644 (file)
@@ -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);
        }
index ca0f48d2df6a0fc75d93b2bbf0fb705799420877..9d71046e3e8afd69f28da7cded27ae0b61964156 100644 (file)
@@ -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 {
index 51b6deb4f817e6a2f451ead2d7b73f554a7795af..9d9fac366f9a0d8f482bc8897b2acae069b00d62 100644 (file)
@@ -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());
index 569c3950e185a009d712f6aadfa46d9948e1aacf..28cc25b18b0a9b5733d99b8b3645e648ffcf8b4e 100644 (file)
Binary files a/test/expected/cbz.cbz and b/test/expected/cbz.cbz differ
index 83d52361a278f83c4a2584966a0275c74528f095..776d05decef0244c9bf3b6a2c99110e1b51f18b6 100644 (file)
Binary files a/test/expected/epub.epub and b/test/expected/epub.epub differ
index 901736e42d0c351e40def02ed36857ed42d67c3f..506e477fd8a4a13cf144ec3d1fcf0f991f8ab35b 100644 (file)
@@ -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"
index 5836ef9006abc665d70d10c12e863baab7d8ae61..cc522dd3bbff15f0fcfc5203eb782e461d4f9d33 100644 (file)
@@ -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"