如何将OdadataSourceHandle从一个设计报告复制到另一个设计报告?

时间:2018-10-25 03:30:03

标签: birt birt-deapi

string targetRptFile = System.getenv(“ LOCAL_BIRT_INPUT”)+“ /"+report.getMergeRptTemplates().getTargetTemplate()+".rptdesign”;         字符串attachRptFile = System.getenv(“ LOCAL_BIRT_INPUT”)+“ /” + report.getMergeRptTemplates()                 .getAttachTemplate()+“。rptdesign”;

    DesignConfig dConfig = new DesignConfig();
    IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);
    IDesignEngine dEngine = factory.createDesignEngine(dConfig);
    SessionHandle session = dEngine.newSessionHandle(null);
    ReportDesignHandle targetRptDesignHandle = null;
    ReportDesignHandle attachRptDesignHandle = null;
    try {
        targetRptDesignHandle = session.openDesign(targetRptFile);
        attachRptDesignHandle = session.openDesign(attachRptFile);
    } catch (DesignFileException e) {
        e.printStackTrace();
    }


    OdaDataSourceHandle attachOdaDataSourceHandle = (OdaDataSourceHandle)attachRptDesignHandle.getAllDataSources()
            .get(0);
    targetRptDesignHandle.getAllDataSources().add(attachOdaDataSourceHandle);


    String newTargetRptFile = System.getenv("LOCAL_BIRT_INPUT") + "/"+report
            .getMergeRptTemplates().getTargetTemplate()+"-merge"+".rptdesign";

    try {
        targetRptDesignHandle.saveAs(newTargetRptFile);
        targetRptDesignHandle.close();
        attachRptDesignHandle.close();
        session.closeAll(true);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:0)

从未这样做,但是当我想复制JDBCDataSource时,我记得一个类似的问题。我通过手动设置所有属性而不是尝试复制整个DS来解决此问题。