KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
16 import java.io.OutputStream JavaDoc;
17
18 import org.jfree.report.JFreeReport;
19 import org.jfree.report.ReportProcessingException;
20 import org.jfree.report.modules.output.table.html.HtmlProcessor;
21 import org.jfree.report.modules.output.table.html.StreamHtmlFilesystem;
22 import org.pentaho.core.repository.IContentRepository;
23 import org.pentaho.core.system.IApplicationContext;
24 import org.pentaho.core.system.PentahoSystem;
25 import org.pentaho.messages.Messages;
26 import org.pentaho.plugin.jfreereport.helper.PentahoHtmlFilesystem;
27 import org.pentaho.plugin.jfreereport.helper.YieldReportListener;
28
29 /**
30  * Creation-Date: 07.07.2006, 20:42:17
31  *
32  * @author Thomas Morgner
33  */

34 public class JFreeReportHtmlComponent extends AbstractGenerateStreamContentComponent {
35     private static final long serialVersionUID = -4296469329232291213L;
36
37     public JFreeReportHtmlComponent() {
38     }
39
40     protected String JavaDoc getMimeType() {
41         return "text/html"; //$NON-NLS-1$
42
}
43
44     protected String JavaDoc getExtension() {
45         return ".html"; //$NON-NLS-1$
46
}
47
48     protected boolean performExport(final JFreeReport report, final OutputStream JavaDoc outputStream) {
49         try {
50             final IContentRepository contentRepository = PentahoSystem.getContentRepository(getSession());
51
52             String JavaDoc contentHandlerPattern = getInputStringValue(REPORTHTML_CONTENTHANDLER);
53             if (contentHandlerPattern == null) {
54                 contentHandlerPattern = "GetContent?id={0}"; //$NON-NLS-1$
55
}
56
57             String JavaDoc format = null;
58             IApplicationContext ctx = PentahoSystem.getApplicationContext();
59             if (ctx != null) {
60                 format = ctx.getBaseUrl() + contentHandlerPattern;
61             }
62
63             if (contentRepository == null || format == null) {
64                 debug(Messages.getString("JFreeReportHtmlComponent.DEBUG_0044_PROCESSING_WITHOUT_CONTENT_REPOS")); //$NON-NLS-1$
65
// without a content repository, we have no choice but to
66
// fall back to the stream mode
67
HtmlProcessor processor = new HtmlProcessor(report);
68                 processor.setFilesystem(new StreamHtmlFilesystem(outputStream));
69                 final int yieldRate = getYieldRate();
70                 if (yieldRate > 0) {
71                     processor.addRepaginationListener(new YieldReportListener(yieldRate));
72                 }
73                 processor.processReport();
74                 outputStream.flush();
75                 return true;
76             }
77
78             debug(Messages.getString("JFreeReportHtmlComponent.DEBUG_045_PROCESSING_WITH_CONTENT_REPOS")); //$NON-NLS-1$
79
// final String description = getActionTitle();
80
// without any documentation, this is the best I could create
81
// The content repository is black magic, isnt it?
82
// final String path = getSolutionName() + "/" + getSolutionPath() + "/" +
83
// getSession().getId(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
84
// //$NON-NLS-4$
85
// final IContentLocation contentPath =
86
// contentRepository.newContentLocation (path,
87
// UUIDUtil.getUUIDAsString(), description, getSolutionName(), true);
88

89             final PentahoHtmlFilesystem filesystem = new PentahoHtmlFilesystem(outputStream, null, getActionName(), false, format);
90
91             HtmlProcessor processor = new HtmlProcessor(report);
92             processor.setFilesystem(filesystem);
93             final int yieldRate = getYieldRate();
94             if (yieldRate > 0) {
95                 processor.addRepaginationListener(new YieldReportListener(yieldRate));
96             }
97             processor.processReport();
98             outputStream.close();
99             return true;
100         } catch (ReportProcessingException e) {
101             error(Messages.getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e); //$NON-NLS-1$
102
return false;
103         } catch (IOException JavaDoc e) {
104             error(Messages.getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e); //$NON-NLS-1$
105
return false;
106         }
107     }
108 }
109
Popular Tags