Futuramente irei demonstrar como alterar DataSource e DataSet em tempo de execuçao.
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Class description
*
*/
public class BuildRelatorio extends HttpServlet {
/** Field description */
private static final long serialVersionUID = 1L;
protected static Logger logger =
Logger.getLogger("org.eclipse.birt");
/**
*
*/
private Connection currentConnection = null;
/**
* Constructor of the object.
*/
private IReportEngine birtReportEngine = null;
/** Field description */
private ObjRelatorio ObjRel;
/**
* Constructs ...
*
*/
public BuildRelatorio() {
super();
}
/**
* Destruction of the servlet.
*
*/
public void destroy() {
super.destroy();
BirtEngine.destroyBirtEngine();
}
/**
* The doGet method of the servlet.
*
* @param req
* @param resp
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
// get report name and launch the engine
resp.setContentType("text/html");
// resp.setContentType( "application/pdf" );
ServletContext sc = req.getSession().
getServletContext();
this.birtReportEngine = BirtEngine.
getBirtEngine(sc);
// setup image directory
HTMLRenderContext renderContext =
new HTMLRenderContext();
String pastaImagens = "pastaImagens";
renderContext.setBaseImageURL(pastaImagens);
renderContext.setImageDirectory(pastaImagens);
logger.log(Level.FINE, pastaImagens);
HashMapcontextMap = Esta parte sera descrita em um post futuro
new HashMap();
contextMap.put(EngineConstants.
APPCONTEXT_HTML_RENDER_CONTEXT, renderContext);
IReportRunnable design;
try {
// Open report design
String reportName = "N";
design = birtReportEngine.
openReportDesign(reportName);
//
//designFactory(design);
// create task to run and render report
IRunAndRenderTask task =
birtReportEngine.createRunAndRenderTask(
design);
task.setAppContext(contextMap);
// set output options
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(HTMLRenderOption.
OUTPUT_FORMAT_HTML);
// options.setOutputFormat(HTMLRenderOption.
OUTPUT_FORMAT_PDF);
options.setOutputStream(resp.getOutputStream());
task.setRenderOption(options);
// run report
task.run();
task.close();
} catch (Exception e) {
e.printStackTrace();
throw new ServletException(e);
}
}
/**
* The doPost method of the servlet. *
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("CODIGOS HTML");
}
/**
* Initialization of the servlet.
*
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
BirtEngine.initBirtConfig();
}
}