private InputStream in;
// quote chars
- private char openQuote = Instance.getTrans().getCharacter(
- StringId.OPEN_SINGLE_QUOTE);
- private char closeQuote = Instance.getTrans().getCharacter(
- StringId.CLOSE_SINGLE_QUOTE);
- private char openDoubleQuote = Instance.getTrans().getCharacter(
- StringId.OPEN_DOUBLE_QUOTE);
- private char closeDoubleQuote = Instance.getTrans().getCharacter(
- StringId.CLOSE_DOUBLE_QUOTE);
+ private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
+ private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
+ private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+ private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
// New methods not used in Deprecated mode
@Override
Story story = new Story();
MetaData meta = getMeta(url, getInput());
if (meta.getCreationDate() == null
- || meta.getCreationDate().isEmpty()) {
- meta.setCreationDate(StringUtils.fromTime(new Date().getTime()));
+ || meta.getCreationDate().trim().isEmpty()) {
+ meta.setCreationDate(bsHelper.formatDate(
+ StringUtils.fromTime(new Date().getTime())));
}
story.setMeta(meta);
+ pg.put("meta", meta);
pg.setProgress(50);
pg.setProgress(60);
if (getDesc) {
- String descChapterName = Instance.getTrans().getString(
- StringId.DESCRIPTION);
- story.getMeta().setResume(
- makeChapter(url, 0, descChapterName,
- getDesc(url, getInput()), null));
+ String descChapterName = Instance.getInstance().getTrans().getString(StringId.DESCRIPTION);
+ story.getMeta().setResume(makeChapter(url, 0, descChapterName, getDesc(url, getInput()), null));
}
pg.setProgress(100);
Progress pgMeta = new Progress();
pg.addProgress(pgMeta, 10);
Story story = processMeta(url, false, true, pgMeta);
+ pg.put("meta", story.getMeta());
if (!pgMeta.isDone()) {
pgMeta.setProgress(pgMeta.getMax()); // 10%
}
- pg.setName("Retrieving " + story.getMeta().getTitle());
-
setCurrentReferer(url);
Progress pgGetChapters = new Progress();
InputStream chapIn = null;
if (chap.getValue() != null) {
setCurrentReferer(chap.getValue());
- chapIn = Instance.getCache().open(chap.getValue(),
- this, false);
+ chapIn = Instance.getInstance().getCache().open(chap.getValue(), this, false);
}
pgChaps.setProgress(i * 100);
try {
words += cc.getWords();
story.getChapters().add(cc);
- story.getMeta().setWords(words);
} finally {
if (chapIn != null) {
chapIn.close();
i++;
}
+
+ story.getMeta().setWords(words);
pgChaps.setName("Extracting chapters");
} else {
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);
+ story.getMeta().setWords(resume.getWords());
+
+ 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
// redundant "Chapter x: " in front of it, or "-" (as in
// "Chapter 5: - Fun!" after the ": " was automatically added)
String chapterName = processPara(name).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();
* @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;
* @return the cover if any, or NULL
*/
static Image getDefaultCover(String subject) {
- if (subject != null && !subject.isEmpty()
- && Instance.getCoverDir() != null) {
+ if (subject != null && !subject.isEmpty() && Instance.getInstance().getCoverDir() != null) {
try {
- File fileCover = new File(Instance.getCoverDir(), subject);
+ File fileCover = new File(Instance.getInstance().getCoverDir(), subject);
return getImage(null, fileCover.toURI().toURL(), subject);
} catch (MalformedURLException e) {
}
}
InputStream in = null;
try {
- in = Instance.getCache().open(url, getSupport(url), true);
- return new Image(in);
+ in = Instance.getInstance().getCache().open(url, getSupport(url), true);
+ Image img = new Image(in);
+ if (img.getSize() == 0) {
+ img.close();
+ throw new IOException(
+ "Empty image not accepted");
+ }
+ return img;
} catch (IOException e) {
} finally {
if (in != null) {
// try for files
if (source != null) {
try {
-
String relPath = null;
String absPath = null;
try {
// try for URLs
try {
for (String ext : getImageExt(true)) {
- if (Instance.getCache()
- .check(new URL(line + ext), true)) {
+ if (Instance.getInstance().getCache().check(new URL(line + ext), true)) {
url = new URL(line + ext);
break;
}
for (String ext : getImageExt(true)) {
try {
url = new URL(line + ext);
- Instance.getCache().refresh(url, support, true);
+ Instance.getInstance().getCache().refresh(url, support, true);
break;
} catch (IOException e) {
// no image with this ext
// refresh the cached file
if (url != null) {
try {
- Instance.getCache().refresh(url, support, true);
+ Instance.getInstance().getCache().refresh(url, support, true);
} catch (IOException e) {
// woops, broken image
url = null;
* in case of I/O error
*/
protected InputStream openInput(URL source) throws IOException {
- return Instance.getCache().open(source, this, false);
+ return Instance.getInstance().getCache().open(source, this, false);
}
/**
* @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();