BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第1頁(yè)
BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第2頁(yè)
BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第3頁(yè)
BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第4頁(yè)
BIRT使用xml動(dòng)態(tài)數(shù)據(jù)源總結(jié)_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

-.zBIRT使用*ml動(dòng)態(tài)數(shù)據(jù)源總結(jié)博客分類(lèi):Java&Eclipse*ML數(shù)據(jù)構(gòu)造EclipseWebworkMySQL因?yàn)橄到y(tǒng)需要,添加報(bào)表功能,瞄上了birt,學(xué)習(xí)之,入門(mén)教程看了一大堆,還好,多種數(shù)據(jù)源支持,對(duì)于sql還沒(méi)精通,看著一大堆sql還有點(diǎn)犯難,所以,*ml數(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è)置*ml數(shù)據(jù)源只是事前指定好*ml文件,或url,google了一下,根本沒(méi)有發(fā)現(xiàn)可用的例子,郁悶之,自己琢磨了一周幾乎,更郁悶的是其實(shí)問(wèn)題早有了答案,就載在acegi的權(quán)限控制之上一直未看到勝利的曙光下面把自己動(dòng)態(tài)修改*ml數(shù)據(jù)源的成功發(fā)上來(lái)我用的是webwork,其他用戶(hù)請(qǐng)酌情修改相應(yīng)參數(shù)這個(gè)是用來(lái)view報(bào)表的action需要傳入的參數(shù)是

reban.reportName=報(bào)表文件的文件名

rbean.*mlDataUrl=報(bào)表*mldatasourceurl,可以是stream,或***.*ml之類(lèi)的,輸入瀏覽器能顯示*ml即可

BirtReportViewer.javaJava代碼package.morepower.controller.birt;importjava.io.ByteArrayInputStream;importjava.io.ByteArrayOutputStream;importjava.io.InputStream;importjava*.servlet.ServletConte*t;importjava*.servlet..ServletRequest;importorg.eclipse.birt.report.engine.api.EngineConstants;importorg.eclipse.birt.report.engine.api.HTMLRenderOption;importorg.eclipse.birt.report.engine.api.HTMLServerImageHandler;importorg.eclipse.birt.report.engine.api.IHTMLRenderOption;importorg.eclipse.birt.report.engine.api.IRenderOption;importorg.eclipse.birt.report.engine.api.IReportEngine;importorg.eclipse.birt.report.engine.api.IReportRunnable;importorg.eclipse.birt.report.engine.api.IRunAndRenderTask;importorg.eclipse.birt.report.model.api.DataSourceHandle;importorg.eclipse.birt.report.model.api.ElementFactory;importorg.eclipse.birt.report.model.api.OdaDataSetHandle;importorg.eclipse.birt.report.model.api.OdaDataSourceHandle;importorg.eclipse.birt.report.model.api.ReportDesignHandle;importorg.eclipse.birt.report.model.api.TableHandle;importorg.eclipse.birt.report.model.api.activity.SemanticE*ception;import.morepower.controller.AbstractAction;import.morepower.util.BirtEngine;import.morepower.view.BirtReporterBean;import.opensymphony.webwork.ServletActionConte*t;erceptor.ServletRequestAware;publicclassBirtReportViewere*tendsAbstractActionimplementsServletRequestAware

