Merge branch 'master' into subtree
[nikiroo-utils.git] / supported / BasicSupport_Deprecated.java
index 4a7b65b93d66c1899853888a759842e49e92ff9f..9aac6d5c61b713a4641fc251796b981e48d3a2ec 100644 (file)
@@ -203,12 +203,19 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        pg.setProgress(30);
 
                        Story story = new Story();
+                       
                        MetaData meta = getMeta(url, getInput());
+                       meta.setType(getType().toString());
+                       meta.setSource(getType().getSourceName());
+                       meta.setPublisher(getType().getSourceName());
+                       
                        if (meta.getCreationDate() == null
-                                       || meta.getCreationDate().isEmpty()) {
-                               meta.setCreationDate(StringUtils.fromTime(new Date().getTime()));
+                                       || meta.getCreationDate().trim().isEmpty()) {
+                               meta.setCreationDate(bsHelper.formatDate(
+                                               StringUtils.fromTime(new Date().getTime())));
                        }
                        story.setMeta(meta);
+                       pg.put("meta", meta);
 
                        pg.setProgress(50);
 
@@ -263,12 +270,11 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        Progress pgMeta = new Progress();
                        pg.addProgress(pgMeta, 10);
                        Story story = processMeta(url, false, true, pgMeta);
+                       pg.put("meta", story.getMeta());
                        if (!pgMeta.isDone()) {
                                pgMeta.setProgress(pgMeta.getMax()); // 10%
                        }
 
-                       pg.setName("Retrieving " + story.getMeta().getTitle());
-
                        setCurrentReferer(url);
 
                        Progress pgGetChapters = new Progress();
@@ -316,7 +322,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
 
                                                words += cc.getWords();
                                                story.getChapters().add(cc);
-                                               story.getMeta().setWords(words);
                                        } finally {
                                                if (chapIn != null) {
                                                        chapIn.close();
@@ -325,14 +330,31 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
 
                                        i++;
                                }
+                               
+                               story.getMeta().setWords(words);
 
                                pgChaps.setName("Extracting chapters");
                        } else {
                                pg.setProgress(80);
                        }
 
-                       return story;
+                       // 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();
 
@@ -372,7 +394,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
         * @param pg
         *            the optional progress reporter
         * 
-        * @return the {@link Chapter}
+        * @return the {@link Chapter}, never NULL
         * 
         * @throws IOException
         *             in case of I/O error
@@ -428,7 +450,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
         * @param pg
         *            the optional progress reporter
         * 
-        * @return the {@link Paragraph}s
+        * @return the {@link Paragraph}s (can be empty, but never NULL)
         * 
         * @throws IOException
         *             in case of I/O error
@@ -446,7 +468,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                }
 
                List<Paragraph> paras = new ArrayList<Paragraph>();
-
                if (content != null && !content.trim().isEmpty()) {
                        if (isHtml()) {
                                String[] tab = content.split("(<p>|</p>|<br>|<br/>)");
@@ -511,7 +532,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
         * @param line
         *            the textual content of the paragraph
         * 
-        * @return the {@link Paragraph}
+        * @return the {@link Paragraph}, never NULL
         */
        private Paragraph makeParagraph(URL source, String line) {
                Image image = null;
@@ -635,7 +656,13 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        InputStream in = null;
                        try {
                                in = Instance.getInstance().getCache().open(url, getSupport(url), true);
-                               return new Image(in);
+                               Image img = new Image(in);
+                               if (img.getSize() == 0) {
+                                       img.close();
+                                       throw new IOException(
+                                                       "Empty image not accepted");
+                               }
+                               return img;
                        } catch (IOException e) {
                        } finally {
                                if (in != null) {
@@ -861,7 +888,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
         * @param line
         *            the raw line
         * 
-        * @return the processed {@link Paragraph}
+        * @return the processed {@link Paragraph}, never NULL
         */
        protected Paragraph processPara(String line) {
                line = ifUnhtml(line).trim();