New support: YiffStar (still no logged-in content)
[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 /**
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 {
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
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 }
49 }
50
51 return source;
52 }
53 }