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
.Instance
;
10 import be
.nikiroo
.fanfix
.data
.MetaData
;
11 import be
.nikiroo
.fanfix
.data
.Paragraph
;
12 import be
.nikiroo
.fanfix
.data
.Story
;
13 import be
.nikiroo
.utils
.IOUtils
;
15 class Cbz
extends BasicOutput
{
19 public File
process(Story story
, File targetDir
, String targetName
)
21 String targetNameOrig
= targetName
;
22 targetName
+= getDefaultExtension(false);
24 File target
= new File(targetDir
, targetName
);
26 dir
= Instance
.getTempFiles().createTempDir("fanfic-reader-cbz-dir");
28 // will also save the images! (except the cover -> false)
30 .getOutput(OutputType
.TEXT
, isWriteInfo(), isWriteCover())
31 // Force cover to FALSE:
32 .setType(OutputType
.TEXT
, isWriteInfo(), false)
33 .process(story
, dir
, targetNameOrig
);
36 super.process(story
, targetDir
, targetNameOrig
);
40 InfoCover
.writeInfo(dir
, targetNameOrig
, story
.getMeta());
41 if (story
.getMeta() != null && !story
.getMeta().isFakeCover()) {
42 InfoCover
.writeCover(dir
, targetNameOrig
, story
.getMeta());
45 IOUtils
.writeSmallFile(dir
, "version", "3.0");
47 IOUtils
.zip(dir
, target
, true);
56 public String
getDefaultExtension(boolean readerTarget
) {
61 protected void writeStoryHeader(Story story
) throws IOException
{
62 MetaData meta
= story
.getMeta();
64 StringBuilder builder
= new StringBuilder();
65 if (meta
!= null && meta
.getResume() != null) {
66 for (Paragraph para
: story
.getMeta().getResume()) {
67 builder
.append(para
.getContent());
72 BufferedWriter writer
= new BufferedWriter(new OutputStreamWriter(
73 new FileOutputStream(new File(dir
, "URL")), "UTF-8"));
76 writer
.write(meta
.getUrl());
82 writer
= new BufferedWriter(new OutputStreamWriter(
83 new FileOutputStream(new File(dir
, "SUMMARY")), "UTF-8"));
86 if (meta
!= null && meta
.getTitle() != null) {
87 title
= meta
.getTitle();
91 if (meta
!= null && meta
.getAuthor() != null) {
93 writer
.write(meta
.getAuthor());
96 writer
.write(builder
.toString());