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 NR |
8 | |
9 | /** | |
10 | * Support class for HTML files created with this program (as we need some | |
11 | * metadata available in those we create). | |
12 | * | |
13 | * @author niki | |
14 | */ | |
15 | class Html extends InfoText { | |
c3305350 NR |
16 | @Override |
17 | public String getSourceName() { | |
18 | return "html"; | |
19 | } | |
20 | ||
21 | @Override | |
22 | protected boolean supports(URL url) { | |
23 | if (url.getPath().toLowerCase() | |
24 | .endsWith(File.separatorChar + "index.html")) { | |
25 | try { | |
26 | File file = new File(url.toURI()).getParentFile(); | |
27 | return super.supports(file.toURI().toURL()); | |
28 | } catch (URISyntaxException e) { | |
29 | } catch (MalformedURLException e) { | |
30 | } | |
31 | } | |
32 | ||
33 | return false; | |
34 | } | |
35 | ||
36 | @Override | |
a4143cd7 NR |
37 | public URL getCanonicalUrl(URL source) throws IOException { |
38 | if (source.toString().endsWith(File.separator + "index.html")) { | |
39 | try { | |
40 | File fakeFile = new File(source.toURI()); // "story/index.html" | |
41 | fakeFile = new File(fakeFile.getParent()); // "story" | |
42 | fakeFile = new File(fakeFile, fakeFile.getName()); // "story/story" | |
43 | return fakeFile.toURI().toURL(); | |
44 | } catch (URISyntaxException e) { | |
45 | throw new IOException( | |
46 | "file not supported (maybe not created with this program or corrupt)", | |
47 | e); | |
48 | } | |
c3305350 | 49 | } |
a4143cd7 NR |
50 | |
51 | return source; | |
c3305350 NR |
52 | } |
53 | } |