X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=supported%2FText.java;h=e082a737f2a7be9c11b9fc133bea0c96f108ae55;hb=31e27ee3108543141f9bfd2efce8c0fa024460a1;hp=daa108fc2c6a31fa322ae7b037b079a0206923a5;hpb=0fc81e6465aa9c1f1dfc19b532082220d609768a;p=nikiroo-utils.git diff --git a/supported/Text.java b/supported/Text.java index daa108f..e082a73 100644 --- a/supported/Text.java +++ b/supported/Text.java @@ -53,8 +53,7 @@ class Text extends BasicSupport { try { in.reset(); } catch (IOException e) { - Instance.getTraceHandler().error( - new IOException("Cannot reset the Text stream", e)); + Instance.getInstance().getTraceHandler().error(new IOException("Cannot reset the Text stream", e)); } return in; @@ -98,7 +97,7 @@ class Text extends BasicSupport { meta.setType(getType().toString()); meta.setImageDocument(false); meta.setCover(getCover(getSourceFile())); - + return meta; } @@ -189,7 +188,7 @@ class Text extends BasicSupport { return content; } - private Image getCover(File sourceFile) { + protected Image getCover(File sourceFile) { String path = sourceFile.getName(); for (String ext : new String[] { ".txt", ".text", ".story" }) { @@ -201,8 +200,7 @@ class Text extends BasicSupport { Image cover = bsImages.getImage(this, sourceFile.getParentFile(), path); if (cover != null) { try { - File tmp = Instance.getTempFiles().createTempFile( - "test_cover_image"); + File tmp = Instance.getInstance().getTempFiles().createTempFile("test_cover_image"); ImageUtils.getInstance().saveAsImage(cover, tmp, "png"); tmp.delete(); } catch (IOException e) { @@ -271,9 +269,8 @@ class Text extends BasicSupport { try { in.close(); } catch (IOException e) { - Instance.getTraceHandler().error( - new IOException( - "Cannot close the text source file input", e)); + Instance.getInstance().getTraceHandler() + .error(new IOException("Cannot close the text source file input", e)); } } @@ -288,6 +285,8 @@ class Text extends BasicSupport { /** * Check if we supports this {@link URL}, that is, if the info file can be * found OR not found. + *

+ * It must also be a file, not another kind of URL. * * @param url * the {@link URL} to check @@ -297,26 +296,28 @@ class Text extends BasicSupport { * @return TRUE if it is supported */ protected boolean supports(URL url, boolean info) { - boolean infoPresent = false; - if ("file".equals(url.getProtocol())) { - File file; - try { - file = new File(url.toURI()); - file = assureNoTxt(file); - file = new File(file.getPath() + ".info"); - } catch (URISyntaxException e) { - Instance.getTraceHandler().error(e); - file = null; - } + if (!"file".equals(url.getProtocol())) { + return false; + } - infoPresent = (file != null && file.exists()); + boolean infoPresent = false; + File file; + try { + file = new File(url.toURI()); + file = assureNoTxt(file); + file = new File(file.getPath() + ".info"); + } catch (URISyntaxException e) { + Instance.getInstance().getTraceHandler().error(e); + file = null; } + infoPresent = (file != null && file.exists()); + return infoPresent == info; } /** - * Remove the ".txt" extension if it is present. + * Remove the ".txt" (or ".text") extension if it is present. * * @param file * the file to process @@ -325,9 +326,11 @@ class Text extends BasicSupport { * was present */ protected File assureNoTxt(File file) { - if (file.getName().endsWith(".txt")) { - file = new File(file.getPath().substring(0, - file.getPath().length() - 4)); + for (String ext : new String[] { ".txt", ".text" }) { + if (file.getName().endsWith(ext)) { + file = new File(file.getPath().substring(0, + file.getPath().length() - ext.length())); + } } return file; @@ -346,9 +349,8 @@ class Text extends BasicSupport { */ static private String detectChapter(String line, int number) { line = line.toUpperCase(); - for (String lang : Instance.getConfig().getList(Config.CONF_CHAPTER)) { - String chapter = Instance.getConfig().getStringX( - Config.CONF_CHAPTER, lang); + for (String lang : Instance.getInstance().getConfig().getList(Config.CONF_CHAPTER)) { + String chapter = Instance.getInstance().getConfig().getStringX(Config.CONF_CHAPTER, lang); if (chapter != null && !chapter.isEmpty()) { chapter = chapter.toUpperCase() + " "; if (line.startsWith(chapter)) {