1 17 18 19 20 21 27 28 package org.apache.fop.render.rtf.rtflib.testdocs; 29 30 import java.util.Date ; 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.io.FileWriter ; 34 35 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea; 36 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection; 37 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile; 38 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph; 39 41 44 45 abstract class TestDocument { 46 private File output; 47 48 final void setOutputDir(File outDir) 49 throws IOException { 50 output = new File (outDir, getRtfFilename()); 51 } 52 53 final String getRtfFilename() { 54 final String name = getClass().getName(); 56 final int pos = name.lastIndexOf('.'); 57 return name.substring(pos + 1) + ".rtf"; 58 } 59 60 final void generateOutput() 61 throws IOException { 62 debugMsg("Generating document " + output + "..."); 63 final RtfFile f = new RtfFile(new FileWriter (output)); 64 final RtfDocumentArea rda = f.startDocumentArea(); 65 final RtfSection sect = rda.newSection(); 66 addIntroComments(sect); 67 generateDocument(rda, sect); 68 f.flush(); 69 } 70 71 protected abstract void generateDocument(RtfDocumentArea rda, RtfSection sect) 72 throws IOException ; 73 74 void debugMsg(String msg) { 75 System.err.println(msg); 76 } 77 78 protected void addIntroComments(RtfSection sect) throws IOException { 79 final RtfParagraph para = sect.newParagraph(); 80 81 para.newText("jfor RTF library test document."); 82 para.newLineBreak(); 83 para.newLineBreak(); 85 para.newText("generated by class " + getClass().getName()); 86 para.newLineBreak(); 87 para.newText("generated on " + new Date ()); 88 para.close(); 89 } 90 } | Popular Tags |