package be.nikiroo.fanfix.supported;
-import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
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;
* @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
* @param pg
* the optional progress reporter
*
- * @return the {@link Story}
+ * @return the {@link Story}, never NULL
*
* @throws IOException
* in case of I/O error
* @param pg
* the optional progress reporter
*
- * @return the {@link Story}
+ * @return the {@link Story}, never NULL
*
* @throws IOException
* in case of I/O error
pgMeta.setProgress(pgMeta.getMax()); // 10%
}
- if (story == null) {
- pg.setProgress(90);
- return null;
- }
-
pg.setName("Retrieving " + story.getMeta().getTitle());
setCurrentReferer(url);
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();
* @return the {@link Paragraph}
*/
private Paragraph makeParagraph(URL source, String line) {
- URL image = null;
+ Image image = null;
if (line.startsWith("[") && line.endsWith("]")) {
- image = getImageUrl(this, source,
- line.substring(1, line.length() - 1).trim());
+ image = getImage(this, source, line.substring(1, line.length() - 1)
+ .trim());
}
if (image != null) {
*
* @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 {
* @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) {
}
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) {