git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
can now use '/' in sources
[fanfix.git]
/
src
/
be
/
nikiroo
/
fanfix
/
supported
/
Html.java
diff --git
a/src/be/nikiroo/fanfix/supported/Html.java
b/src/be/nikiroo/fanfix/supported/Html.java
index f66032bfce20032f784b6df0ab4b51ce7883fce7..c7db5d83ce3c0f16d1525dbb591f9453571cd420 100644
(file)
--- a/
src/be/nikiroo/fanfix/supported/Html.java
+++ b/
src/be/nikiroo/fanfix/supported/Html.java
@@
-3,7
+3,6
@@
package be.nikiroo.fanfix.supported;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.net.URL;
import be.nikiroo.fanfix.Instance;
import java.net.URL;
import be.nikiroo.fanfix.Instance;
@@
-23,15
+22,10
@@
class Html extends InfoText {
@Override
protected boolean supports(URL url) {
try {
@Override
protected boolean supports(URL url) {
try {
- File
file = new File(url.toURI()
);
- if (
file.getName().equals("index.html")
) {
-
file = file.getParentFile(
);
+ File
txt = getTxt(url
);
+ if (
txt != null
) {
+
return super.supports(txt.toURI().toURL()
);
}
}
-
- file = new File(file, file.getName());
-
- return super.supports(file.toURI().toURL());
- } catch (URISyntaxException e) {
} catch (MalformedURLException e) {
}
} catch (MalformedURLException e) {
}
@@
-40,7
+34,29
@@
class Html extends InfoText {
@Override
public URL getCanonicalUrl(URL source) {
@Override
public URL getCanonicalUrl(URL source) {
+ File txt = getTxt(source);
+ if (txt != null) {
+ try {
+ source = txt.toURI().toURL();
+ } catch (MalformedURLException e) {
+ Instance.getTraceHandler().error(
+ new IOException("Cannot convert the right URL for "
+ + source, e));
+ }
+ }
+ return source;
+ }
+
+ /**
+ * Return the associated TXT source file if it can be found.
+ *
+ * @param source
+ * the source URL
+ *
+ * @return the supported source text file or NULL
+ */
+ private static File getTxt(URL source) {
try {
File fakeFile = new File(source.toURI());
if (fakeFile.getName().equals("index.html")) { // "story/index.html"
try {
File fakeFile = new File(source.toURI());
if (fakeFile.getName().equals("index.html")) { // "story/index.html"
@@
-51,13
+67,12
@@
class Html extends InfoText {
fakeFile = new File(fakeFile, fakeFile.getName() + ".txt"); // "story/story.txt"
}
fakeFile = new File(fakeFile, fakeFile.getName() + ".txt"); // "story/story.txt"
}
- return fakeFile.toURI().toURL();
+ if (fakeFile.getName().endsWith(".txt")) {
+ return fakeFile;
+ }
} catch (Exception e) {
} catch (Exception e) {
- Instance.getTraceHandler().error(
- new IOException("Cannot find the right URL for " + source,
- e));
}
}
- return
source
;
+ return
null
;
}
}
}
}