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.JRRtfExporter; 39 import net.sf.jasperreports.view.JRSaveContributor; 40 41 45 public class JRRtfSaveContributor extends JRSaveContributor 46 { 47 48 51 private static final String EXTENSION_RTF = ".rtf"; 52 public static final JRRtfSaveContributor INSTANCE = new JRRtfSaveContributor(); 53 54 57 public static JRRtfSaveContributor getInstance() 58 { 59 return INSTANCE; 60 } 61 62 65 public boolean accept(File file) 66 { 67 if(file.isDirectory()){ 68 return true; 69 } 70 return file.getName().toLowerCase().endsWith(EXTENSION_RTF); 71 } 72 73 74 77 public String getDescription() 78 { 79 return "RTF (*.rtf)"; 80 } 81 82 85 public void save(JasperPrint jasperPrint, File file) throws JRException 86 { 87 if(!file.getName().endsWith(EXTENSION_RTF)) 88 { 89 file = new File (file.getAbsolutePath() + EXTENSION_RTF); 90 } 91 92 if ( 93 !file.exists() || 94 JOptionPane.OK_OPTION == 95 JOptionPane.showConfirmDialog( 96 null, 97 MessageFormat.format( 98 java.util.ResourceBundle.getBundle("net/sf/jasperreports/view/viewer").getString("file.exists"), 99 new Object []{file.getName()} 100 ), 101 java.util.ResourceBundle.getBundle("net/sf/jasperreports/view/viewer").getString("save"), 102 JOptionPane.OK_CANCEL_OPTION 103 ) 104 ) 105 { 106 JRRtfExporter exporter = new JRRtfExporter(); 107 exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 108 exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file); 109 exporter.exportReport(); 110 } 111 } 112 } 113 | Popular Tags |