import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.StringUtils;
+import be.nikiroo.utils.ui.Progress;
/**
* This class is the base class used by the other support classes. It can be
*
* @param url
* the story resource
+ * @param pg
+ * the optional progress reporter
*
* @return the {@link Story}
*
* @throws IOException
* in case of I/O error
*/
- public Story process(URL url) throws IOException {
+ public Story process(URL url, Progress pg) throws IOException {
+ if (pg == null) {
+ pg = new Progress();
+ } else {
+ pg.setMinMax(0, 100);
+ }
+
setCurrentReferer(url);
+ pg.setProgress(1);
try {
Story story = processMeta(url, false, true);
+ pg.setProgress(10);
if (story == null) {
+ pg.setProgress(100);
return null;
}
story.setChapters(new ArrayList<Chapter>());
List<Entry<String, URL>> chapters = getChapters(url, getInput());
+ pg.setProgress(20);
+
int i = 1;
if (chapters != null) {
+ Progress pgChaps = new Progress(0, chapters.size());
+ pg.addProgress(pgChaps, 80);
+
for (Entry<String, URL> chap : chapters) {
setCurrentReferer(chap.getValue());
InputStream chapIn = Instance.getCache().open(
chapIn.close();
}
+ pgChaps.setProgress(i);
i++;
}
+ } else {
+ pg.setProgress(100);
}
return story;
*/
protected Chapter makeChapter(URL source, int number, String name,
String content) throws IOException {
-
// Chapter name: process it correctly, then remove the possible
// redundant "Chapter x: " in front of it
String chapterName = processPara(name).getContent().trim();
boolean singleQ = line.startsWith("" + openQuote);
boolean doubleQ = line.startsWith("" + openDoubleQuote);
+ // Do not try when more than one quote at a time
+ // (some stories are not easily readable if we do)
+ if (singleQ
+ && line.indexOf(closeQuote, 1) < line
+ .lastIndexOf(closeQuote)) {
+ newParas.add(para);
+ return newParas;
+ }
+ if (doubleQ
+ && line.indexOf(closeDoubleQuote, 1) < line
+ .lastIndexOf(closeDoubleQuote)) {
+ newParas.add(para);
+ return newParas;
+ }
+ //
+
if (!singleQ && !doubleQ) {
line = openDoubleQuote + line + closeDoubleQuote;
newParas.add(new Paragraph(ParagraphType.QUOTE, line));