Reputation: 647
We recently integrated jasper report to our system. Now we can run report and show result to users with jasper report via standard way, run and show result to user.
But in some cases we need to save result to an object storage and show user when requested, as a document. As far as I know JasperPrint
is a serialized object. saving report result to object storage as a serialized object is not a good way as we experienced our prior report tool. if the object changed the serialization mechanism could not deserialize object.
So we want to save jasper result in xml format to object storage but we couldn't find any way to show exported xml in JRViewer
.
Is there any way to convert exported xml to a visual form?
Upvotes: 1
Views: 1903
Reputation: 21710
Jasper Report provides two method's for saving and loading your filled report, JasperPrint
(note: excluding export's to other formats as pdf,xls ecc, since it would be very difficult to load and export to another format).
With courtesy of @Robert Mugattarov, What is the difference between JasperReport formats?
.jrprint is a serialized JasperPrint object i.e. an actual report instance i.e. a template that has been filled with data. This file can be deserialized back into a JasperPrint object.
.jrpxml is a human readable XML represenatation of a JasperPrint object i.e. an XML version of a template that has been filled with data. This file can be unmarshalled back into a JasperPrint object.
Since you do not wish do have a serialized object, the solution that remains is the jrpxml
format in xml.
Example of saving and loading to jrpxml
.
//Save JasperPrint to jrpxml (xml format)
JRXmlExporter exporter = new JRXmlExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleWriterExporterOutput(new File("myJasperPrint.jrpxml")));
exporter.exportReport();
//Load jrpxml to JasperPrint object
JasperPrint print = JRPrintXmlLoader.load("myJasperPrint.jrpxml");
//To show it in JasperViewer
JRViewer jrv = new JRViewer(print);
If you need to reduce file size I suggest that you zip/unzip the jrpxml
file.
What is a good Java library to zip/unzip files?
Upvotes: 1