1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
package com.hps.reporting.jasper;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;
import com.hps.reporting.JRGenerator;
public class JRGeneratorImpl implements JRGenerator {
private String reportsLocation;
private String genLocation;
public JRGeneratorImpl() {
}
public void generate(String report, String format, Map<String, Object> map) {
System.out.println("generate the report [" + report
+ "], with the format [" + format + "]");
doPdf(report, map);
System.out.println("END OF PRINTING ...");
}
private void doPdf(String report, Map<String, Object> map) {
map = new HashMap<String, Object>();
//String classpath = JRGeneratorImpl.class.getResource("/").getPath();
//System.out.println("GET PATH : " + classpath);
try {
ServletContext context;
JasperRunManager.runReportToPdfFile(
//c'est là ou je plente, j'arrive pas a définir le bon chemin de mon fichier jasper
reportsLocation + "/" + "myReport.jasper",
genLocation + "/myReport.pdf",
map,
new JREmptyDataSource()
);
} catch (JRException e) {
System.out.println(e.getMessage());
e.getStackTrace();
}
}
public void setReportsLocation(String reportsLocation) {
this.reportsLocation = reportsLocation;
}
public void setGenLocation(String genLocation) {
this.genLocation = genLocation;
}
} |
Partager