X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Foutput%2FHtml.java;h=3ed52ad6a3b22491397b61aeb31175320dbcdada;hb=refs%2Ftags%2Ffanfix-1.0.0;hp=4226bf84b75dfa6ea97d3770c93a44416f04e38d;hpb=2206ef66ee00ad42d806f04a7b7ad6f8cb2d8828;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/output/Html.java b/src/be/nikiroo/fanfix/output/Html.java index 4226bf8..3ed52ad 100644 --- a/src/be/nikiroo/fanfix/output/Html.java +++ b/src/be/nikiroo/fanfix/output/Html.java @@ -1,6 +1,261 @@ package be.nikiroo.fanfix.output; -//TODO: implement it for LocalReader -class Html extends Text { +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import javax.imageio.ImageIO; + +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.bundles.Config; +import be.nikiroo.fanfix.data.Chapter; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Paragraph; +import be.nikiroo.fanfix.data.Paragraph.ParagraphType; +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.StringUtils; + +class Html extends BasicOutput { + private File dir; + protected BufferedWriter writer; + private boolean inDialogue = false; + private boolean inNormal = false; + + @Override + public File process(Story story, File targetDir, String targetName) + throws IOException { + String targetNameOrig = targetName; + + File target = new File(targetDir, targetName); + target.mkdir(); + dir = target; + + targetName += getDefaultExtension(); + + target = new File(targetDir, targetName); + + writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(target), "UTF-8")); + try { + super.process(story, targetDir, targetNameOrig); + } finally { + writer.close(); + writer = null; + } + + String format = Instance.getConfig() + .getString(Config.IMAGE_FORMAT_COVER).toLowerCase(); + if (story.getMeta().getCover() != null) { + ImageIO.write(story.getMeta().getCover(), format, new File(dir, + "cover." + format)); + } + + return target; + } + + @Override + public String getDefaultExtension() { + return File.separator + "index.html"; + } + + @Override + protected void writeStoryHeader(Story story) throws IOException { + String title = ""; + String tags = ""; + String author = ""; + Chapter resume = null; + if (story.getMeta() != null) { + MetaData meta = story.getMeta(); + title = meta.getTitle(); + resume = meta.getResume(); + if (meta.getTags() != null) { + for (String tag : meta.getTags()) { + if (!tags.isEmpty()) { + tags += ", "; + } + tags += tag; + } + + if (!tags.isEmpty()) { + tags = "(" + tags + ")"; + } + } + author = meta.getAuthor(); + } + + String format = Instance.getConfig() + .getString(Config.IMAGE_FORMAT_COVER).toLowerCase(); + + InputStream inStyle = getClass().getResourceAsStream("html.style.css"); + if (inStyle == null) { + throw new IOException("Cannot find style.css resource"); + } + try { + IOUtils.write(inStyle, new File(dir, "style.css")); + } finally { + inStyle.close(); + } + + writer.write(""); + writer.write("\n"); + writer.write("\n
"); + writer.write("\n "); + writer.write("\n "); + writer.write("\n "); + writer.write("\n