1 package be
.nikiroo
.fanfix
.output
;
3 import java
.io
.BufferedWriter
;
5 import java
.io
.FileOutputStream
;
6 import java
.io
.IOException
;
7 import java
.io
.OutputStreamWriter
;
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
;
14 class Cbz
extends BasicOutput
{
18 public File
process(Story story
, File targetDir
, String targetName
)
20 String targetNameOrig
= targetName
;
21 targetName
+= getDefaultExtension(false);
23 File target
= new File(targetDir
, targetName
);
25 dir
= File
.createTempFile("fanfic-reader-cbz-dir", ".wip");
29 // will also save the images!
30 new InfoText().process(story
, dir
, targetNameOrig
);
32 InfoCover
.writeInfo(dir
, targetNameOrig
, story
.getMeta());
33 if (story
.getMeta() != null && !story
.getMeta().isFakeCover()) {
34 InfoCover
.writeCover(dir
, targetNameOrig
, story
.getMeta());
37 IOUtils
.writeSmallFile(dir
, "version", "3.0");
40 super.process(story
, targetDir
, targetNameOrig
);
44 IOUtils
.zip(dir
, target
, true);
51 public String
getDefaultExtension(boolean readerTarget
) {
56 protected void writeStoryHeader(Story story
) throws IOException
{
57 MetaData meta
= story
.getMeta();
59 StringBuilder builder
= new StringBuilder();
60 if (meta
!= null && meta
.getResume() != null) {
61 for (Paragraph para
: story
.getMeta().getResume()) {
62 builder
.append(para
.getContent());
67 BufferedWriter writer
= new BufferedWriter(new OutputStreamWriter(
68 new FileOutputStream(new File(dir
, "URL")), "UTF-8"));
71 writer
.write(meta
.getUuid());
74 writer
.write(builder
.toString());
79 writer
= new BufferedWriter(new OutputStreamWriter(
80 new FileOutputStream(new File(dir
, "SUMMARY")), "UTF-8"));
83 if (meta
!= null && meta
.getTitle() != null) {
84 title
= meta
.getTitle();
88 if (meta
!= null && meta
.getAuthor() != null) {
90 writer
.write(meta
.getAuthor());
93 writer
.write(builder
.toString());