/**
* 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.
* @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
* @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();
*
* @return the correctly (or so we hope) quotified paragraphs
*/
- private static List<Paragraph> requotify(Paragraph para, boolean html) {
+ protected List<Paragraph> requotify(Paragraph para, boolean html) {
List<Paragraph> newParas = new ArrayList<Paragraph>();
if (para.getType() == ParagraphType.QUOTE
* @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();
}
* 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
* @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<Paragraph> makeParagraphs(BasicSupport support,
+ protected List<Paragraph> makeParagraphs(BasicSupport support,
URL source, String content, boolean html, Progress pg)
throws IOException {
if (pg == null) {
paras.add(makeParagraph(support, source, line.trim(), html));
pg.setProgress(i++);
}
- pg.setName(null);
} else {
List<String> lines = new ArrayList<String>();
BufferedReader buff = null;
paras.add(makeParagraph(support, source, line, html));
pg.setProgress(i++);
}
- pg.setName(null);
}
+ pg.done();
+ pg.setName(null);
+
// Check quotes for "bad" format
List<Paragraph> newParas = new ArrayList<Paragraph>();
for (Paragraph para : paras) {
- newParas.addAll(BasicSupportPara.requotify(para, html));
+ newParas.addAll(requotify(para, html));
}
paras = newParas;
* 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());
}
return new Paragraph(image);
}
- return BasicSupportPara.processPara(line, html);
+ return processPara(line, html);
}
/**
* @param paras
* the list of {@link Paragraph}s to fix
*/
- private static void fixBlanksBreaks(List<Paragraph> paras) {
+ protected void fixBlanksBreaks(List<Paragraph> paras) {
boolean space = false;
boolean brk = true;
for (int i = 0; i < paras.size(); i++) {