sourceNode = loadDocument(source);
try {
- return doProcess(pg);
+ Story story = doProcess(pg);
+
+ // Check for "no chapters" stories
+ if (story.getChapters().isEmpty()
+ && story.getMeta().getResume() != null
+ && !story.getMeta().getResume().getParagraphs().isEmpty()) {
+ Chapter resume = story.getMeta().getResume();
+ resume.setName("");
+ resume.setNumber(1);
+ story.getChapters().add(resume);
+
+ String descChapterName = Instance.getInstance().getTrans()
+ .getString(StringId.DESCRIPTION);
+ resume = new Chapter(0, descChapterName);
+ story.getMeta().setResume(resume);
+ }
+
+ return story;
} finally {
close();
}
* the chapter name
* @param content
* the content of the chapter
- * @return the {@link Chapter}
+ *
+ * @return the {@link Chapter}, never NULL
*
* @throws IOException
* in case of I/O error
* @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
* @param html
* TRUE if the input content is in HTML mode
*
- * @return the processed {@link Paragraph}
+ * @return the processed {@link Paragraph}, never NULL
*/
protected Paragraph processPara(String line, boolean html) {
if (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
* @param html
* TRUE if the input content is in HTML mode
*
- * @return the {@link Paragraph}
+ * @return the {@link Paragraph}, never NULL
*/
protected Paragraph makeParagraph(BasicSupport support, URL source,
String line, boolean html) {
pg.setProgress(80);
}
- return story;
+ // Check for "no chapters" stories
+ if (story.getChapters().isEmpty()
+ && story.getMeta().getResume() != null
+ && !story.getMeta().getResume().getParagraphs().isEmpty()) {
+ Chapter resume = story.getMeta().getResume();
+ resume.setName("");
+ resume.setNumber(1);
+ story.getChapters().add(resume);
+
+ String descChapterName = Instance.getInstance().getTrans()
+ .getString(StringId.DESCRIPTION);
+ resume = new Chapter(0, descChapterName);
+ story.getMeta().setResume(resume);
+ }
+ return story;
} finally {
close();
* @param pg
* the optional progress reporter
*
- * @return the {@link Chapter}
+ * @return the {@link Chapter}, never NULL
*
* @throws IOException
* in case of I/O error
* @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
}
List<Paragraph> paras = new ArrayList<Paragraph>();
-
if (content != null && !content.trim().isEmpty()) {
if (isHtml()) {
String[] tab = content.split("(<p>|</p>|<br>|<br/>)");
* @param line
* the textual content of the paragraph
*
- * @return the {@link Paragraph}
+ * @return the {@link Paragraph}, never NULL
*/
private Paragraph makeParagraph(URL source, String line) {
Image image = null;
* @param line
* the raw line
*
- * @return the processed {@link Paragraph}
+ * @return the processed {@link Paragraph}, never NULL
*/
protected Paragraph processPara(String line) {
line = ifUnhtml(line).trim();
}
if (!imagesList.isEmpty()) {
- Chapter chap = new Chapter(story.getChapters().size() + 1, null);
+ Chapter chap = new Chapter(story.getChapters().size() + 1, "");
story.getChapters().add(chap);
for (String uuid : imagesList) {
// There is no chapters on e621, just pagination...
Story story = super.process(url, pg);
- Chapter only = new Chapter(1, null);
+ Chapter only = new Chapter(1, "");
for (Chapter chap : story) {
only.getParagraphs().addAll(chap.getParagraphs());
}
}
private String getLang() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
scan.next(); // Title
}
private String getTitle() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
return scan.next();
}
private String getAuthor() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
scan.next();
}
private String getDate() {
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
scan.next();
protected List<Entry<String, URL>> getChapters(Progress pg)
throws IOException {
List<Entry<String, URL>> chaps = new ArrayList<Entry<String, URL>>();
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
- boolean prevLineEmpty = false;
+ String line = "first is not empty";
while (scan.hasNext()) {
- String line = scan.next();
+ boolean prevLineEmpty = line.trim().isEmpty();
+ line = scan.next();
if (prevLineEmpty && detectChapter(line, chaps.size() + 1) != null) {
String chapName = Integer.toString(chaps.size() + 1);
int pos = line.indexOf(':');
chapName, //
getSourceFile().toURI().toURL()));
}
-
- prevLineEmpty = line.trim().isEmpty();
}
-
+
return chaps;
}
protected String getChapterContent(URL source, int number, Progress pg)
throws IOException {
StringBuilder builder = new StringBuilder();
- @SuppressWarnings("resource")
+ @SuppressWarnings("resource") // cannot close, or we loose getInput()!
Scanner scan = new Scanner(getInput(), "UTF-8");
scan.useDelimiter("\\n");
- boolean inChap = false;
+ scan.next(); // title
+ scan.next(); // author
+ scan.next(); // date or empty
+ Boolean inChap = null;
+ String line = "";
while (scan.hasNext()) {
- String line = scan.next();
- if (!inChap && detectChapter(line, number) != null) {
+ if (number == 0 && !line.trim().isEmpty()) {
+ // We found pre-chapter content, we are checking for
+ // Chapter 0 (fake chapter) --> keep the content
+ if (inChap == null)
+ inChap = true;
+ }
+ line = scan.next();
+ if ((inChap == null || !inChap) && detectChapter(line, number) != null) {
inChap = true;
} else if (detectChapter(line, number + 1) != null) {
break;
- } else if (inChap) {
+ } else if (inChap != null && inChap) {
builder.append(line);
builder.append("\n");
}