X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupportPara.java;h=e550d82ee0257ffb84bd8a9aee0eddf044d3c55e;hb=34f8780d16faf3a5466c45261bd84f1b31516790;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..e550d82 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupportPara.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupportPara.java @@ -20,30 +20,46 @@ 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; + + /** + * Create a new {@link BasicSupportPara}. + *

+ * Note that you need an instance of both {@link BasicSupportHelper} and + * {@link BasicSupportImages} for it to work. + * + * @param bsHelper + * the required {@link BasicSupportHelper} + * @param bsImages + * the required {@link BasicSupportImages} + */ + 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. * * @param support - * the linked {@link BasicSupport} + * the linked {@link BasicSupport} (can be NULL) * @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 @@ -55,23 +71,21 @@ class BasicSupportPara { * @param html * TRUE if the input content is in HTML mode * - * @return the {@link Chapter} + * @return the {@link Chapter}, never NULL * * @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 +131,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 @@ -199,9 +213,9 @@ class BasicSupportPara { * @param html * TRUE if the input content is in HTML mode * - * @return the processed {@link Paragraph} + * @return the processed {@link Paragraph}, never NULL */ - private static Paragraph processPara(String line, boolean html) { + protected Paragraph processPara(String line, boolean html) { if (html) { line = StringUtils.unhtml(line).trim(); } @@ -408,9 +422,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 @@ -418,12 +434,12 @@ class BasicSupportPara { * @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 */ - 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 +500,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,21 +515,23 @@ 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 * TRUE if the input content is in HTML mode * - * @return the {@link Paragraph} + * @return the {@link Paragraph}, never NULL */ - 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 +539,7 @@ class BasicSupportPara { return new Paragraph(image); } - return BasicSupportPara.processPara(line, html); + return processPara(line, html); } /** @@ -534,7 +552,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++) {