Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » [Tribix 2.5.1] xls is lock, can't release.
[Tribix 2.5.1] xls is lock, can't release. [message #512825] Mon, 08 February 2010 06:09
TZ  is currently offline TZ Friend
Messages: 3
Registered: February 2010
Junior Member
here is my test code . even after Platform.shutdown(), i can't delete or modify the xls in explorer.
version: org.uguess.birt.report.engine.emitter.xls_2.5.1.201001221050 .jar
Code:

package com.symbol.elvisapp.report;

import java.io.File;
import java.util.logging.Level;

import org.apache.log4j.PropertyConfigurator;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.IPlatformContext;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.PlatformFileContext;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
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.IRunAndRenderTask;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.ScriptDataSetHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Test Case for Birt
 */
public class TestBirt {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    private String rootPath = this.getClass().getClassLoader().getResource("").getPath();
    private String birtHome = "ReportEngine";
    private String birtLogPath = "report" + File.separator + "log" + File.separator;
    private String birtTemplatePath = "report" + File.separator + "tpl" + File.separator;
    private String birtOutputPath = "report" + File.separator + "output" + File.separator;

    private IReportEngine engine;

    public TestBirt() {
        PropertyConfigurator.configure(getClass().getClassLoader().getResource("config/log4j.properties"));
        initReportEngine();
    }

    private void initReportEngine() {
        try {
            logger.info("Init BirtHome:{}", birtHome);
            EngineConfig config = new EngineConfig();
            config.setBIRTHome(rootPath + birtHome);
            config.setLogConfig(rootPath + birtLogPath, Level.WARNING);

            IPlatformContext context = new PlatformFileContext(config);
            config.setPlatformContext(context);
            logger.info("to startup platform");
            Platform.startup(config);
            logger.info("finish startup platform,to create factory");
            IReportEngineFactory factory = (IReportEngineFactory) Platform
                    .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
            logger.info("finish create factory,to create engine");
            engine = factory.createReportEngine(config);
            logger.info("finish create engine");
        } catch (BirtException e) {
            logger.error("Init Birt fail,{}", e.toString());
        }
    }

    public void test() {
        try {
            logger.info("open TestReport.rptdesign");
            // a simple report from birt 
            IReportRunnable reportRunnable = engine.openReportDesign(rootPath + birtTemplatePath
                    + "TestReport.rptdesign");

            ReportDesignHandle rdh = (ReportDesignHandle) reportRunnable.getDesignHandle();
            ScriptDataSetHandle sdsh = (ScriptDataSetHandle) rdh.findDataSet("MyDataSet");
            logger.info("create task");
            IRunAndRenderTask task = engine.createRunAndRenderTask(reportRunnable);
            EXCELRenderOption excelRenderOption = new EXCELRenderOption();
            excelRenderOption.closeOutputStreamOnExit(true);
            excelRenderOption.setOutputFormat("xls");
            excelRenderOption.setOutputFileName(rootPath + birtOutputPath + "TestReport.xls");
            task.setRenderOption(excelRenderOption);
            logger.info("to run task");
            task.run();
            logger.info("finish run task,to close task");
            SlotHandle sh = rdh.getDataSets();
            task.close();
            logger.info("finish close task, to destroy engine.");
            engine.destroy();
            logger.info("finish destroy engine,to shutdown platform");
            Platform.shutdown();
            logger.info("finish shutdown platform");
            //sleep to test delete
            Thread.sleep(5000);
            logger.info("exit");
        } catch (EngineException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void testDataSet() {
    }

    public static void main(String[] args) {
        new TestBirt().test();
    }

}

Previous Topic:Interpolating values: how?
Next Topic:Problem : localizing message with parameters
Goto Forum:
  


Current Time: Thu Apr 25 13:47:00 GMT 2024

Powered by FUDForum. Page generated in 0.03199 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top