X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=output%2FInfoCover.java;h=fe530a852b1547ee498c0b66afa8e9fa0fe7a05f;hp=d8ca49a6876bcb1a759845d117b26cdd302bdfe6;hb=e992c260c059c53c4aabc980db85efd58f190205;hpb=002972e9de731678035d56304d75a6d9e8233635 diff --git a/output/InfoCover.java b/output/InfoCover.java index d8ca49a..fe530a8 100644 --- a/output/InfoCover.java +++ b/output/InfoCover.java @@ -5,22 +5,45 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.util.Arrays; 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.Story; +/** + * Helper class to write info, cover and summary (resume) files. + * + * @author niki + */ public class InfoCover { + /** + * Write both the .info and the .summary files by taking + * the information from the {@link MetaData}. + * + * @param targetDir + * the directory where to write the 2 files + * @param targetName + * the target name (no extension) to use (so you will get + * targetName.info and targetName.summary) + * @param meta + * the {@link MetaData} to get the data out of + * + * @throws IOException + * in case of I/O error + */ public static void writeInfo(File targetDir, String targetName, MetaData meta) throws IOException { File info = new File(targetDir, targetName + ".info"); - BufferedWriter infoWriter = null; - try { - infoWriter = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(info), "UTF-8")); + if (meta != null) { + BufferedWriter infoWriter = null; + try { + infoWriter = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(info), "UTF-8")); - if (meta != null) { String tags = ""; if (meta.getTags() != null) { for (String tag : meta.getTags()) { @@ -47,7 +70,8 @@ public class InfoCover { writeMeta(infoWriter, "TYPE", meta.getType()); if (meta.getCover() != null) { String format = Instance.getInstance().getConfig() - .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER).toLowerCase(); + .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER) + .toLowerCase(); writeMeta(infoWriter, "COVER", targetName + "." + format); } else { writeMeta(infoWriter, "COVER", ""); @@ -59,14 +83,69 @@ public class InfoCover { writeMeta(infoWriter, "CREATION_DATE", meta.getCreationDate()); writeMeta(infoWriter, "FAKE_COVER", Boolean.toString(meta.isFakeCover())); + } finally { + if (infoWriter != null) { + infoWriter.close(); + } } - } finally { - if (infoWriter != null) { - infoWriter.close(); + + if (meta.getResume() != null) { + Story fakeStory = new Story(); + fakeStory.setMeta(meta); + fakeStory.setChapters(Arrays.asList(meta.getResume())); + + Text summaryText = new Text() { + @Override + protected boolean isWriteCover() { + return false; + } + + @Override + protected boolean isWriteInfo() { + return false; // infinite loop if not! + } + + @Override + public String getDefaultExtension(boolean readerTarget) { + return ".summary"; + } + + @Override + protected void writeStoryHeader(Story story) + throws IOException { + } + + @Override + protected void writeStoryFooter(Story story) + throws IOException { + } + + @Override + protected void writeChapterHeader(Chapter chap) + throws IOException { + } + + @Override + protected void writeChapterFooter(Chapter chap) + throws IOException { + } + }; + + summaryText.process(fakeStory, targetDir, targetName); } } } + /** + * Write the cover file. + * + * @param targetDir + * the target directory + * @param targetName + * the target name for the cover (the extension will be added) + * @param meta + * the meta to get the information out of + */ public static void writeCover(File targetDir, String targetName, MetaData meta) { if (meta != null && meta.getCover() != null) {