1 package be
.nikiroo
.fanfix
.supported
;
4 import java
.io
.FileInputStream
;
5 import java
.io
.IOException
;
6 import java
.io
.InputStream
;
7 import java
.net
.MalformedURLException
;
8 import java
.net
.URISyntaxException
;
10 import java
.util
.List
;
11 import java
.util
.Map
.Entry
;
13 import be
.nikiroo
.fanfix
.data
.MetaData
;
14 import be
.nikiroo
.utils
.MarkableFileInputStream
;
17 * Support class for HTML files created with this program (as we need some
18 * metadata available in those we create).
22 class Html
extends InfoText
{
23 private URL fakeSource
;
26 public String
getSourceName() {
31 protected boolean supports(URL url
) {
32 if (url
.getPath().toLowerCase()
33 .endsWith(File
.separatorChar
+ "index.html")) {
35 File file
= new File(url
.toURI()).getParentFile();
36 return super.supports(file
.toURI().toURL());
37 } catch (URISyntaxException e
) {
38 } catch (MalformedURLException e
) {
46 protected MetaData
getMeta(URL source
, InputStream in
) throws IOException
{
47 return super.getMeta(fakeSource
, in
);
51 protected String
getDesc(URL source
, InputStream in
) throws IOException
{
52 return super.getDesc(fakeSource
, in
);
56 protected List
<Entry
<String
, URL
>> getChapters(URL source
, InputStream in
)
58 return super.getChapters(fakeSource
, in
);
62 protected String
getChapterContent(URL source
, InputStream in
, int number
)
64 return super.getChapterContent(fakeSource
, in
, number
);
68 protected InputStream
openInput(URL source
) throws IOException
{
70 File fakeFile
= new File(source
.toURI()); // "story/index.html"
71 fakeFile
= new File(fakeFile
.getParent()); // "story"
72 fakeFile
= new File(fakeFile
, fakeFile
.getName()); // "story/story"
73 fakeSource
= fakeFile
.toURI().toURL();
74 return new MarkableFileInputStream(new FileInputStream(fakeFile
));
75 } catch (URISyntaxException e
) {
76 throw new IOException(
77 "file not supported (maybe not created with this program or corrupt)",
79 } catch (MalformedURLException e
) {
80 throw new IOException("file not supported (bad URL)", e
);