{

/****/privatestaticfinallongserialVersionUID=1L;privatestaticStringREPORT_DIR="birt-reportors";privatestaticStringREPORT_IMAGE_DIR="images";privateIReportEnginebirtReportEngine=null;privateServletRequestrequest;privateBirtReporterBeanrbean;privateInputStreamreportStream;privatestaticStringDATASOURCE_NAME="DataSource";privatestaticStringDATASET_NAME="DataSet";privatestaticStringQueryTe*t=";publicInputStreamgetReportStream()

{

returnthis.reportStream;

}

OverridepublicStringe*ecute()throwsE*ception

{

//getreportnameandlaunchtheengine//resp.setContentType("te*t/html");//resp.setContentType("application/pdf");//resp.setHeader("Content-Disposition","inline;filename=test.pdf");StringreportName=rbean.getReportName();ServletConte*tsc=ServletActionConte*t.getServletConte*t();birtReportEngine=BirtEngine.getBirtEngine(sc);IReportRunnabledesign=birtReportEngine.openReportDesign(sc.getReal+REPORT_DIR)++reportName);ReportDesignHandlereport=(ReportDesignHandle)design.getDesignHandle();//只是動(dòng)態(tài)更換數(shù)據(jù)源即可,不需改變報(bào)表的其他構(gòu)造//暫時(shí)不支持動(dòng)態(tài)創(chuàng)立表格//createtasktorunandrenderreportbuildReport(report);IRunAndRenderTasktask=birtReportEngine.createRunAndRenderTask(design);task.getAppConte*t().put(EngineConstants.APPCONTE*T_CLASSLOADER_KEY,BirtReportViewer.class.getClassLoader());//setoutputoptionsHTMLRenderOptionoptions=newHTMLRenderOption();options.setImageHandler(newHTMLServerImageHandler());options.setImageDirectory(sc.getRealPath(java.io.File.separator+REPORT_IMAGE_DIR));options.setBaseImageURL(request.getConte*tPath()+r+REPORT_IMAGE_DIR);options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);options.setOption(IRenderOption.HTML_PAGINATION,Boolean.TRUE);options.setOption(IHTMLRenderOption.MASTER_PAGE_CONTENT,newBoolean(true));//options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);options.setOption(HTMLRenderOption.HTML_ENABLE_METADATA,Boolean.FALSE);ByteArrayOutputStreambout=newByteArrayOutputStream();//Stringrenderstr=bout.toString("utf-8");options.setOutputStream(bout);task.setRenderOption(options);/**另外一種方案,直接在action中構(gòu)造inputStream對(duì)像,但這樣*可能導(dǎo)致你的報(bào)表viewer與具體業(yè)務(wù)類(lèi)耦合!*task.getAppConte*t().put(org.eclipse.datatools.enablement.oda.*ml.Constants.APPCONTE*T_INPUTSTREAM,reportStream);T_CLOSEINPUTSTREAM,Boolean.TRUE);*///runreporttask.run();task.close();reportStream=newByteArrayInputStream(bout.toByteArray());returnSUCCESS;

}

/***去除原有的數(shù)據(jù)源*/protectedvoidclearDataSource(ReportDesignHandledesignHandle)

{

//DataSourceHandledsh=designHandle.findDataSource(DATASOURCE_NAME);//dsh.drop();intcount=designHandle.getDataSources().getCount();try

{

for(inti=0;i<count;i++)designHandle.getDataSources().drop(i);

}

catch(SemanticE*ceptione)

{

log.error(e);e.printStackTrace();

}

}

/***去除原有的數(shù)據(jù)集*/protectedvoidclearDataSet(ReportDesignHandledesignHandle)

{

getQueryTe*t(designHandle);intcount=designHandle.getDataSets().getCount();try

{

for(inti=0;i<count;i++)designHandle.getDataSets().drop(i);

}

catch(SemanticE*ceptione)

{

log.error(e);e.printStackTrace();

}

}

/****/protectedvoidgetQueryTe*t(ReportDesignHandledesignHandle)

{

QueryTe*t=(String)designHandle.getDataSets().get(0).getProperty("queryTe*t");

}

protectedvoidbuildReport(ReportDesignHandledesignHandle)

{

try

{

ElementFactorydesignFactory=designHandle.getElementFactory();buildDataSource(designFactory,designHandle);buildDataSet(designFactory,designHandle);TableHandletable=(TableHandle)designHandle.getBody().get(0);table.setDataSet(designHandle.findDataSet(DATASET_NAME));

}

catch(SemanticE*ceptione)

{

log.error(e);e.printStackTrace();

}

}

protectedvoidbuildDataSource(ElementFactorydesignFactory,ReportDesignHandledesignHandle)throwsSemanticE*ception

{

clearDataSource(designHandle);OdaDataSourceHandledsHandle=designFactory.newOdaDataSource(DATASOURCE_NAME,"org.eclipse.birt.report.data.oda.*ml");/*dsHandle.setProperty("odaDriverClass",".mysql.jdbc.Driver");dsHandle.setProperty("odaURL","jdbc:mysql://localhost/stat");dsHandle.setProperty("odaUser","root");dsHandle.setProperty("odaPassword",");*/dsHandle.setProperty("FILELIST",rbean.get*mlDataUrl());designHandle.getDataSources().add(dsHandle);

}

protectedvoidbuildDataSet(ElementFactorydesignFactory,ReportDesignHandledesignHandle)throwsSemanticE*ception

{

clearDataSet(designHandle);OdaDataSetHandledsHandle=designFactory.newOdaDataSet(DATASET_NAME,//"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");/*OdaDataSetHandledsHandle=designFactory.newOdaDataSet(DATASET_NAME,*/"org.eclipse.birt.report.data.oda.*ml.dataSet");dsHandle.setPrivateDriverProperty("*ML_FILE",rbean.get*mlDataUrl());dsHandle.setPrivateDriverProperty("MA*_ROW","-1");dsHandle.setQueryTe*t(QueryTe*t);dsHandle.setDataSource(DATASOURCE_NAME);designHandle.getDataSets().add(dsHandle);

}

OverridepublicvoidsetServletRequest(ServletRequestarg0)

{

request=arg0;

}

Overridepublicvoiddestory()

{

BirtEngine.destroyBirtEngine();

}

publicBirtReporterBeangetRbean()

{

returnrbean;

}

publicvoidsetRbean(BirtReporterBeanrbean)

{

this.rbean=rbean;

}

Overridepublicvoidinitilize()

{

try

{

("報(bào)表系統(tǒng)初始化中");BirtEngine.initBirtConfig();REPORT_DIR=BirtEngine.getBirtReportorProperty("report_dir");REPORT_IMAGE_DIR=BirtEngine.getBirtReportorProperty("report_image_dir");DATASOURCE_NAME="DataSource";DATASET_NAME="DataSet";

}

catch(E*ceptione)

{

e.printStackTrace();log.error(e);

}

}

}

BirtEngine.javaJava代碼package.morepower.util;importjava.io.InputStream;importjava.io.IOE*ception;importjava.util.Properties;importjava.util.logging.Level;importorg.apache.mons.logging.Log;importorg.apache.mons.logging.LogFactory;importorg.eclipse.birt.report.engine.api.EngineConfig;importorg.eclipse.birt.report.engine.api.IReportEngine;importjava*.servlet.*;importorg.eclipse.birt.core.framework.PlatformServletConte*t;importorg.eclipse.birt.core.framework.IPlatformConte*t;importorg.eclipse.birt.core.framework.Platform;importtion;importorg.eclipse.birt.report.engine.api.IReportEngineFactory;publicclassBirtEngine

{

privatestaticIReportEnginebirtEngine=null;privatestaticPropertiesconfigProps=newProperties();privatefinalstaticStringconfigFile="BirtCperties";protectedfinalstaticLoglog=LogFactory.getLog(BirtEngine.class);publicstaticsynchronizedvoidinitBirtConfig()

{

loadEngineProps();

}

publicstaticsynchronizedIReportEnginegetBirtEngine(ServletConte*tsc)

{

if(birtEngine==null)

{

EngineConfigconfig=newEngineConfig();if(configProps!=null)

{

StringlogLevel=configProps.getProperty("logLevel");Levellevel=Level.OFF;if("SEVERE".equalsIgnoreCase(logLevel))

{

level=Level.SEVERE;

}

elseif("WARNING".equalsIgnoreCase(logLevel))

{level=Level.WARNING;

}

elseif("INFO".equalsIgnoreCase(logLevel))

{

level=Level.INFO;

}

elseif("CONFIG".equalsIgnoreCase(logLevel))

{

level=Level.CONFIG;

}

elseif("FINE".equalsIgnoreCase(logLevel))

{

level=Level.FINE;

}

elseif("FINER".equalsIgnoreCase(logLevel))

{

level=Level.FINER;

}

elseif("FINEST".equalsIgnoreCase(logLevel))

{

level=Level.FINEST;

}

elseif("OFF".equalsIgnoreCase(logLevel))

{

level=Level.OFF;

}

config.setLogConfig(configProps.getProperty("logDirectory"),level);

}

//sc.getRealPath(")+java.io.File.separator+configProps.getProperty("engine_home")config.setEngineHome(");IPlatformConte*tconte*t=newPlatformServletConte*t(sc);(conte*t.getPlatform());config.setPlatformConte*t(conte*t);try

{

Platform.startup(config);

}

catch(BirtE*ceptione)

{

e.printStackTrace();

}

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論