Fix some bad line breaks on HTML supports
authorNiki Roo <niki@nikiroo.be>
Sun, 5 Mar 2017 19:24:57 +0000 (20:24 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 5 Mar 2017 19:24:57 +0000 (20:24 +0100)
src/be/nikiroo/fanfix/output/BasicOutput.java
src/be/nikiroo/fanfix/reader/LocalReaderFrame.java
src/be/nikiroo/fanfix/supported/BasicSupport.java

index 9bf096cca1ef8f5b7e5594694dc88da558f2ec11..1ac6101d5852b57b0759b30294b4b87b1db4081f 100644 (file)
@@ -175,15 +175,19 @@ public abstract class BasicOutput {
                        throws IOException {
                storyPg = pg;
 
-               target = new File(target).getAbsolutePath();
-               File targetDir = new File(target).getParentFile();
-               String targetName = new File(target).getName();
-
-               String ext = getDefaultExtension(false);
-               if (ext != null && !ext.isEmpty()) {
-                       if (targetName.toLowerCase().endsWith(ext)) {
-                               targetName = targetName.substring(0,
-                                               targetName.length() - ext.length());
+               File targetDir = null;
+               String targetName = null;
+               if (target != null) {
+                       target = new File(target).getAbsolutePath();
+                       targetDir = new File(target).getParentFile();
+                       targetName = new File(target).getName();
+
+                       String ext = getDefaultExtension(false);
+                       if (ext != null && !ext.isEmpty()) {
+                               if (targetName.toLowerCase().endsWith(ext)) {
+                                       targetName = targetName.substring(0, targetName.length()
+                                                       - ext.length());
+                               }
                        }
                }
 
index 1dc63e784d07fd1c74a4c59f0ae36817eac70e02..a7935138d6ff2157cf11a5e356d8eb366862d112 100644 (file)
@@ -562,7 +562,7 @@ class LocalReaderFrame extends JFrame {
         */
        private void outOfUi(Progress progress, final Runnable run) {
                final Progress pg = new Progress();
-               final Progress reload = new Progress("Reload local caches");
+               final Progress reload = new Progress("Reload books");
                if (progress == null) {
                        progress = new Progress();
                }
index e3b6fab345faa1886e491f6d22742624d6415c19..18113188b8ac358b19af20ff62a845a91d7be9b1 100644 (file)
@@ -597,57 +597,71 @@ public abstract class BasicSupport {
                if (isHtml()) {
                        // Special <HR> processing:
                        content = content.replaceAll("(<hr [^>]*>)|(<hr/>)|(<hr>)",
-                                       "\n* * *\n");
+                                       "<br/>* * *<br/>");
                }
 
                List<Paragraph> paras = new ArrayList<Paragraph>();
-               InputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
-               try {
-                       BufferedReader buff = new BufferedReader(new InputStreamReader(in,
-                                       "UTF-8"));
-
-                       for (String encodedLine = buff.readLine(); encodedLine != null; encodedLine = buff
-                                       .readLine()) {
-                               String lines[];
-                               if (isHtml()) {
-                                       lines = encodedLine.split("(<p>|</p>|<br>|<br/>|\\n)");
-                               } else {
-                                       lines = new String[] { encodedLine };
-                               }
-
-                               for (String aline : lines) {
-                                       String line = aline.trim();
 
-                                       URL image = null;
-                                       if (line.startsWith("[") && line.endsWith("]")) {
-                                               image = getImageUrl(this, source,
-                                                               line.substring(1, line.length() - 1).trim());
+               if (content != null && !content.trim().isEmpty()) {
+                       if (isHtml()) {
+                               for (String line : content.split("(<p>|</p>|<br>|<br/>)")) {
+                                       paras.add(makeParagraph(source, line.trim()));
+                               }
+                       } else {
+                               BufferedReader buff = null;
+                               try {
+                                       buff = new BufferedReader(
+                                                       new InputStreamReader(new ByteArrayInputStream(
+                                                                       content.getBytes("UTF-8")), "UTF-8"));
+                                       for (String line = buff.readLine(); line != null; line = buff
+                                                       .readLine()) {
+                                               paras.add(makeParagraph(source, line.trim()));
                                        }
-
-                                       if (image != null) {
-                                               paras.add(new Paragraph(image));
-                                       } else {
-                                               paras.add(processPara(line));
+                               } finally {
+                                       if (buff != null) {
+                                               buff.close();
                                        }
                                }
                        }
-               } finally {
-                       in.close();
-               }
 
-               // Check quotes for "bad" format
-               List<Paragraph> newParas = new ArrayList<Paragraph>();
-               for (Paragraph para : paras) {
-                       newParas.addAll(requotify(para));
-               }
-               paras = newParas;
+                       // Check quotes for "bad" format
+                       List<Paragraph> newParas = new ArrayList<Paragraph>();
+                       for (Paragraph para : paras) {
+                               newParas.addAll(requotify(para));
+                       }
+                       paras = newParas;
 
-               // Remove double blanks/brks
-               fixBlanksBreaks(paras);
+                       // Remove double blanks/brks
+                       fixBlanksBreaks(paras);
+               }
 
                return paras;
        }
 
+       /**
+        * Convert the given line into a single {@link Paragraph}.
+        * 
+        * @param source
+        *            the source URL of the story
+        * @param line
+        *            the textual content of the paragraph
+        * 
+        * @return the {@link Paragraph}
+        */
+       private Paragraph makeParagraph(URL source, String line) {
+               URL image = null;
+               if (line.startsWith("[") && line.endsWith("]")) {
+                       image = getImageUrl(this, source,
+                                       line.substring(1, line.length() - 1).trim());
+               }
+
+               if (image != null) {
+                       return new Paragraph(image);
+               } else {
+                       return processPara(line);
+               }
+       }
+
        /**
         * Fix the {@link ParagraphType#BLANK}s and {@link ParagraphType#BREAK}s of
         * those {@link Paragraph}s.