1 13 package org.pentaho.plugin.jfreereport.outputs; 14 15 import java.io.File ; 16 import java.io.IOException ; 17 18 import org.jfree.report.JFreeReport; 19 import org.jfree.report.ReportProcessingException; 20 import org.jfree.report.modules.output.table.html.DirectoryHtmlFilesystem; 21 import org.jfree.report.modules.output.table.html.HtmlProcessor; 22 import org.pentaho.plugin.jfreereport.helper.YieldReportListener; 23 24 29 public class JFreeReportDirectoryHtmlComponent extends AbstractGenerateContentComponent { 30 private static final long serialVersionUID = -7511578647689368225L; 31 32 public JFreeReportDirectoryHtmlComponent() { 33 } 34 35 protected String getMimeType() { 36 return "text/html"; } 38 39 protected String getExtension() { 40 return ".html"; } 42 43 private File getInputFileValue(String inputName) { 44 Object input = getInputValue(inputName); 45 if (input == null) { 46 return null; 47 } 48 if (input instanceof File ) { 49 return (File ) input; 50 } 51 if (input instanceof String ) { 52 return new File ((String ) input); 53 } 54 return null; 55 } 56 57 protected boolean performExport(final JFreeReport report) { 58 try { 59 File target = getInputFileValue(REPORTDIRECTORYHTML_TARGETFILE); 60 if (target == null) { 61 return false; 62 } 63 64 File dataDirectory = getInputFileValue(REPORTDIRECTORYHTML_DATADIR); 65 if (dataDirectory == null) { 66 dataDirectory = new File (target, "data/"); } 68 69 HtmlProcessor processor = new HtmlProcessor(report); 70 processor.setFilesystem(new DirectoryHtmlFilesystem(target, dataDirectory)); 71 final int yieldRate = getYieldRate(); 72 if (yieldRate > 0) { 73 processor.addRepaginationListener(new YieldReportListener(yieldRate)); 74 } 75 processor.processReport(); 76 return true; 77 } catch (ReportProcessingException e) { 78 return false; 79 } catch (IOException e) { 80 return false; 81 } 82 } 83 } 84 | Popular Tags |