Continue conversion test + HTML.supports() fix
[fanfix.git] / src / be / nikiroo / fanfix / supported / Html.java
1 package be.nikiroo.fanfix.supported;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.net.MalformedURLException;
6 import java.net.URISyntaxException;
7 import java.net.URL;
8
9 import be.nikiroo.fanfix.Instance;
10
11 /**
12 * Support class for HTML files created with this program (as we need some
13 * metadata available in those we create).
14 *
15 * @author niki
16 */
17 class Html extends InfoText {
18 @Override
19 public String getSourceName() {
20 return "html";
21 }
22
23 @Override
24 protected boolean supports(URL url) {
25 try {
26 File file = new File(url.toURI());
27 if (file.getName().equals("index.html")) {
28 file = file.getParentFile();
29 }
30
31 file = new File(file, file.getName());
32
33 return super.supports(file.toURI().toURL());
34 } catch (URISyntaxException e) {
35 } catch (MalformedURLException e) {
36 }
37
38 return false;
39 }
40
41 @Override
42 public URL getCanonicalUrl(URL source) {
43
44 try {
45 File fakeFile = new File(source.toURI());
46 if (fakeFile.getName().equals("index.html")) { // "story/index.html"
47 fakeFile = new File(fakeFile.getParent()); // -> "story/"
48 }
49
50 if (fakeFile.isDirectory()) { // "story/"
51 fakeFile = new File(fakeFile, fakeFile.getName() + ".txt"); // "story/story.txt"
52 }
53
54 return fakeFile.toURI().toURL();
55 } catch (Exception e) {
56 Instance.getTraceHandler().error(
57 new IOException("Cannot find the right URL for " + source,
58 e));
59 }
60
61 return source;
62 }
63 }