Source Code Cross Referenced for CSVDataExportTask.java in  » Report » pentaho-report » org » jfree » report » modules » gui » csv » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.jfree.report.modules.gui.csv 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ===========================================
003:         * JFreeReport : a free Java reporting library
004:         * ===========================================
005:         *
006:         * Project Info:  http://reporting.pentaho.org/
007:         *
008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either version 2.1 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         *
022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023:         * in the United States and other countries.]
024:         *
025:         * ------------
026:         * CSVDataExportTask.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.modules.gui.csv;
030:
031:        import java.io.BufferedWriter;
032:        import java.io.File;
033:        import java.io.FileOutputStream;
034:        import java.io.IOException;
035:        import java.io.OutputStreamWriter;
036:        import java.io.Writer;
037:
038:        import org.jfree.report.JFreeReport;
039:        import org.jfree.report.ReportInterruptedException;
040:        import org.jfree.report.ReportProcessingException;
041:        import org.jfree.report.modules.gui.common.StatusListener;
042:        import org.jfree.report.modules.gui.commonswing.ReportProgressDialog;
043:        import org.jfree.report.modules.gui.commonswing.StatusType;
044:        import org.jfree.report.modules.gui.commonswing.SwingGuiContext;
045:        import org.jfree.report.modules.output.csv.CSVProcessor;
046:        import org.jfree.report.util.i18n.Messages;
047:        import org.jfree.util.Log;
048:
049:        /**
050:         * An export task implementation that writes an report into a CSV file, and uses the raw
051:         * target to create layouted content.
052:         *
053:         * @author Thomas Morgner
054:         */
055:        public class CSVDataExportTask implements  Runnable {
056:            /**
057:             * Provides access to externalized strings
058:             */
059:            private Messages messages;
060:            /**
061:             * The name of the output file.
062:             */
063:            private final String fileName;
064:            /**
065:             * The encoding to be used for the file.
066:             */
067:            private final String encoding;
068:            /**
069:             * The report that should be exported.
070:             */
071:            private final JFreeReport report;
072:            private ReportProgressDialog progressDialog;
073:            private StatusListener statusListener;
074:
075:            /**
076:             * Creates a new CSV export task.
077:             *
078:             * @param report          the report that should be exported.
079:             * @param dialog          the progress dialog to inform the user about the report progress.
080:             * @param swingGuiContext the context connecting the task to the outside UI.
081:             */
082:            public CSVDataExportTask(final JFreeReport report,
083:                    final ReportProgressDialog dialog,
084:                    final SwingGuiContext swingGuiContext)
085:                    throws ReportProcessingException {
086:                if (report == null) {
087:                    throw new NullPointerException(
088:                            "CSVDataExportTask(..): Report parameter cannot be null"); //$NON-NLS-1$
089:                }
090:
091:                final String filename = report.getConfiguration()
092:                        .getConfigProperty(
093:                                "org.jfree.report.modules.gui.csv.FileName"); //$NON-NLS-1$
094:                if (filename == null) {
095:                    throw new ReportProcessingException(
096:                            "CSVDataExportTask(..): Configuration does not contain a valid filename"); //$NON-NLS-1$
097:                }
098:
099:                this .encoding = report.getConfiguration().getConfigProperty(
100:                        CSVDataExportDialog.CSV_OUTPUT_ENCODING,
101:                        CSVDataExportDialog.CSV_OUTPUT_ENCODING_DEFAULT);
102:                this .fileName = filename;
103:                this .report = report;
104:                this .progressDialog = dialog;
105:                if (swingGuiContext != null) {
106:                    this .statusListener = swingGuiContext.getStatusListener();
107:                    this .messages = new Messages(swingGuiContext.getLocale(),
108:                            CSVDataExportPlugin.BASE_RESOURCE_CLASS);
109:                }
110:            }
111:
112:            /**
113:             * Exports the report into a CSV file.
114:             */
115:            public void run() {
116:                Writer out = null;
117:                final File file = new File(fileName);
118:                try {
119:                    final File directory = file.getAbsoluteFile()
120:                            .getParentFile();
121:                    if (directory != null) {
122:                        if (directory.exists() == false) {
123:                            if (directory.mkdirs() == false) {
124:                                Log
125:                                        .warn("Can't create directories. Hoping and praying now.."); //$NON-NLS-1$
126:                            }
127:                        }
128:                    }
129:
130:                    out = new BufferedWriter(new OutputStreamWriter(
131:                            new FileOutputStream(file), encoding));
132:
133:                    final CSVProcessor target = new CSVProcessor(report);
134:                    if (progressDialog != null) {
135:                        progressDialog.setModal(false);
136:                        progressDialog.setVisible(true);
137:                        target.addReportProgressListener(progressDialog);
138:                    }
139:                    target.setWriter(out);
140:                    target.processReport();
141:                    out.close();
142:                    out = null;
143:
144:                    if (progressDialog != null) {
145:                        target.removeReportProgressListener(progressDialog);
146:                    }
147:
148:                    if (statusListener != null) {
149:                        statusListener
150:                                .setStatus(
151:                                        StatusType.INFORMATION,
152:                                        messages
153:                                                .getString("CSVRawExportTask.USER_TASK_COMPLETE")); //$NON-NLS-1$
154:                    }
155:                } catch (ReportInterruptedException re) {
156:                    if (statusListener != null) {
157:                        statusListener
158:                                .setStatus(
159:                                        StatusType.INFORMATION,
160:                                        messages
161:                                                .getString("CSVRawExportTask.USER_TASK_ABORTED")); //$NON-NLS-1$
162:                    }
163:                    try {
164:                        out.close();
165:                        out = null;
166:                        if (file.delete() == false) {
167:                            Log
168:                                    .warn(new Log.SimpleMessage(
169:                                            "Unable to delete incomplete export:", file)); //$NON-NLS-1$
170:                        }
171:                    } catch (SecurityException se) {
172:                        // ignore me
173:                    } catch (IOException ioe) {
174:                        // ignore me...
175:                    }
176:                } catch (Exception re) {
177:                    Log.error("Exporting failed .", re); //$NON-NLS-1$
178:                    if (statusListener != null) {
179:                        statusListener
180:                                .setStatus(
181:                                        StatusType.ERROR,
182:                                        messages
183:                                                .getString("CSVRawExportTask.USER_TASK_FAILED")); //$NON-NLS-1$
184:                    }
185:                } finally {
186:                    try {
187:                        if (out != null) {
188:                            out.close();
189:                        }
190:                    } catch (Exception e) {
191:                        if (statusListener != null) {
192:                            statusListener
193:                                    .setStatus(
194:                                            StatusType.ERROR,
195:                                            messages
196:                                                    .getString("CSVRawExportTask.USER_TASK_FAILED")); //$NON-NLS-1$
197:                        }
198:                        Log.error("Unable to close the output stream.", e); //$NON-NLS-1$
199:                    }
200:
201:                    if (progressDialog != null) {
202:                        progressDialog.setVisible(false);
203:                    }
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.