1 28 package net.sf.jasperreports.view.save; 29 30 import java.io.File ; 31 import java.text.MessageFormat ; 32 33 import javax.swing.JOptionPane ; 34 35 import net.sf.jasperreports.engine.JRException; 36 import net.sf.jasperreports.engine.JRExporterParameter; 37 import net.sf.jasperreports.engine.JasperPrint; 38 import net.sf.jasperreports.engine.export.JRXmlExporter; 39 import net.sf.jasperreports.engine.export.JRXmlExporterParameter; 40 import net.sf.jasperreports.view.JRSaveContributor; 41 42 46 public class JREmbeddedImagesXmlSaveContributor extends JRSaveContributor 47 { 48 49 52 private static final String EXTENSION_XML = ".xml"; 53 private static final String EXTENSION_JRPXML = ".jrpxml"; 54 public static final JREmbeddedImagesXmlSaveContributor INSTANCE = new JREmbeddedImagesXmlSaveContributor(); 55 56 59 public static JREmbeddedImagesXmlSaveContributor getInstance() 60 { 61 return INSTANCE; 62 } 63 64 67 public boolean accept(File file) 68 { 69 if (file.isDirectory()) 70 { 71 return true; 72 } 73 String name = file.getName().toLowerCase(); 74 return (name.endsWith(EXTENSION_XML) || name.endsWith(EXTENSION_JRPXML)); 75 } 76 77 80 public String getDescription() 81 { 82 return "Embedded images XML (*.jrpxml, *.xml)"; 83 } 84 85 88 public void save(JasperPrint jasperPrint, File file) throws JRException 89 { 90 if ( 91 !file.getName().endsWith(EXTENSION_XML) 92 && !file.getName().endsWith(EXTENSION_JRPXML) 93 ) 94 { 95 file = new File (file.getAbsolutePath() + EXTENSION_JRPXML); 96 } 97 98 if ( 99 !file.exists() || 100 JOptionPane.OK_OPTION == 101 JOptionPane.showConfirmDialog( 102 null, 103 MessageFormat.format( 104 java.util.ResourceBundle.getBundle("net/sf/jasperreports/view/viewer").getString("file.exists"), 105 new Object []{file.getName()} 106 ), 107 java.util.ResourceBundle.getBundle("net/sf/jasperreports/view/viewer").getString("save"), 108 JOptionPane.OK_CANCEL_OPTION 109 ) 110 ) 111 { 112 JRXmlExporter exporter = new JRXmlExporter(); 113 exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 114 exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file); 115 exporter.setParameter(JRXmlExporterParameter.IS_EMBEDDING_IMAGES, Boolean.TRUE); 116 exporter.exportReport(); 117 } 118 } 119 120 } 121 | Popular Tags |