KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreereport > outputs > JFreeReportDirectoryHtmlComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  */

13 package org.pentaho.plugin.jfreereport.outputs;
14
15 import java.io.File JavaDoc;
16 import java.io.IOException JavaDoc;
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 /**
25  * Creation-Date: 07.07.2006, 20:42:17
26  *
27  * @author Thomas Morgner
28  */

29 public class JFreeReportDirectoryHtmlComponent extends AbstractGenerateContentComponent {
30     private static final long serialVersionUID = -7511578647689368225L;
31
32     public JFreeReportDirectoryHtmlComponent() {
33     }
34
35     protected String JavaDoc getMimeType() {
36         return "text/html"; //$NON-NLS-1$
37
}
38
39     protected String JavaDoc getExtension() {
40         return ".html"; //$NON-NLS-1$
41
}
42
43     private File JavaDoc getInputFileValue(String JavaDoc inputName) {
44         Object JavaDoc input = getInputValue(inputName);
45         if (input == null) {
46             return null;
47         }
48         if (input instanceof File JavaDoc) {
49             return (File JavaDoc) input;
50         }
51         if (input instanceof String JavaDoc) {
52             return new File JavaDoc((String JavaDoc) input);
53         }
54         return null;
55     }
56
57     protected boolean performExport(final JFreeReport report) {
58         try {
59             File JavaDoc target = getInputFileValue(REPORTDIRECTORYHTML_TARGETFILE);
60             if (target == null) {
61                 return false;
62             }
63
64             File JavaDoc dataDirectory = getInputFileValue(REPORTDIRECTORYHTML_DATADIR);
65             if (dataDirectory == null) {
66                 dataDirectory = new File JavaDoc(target, "data/"); //$NON-NLS-1$
67
}
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 JavaDoc e) {
80             return false;
81         }
82     }
83 }
84
Popular Tags