1 package be
.nikiroo
.fanfix
.supported
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
6 import java
.net
.URISyntaxException
;
9 import be
.nikiroo
.fanfix
.Instance
;
10 import be
.nikiroo
.fanfix
.data
.MetaData
;
13 * Support class for <tt>.info</tt> text files ({@link Text} files with a
14 * <tt>.info</tt> metadata file next to them).
16 * The <tt>.info</tt> file is supposed to be written by this program, or
21 class InfoText
extends Text
{
23 public String
getSourceName() {
28 protected MetaData
getMeta(URL source
, InputStream in
) throws IOException
{
30 MetaData meta
= InfoReader
.readMeta(
31 new File(new File(source
.toURI()).getPath() + ".info"),
34 // Some old .info files don't have those now required fields...
35 String test
= meta
.getTitle() == null ?
"" : meta
.getTitle();
36 test
+= meta
.getAuthor() == null ?
"" : meta
.getAuthor();
37 test
+= meta
.getDate() == null ?
"" : meta
.getDate();
38 test
+= meta
.getUrl() == null ?
"" : meta
.getUrl();
40 MetaData superMeta
= super.getMeta(source
, reset(in
));
41 if (meta
.getTitle() == null || meta
.getTitle().isEmpty()) {
42 meta
.setTitle(superMeta
.getTitle());
44 if (meta
.getAuthor() == null || meta
.getAuthor().isEmpty()) {
45 meta
.setAuthor(superMeta
.getAuthor());
47 if (meta
.getDate() == null || meta
.getDate().isEmpty()) {
48 meta
.setDate(superMeta
.getDate());
50 if (meta
.getUrl() == null || meta
.getUrl().isEmpty()) {
51 meta
.setUrl(superMeta
.getUrl());
57 } catch (URISyntaxException e
) {
58 throw new IOException("Cannot parse URL to file: " + source
, e
);
63 protected boolean supports(URL url
) {
64 if ("file".equals(url
.getProtocol())) {
67 file
= new File(url
.toURI());
68 file
= new File(file
.getPath() + ".info");
69 } catch (URISyntaxException e
) {
74 return file
!= null && file
.exists();