X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupportPara.java;h=58c363af59b77e1b4f4d1c323fefe2af350ad31b;hb=d66deb8d8b30cff6b54db352eef34a3508939f84;hp=d3beea53b47c39b251c5b31647397f54628ac54f;hpb=68328e172319fe97d76805d60f560376af2fcb5b;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/BasicSupportPara.java b/src/be/nikiroo/fanfix/supported/BasicSupportPara.java index d3beea5..58c363a 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupportPara.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupportPara.java @@ -20,22 +20,26 @@ import be.nikiroo.utils.StringUtils; /** * Helper class for {@link BasicSupport}, mostly dedicated to {@link Paragraph} - * and text formating for the {@link BasicSupport} class itself (not its - * children). + * and text formating for the {@link BasicSupport} class. * * @author niki */ -class BasicSupportPara { +public class BasicSupportPara { // quote chars - private static char openQuote = Instance.getTrans().getCharacter( - StringId.OPEN_SINGLE_QUOTE); - private static char closeQuote = Instance.getTrans().getCharacter( - StringId.CLOSE_SINGLE_QUOTE); - private static char openDoubleQuote = Instance.getTrans().getCharacter( - StringId.OPEN_DOUBLE_QUOTE); - private static char closeDoubleQuote = Instance.getTrans().getCharacter( - StringId.CLOSE_DOUBLE_QUOTE); - + private static char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE); + private static char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE); + private static char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE); + private static char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE); + + // used by this class: + BasicSupportHelper bsHelper; + BasicSupportImages bsImages; + + public BasicSupportPara(BasicSupportHelper bsHelper, BasicSupportImages bsImages) { + this.bsHelper = bsHelper; + this.bsImages = bsImages; + } + /** * Create a {@link Chapter} object from the given information, formatting * the content as it should be. @@ -43,7 +47,8 @@ class BasicSupportPara { * @param support * the linked {@link BasicSupport} * @param source - * the source of the story + * the source of the story (for image lookup in the same path if + * the source is a file, can be NULL) * @param number * the chapter number * @param name @@ -60,18 +65,16 @@ class BasicSupportPara { * @throws IOException * in case of I/O error */ - public static Chapter makeChapter(BasicSupport support, URL source, + public Chapter makeChapter(BasicSupport support, URL source, int number, String name, String content, boolean html, Progress pg) throws IOException { // Chapter name: process it correctly, then remove the possible // redundant "Chapter x: " in front of it, or "-" (as in // "Chapter 5: - Fun!" after the ": " was automatically added) - String chapterName = BasicSupportPara.processPara(name, false) + String chapterName = processPara(name, false) .getContent().trim(); - for (String lang : Instance.getConfig().getString(Config.CHAPTER) - .split(",")) { - String chapterWord = Instance.getConfig().getStringX( - Config.CHAPTER, lang); + for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) { + String chapterWord = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER, lang); if (chapterName.startsWith(chapterWord)) { chapterName = chapterName.substring(chapterWord.length()) .trim(); @@ -117,7 +120,7 @@ class BasicSupportPara { * * @return the correctly (or so we hope) quotified paragraphs */ - private static List requotify(Paragraph para, boolean html) { + protected List requotify(Paragraph para, boolean html) { List newParas = new ArrayList(); if (para.getType() == ParagraphType.QUOTE @@ -201,7 +204,7 @@ class BasicSupportPara { * * @return the processed {@link Paragraph} */ - private static Paragraph processPara(String line, boolean html) { + protected Paragraph processPara(String line, boolean html) { if (html) { line = StringUtils.unhtml(line).trim(); } @@ -408,9 +411,11 @@ class BasicSupportPara { * Convert the given content into {@link Paragraph}s. * * @param support - * the linked {@link BasicSupport} + * the linked {@link BasicSupport} (can be NULL), used to + * download optional image content in [] * @param source - * the source URL of the story + * the source URL of the story (for image lookup in the same path + * if the source is a file, can be NULL) * @param content * the textual content * @param html @@ -423,7 +428,7 @@ class BasicSupportPara { * @throws IOException * in case of I/O error */ - private static List makeParagraphs(BasicSupport support, + protected List makeParagraphs(BasicSupport support, URL source, String content, boolean html, Progress pg) throws IOException { if (pg == null) { @@ -484,7 +489,7 @@ class BasicSupportPara { // Check quotes for "bad" format List newParas = new ArrayList(); for (Paragraph para : paras) { - newParas.addAll(BasicSupportPara.requotify(para, html)); + newParas.addAll(requotify(para, html)); } paras = newParas; @@ -499,9 +504,11 @@ class BasicSupportPara { * Convert the given line into a single {@link Paragraph}. * * @param support - * the linked {@link BasicSupport} + * the linked {@link BasicSupport} (can be NULL), used to + * download optional image content in [] * @param source - * the source URL of the story + * the source URL of the story (for image lookup in the same path + * if the source is a file, can be NULL) * @param line * the textual content of the paragraph * @param html @@ -509,11 +516,11 @@ class BasicSupportPara { * * @return the {@link Paragraph} */ - private static Paragraph makeParagraph(BasicSupport support, URL source, + protected Paragraph makeParagraph(BasicSupport support, URL source, String line, boolean html) { Image image = null; if (line.startsWith("[") && line.endsWith("]")) { - image = BasicSupportHelper.getImage(support, source, line + image = bsHelper.getImage(support, source, line .substring(1, line.length() - 1).trim()); } @@ -521,7 +528,7 @@ class BasicSupportPara { return new Paragraph(image); } - return BasicSupportPara.processPara(line, html); + return processPara(line, html); } /** @@ -534,7 +541,7 @@ class BasicSupportPara { * @param paras * the list of {@link Paragraph}s to fix */ - private static void fixBlanksBreaks(List paras) { + protected void fixBlanksBreaks(List paras) { boolean space = false; boolean brk = true; for (int i = 0; i < paras.size(); i++) {