1 package be
.nikiroo
.fanfix
.output
;
4 import java
.io
.FileWriter
;
5 import java
.io
.IOException
;
7 import javax
.imageio
.ImageIO
;
9 import be
.nikiroo
.fanfix
.Instance
;
10 import be
.nikiroo
.fanfix
.bundles
.Config
;
11 import be
.nikiroo
.fanfix
.data
.MetaData
;
14 public static void writeInfo(File targetDir
, String targetName
,
15 MetaData meta
) throws IOException
{
16 File info
= new File(targetDir
, targetName
+ ".info");
17 FileWriter infoWriter
= new FileWriter(info
);
22 if (meta
.getTags() != null) {
23 for (String tag
: meta
.getTags()) {
24 if (!tags
.isEmpty()) {
31 writeMeta(infoWriter
, "TITLE", meta
.getTitle());
32 writeMeta(infoWriter
, "AUTHOR", meta
.getAuthor());
33 writeMeta(infoWriter
, "DATE", meta
.getDate());
34 writeMeta(infoWriter
, "SUBJECT", meta
.getSubject());
35 writeMeta(infoWriter
, "SOURCE", meta
.getSource());
36 writeMeta(infoWriter
, "URL", meta
.getUrl());
37 writeMeta(infoWriter
, "TAGS", tags
);
38 writeMeta(infoWriter
, "UUID", meta
.getUuid());
39 writeMeta(infoWriter
, "LUID", meta
.getLuid());
40 writeMeta(infoWriter
, "LANG", meta
.getLang() == null ?
""
41 : meta
.getLang().toLowerCase());
42 writeMeta(infoWriter
, "IMAGES_DOCUMENT",
43 meta
.isImageDocument() ?
"true" : "false");
44 writeMeta(infoWriter
, "TYPE", meta
.getType());
45 if (meta
.getCover() != null) {
46 String format
= Instance
.getConfig()
47 .getString(Config
.IMAGE_FORMAT_COVER
).toLowerCase();
48 writeMeta(infoWriter
, "COVER", targetName
+ "." + format
);
50 writeMeta(infoWriter
, "COVER", "");
52 writeMeta(infoWriter
, "EPUBCREATOR", BasicOutput
.EPUB_CREATOR
);
53 writeMeta(infoWriter
, "PUBLISHER", meta
.getPublisher());
60 public static void writeCover(File targetDir
, String targetName
,
62 if (meta
!= null && meta
.getCover() != null) {
64 String format
= Instance
.getConfig()
65 .getString(Config
.IMAGE_FORMAT_COVER
).toLowerCase();
66 ImageIO
.write(meta
.getCover(), format
, new File(targetDir
,
67 targetName
+ "." + format
));
68 } catch (IOException e
) {
69 // Allow to continue without cover
70 Instance
.syserr(new IOException(
71 "Failed to save the cover image", e
));
76 private static void writeMeta(FileWriter writer
, String key
, String value
)
82 writer
.write(String
.format("%s=\"%s\"\n", key
, value
.replace("\"", "'")));