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
;
10 import be
.nikiroo
.fanfix
.Instance
;
11 import be
.nikiroo
.fanfix
.bundles
.StringId
;
12 import be
.nikiroo
.fanfix
.data
.Chapter
;
13 import be
.nikiroo
.fanfix
.data
.MetaData
;
14 import be
.nikiroo
.fanfix
.data
.Paragraph
;
15 import be
.nikiroo
.fanfix
.data
.Paragraph
.ParagraphType
;
16 import be
.nikiroo
.fanfix
.data
.Story
;
18 class Text
extends BasicOutput
{
19 protected BufferedWriter writer
;
20 protected File targetDir
;
23 public File
process(Story story
, File targetDir
, String targetName
)
25 String targetNameOrig
= targetName
;
26 targetName
+= getDefaultExtension(false);
28 this.targetDir
= targetDir
;
30 File target
= new File(targetDir
, targetName
);
32 writer
= new BufferedWriter(new OutputStreamWriter(
33 new FileOutputStream(target
), "UTF-8"));
35 super.process(story
, targetDir
, targetNameOrig
);
45 public String
getDefaultExtension(boolean readerTarget
) {
50 protected void writeStoryHeader(Story story
) throws IOException
{
55 MetaData meta
= story
.getMeta();
57 title
= meta
.getTitle() == null ?
"" : meta
.getTitle();
58 author
= meta
.getAuthor();
59 date
= meta
.getDate();
64 if (author
!= null && !author
.isEmpty()) {
65 writer
.write(Instance
.getTrans().getString(StringId
.BY
) + " "
68 if (date
!= null && !date
.isEmpty()) {
76 if (meta
!= null && meta
.getResume() != null) {
77 writeChapter(meta
.getResume());
82 protected void writeChapterHeader(Chapter chap
) throws IOException
{
84 if (chap
.getName() != null && !chap
.getName().isEmpty()) {
85 txt
= Instance
.getTrans().getString(StringId
.CHAPTER_NAMED
,
86 chap
.getNumber(), chap
.getName());
88 txt
= Instance
.getTrans().getString(StringId
.CHAPTER_UNNAMED
,
92 writer
.write("\n" + txt
+ "\n");
93 for (int i
= 0; i
< txt
.length(); i
++) {
100 protected void writeParagraphFooter(Paragraph para
) throws IOException
{
105 protected void writeParagraphHeader(Paragraph para
) throws IOException
{
106 if (para
.getType() == ParagraphType
.IMAGE
) {
107 File file
= new File(targetDir
, getCurrentImageBestName(true));
108 Instance
.getCache().saveAsImage(new URL(para
.getContent()), file
);
113 protected void writeTextLine(ParagraphType type
, String line
)
119 writer
.write("\n* * *\n");
126 writer
.write("[" + getCurrentImageBestName(true) + "]");