// fileChooser.addChoosableFileFilter(rtfSaveContrib);
// } catch (Exception ex) {
// ex.printStackTrace();
// }
JRSaveContributor htmlSaver = null;
try {
Class htmlSaverClass = JRClassLoader
.loadClassForName("net.sf.jasperreports.view.save.JRHtmlSaveContributor");
htmlSaver = (JRSaveContributor) htmlSaverClass.newInstance();
fileChooser.addChoosableFileFilter(htmlSaver);
} catch (Exception e) {
e.printStackTrace();
}
JRSaveContributor csvSaver = null;
try {
Class csvSaverClass = JRClassLoader
.loadClassForName("net.sf.jasperreports.view.save.JRCsvSaveContributor");
csvSaver = (JRSaveContributor) csvSaverClass.newInstance();
fileChooser.addChoosableFileFilter(csvSaver);
} catch (Exception e) {
e.printStackTrace();
}
JRPdfSaveContributor pdfSaveContrib = null;
try {
// Class pdfSaveContribClass = JRClassLoader
// .loadClassForName("net.sf.jasperreports.view.save.JRPdfSaveContributor");
pdfSaveContrib = new JRPdfSaveContributor(null, null);
// pdfSaveContrib = (JRSaveContributor) pdfSaveContribClass
// .newInstance();
fileChooser.addChoosableFileFilter(pdfSaveContrib);
} catch (Exception e) {
e.printStackTrace();
}
int retValue = fileChooser.showSaveDialog(this);
if (retValue == JFileChooser.APPROVE_OPTION) {
FileFilter fileFilter = fileChooser.getFileFilter();
File file = fileChooser.getSelectedFile();
String lowerCaseFileName = file.getName().toLowerCase();
try {
if (fileFilter instanceof JRSaveContributor) {
((JRSaveContributor) fileFilter).save(jasperPrint, file);
} else {
if (lowerCaseFileName.endsWith(".jrprint")) {
JRSaver.saveObject(jasperPrint, file);
} else if (lowerCaseFileName.endsWith(".pdf")
&& pdfSaveContrib != null) {
pdfSaveContrib.save(jasperPrint, file);
} else if ((lowerCaseFileName.endsWith(".html") || lowerCaseFileName
.endsWith(".htm"))
&& htmlSaver != null) {
htmlSaver.save(jasperPrint, file);
} else if (lowerCaseFileName.endsWith(".csv")
&& csvSaver != null) {
csvSaver.save(jasperPrint, file);
} else {
// if (!file.getName().endsWith(".jrprint")) {
// file = new File(file.getAbsolutePath() + ".jrprint");
// }