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
;
12 import be
.nikiroo
.fanfix
.Instance
;
15 * Support class for <tt>.info</tt> text files ({@link Text} files with a
16 * <tt>.info</tt> metadata file next to them).
18 * The <tt>.info</tt> file is supposed to be written by this program, or
23 class InfoText
extends Text
{
25 public String
getSourceName() {
30 protected String
getTitle(URL source
, InputStream in
) throws IOException
{
31 String tag
= getInfoTag(source
, "TITLE");
36 return super.getTitle(source
, in
);
40 protected String
getAuthor(URL source
, InputStream in
) throws IOException
{
41 String tag
= getInfoTag(source
, "AUTHOR");
46 return super.getAuthor(source
, in
);
50 protected String
getDate(URL source
, InputStream in
) throws IOException
{
51 String tag
= getInfoTag(source
, "DATE");
56 return super.getDate(source
, in
);
60 protected String
getSubject(URL source
, InputStream in
) throws IOException
{
61 String tag
= getInfoTag(source
, "SUBJECT");
66 return super.getSubject(source
, in
);
70 protected String
getLang(URL source
, InputStream in
) throws IOException
{
71 String tag
= getInfoTag(source
, "LANG");
76 return super.getLang(source
, in
);
80 protected String
getPublisher(URL source
, InputStream in
)
82 String tag
= getInfoTag(source
, "PUBLISHER");
87 return super.getPublisher(source
, in
);
91 protected String
getUuid(URL source
, InputStream in
) throws IOException
{
92 String tag
= getInfoTag(source
, "UUID");
97 return super.getUuid(source
, in
);
101 protected String
getLuid(URL source
, InputStream in
) throws IOException
{
102 String tag
= getInfoTag(source
, "LUID");
107 return super.getLuid(source
, in
);
111 protected List
<String
> getTags(URL source
, InputStream in
)
113 List
<String
> tags
= super.getTags(source
, in
);
115 String tt
= getInfoTag(source
, "TAGS");
117 for (String tag
: tt
.split(",")) {
118 tags
.add(tag
.trim());
126 public boolean isImageDocument(URL source
, InputStream in
)
128 String tag
= getInfoTag(source
, "IMAGES_DOCUMENT");
130 return tag
.trim().toLowerCase().equals("true");
133 return super.isImageDocument(source
, in
);
137 protected URL
getCover(URL source
, InputStream in
) {
140 file
= new File(source
.toURI());
141 file
= new File(file
.getPath() + ".info");
142 } catch (URISyntaxException e
) {
148 if (file
!= null && file
.exists()) {
150 InputStream infoIn
= new FileInputStream(file
);
152 String key
= "COVER=";
153 String tt
= getLine(infoIn
, key
, 0);
154 if (tt
!= null && !tt
.isEmpty()) {
155 tt
= tt
.substring(key
.length()).trim();
156 if (tt
.startsWith("'") && tt
.endsWith("'")) {
157 tt
= tt
.substring(1, tt
.length() - 1).trim();
160 URL cover
= getImage(source
, tt
);
162 path
= cover
.getFile();
168 } catch (MalformedURLException e
) {
170 } catch (IOException e
) {
177 return new File(path
).toURI().toURL();
178 } catch (MalformedURLException e
) {
187 protected boolean supports(URL url
) {
188 if ("file".equals(url
.getProtocol())) {
191 file
= new File(url
.toURI());
192 file
= new File(file
.getPath() + ".info");
193 } catch (URISyntaxException e
) {
198 return file
!= null && file
.exists();
205 * Return the value of the given tag in the <tt>.info</tt> file if present.
208 * the source story {@link URL}
212 * @return the value or NULL
214 * @throws IOException
215 * in case of I/O error
217 private String
getInfoTag(URL source
, String key
) throws IOException
{
218 key
= "^" + key
+ "=";
222 file
= new File(source
.toURI());
223 file
= new File(file
.getPath() + ".info");
224 } catch (URISyntaxException e
) {
225 throw new IOException(e
);
229 InputStream infoIn
= new FileInputStream(file
);
231 String value
= getLine(infoIn
, key
, 0);
232 if (value
!= null && !value
.isEmpty()) {
233 value
= value
.trim().substring(key
.length() - 1).trim();
234 if (value
.startsWith("'") && value
.endsWith("'")
235 || value
.startsWith("\"") && value
.endsWith("\"")) {
236 value
= value
.substring(1, value
.length() - 1).trim();