[jboss-svn-commits] JBL Code SVN: r8083 - in labs/reportingservices/trunk/dev/modules/extensions: . birtreport birtreport/src birtreport/src/main birtreport/src/main/java birtreport/src/main/java/org birtreport/src/main/java/org/jboss birtreport/src/main/java/org/jboss/reporting birtreport/src/main/java/org/jboss/reporting/server birtreport/src/main/java/org/jboss/reporting/server/deployer birtreport/src/main/java/org/jboss/reporting/server/engine birtreport/src/main/resources birtreport/src/main/resources/META-INF
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 6 04:40:31 EST 2006
Author: noel.rocher at jboss.com
Date: 2006-12-06 04:40:27 -0500 (Wed, 06 Dec 2006)
New Revision: 8083
Added:
labs/reportingservices/trunk/dev/modules/extensions/birtreport/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/pom.xml
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/deployer/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReport.java
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReportMBean.java
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/resources/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/resources/META-INF/
labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/resources/META-INF/jboss-service.xml
Log:
Added: labs/reportingservices/trunk/dev/modules/extensions/birtreport/pom.xml
===================================================================
--- labs/reportingservices/trunk/dev/modules/extensions/birtreport/pom.xml 2006-12-06 09:39:23 UTC (rev 8082)
+++ labs/reportingservices/trunk/dev/modules/extensions/birtreport/pom.xml 2006-12-06 09:40:27 UTC (rev 8083)
@@ -0,0 +1,200 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>jboss.reportingservices</groupId>
+ <artifactId>engine</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ </parent>
+
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>engine-BIRT</artifactId>
+ <name>Engine - BIRT</name>
+ <packaging>sar</packaging>
+
+ <dependencies>
+ <!-- internal dependencies -->
+ <dependency>
+ <groupId>jboss.reportingservices</groupId>
+ <artifactId>reporting-services-common</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss.reportingservices</groupId>
+ <artifactId>server-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss.reportingservices</groupId>
+ <artifactId>reporting-services-client-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+
+ <!-- JBoss dependencies will be provided at runtime no need to bundle them -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-system</artifactId>
+ <version>4.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-remoting</artifactId>
+ <version>1.4.1_final</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-serialization</artifactId>
+ <version>1.0.3.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common</artifactId>
+ <version>4.0.2</version>
+ <scope>provided</scope>
+ </dependency>
+
+
+ <!-- BIRT DEPENDENCIES -->
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>chartengine</artifactId>
+ <version>2.2.0.v20061014-0630</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>coreapi</artifactId>
+ <version>2.2M1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>dataadapterapi</artifactId>
+ <version>2.2M1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>engineapi</artifactId>
+ <version>2.2M1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>modelapi</artifactId>
+ <version>2.2M1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>scriptapi</artifactId>
+ <version>2.2M1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.birt</groupId>
+ <artifactId>dteapi</artifactId>
+ <version>2.2M1</version>
+ </dependency>
+
+ <!-- EMF (Eclipse Modeling Framework ) -->
+ <dependency>
+ <groupId>org.eclipse.emf.ecore</groupId>
+ <artifactId>org.eclipse.emf.ecore</artifactId>
+ <version>2.2.1.v200609210005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.emf.ecore.xmi</groupId>
+ <artifactId>org.eclipse.emf.ecore.xmi</artifactId>
+ <version>2.2.1.v200609210005</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.emf.common</groupId>
+ <artifactId>org.eclipse.emf.common</artifactId>
+ <version>2.2.1.v200609210005</version>
+ </dependency>
+
+ <!-- W3C -->
+ <dependency>
+ <groupId>org.w3c</groupId>
+ <artifactId>flute</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.w3c</groupId>
+ <artifactId>sac</artifactId>
+ <version>1.3</version>
+ </dependency>
+
+ <!-- Commons -->
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ <!-- removing unwanted transitive dependencies -->
+ <exclusions>
+ <exclusion>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.0</version>
+ <!-- removing unwanted transitive dependencies -->
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-lang</artifactId>
+ <groupId>commons-lang</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-discovery</groupId>
+ <artifactId>commons-discovery</artifactId>
+ <version>0.2</version>
+ </dependency>
+ <!-- misc -->
+ <dependency>
+ <groupId>com.lowagie</groupId>
+ <artifactId>itext</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm</groupId>
+ <artifactId>icu</artifactId>
+ <version>3.4.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mozilla.rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.6R1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jboss-sar-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java 2006-12-06 09:39:23 UTC (rev 8082)
+++ labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java 2006-12-06 09:40:27 UTC (rev 8083)
@@ -0,0 +1,265 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.reporting.server.deployer;
+
+import java.io.File;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.ObjectName;
+
+//import org.eclipse.birt.report.engine.api.IReportDocument;
+import org.jboss.deployment.DeploymentException;
+import org.jboss.deployment.DeploymentInfo;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.reporting.api.Report;
+import org.jboss.reporting.server.ReportInfo;
+import org.jboss.reporting.server.engine.ReportEngineMBean;
+import org.jboss.reporting.server.repository.RepositoryEntry;
+
+/**
+ * This deployer compiles a BIRT Report xml design and puts the result into the
+ * repository
+ *
+ * @jmx:mbean name="reporting:service=ReportsDeployer,type=RPTDESIGN" extends="org.jboss.deployment.SubDeployerMBean"
+ *
+ * @version <tt>$Revision: 1.0 $</tt>
+ * @author <a href="mailto:noel.rocher at jboss.org">Noel Rocher</a>
+ */
+public class DeployerRPTDESIGN extends AbstractReportDeployer implements DeployerRPTDESIGNMBean
+{
+
+ private static final ObjectName OBJECT_NAME = ObjectNameFactory.create("reporting:service=ReportsDeployer,type=RPTDESIGN");
+
+ private ReportEngineMBean engine;
+
+ private ObjectName reportEngine;
+
+ protected ObjectName getObjectName(MBeanServer server, ObjectName name) throws MalformedObjectNameException
+ {
+ return name == null ? OBJECT_NAME : name;
+ }
+
+ /**
+ * Get the value of ReportEngine.
+ *
+ * @jmx:managed-attribute
+ * @return value of ReportEngine.
+ */
+ public ObjectName getReportEngine()
+ {
+ return reportEngine;
+ }
+
+ /**
+ * Set the value of ReportEngine.
+ *
+ * @jmx:managed-attribute
+ * @param v
+ * Value to assign to ReportEngine.
+ */
+ public void setReportEngine(ObjectName objectName)
+ {
+ this.reportEngine = objectName;
+ }
+
+ /**
+ * Gets a reference to the JasperReports Engine MBean
+ */
+ protected void startService() throws Exception
+ {
+ engine = (ReportEngineMBean) MBeanProxyExt.create(ReportEngineMBean.class, reportEngine, server);
+
+ // register with MainDeployer
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+ // deregister with MainDeployer
+ super.stopService();
+ engine = null;
+ }
+
+ /**
+ * accepts xxx.rptdesign files
+ */
+ public boolean accepts(DeploymentInfo di)
+ {
+ // To be accepted the deployment's root name must end in jar
+ String urlStr = di.url.getFile();
+ if (!urlStr.toUpperCase().endsWith("RPTDESIGN"))
+ {
+ return false;
+ }
+ else
+ {
+ log.debug("accepts> url=" + di.url + ", accepted=" + true);
+ return true;
+ }
+ }
+
+ /**
+ * initialize the URL to be watched
+ */
+ public void init(DeploymentInfo di) throws DeploymentException
+ {
+ log.info("init, " + di.shortName);
+
+ try
+ {
+ di.watch = di.url;
+ log.info("Watch file : " + di.url);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof DeploymentException) throw (DeploymentException) e;
+ throw new DeploymentException("failed to initialize", e);
+ }
+
+ // invoke super-class initialization
+ di.isXML = true;
+ super.init(di);
+ }
+
+ /**
+ * <li>compile the report</li>
+ * <li>bind or rebind it into the JNDI tree</li>
+ */
+ public synchronized void start(DeploymentInfo di) throws DeploymentException
+ {
+ super.start(di);
+// try
+// {
+// ObjectName engineName = new ObjectName("reporting:service=ReportEngine,type=" + di.shortName.substring(di.shortName.lastIndexOf('.') + 1).toUpperCase());
+// IReportDocument report = (IReportDocument) engine.compile(new java.io.FileInputStream(di.url.getFile()), engineName);
+// String jndi_name = toJndiName(di.shortName);
+// String jndi_path = DEFAULT_DOMAIN;
+// repository.put(jndi_path + "/" + jndi_name, new RepositoryEntry(report, engineName));
+//
+// // build the ReportInfo for notification
+// ReportInfo ri = new ReportInfo();
+// ri.setFile(new File(di.url.getFile()));
+//
+// Report r = new Report();
+// r.setReport_name(jndi_name);
+// r.setReport_path(jndi_path);
+// /*
+// * JRParameter[] jr_params = report.getParameters(); if (jr_params !=
+// * null && jr_params.length > 0) { Map parameters = new
+// * java.util.HashMap(jr_params.length); for (int i=0; i <
+// * jr_params.length ; i++ ) { if (jr_params[i].isForPrompting()) {
+// * parameters.put(jr_params[i].getName(),
+// * jr_params[i].getDescription()); } } r.setParameters(parameters); }
+// */
+//
+// ri.setReport(r);
+//
+// // Issue the DeployerJRXML.ADD_REPORT_NOTIFICATION
+// Notification msg = new Notification(AbstractReportDeployer.ADD_REPORT_NOTIFICATION, this, getNextNotificationSequenceNumber());
+// msg.setUserData(ri);
+// sendNotification(msg);
+// }
+// catch (Exception e)
+// {
+// log.error(e.getMessage());
+// }
+
+ }
+
+ /**
+ * <li>unbind the report from the JNDI tree</li>
+ */
+ public void stop(DeploymentInfo di) throws DeploymentException
+ {
+ super.stop(di);
+ try
+ {
+ String jndi_name = toJndiName(di.shortName);
+ String jndi_path = DEFAULT_DOMAIN;
+ repository.remove(jndi_path + "/" + jndi_name);
+ // build the ReportInfo for notification (only jndi path & name are
+ // necessary)
+ ReportInfo ri = new ReportInfo();
+ Report r = new Report();
+ r.setReport_path(jndi_path);
+ r.setReport_name(jndi_name);
+ ri.setReport(r);
+
+ // Issue the DeployerJRXML.REMOVE_REPORT_NOTIFICATION
+ Notification msg = new Notification(AbstractReportDeployer.REMOVE_REPORT_NOTIFICATION, this, getNextNotificationSequenceNumber());
+ msg.setUserData(ri);
+ sendNotification(msg);
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage());
+ }
+ }
+
+ // -----------------------------------------
+
+ // /**
+ // * Bind the report into jndi
+ // */
+ // protected void bindReport(String jndi_path, String jndi_name,JasperReport
+ // report) throws Exception
+ // {
+ // InitialContext ctx = new InitialContext();
+ // try
+ // {
+ // log.debug("Binding object '" + jndi_name + "' into JNDI at 'java:/" +
+ // jndi_path + "/'");
+ // Name name = ctx.getNameParser("").parse(jndi_path+"/"+jndi_name);
+ // NonSerializableFactory.rebind(name, report, true);
+ // log.info("Bound Report '" + jndi_name + " to JNDI name '" + name + "'");
+ // }
+ // catch (NamingException ne)
+ // {
+ // ne.printStackTrace();
+ // throw new DeploymentException("Could not bind Report into jndi: " +
+ // jndi_path + "/" + jndi_name);
+ // }
+ // finally
+ // {
+ // ctx.close();
+ // }
+ // }
+ //
+ // /**
+ // * Unbind the report from jndi
+ // */
+ // protected void unbindReport(String jndi_path, String jndi_name) throws
+ // Exception
+ // {
+ // InitialContext ctx = new InitialContext();
+ // try
+ // {
+ // Name name = ctx.getNameParser("").parse(jndi_path+"/"+jndi_name);
+ // NonSerializableFactory.unbind(name);
+ // ctx.unbind(name);
+ // log.info("Unbound Report '" + jndi_name + " from JNDI name '" + name +
+ // "'");
+ // }
+ // catch (NamingException ne)
+ // {
+ // ne.printStackTrace();
+ // log.error("Could not unbind Report from jndi: " + jndi_path + "/" + jndi_name, ne);
+ // }
+ // finally
+ // {
+ // ctx.close();
+ // }
+ // }
+
+ protected static String toJndiName(String in_string)
+ {
+ return in_string.replaceAll(".rptdesign", "").replaceAll(".RPTDESIGN", "").replaceAll(" ", "_");
+ }
+}
Added: labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReport.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReport.java 2006-12-06 09:39:23 UTC (rev 8082)
+++ labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReport.java 2006-12-06 09:40:27 UTC (rev 8083)
@@ -0,0 +1,264 @@
+package org.jboss.reporting.server.engine;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.logging.Level;
+
+import org.eclipse.birt.core.exception.BirtException;
+import org.eclipse.birt.core.framework.Platform;
+import org.eclipse.birt.report.engine.api.EngineConfig;
+import org.eclipse.birt.report.engine.api.EngineException;
+import org.eclipse.birt.report.engine.api.HTMLRenderOption;
+import org.eclipse.birt.report.engine.api.IRenderOption;
+import org.eclipse.birt.report.engine.api.IRenderTask;
+import org.eclipse.birt.report.engine.api.IReportDocument;
+import org.eclipse.birt.report.engine.api.IReportEngine;
+import org.eclipse.birt.report.engine.api.IReportEngineFactory;
+import org.eclipse.birt.report.engine.api.IReportRunnable;
+import org.eclipse.birt.report.engine.api.IRunTask;
+import org.eclipse.birt.report.engine.api.RenderOptionBase;
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.reporting.api.ReportData;
+import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.system.server.ServerConfigImplMBean;
+
+public class BirtReport extends ServiceMBeanSupport implements BirtReportMBean,ReportEngineModule
+{
+
+ private final Logger log = Logger.getLogger(BirtReport.class);// provide logging
+ private final String BIRT_TEMP_DIR_NAME = "jrs_birt"; // tmp dir name for birt to work
+ /**
+ * The target file name
+ */
+ //protected String targetFile = null;
+ /**
+ /**
+ * the output locale.
+ */
+ protected String locale = "en";
+ /**
+ * the default output format, used in Render and RunAndRender.
+ */
+ protected String format = "PDF"; // The output format, defaults to HTML
+ /**
+ * used to decorate the HTML output, used in Render and RunAndRender mode.
+ */
+ //protected String htmlType = "HTML"; // The type of html
+ /**
+ * the output encoding, used in html format in Render and RunAndRender
+ * modes.
+ */
+ protected String encoding = "utf-8"; // the targe encoding
+ /**
+ * parameters used to execute the report, used in Run and RunAndRender modes.
+ */
+ protected HashMap params = new HashMap( ); // the input params
+ /**
+ * output page number, used in Render mode.
+ */
+ protected long pageNumber = -1;
+
+ /**
+ * engine used to execute the tasks.
+ */
+ private IReportEngine engine;
+
+ private final String COMPILED_EXTENSION = ".rptdocument";
+
+ public Object compileReport(InputStream in_stream) throws Exception
+ {
+ String tmpDoc = System.getProperty("birt.reports.compile.temp")+Long.toString(System.currentTimeMillis())+COMPILED_EXTENSION;
+ try
+ {
+ IReportRunnable runnable = engine.openReportDesign( in_stream );// parse the source to get the report runnable
+ IRunTask task = engine.createRunTask( runnable );// create the report task
+ //HashMap inputValues = evaluateParameterValues( runnable );// set the paramter values
+ //task.setParameterValues( inputValues );
+
+ task.setAppContext( new HashMap( ) );// set the application context
+ log.info("Compiling Report in : "+tmpDoc+" ... ");
+ task.run( tmpDoc );// run the task to create the report document
+ task.close( );// close the task.
+ log.info("Compilation successful :) ");
+ IReportDocument rptdoc = engine.openReportDocument(tmpDoc);
+ String plural = rptdoc.getPageCount()==1 ? "":"s" ;
+ log.info("Report "+rptdoc.getName()+" contained "+rptdoc.getPageCount()+" page"+plural+".");
+ return rptdoc;
+ }
+ catch ( EngineException e )
+ {
+ log.error( e.getMessage( ), e );
+ return null;
+ }
+ finally
+ {
+ File tmpCompiledReport = new File(tmpDoc);
+ log.info("Cleanup...");
+ if (tmpCompiledReport != null && tmpCompiledReport.exists()) tmpCompiledReport.delete();
+ log.info("Temp file "+tmpDoc+" deleted [OK] ");
+ }
+ }
+
+ public byte[] runReportToPdf(String in_reportName, Object in_report, Map in_parameters, String in_datasource_jndi_name)
+ {
+ try
+ {
+ IReportDocument document=(IReportDocument)in_report;
+ IRenderTask task = engine.createRenderTask( document );// create the render task
+ IRenderOption options;// set report render options
+ options = new RenderOptionBase();
+
+ options.setOutputFormat( format );// set the output format
+ options.getOutputSetting( ).put( HTMLRenderOption.URL_ENCODING,encoding );// setup the output encoding
+
+ task.setRenderOption( options );// set the render options
+
+ task.setLocale( getLocale( locale ) );// setup the locale
+ /** @TODO : decide whether to store the reports on the filesystem or keep it in memory **/
+ String tmpReport = System.getProperty("birt.reports.compile.temp")+"rendering_"+in_reportName;
+ log.info("Render ouput : "+tmpReport);
+ //OutputStream os = new ByteArrayOutputStream();
+ if ( pageNumber <= 0 )// setup the output file
+ {
+ options.setOutputFileName( tmpReport );
+ //options.setOutputStream(os);
+ log.info("Rendering all pages...");
+ task.render();
+ log.info("Rendering done.");
+
+ }
+ else
+ {
+ options.setOutputFileName( tmpReport );
+ //options.setOutputStream(os);
+ log.info("Rendering page "+pageNumber+" ...");
+ task.setPageNumber(pageNumber);
+ task.render();
+ log.info("Rendering done.");
+ }
+ task.close( );
+ File tmpReportFile = new File(tmpReport);
+ /** @TODO : DELETE TEMP FILES !!! **/
+
+ byte[] reportBytes=null;
+ try
+ {
+ reportBytes = getBytesFromFile(tmpReportFile);
+ }
+ catch (IOException e) {e.printStackTrace(); }
+
+ return reportBytes;
+
+ }
+ catch ( org.eclipse.birt.report.engine.api.EngineException e )
+ {
+ log.error(e.getMessage( ), e );
+ return null;
+ }
+ }
+
+ public byte[] runReportToPdf(String in_reportName, Object in_report, Map in_parameters, ReportData in_data) throws Exception
+ {
+ // temporary
+ return runReportToPdf(in_reportName,in_report,null,"");
+ }
+
+ /**
+ * Configure required properties from server config info
+ */
+ public void startService()
+ {
+ System.setProperty("RUN_UNDER_ECLIPSE","false");
+ File birt_temp_dir=null;
+
+ ServerConfigImplMBean serverConfig = (ServerConfigImplMBean)
+ MBeanProxyExt.create(ServerConfigImplMBean.class,ServerConfigImplMBean.OBJECT_NAME, server);
+ birt_temp_dir = new File(serverConfig.getServerTempDir(),BIRT_TEMP_DIR_NAME);
+ if ( ! birt_temp_dir.exists()) birt_temp_dir.mkdir();
+ System.setProperty("birt.reports.compile.temp", birt_temp_dir.getAbsolutePath());
+
+ if ( engine == null )
+ {
+ EngineConfig config = new EngineConfig( );
+ config.setEngineHome(serverConfig.getServerHomeDir().getAbsolutePath()+"/deploy/engine-BIRT-0.2-SNAPSHOT.sar/");
+ try
+ {
+ log.info("Attempting to start platform");
+ Platform.startup( config );
+ log.info("Platform is of type : "+Platform.ECLIPSE_PLATFORM);
+ }
+ catch (BirtException e)
+ {
+ e.printStackTrace();
+ }
+ log.info("Platform started");
+ //log.info("waiting 3 secs");
+ //try {Thread.sleep(3000);}catch (InterruptedException e){e.printStackTrace();} "org.eclipse.birt.report.engine.ReportEngineFactory"
+ IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
+
+ //ReportEngineFactory factory = new ReportEngineFactory();
+ //try {Thread.sleep(3000);}catch (InterruptedException e){e.printStackTrace();}
+ //log.info("waiting 3 secs");
+ if (factory==null ) log.error("ReportEngineFactory \"factory\"is NULL !!");
+ if (config==null ) log.error("EngineConfig \"config\" is NULL !!");
+ engine = factory.createReportEngine( config );
+ if (config==null ) log.error("IReportEngine \"engine\" is NULL !!");
+ //engine = (IReportEngine) new ReportEngine( config) ;
+ engine.changeLogLevel( Level.WARNING );
+ log.info("ReportEngine started");
+
+ }
+ }
+ /**
+ * Private function to convert a locale name string to a locale object
+ *
+ * @param locale -locale name string
+ * @return A locale object
+ */
+ private Locale getLocale( String locale )
+ {
+ int index = locale.indexOf( '_' );
+ if ( index != -1 )
+ {
+ // e.g, zh_CN (language_country)
+ String language = locale.substring( 0, index );
+ String country = locale.substring( index + 1 );
+ return new Locale( language, country );
+ }
+
+ // e.g, en (language)
+ return new Locale( locale );
+ }
+
+ public byte[] getBytesFromFile(File file) throws IOException
+ {
+ InputStream is = new FileInputStream(file);
+
+ long length = file.length();
+ //Cannot read file larger than 2GB , shouldn't be a problem .
+ if (length > Integer.MAX_VALUE) throw new IOException("File "+file.getName()+" is too large to be read");;
+ byte[] bytes = new byte[(int)length];// Create the byte array to hold the data
+
+ // Read in the bytes
+ int offset = 0;
+ int numRead = 0;
+ while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) offset += numRead;
+
+ // Ensure all the bytes have been read in
+ if (offset < bytes.length)
+ throw new IOException("Could not completely read file "+file.getName());
+
+ // Close the input stream and return bytes
+ is.close();
+ return bytes;
+ }
+
+
+
+}
Added: labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReportMBean.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReportMBean.java 2006-12-06 09:39:23 UTC (rev 8082)
+++ labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/java/org/jboss/reporting/server/engine/BirtReportMBean.java 2006-12-06 09:40:27 UTC (rev 8083)
@@ -0,0 +1,20 @@
+/*
+ * Generated file - Do not edit!
+ */
+package org.jboss.reporting.server.engine;
+
+/**
+ * MBean interface.
+ */
+public interface BirtReportMBean extends org.jboss.system.ServiceMBean {
+
+ //default object name
+ public static final javax.management.ObjectName OBJECT_NAME = org.jboss.mx.util.ObjectNameFactory.create("reporting:service=ReportEngine,type=RPTDESIGN");
+
+ java.lang.Object compileReport(java.io.InputStream in_stream) throws java.lang.Exception;
+
+ byte[] runReportToPdf(java.lang.String in_reportName,java.lang.Object in_report,java.util.Map in_parameters,java.lang.String in_datasource_jndi_name) throws java.lang.Exception;
+
+ byte[] runReportToPdf(java.lang.String in_reportName,java.lang.Object in_report,java.util.Map in_parameters,org.jboss.reporting.api.ReportData in_data) throws java.lang.Exception;
+
+}
Added: labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/resources/META-INF/jboss-service.xml
===================================================================
--- labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/resources/META-INF/jboss-service.xml 2006-12-06 09:39:23 UTC (rev 8082)
+++ labs/reportingservices/trunk/dev/modules/extensions/birtreport/src/main/resources/META-INF/jboss-service.xml 2006-12-06 09:40:27 UTC (rev 8083)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+
+ <!-- ==================================================================== -->
+ <!-- BIRT REPORT ENGINE -->
+ <!-- ==================================================================== -->
+
+ <!--
+ | ENGINES : type= should correspond to the file extension of reports files .
+ | It's used by the Deployer to build the right engine ObjectName
+ -->
+ <mbean code="org.jboss.reporting.server.engine.BirtReport"
+ name="reporting:service=ReportEngine,type=RPTDESIGN">
+ </mbean>
+
+</server>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list