Some jDoc fixes
[nikiroo-utils.git] / src / be / nikiroo / fanfix / output / Cbz.java
1 package be.nikiroo.fanfix.output;
2
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.io.OutputStreamWriter;
8
9 import be.nikiroo.fanfix.data.MetaData;
10 import be.nikiroo.fanfix.data.Paragraph;
11 import be.nikiroo.fanfix.data.Story;
12 import be.nikiroo.utils.IOUtils;
13
14 class Cbz extends BasicOutput {
15 private File dir;
16
17 @Override
18 public File process(Story story, File targetDir, String targetName)
19 throws IOException {
20 String targetNameOrig = targetName;
21 targetName += getDefaultExtension(false);
22
23 File target = new File(targetDir, targetName);
24
25 dir = File.createTempFile("fanfic-reader-cbz-dir", ".wip");
26 dir.delete();
27 dir.mkdir();
28
29 // will also save the images!
30 new InfoText().process(story, dir, targetNameOrig);
31
32 InfoCover.writeInfo(dir, targetNameOrig, story.getMeta());
33 if (story.getMeta() != null && !story.getMeta().isFakeCover()) {
34 InfoCover.writeCover(dir, targetNameOrig, story.getMeta());
35 }
36
37 IOUtils.writeSmallFile(dir, "version", "3.0");
38
39 try {
40 super.process(story, targetDir, targetNameOrig);
41 } finally {
42 }
43
44 IOUtils.zip(dir, target, true);
45 IOUtils.deltree(dir);
46
47 return target;
48 }
49
50 @Override
51 public String getDefaultExtension(boolean readerTarget) {
52 return ".cbz";
53 }
54
55 @Override
56 protected void writeStoryHeader(Story story) throws IOException {
57 MetaData meta = story.getMeta();
58
59 StringBuilder builder = new StringBuilder();
60 if (meta != null && meta.getResume() != null) {
61 for (Paragraph para : story.getMeta().getResume()) {
62 builder.append(para.getContent());
63 builder.append("\n");
64 }
65 }
66
67 BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
68 new FileOutputStream(new File(dir, "URL")), "UTF-8"));
69 try {
70 if (meta != null) {
71 writer.write(meta.getUuid());
72 }
73 writer.write("\n\n");
74 writer.write(builder.toString());
75 } finally {
76 writer.close();
77 }
78
79 writer = new BufferedWriter(new OutputStreamWriter(
80 new FileOutputStream(new File(dir, "SUMMARY")), "UTF-8"));
81 try {
82 String title = "";
83 if (meta != null && meta.getTitle() != null) {
84 title = meta.getTitle();
85 }
86
87 writer.write(title);
88 if (meta != null && meta.getAuthor() != null) {
89 writer.write("\n©");
90 writer.write(meta.getAuthor());
91 }
92 writer.write("\n\n");
93 writer.write(builder.toString());
94 } finally {
95 writer.close();
96 }
97 }
98 }