Change BasicSupport to use jsoup
[nikiroo-utils.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 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
39 public URL getCanonicalUrl(URL source) {
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();
46 } catch (Exception e) {
47 Instance.getTraceHandler().error(
48 new IOException("Cannot find the right URL for "
49 + source, e));
50 }
51 }
52
53 return source;
54 }
55 }