![BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第1頁(yè)](http://file4.renrendoc.com/view/7254e50b12e80779fd9312e5f6ee0276/7254e50b12e80779fd9312e5f6ee02761.gif)
![BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第2頁(yè)](http://file4.renrendoc.com/view/7254e50b12e80779fd9312e5f6ee0276/7254e50b12e80779fd9312e5f6ee02762.gif)
![BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第3頁(yè)](http://file4.renrendoc.com/view/7254e50b12e80779fd9312e5f6ee0276/7254e50b12e80779fd9312e5f6ee02763.gif)
![BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第4頁(yè)](http://file4.renrendoc.com/view/7254e50b12e80779fd9312e5f6ee0276/7254e50b12e80779fd9312e5f6ee02764.gif)
![BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第5頁(yè)](http://file4.renrendoc.com/view/7254e50b12e80779fd9312e5f6ee0276/7254e50b12e80779fd9312e5f6ee02765.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)XML數(shù)據(jù)結(jié)構(gòu)EclipseWebworkMySQL因?yàn)橄到y(tǒng)需要,添加報(bào)表功能,瞄上了birt,學(xué)習(xí)之,入門教程看了一大堆,還好,多種數(shù)據(jù)源支持,對(duì)于sql還沒(méi)精通,看著一大堆sql還有點(diǎn)犯難,所以,xml數(shù)據(jù)源成了我的首選,仔細(xì)研究之下,發(fā)現(xiàn)原來(lái) birt 提供的初級(jí)功能原來(lái)很少,報(bào)表經(jīng)常需要替換數(shù)據(jù)源來(lái)顯示其不同的內(nèi)容,而傳統(tǒng)的設(shè)置 xml數(shù)據(jù)源只是事前指定好 xml文件,或url,google了一下,基本沒(méi)有發(fā)現(xiàn)可用 的例子,郁悶之,自己琢磨了一周幾乎,更郁悶的是其實(shí)問(wèn)題早有了答案,就載在acegi的權(quán)限控制之上一直未看到勝利的曙光下面把自己動(dòng)態(tài)修改 xml數(shù)據(jù)源的成功發(fā)上來(lái)我用的是 webwork,其他用戶請(qǐng)酌情修改相應(yīng)參數(shù)這個(gè)是用來(lái)view報(bào)表的action 需要傳入的參數(shù)是reban.reportName= 報(bào)表文件的文件名rbean.xmlDataUrl= 報(bào)表xmldatasourceurl ,可以是stream,或xxx.xml之類的,輸入瀏覽器能顯示 xml即可BirtReportViewer.javaJava代碼3.importjava.io.ByteArrayInputStream;4.importjava.io.ByteArrayOutputStream;5.importjava.io.InputStream;6.7.importjavax.servlet.ServletContext;8.importjavax.servlet.http.HttpServletRequest;9.10.importorg.eclipse.birt.report.engine.api.EngineConstants;11.importorg.eclipse.birt.report.engine.api.HTMLRenderOption;12.importorg.eclipse.birt.report.engine.api.HTMLServerImageHandler;13.importorg.eclipse.birt.report.engine.api.IHTMLRenderOption;14.importorg.eclipse.birt.report.engine.api.IRenderOption;15.importorg.eclipse.birt.report.engine.api.IReportEngine;16.import 17.import 18.import 19.import 20.import 21.import 22.import 23.import 24.import25.26.27.importcom.morepower.controller.AbstractAction;28.importcom.morepower.util.BirtEngine;29.importcom.morepower.view.BirtReporterBean;30.importcom.opensymphony.webwork.ServletActionContext;31.erceptor.ServletRequestAware;32.33.publicclassBirtReportViewerextendsAbstractActionimplements34.ServletRequestAware{35./**36.*37.*/38.privatestaticfinallongserialVersionUID=1L;39.privatestaticStringREPORT_DIR="birt-reportors";40.privatestaticStringREPORT_IMAGE_DIR="images";41.privateIReportEnginebirtReportEngine=null;42.privateHttpServletRequestrequest;43.privateBirtReporterBeanrbean;44.privateInputStreamreportStream;45.privatestaticStringDATASOURCE_NAME="DataSource";46.privatestaticStringDATASET_NAME="DataSet";47.privatestaticStringQueryText="";48.49.publicInputStreamgetReportStream(){50.returnthis.reportStream;51.}52.53.@Override54.publicStringexecute()throwsException{55.//getreportnameandlaunchtheengine56.//resp.setContentType("text/html");57.//resp.setContentType("application/pdf");58.//resp.setHeader("Content-Disposition","inline;filename=test.pdf");59.StringreportName=rbean.getReportName();60.ServletContextsc=ServletActionContext.getServletContext();61.birtReportEngine=BirtEngine.getBirtEngine(sc);62. IReportRunnabledesign=birtReportEngine.openReportDesign(sc63. ator+REPORT_DIR)64.+java.io.File.separator+reportName);65.66.ReportDesignHandlereport=(ReportDesignHandle)design67..getDesignHandle();68.69.//只是動(dòng)態(tài)更換數(shù)據(jù)源即可,不需改變報(bào)表的其他結(jié)構(gòu)70.//暫時(shí)不支持動(dòng)態(tài)創(chuàng)建表格71.72.//createtasktorunandrenderreport73.buildReport(report);74.IRunAndRenderTasktask=birtReportEngine75. .createRunAndRenderTask(design);76. task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,77. 78.79. // set output options80. HTMLRenderOptionoptions = new HTMLRenderOption();81. options.setImageHandler(newHTMLServerImageHandler());82. 83.+REPORT_IMAGE_DIR));84.options.setBaseImageURL(request.getContextPath()85.+java.io.File.separator+REPORT_IMAGE_DIR);86.options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);87.options.setOption(IRenderOption.HTML_PAGINATION,Boolean.TRUE);88. options.setOption(IHTMLRenderOption.MASTER_PAGE_CONTENT,newBoolean(89.true));90.91.//options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);92.options.setOption(HTMLRenderOption.HTML_ENABLE_METADATA,Boolean.FALSE);93.ByteArrayOutputStreambout=newByteArrayOutputStream();94.//Stringrenderstr=bout.toString("utf-8");95.options.setOutputStream(bout);96.task.setRenderOption(options);97.98./*99.*另外一種方案,直接在action中構(gòu)造inputStream對(duì)像,但這樣100.*可能導(dǎo)致你的報(bào)表viewer與具體業(yè)務(wù)類耦合!101.102.reportStream);103.task.getAppContext().put(org.eclipse.datat104.Boolean.TRUE);*/105.106.//runreport107.108.task.run();109.task.close();110.reportStream=newByteArrayInputStream(bout.toByteArray());111.112.returnSUCCESS;113.}114.115./**116.*清除原有的數(shù)據(jù)源117.*/118.protectedvoidclearDataSource(ReportDesignHandledesignHandle){119.//DataSourceHandledsh=designHandle.findDataSource(DATASOURCE_NAME);120.//dsh.drop();121.intcount=designHandle.getDataSources().getCount();122.123.try{124.for(inti=0;i<count;i++)125.designHandle.getDataSources().drop(i);126.}catch(SemanticExceptione){127.log.error(e);128.e.printStackTrace();129.}130.}131.132./**133.*清除原有的數(shù)據(jù)集134.*/135.protectedvoidclearDataSet(ReportDesignHandledesignHandle){136.getQueryText(designHandle);137.intcount=designHandle.getDataSets().getCount();138.try{139.for(inti=0;i<count;i++)140.designHandle.getDataSets().drop(i);141.}catch(SemanticExceptione){142.log.error(e);143.e.printStackTrace();144.}145.}146.147./**148.*149.*/150.protectedvoidgetQueryText(ReportDesignHandledesignHandle){151.QueryText=(String)designHandle.getDataSets().get(0).getProperty(152."queryText");153.}154.155.protectedvoidbuildReport(ReportDesignHandledesignHandle){156.try{157.ElementFactorydesignFactory=designHandle.getElementFactory();158.buildDataSource(designFactory,designHandle);159.buildDataSet(designFactory,designHandle);160.TableHandletable=(TableHandle)designHandle.getBody().get(0);161.table.setDataSet(designHandle.findDataSet(DATASET_NAME));162.163.}catch(SemanticExceptione){164.log.error(e);165.e.printStackTrace();166.}167.168.}169.170.protectedvoidbuildDataSource(ElementFactorydesignFactory,171.ReportDesignHandledesignHandle)throwsSemanticException{172.clearDataSource(designHandle);173.OdaDataSourceHandledsHandle=designFactory.newOdaDataSource(174.DATASOURCE_NAME,175."org.eclipse.birt.report.data.oda.xml");176./*dsHandle.setProperty("odaDriverClass",177."com.mysql.jdbc.Driver");178.dsHandle.setProperty("odaURL","jdbc:mysql://localhost/stat");179.dsHandle.setProperty("odaUser","root");180.dsHandle.setProperty("odaPassword","");*/181.dsHandle.setProperty("FILELIST",rbean.getXmlDataUrl());182.designHandle.getDataSources().add(dsHandle);183.}184.185.protectedvoidbuildDataSet(ElementFactorydesignFactory,186.ReportDesignHandledesignHandle)throwsSemanticException{187.188.clearDataSet(designHandle);189.OdaDataSetHandledsHandle=designFactory.newOdaDataSet(DATASET_NAME,190.//"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");191./*OdaDataSetHandledsHandle=designFactory.newOdaDataSet(DATASET_NAME,*/192."org.eclipse.birt.report.data.oda.xml.dataSet");193.dsHandle.setPrivateDriverProperty("XML_FILE", rbean.getXmlDataUrl());194.dsHandle.setPrivateDriverProperty("MAX_ROW","-1");195.dsHandle.setQueryText(QueryText);196.dsHandle.setDataSource(DATASOURCE_NAME);197.designHandle.getDataSets().add(dsHandle);198.199.}200.201.@Override202.publicvoidsetServletRequest(HttpServletRequestarg0){203.request=arg0;204.205.}206.207.@Override208.publicvoiddestory(){209.BirtEngine.destroyBirtEngine();210.}211.212.publicBirtReporterBeangetRbean(){213.returnrbean;214.}215.216.publicvoidsetRbean(BirtReporterBeanrbean){217.this.rbean=rbean;218.}219.220.@Override221.publicvoidinitilize(){222.try{223.("報(bào)表系統(tǒng)初始化中");224.BirtEngine.initBirtConfig();225.REPORT_DIR=BirtEngine.getBirtReportorProperty("report_dir");226.REPORT_IMAGE_DIR=BirtEngine227..getBirtReportorProperty("report_image_dir");228.DATASOURCE_NAME="DataSource";229.DATASET_NAME="DataSet";230.}catch(Exceptione){231.e.printStackTrace();232.log.error(e);233.}234.}235.}BirtEngine.javaJava代碼6.7.mons.logging.Log;8.mons.logging.LogFactory;9.importorg.eclipse.birt.report.engine.api.EngineConfig;10.importorg.eclipse.birt.report.engine.api.IReportEngine;11.importjavax.servlet.*;12.importorg.eclipse.birt.core.framework.PlatformServletContext;13.importorg.eclipse.birt.core.framework.IPlatformContext;14.importorg.eclipse.birt.core.framework.Platform;15.importorg.eclipse.birt.core.exception.BirtException;16.importorg.eclipse.birt.report.engine.api.IReportEngineFactory;17.18.publicclassBirtEngine{19.privatestaticIReportEnginebirtEngine=null;20.privatestaticPropertiesconfigProps=newProperties();21.privatefinalstaticStringconfigFile="BirtCperties";22.protectedfinalstaticLoglog=LogFactory.getLog(BirtEngine.class);23. public static synchronized void initBirtConfig() {24.25. loadEngineProps();26. }27.28. public static synchronized IReportEngine getBirtEngine(ServletContext sc) {29.if(birtEngine==null){30.EngineConfigconfig=newEngineConfig();31.if(configProps!=null){32.StringlogLevel=configProps.getProperty("logLevel");33.Levellevel=Level.OFF;34.if("SEVERE".equalsIgnoreCase(logLevel)){35.level=Level.SEVERE;36.}elseif("WARNING".equalsIgnoreCase(logLevel)){37.level=Level.WARNING;38.}elseif("INFO".equalsIgnoreCase(logLevel)){39.level=Level.INFO;40.}elseif("CONFIG".equalsIgnoreCase(logLevel)){41.level=Level.CONFIG;42.}elseif("FINE".equalsIgnoreCase(logLevel)){43.level=Level.FINE;44.}elseif("FINER".equalsIgnoreCase(logLevel)){45.level=Level.FINER;46.}elseif("FINEST".equalsIgnoreCase(logLevel)){47.level=Level.FINEST;48.}elseif("OFF".equalsIgnoreCase(logLevel)){49.level=Level.OFF;50.}51.52..getProperty("logDirectory"),config.setLogConfig(configProps53.level);54.}55.//sc.getRealPath("")+java.io.File.separator+configProps.getProperty("engine_home")56.config.setEngineHome("");57.IPlatformContextcontext=newPlatformServletContext(sc);58.(context.getPlatform());59.config.setPlatformContext(context);60.61.try{62.Platform.startup(config);63.}catch(BirtExceptione){64.e.printStackTrace();65.}66.67.IReportEngineFactoryfactory=(IReportEngineFactory)Platform68
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 第三季度財(cái)務(wù)工作總結(jié)
- 采購(gòu)計(jì)劃年終工作總結(jié)
- 聽評(píng)課記錄二年級(jí)語(yǔ)文
- 領(lǐng)導(dǎo)給員工的評(píng)語(yǔ)與希望
- 太陽(yáng)能光伏發(fā)電站EC總承包合同范本
- 交叉作業(yè)安全管理協(xié)議書范本
- 江蘇理工學(xué)院《平面構(gòu)成與構(gòu)圖學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 吉林工商學(xué)院《計(jì)算流體力學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 快遞大客戶合同范本
- 蘇科版數(shù)學(xué)八年級(jí)上冊(cè)1.2《全等三角形》聽評(píng)課記錄
- 2025年度化妝品電商平臺(tái)流量互換銷售合作合同
- 學(xué)習(xí)解讀2025年印發(fā)《教育強(qiáng)國(guó)建設(shè)規(guī)劃綱要(2024-2035年)》課件
- 全過(guò)程造價(jià)咨詢服務(wù)的質(zhì)量、進(jìn)度、保密等保證措施
- 縣城屠宰場(chǎng)建設(shè)可行性研究報(bào)告
- 25學(xué)年六年級(jí)數(shù)學(xué)寒假作業(yè)《每日一練》
- 2025高考數(shù)學(xué)一輪復(fù)習(xí)-第8章-第3節(jié) 圓的方程【課件】
- 人文關(guān)懷在護(hù)理工作中的體現(xiàn)
- 2025年1月八省聯(lián)考高考綜合改革適應(yīng)性測(cè)試-高三生物(陜西、山西、寧夏、青海卷) 含解析
- 環(huán)保行業(yè)深度研究報(bào)告
- 保障性住房補(bǔ)貼委托書范本
- 社會(huì)主義核心價(jià)值觀課件
評(píng)論
0/150
提交評(píng)論