doc
[nikiroo-utils.git] / supported / InfoText.java
... / ...
CommitLineData
1package be.nikiroo.fanfix.supported;
2
3import java.io.File;
4import java.io.IOException;
5import java.net.URL;
6
7import be.nikiroo.fanfix.data.MetaData;
8
9/**
10 * Support class for <tt>.info</tt> text files ({@link Text} files with a
11 * <tt>.info</tt> metadata file next to them).
12 * <p>
13 * The <tt>.info</tt> file is supposed to be written by this program, or
14 * compatible.
15 *
16 * @author niki
17 */
18class InfoText extends Text {
19 protected File getInfoFile() {
20 return new File(assureNoTxt(getSourceFile()).getPath() + ".info");
21 }
22
23 @Override
24 protected MetaData getMeta() throws IOException {
25 MetaData meta = InfoReader.readMeta(getInfoFile(), true);
26
27 // Some old .info files don't have those now required fields...
28 String test = meta.getTitle() == null ? "" : meta.getTitle();
29 test += meta.getAuthor() == null ? "" : meta.getAuthor();
30 test += meta.getDate() == null ? "" : meta.getDate();
31 test += meta.getUrl() == null ? "" : meta.getUrl();
32 if (test.isEmpty()) {
33 MetaData superMeta = super.getMeta();
34 if (meta.getTitle() == null || meta.getTitle().isEmpty()) {
35 meta.setTitle(superMeta.getTitle());
36 }
37 if (meta.getAuthor() == null || meta.getAuthor().isEmpty()) {
38 meta.setAuthor(superMeta.getAuthor());
39 }
40 if (meta.getDate() == null || meta.getDate().isEmpty()) {
41 meta.setDate(superMeta.getDate());
42 }
43 if (meta.getUrl() == null || meta.getUrl().isEmpty()) {
44 meta.setUrl(superMeta.getUrl());
45 }
46 }
47
48 return meta;
49 }
50
51 @Override
52 protected boolean supports(URL url) {
53 return supports(url, true);
54 }
55}