|
From: <mic...@us...> - 2003-11-24 09:01:23
|
Update of /cvsroot/babeldoc/babeldoc/modules/jfreereports/src/com/babeldoc/jfreereports/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv5852/modules/jfreereports/src/com/babeldoc/jfreereports/pipeline/stage
Modified Files:
Tag: TEMP_MIKEA
JFRPipelineStage.java
Log Message:
Added some debug logging to a few classes
Index: JFRPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/jfreereports/src/com/babeldoc/jfreereports/pipeline/stage/Attic/JFRPipelineStage.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** JFRPipelineStage.java 21 Nov 2003 09:17:04 -0000 1.1.2.2
--- JFRPipelineStage.java 24 Nov 2003 09:01:19 -0000 1.1.2.3
***************
*** 92,95 ****
--- 92,98 ----
import java.util.Collection;
import java.util.Iterator;
+ import java.io.FileInputStream;
+ import java.io.InputStream;
+ import java.io.StringReader;
import javax.swing.table.DefaultTableModel;
***************
*** 107,110 ****
--- 110,115 ----
import org.jfree.report.modules.output.pageable.pdf.PDFReportUtil;
+ import org.xml.sax.InputSource;
+
/**
* @author mikea
***************
*** 159,195 ****
// Find the report definition
String xmlReportDefinition = getReportDefinition();
- File f = new File(System.getProperties().get("java.io.tmpdir") + "/tmprpt.xml");
- try {
- FileWriter writer = new FileWriter(f);
- writer.write(xmlReportDefinition);
- writer.flush();
- writer.close();
- } catch (java.io.IOException e) {
- log.logError(e);
- }
-
- // Set up the table model
- TableModel tm = null;
- try {
- tm = getTableModel();
- } catch (DocumentException e) {
- log.logError(e);
- }
- ReportGenerator gen = ReportGenerator.getInstance();
JFreeReport report = null;
try {
! report = gen.parseReport(f);
! } catch (java.io.IOException e) {
! log.logError(e);
} catch (org.jfree.xml.ElementDefinitionException e2) {
log.logError(e2);
}
! report.setData(tm);
!
! PDFReportUtil.createPDF(report, System.getProperties().get("java.io.tmpdir") + "/output.pdf");
!
! // TODO Auto-generated method stub
! return null;
}
--- 164,210 ----
// Find the report definition
String xmlReportDefinition = getReportDefinition();
JFreeReport report = null;
+ String outputFile = null;
try {
! // Set up the table model
! TableModel tm = getTableModel();
! // Create a report with the correct definition
! StringReader reader = new StringReader (xmlReportDefinition);
! URL contentBaseURL = new URL ("file:///");
! report = ReportGenerator.getInstance().parseReport(new InputSource(reader), contentBaseURL);
! // Put the data in
! report.setData(tm);
! // Generate the report output
! outputFile = getTempFilename() + ".pdf";
! PDFReportUtil.createPDF(report, outputFile);
! } catch (java.net.MalformedURLException e1) {
! // From new URL()
! log.logError(e1);
! throw new PipelineException(I18n.get("jfr.105"), e1);
} catch (org.jfree.xml.ElementDefinitionException e2) {
+ // From parseReport()
log.logError(e2);
+ throw new PipelineException(I18n.get("jfr.106"), e2);
+ } catch (DocumentException e3) {
+ // From getTableModel()
+ log.logError(e3);
+ throw new PipelineException(I18n.get("jfr.107"), e3);
}
!
! PipelineDocument newDocument = null;
! if (outputFile == null || outputFile.equals("")) {
! try {
! byte[] data = getBytesFromFile(new File(outputFile));
! newDocument = new PipelineDocument(this.getDocument(), data);
! newDocument.setBinary(true);
! newDocument.setMimeType("application/pdf");
! } catch (java.io.IOException e) {
! log.logError(e);
! throw new PipelineException(I18n.get("jfr.108"), e);
! }
!
! }
! return super.processHelper(newDocument);
}
***************
*** 262,265 ****
--- 277,318 ----
tm.setDocument(doc);
return (tm);
+ }
+ // Returns the contents of the file in a byte array.
+ public byte[] getBytesFromFile(File file) throws IOException {
+ InputStream is = new FileInputStream(file);
+
+ // Get the size of the file
+ long length = file.length();
+
+ // You cannot create an array using a long type.
+ // It needs to be an int type.
+ // Before converting to an int type, check
+ // to ensure that file is not larger than Integer.MAX_VALUE.
+ if (length > Integer.MAX_VALUE) {
+ // File is too large
+ }
+
+ // Create the byte array to hold the data
+ byte[] bytes = new byte[(int)length];
+
+ // Read in the bytes
+ int offset = 0;
+ int numRead = 0;
+ while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
+ offset += numRead;
+ }
+
+ // Ensure all the bytes have been read in
+ if (offset < bytes.length) {
+ throw new IOException("Could not completely read file "+file.getName());
+ }
+
+ // Close the input stream and return bytes
+ is.close();
+ return bytes;
+ }
+
+ private String getTempFilename() {
+ return ("tempfile");
}
}
|