import java.util.Map.Entry;
import java.util.Scanner;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.StringUtils;
/**
} finally {
chapIn.close();
}
+
i++;
}
}
String line = scan.next().trim();
boolean image = false;
if (line.startsWith("[") && line.endsWith("]")) {
- URL url = getImageUrl(source,
+ URL url = getImageUrl(this, source,
line.substring(1, line.length() - 1).trim());
if (url != null) {
paras.add(new Paragraph(url));
&& Instance.getCoverDir() != null) {
try {
File fileCover = new File(Instance.getCoverDir(), subject);
- return getImage(fileCover.toURI().toURL(), subject);
+ return getImage(null, fileCover.toURI().toURL(), subject);
} catch (MalformedURLException e) {
}
}
}
}
- static BufferedImage getImage(URL source, String line) {
- URL url = getImageUrl(source, line);
+ static BufferedImage getImage(BasicSupport support, URL source, String line) {
+ URL url = getImageUrl(support, source, line);
if (url != null) {
InputStream in = null;
try {
in = Instance.getCache().open(url, getSupport(url), true);
- return ImageIO.read(in);
+ return IOUtils.toImage(in);
} catch (IOException e) {
} finally {
if (in != null) {
* @return the image URL if found, or NULL
*
*/
- static URL getImageUrl(URL source, String line) {
+ static URL getImageUrl(BasicSupport support, URL source, String line) {
URL url = null;
if (line != null) {
if (source != null) {
path = new File(source.getFile()).getParent();
try {
- String urlBase = new File(new File(path), line.trim())
- .toURI().toURL().toString();
+ String basePath = new File(new File(path), line.trim())
+ .getAbsolutePath();
for (String ext : getImageExt(true)) {
- if (new File(urlBase + ext).exists()) {
- url = new File(urlBase + ext).toURI().toURL();
+ if (new File(basePath + ext).exists()) {
+ url = new File(basePath + ext).toURI().toURL();
}
}
} catch (Exception e) {
for (String ext : getImageExt(true)) {
if (Instance.getCache().check(new URL(line + ext))) {
url = new URL(line + ext);
+ break;
}
}
for (String ext : getImageExt(true)) {
try {
url = new URL(line + ext);
- Instance.getCache().refresh(url,
- getSupport(url), true);
+ Instance.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, getSupport(url), true);
+ Instance.getCache().refresh(url, support, true);
} catch (IOException e) {
// woops, broken image
url = null;
line = openDoubleQuote + line + closeDoubleQuote;
newParas.add(new Paragraph(ParagraphType.QUOTE, line));
} else {
+ char open = singleQ ? openQuote : openDoubleQuote;
char close = singleQ ? closeQuote : closeDoubleQuote;
- int posClose = line.indexOf(close, 1);
- int posDot = line.indexOf(".");
- while (posDot >= 0 && posDot < posClose) {
- posDot = line.indexOf(".", posDot + 1);
+
+ int posDot = -1;
+ boolean inQuote = false;
+ int i = 0;
+ for (char car : line.toCharArray()) {
+ if (car == open) {
+ inQuote = true;
+ } else if (car == close) {
+ inQuote = false;
+ } else if (car == '.' && !inQuote) {
+ posDot = i;
+ break;
+ }
+ i++;
}
if (posDot >= 0) {