Commit | Line | Data |
---|---|---|
c3305350 NR |
1 | package be.nikiroo.fanfix.supported; |
2 | ||
3 | import java.io.File; | |
c3305350 | 4 | import java.io.IOException; |
c3305350 NR |
5 | import java.net.MalformedURLException; |
6 | import java.net.URISyntaxException; | |
7 | import java.net.URL; | |
c3305350 | 8 | |
0ffa4754 NR |
9 | import 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 | */ | |
17 | class Html extends InfoText { | |
c3305350 NR |
18 | @Override |
19 | public String getSourceName() { | |
20 | return "html"; | |
21 | } | |
22 | ||
23 | @Override | |
24 | protected boolean supports(URL url) { | |
25 | if (url.getPath().toLowerCase() | |
26 | .endsWith(File.separatorChar + "index.html")) { | |
27 | try { | |
28 | File file = new File(url.toURI()).getParentFile(); | |
29 | return super.supports(file.toURI().toURL()); | |
30 | } catch (URISyntaxException e) { | |
31 | } catch (MalformedURLException e) { | |
32 | } | |
33 | } | |
34 | ||
35 | return false; | |
36 | } | |
37 | ||
38 | @Override | |
0ffa4754 | 39 | public URL getCanonicalUrl(URL source) { |
a4143cd7 NR |
40 | if (source.toString().endsWith(File.separator + "index.html")) { |
41 | try { | |
42 | File fakeFile = new File(source.toURI()); // "story/index.html" | |
43 | fakeFile = new File(fakeFile.getParent()); // "story" | |
44 | fakeFile = new File(fakeFile, fakeFile.getName()); // "story/story" | |
45 | return fakeFile.toURI().toURL(); | |
0ffa4754 NR |
46 | } catch (Exception e) { |
47 | Instance.getTraceHandler().error( | |
48 | new IOException("Cannot find the right URL for " | |
49 | + source, e)); | |
a4143cd7 | 50 | } |
c3305350 | 51 | } |
a4143cd7 NR |
52 | |
53 | return source; | |
c3305350 NR |
54 | } |
55 | } |