X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupport_Deprecated.java;h=40ff3fc027c7e52beca3426017e1a6a58972fbbe;hp=e22724a20aad5634fb38523dac7d9ddc231cf25f;hb=0a264fbe3d5a43516006052574a5f322d9d38897;hpb=4ec79417fe5bd4344ac12b39ac8c98db8f9276f6 diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java index e22724a..40ff3fc 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java @@ -40,17 +40,12 @@ import be.nikiroo.utils.StringUtils; @Deprecated public abstract class BasicSupport_Deprecated extends BasicSupport { private InputStream in; - private URL currentReferer; // with only one 'r', as in 'HTTP'... // 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 @@ -75,6 +70,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { throw new RuntimeException("should not be used by legacy code"); } + @Override public Story process(Progress pg) throws IOException { return process(getSource(), pg); } @@ -209,10 +205,12 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { 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); @@ -223,11 +221,8 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { 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); @@ -270,12 +265,11 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { 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(); @@ -299,8 +293,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { 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 { @@ -324,7 +317,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { words += cc.getWords(); story.getChapters().add(cc); - story.getMeta().setWords(words); } finally { if (chapIn != null) { chapIn.close(); @@ -333,14 +325,31 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { 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(); @@ -380,7 +389,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * @param pg * the optional progress reporter * - * @return the {@link Chapter} + * @return the {@link Chapter}, never NULL * * @throws IOException * in case of I/O error @@ -391,10 +400,8 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { // 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(); @@ -438,7 +445,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * @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 @@ -456,7 +463,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { } List paras = new ArrayList(); - if (content != null && !content.trim().isEmpty()) { if (isHtml()) { String[] tab = content.split("(

|

|
|
)"); @@ -521,7 +527,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * @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; @@ -592,10 +598,9 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * @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) { } @@ -645,8 +650,14 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { } 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) { @@ -681,7 +692,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { // try for files if (source != null) { try { - String relPath = null; String absPath = null; try { @@ -718,8 +728,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { // 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; } @@ -730,7 +739,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { 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 @@ -746,7 +755,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { // 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; @@ -772,7 +781,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * 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); } /** @@ -874,7 +883,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * @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(); @@ -1128,7 +1137,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * the line to return based upon the target line position (-1 = * the line before, 0 = the target line...) * - * @return the line + * @return the line, or NULL if not found */ static protected String getLine(InputStream in, String needle, int relativeLine) { @@ -1152,7 +1161,7 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { * takes the first result (as opposed to the last one, which will * also always spend the input) * - * @return the line + * @return the line, or NULL if not found */ static protected String getLine(InputStream in, String needle, int relativeLine, boolean first) {