X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupport.java;h=f16cdc7b6453ac00753bb479850ab7eb2edcafc5;hb=16a81ef7656c5c692fb831927e75edde25dd77a0;hp=c609c70324dd665313cc07b1de4eaa91ccb48060;hpb=2a25f7814eec9854022f1c9dee188bfbdb955591;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index c609c70..f16cdc7 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -1,6 +1,5 @@ package be.nikiroo.fanfix.supported; -import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; @@ -25,7 +24,7 @@ import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Paragraph.ParagraphType; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.utils.ImageUtils; +import be.nikiroo.utils.Image; import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; @@ -202,7 +201,7 @@ public abstract class BasicSupport { * @param in * the input (the main resource) * - * @return the associated {@link MetaData} + * @return the associated {@link MetaData}, never NULL * * @throws IOException * in case of I/O error @@ -342,7 +341,7 @@ public abstract class BasicSupport { * @param pg * the optional progress reporter * - * @return the {@link Story} + * @return the {@link Story}, never NULL * * @throws IOException * in case of I/O error @@ -419,7 +418,7 @@ public abstract class BasicSupport { * @param pg * the optional progress reporter * - * @return the {@link Story} + * @return the {@link Story}, never NULL * * @throws IOException * in case of I/O error @@ -441,11 +440,6 @@ public abstract class BasicSupport { pgMeta.setProgress(pgMeta.getMax()); // 10% } - if (story == null) { - pg.setProgress(90); - return null; - } - pg.setName("Retrieving " + story.getMeta().getTitle()); setCurrentReferer(url); @@ -496,9 +490,7 @@ public abstract class BasicSupport { words += cc.getWords(); story.getChapters().add(cc); - if (story.getMeta() != null) { - story.getMeta().setWords(words); - } + story.getMeta().setWords(words); } finally { if (chapIn != null) { chapIn.close(); @@ -757,7 +749,7 @@ public abstract class BasicSupport { * @return the {@link Paragraph} */ private Paragraph makeParagraph(URL source, String line) { - BufferedImage image = null; + Image image = null; if (line.startsWith("[") && line.endsWith("]")) { image = getImage(this, source, line.substring(1, line.length() - 1) .trim()); @@ -824,7 +816,7 @@ public abstract class BasicSupport { * * @return the cover if any, or NULL */ - static BufferedImage getDefaultCover(String subject) { + static Image getDefaultCover(String subject) { if (subject != null && !subject.isEmpty() && Instance.getCoverDir() != null) { try { @@ -867,13 +859,18 @@ public abstract class BasicSupport { * @return the image if found, or NULL * */ - static BufferedImage getImage(BasicSupport support, URL source, String line) { + static Image getImage(BasicSupport support, URL source, String line) { URL url = getImageUrl(support, source, line); if (url != null) { + if ("file".equals(url.getProtocol())) { + if (new File(url.getPath()).isDirectory()) { + return null; + } + } InputStream in = null; try { in = Instance.getCache().open(url, getSupport(url), true); - return ImageUtils.fromStream(in); + return new Image(in); } catch (IOException e) { } finally { if (in != null) { @@ -925,11 +922,14 @@ public abstract class BasicSupport { } for (String ext : getImageExt(true)) { - if (absPath != null && new File(absPath + ext).exists()) { - url = new File(absPath + ext).toURI().toURL(); - } else if (relPath != null - && new File(relPath + ext).exists()) { - url = new File(relPath + ext).toURI().toURL(); + File absFile = new File(absPath + ext); + File relFile = new File(relPath + ext); + if (absPath != null && absFile.exists() + && absFile.isFile()) { + url = absFile.toURI().toURL(); + } else if (relPath != null && relFile.exists() + && relFile.isFile()) { + url = relFile.toURI().toURL(); } } } catch (Exception e) {