Support for no-chapter stories or stories with descriiption before Chatper
[nikiroo-utils.git] / supported / BasicSupport_Deprecated.java
index 47cb7a2c94ed2b965e865e398638d683a8967898..ad030c0ced64825def174a7bfed5d81b4f00c7d9 100644 (file)
@@ -205,8 +205,9 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                        Story story = new Story();
                        MetaData meta = getMeta(url, getInput());
                        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);
@@ -331,8 +332,22 @@ public abstract class BasicSupport_Deprecated extends BasicSupport {
                                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);
+
+                               String descChapterName = Instance.getInstance().getTrans()
+                                               .getString(StringId.DESCRIPTION);
+                               resume = new Chapter(0, descChapterName);
+                               story.getMeta().setResume(resume);
+                       }
 
+                       return story;
                } finally {
                        close();
 
@@ -372,7 +387,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 +443,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 +461,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 +525,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;
@@ -861,7 +875,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();