1 30 31 package it.businesslogic.ireport.examples; 32 33 import it.businesslogic.ireport.connection.JRXMLDataSource; 34 import net.sf.jasperreports.engine.export.JRPdfExporter; 35 36 import net.sf.jasperreports.engine.*; 37 import java.util.HashMap ; 38 39 40 public class XMLDataSourceExample { 41 42 public static void main(String [] args) throws Exception { 43 44 String reportFileName = "/addressbook.jasper"; 45 String outFileName = "/addressbook.pdf"; 46 String xmlFileName = "/addressbook.xml"; 47 String recordPath = "/addressbook/category/person"; 48 49 JRXMLDataSource jrxmlds = new JRXMLDataSource(xmlFileName,recordPath); 50 51 HashMap hm = new HashMap (); 52 53 try 54 { 55 JasperPrint print = JasperFillManager.fillReport( 56 reportFileName, 57 hm, 58 jrxmlds); 59 60 JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter(); 61 62 exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,outFileName); 63 exporter.setParameter(JRExporterParameter.JASPER_PRINT,print); 64 65 exporter.exportReport(); 66 System.out.println("Created file: " + outFileName); 67 } 68 catch (JRException e) 69 { 70 e.printStackTrace(); 71 System.exit(1); 72 } 73 catch (Exception e) 74 { 75 e.printStackTrace(); 76 System.exit(1); 77 } 78 79 } 80 81 } 82 83 84 | Popular Tags |