karurkarthi / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

XDocReport dump (generates Java Main instead of the report) #314

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When XDocReport is used in an Application on production mode and there are some 
problems (reports crashes, report is not the waited report, etc), its very hard 
for the developer to produce the same problem in her local computer (he must 
retrieve the same docx/odt and the same data which can be hard to retrieve).

The "XDocReport CodeGen" feature will provide the capability to generates a 
Java Main file instead of the report. This Java Main will contains : 

1) the docx template as string (encoded with 64 binary).
2) the Java Pojo context as JSON string.

Today we have : 

 * IXDocReport#process which generates the report.
 * IXDocReport#convert which generates and convert the report.

The codegen could be called with new methods like IXDocReport#codegen.

The codegen "template" could use Velocity and Feeemarker templates to generate 
Java main class.

Take a sample : 

------------------------------------------------
InputStream in = 
DocxProjectWithVelocity.class.getResourceAsStream("DocxProjectWithVelocity.docx"
);
IXDocReport report = 
XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);

IContext context = report.createContext();
Project project = new Project("XDocReport");
context.put("project", project);

OutputStream out = new FileOutputStream(new 
File("DocxProjectWithVelocity_Out.java"));
report.gencode(context, out);
------------------------------------------------

This code will geneates a Java Main DocxProjectWithVelocity_Out.java like this 
: 

--------------------------------------------------------------
package xxx;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import fr.opensagres.xdocreport.core.XDocReportException;
import fr.opensagres.xdocreport.document.IXDocReport;
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
import fr.opensagres.xdocreport.samples.docxandvelocity.model.Project;
import fr.opensagres.xdocreport.template.IContext;
import fr.opensagres.xdocreport.template.TemplateEngineKind;
import fr.opensagres.xdocreport.core.utils.Base64Utility
import fr.opensagres.xdocreport.remoting.reporting.json.JSONObject;

public class DocxProjectWithVelocity {

  public static void main(String[] args) {
    try {
      InputStream in = new ByteArryInputStream(Base64Utility.decode("docx as base 64")).
      IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);

      // 2) Create context Java model
      String json = "{\"project\" : {\"name\" : \"XDocReport\"}}";
      Map context = new JSONObject( json );

      // 3) Generate report by merging Java model with the Docx
      OutputStream out = new FileOutputStream(new File("DocxProjectWithVelocity_Out.docx"));
      report.process(context, out);

    } catch (IOException e) {
      e.printStackTrace();
    } catch (XDocReportException e) {
      e.printStackTrace();
    }
  }
}
--------------------------------------------------------------

Original issue reported on code.google.com by angelo.z...@gmail.com on 8 Oct 2013 at 1:58

GoogleCodeExporter commented 9 years ago
dum should be a better name I think instead of codegen.

We could have several dump implementation to ::

1) generate dump with just Java main class.
2)generate a zip which contains the Java main, JSON data, XMLfields available, 
docx/odt
3) generate the same zip but with Eclipse .project 

Original comment by angelo.z...@gmail.com on 8 Oct 2013 at 7:21

GoogleCodeExporter commented 9 years ago

Original comment by angelo.z...@gmail.com on 8 Oct 2013 at 8:17

GoogleCodeExporter commented 9 years ago
Available for 1.0.3

Read wiki at https://code.google.com/p/xdocreport/wiki/XDocReportDumper

Original comment by angelo.z...@gmail.com on 24 Oct 2013 at 12:04

GoogleCodeExporter commented 9 years ago
cleanup

Original comment by pascal.leclercq on 10 Oct 2014 at 7:37