Fix tests:
[fanfix.git] / src / be / nikiroo / fanfix / supported / Html.java
CommitLineData
c3305350
NR
1package be.nikiroo.fanfix.supported;
2
3import java.io.File;
c3305350 4import java.io.IOException;
c3305350
NR
5import java.net.MalformedURLException;
6import java.net.URISyntaxException;
7import java.net.URL;
c3305350 8
0ffa4754
NR
9import be.nikiroo.fanfix.Instance;
10
c3305350
NR
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 */
17class Html extends InfoText {
c3305350
NR
18 @Override
19 public String getSourceName() {
20 return "html";
21 }
22
23 @Override
24 protected boolean supports(URL url) {
86d49dbc
NR
25 try {
26 File file = new File(url.toURI());
27 if (file.getName().equals("index.html")) {
28 file = file.getParentFile();
c3305350 29 }
86d49dbc
NR
30
31 file = new File(file, file.getName());
32
33 return super.supports(file.toURI().toURL());
34 } catch (URISyntaxException e) {
35 } catch (MalformedURLException e) {
c3305350
NR
36 }
37
38 return false;
39 }
40
41 @Override
0ffa4754 42 public URL getCanonicalUrl(URL source) {
86d49dbc
NR
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/"
a4143cd7 48 }
86d49dbc
NR
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));
c3305350 59 }
a4143cd7
NR
60
61 return source;
c3305350
NR
62 }
63}