好文档 - 专业文书写作范文服务资料分享网站

Cognos 8 SDK简介 

天下 分享 时间: 加入收藏 我要投稿 点赞

reportSpec = (

(AsynchDetailReportObject)qResult.getDetails()[i]).getReport().getSpecific ation().getValue(); } } } }

2:将报表定义解析为XML对象树,此处用dom4j作为文档对象模型(DOM)解析器来修改报表定义

Private Document oDocument; //初始化SAX对象

SAXReader xmlReader = new SAXReader(); ByteArrayInputStream bais = new

ByteArrayInputStream(sReportSpec.getBytes(\//装载document对象

oDocument = xmlReader.read(bais);

3.修改报表定义XML,此方法为加入一个查询

public void addQuery(String p_sName) {

//找出所有查询的父结点

Element n = (Element) oDocument.selectSingleNode(\if (n == null) {

//如果没有父结点则先加上父结点 addQueries();

n = (Element) oDocument.selectSingleNode(\}

//新建一个查询元素

Element e = DocumentHelper.createElement(\//加上名称属性

e.addAttribute(\//加入查询 n.add(e); }

4:把报表定义写回内容库content store

//报表对象BaseClass数组

com.cognos.developer.schemas.bibus._3.BaseClass bc[] =

new com.cognos.developer.schemas.bibus._3.BaseClass[1]; //报表对象

Report rpt = new Report(); //添加选项

AddOptions addOpts = new AddOptions(); //报表名称属性对象

TokenProp rptDefaultName = new TokenProp(); AnyTypeProp ap = new AnyTypeProp(); rptDefaultName.setValue(reportName); //得到报表定义XML

String reportXML = getXML();

int iStartReport = reportXML.indexOf(\String reportOut = reportXML.substring(iStartReport); //设置属性

ap.setValue(reportOut);

rpt.setDefaultName(rptDefaultName); rpt.setSpecification(ap);

addOpts.setUpdateAction(UpdateActionEnum.replace); //父结点的搜索路径

String parentPath =parent.getSearchPath().getValue(); try {

//根据报表定义添加报表

connection.getReportService().add(new SearchPathSingleObject(parentPath), rpt, addOpts); }

//handle uncaught exceptions

首先从内容库content store中得到报表定义,然后报表定义被解析为树型结构并用DOM解析器进行修改,最后转换为XML写回内容库content store。

用query(objectPath, parameterValues,options)方法得到报表的定义,query方法得到报表对象,包括报表对象的所有信息,报表定义是报表对象的specification属性。用适当的XML解析器来修改报表的XML

定义,例如DOM解析器.

用validateSpecification(specification, parameterValues, options)方法验证报表定义是否正确.

保存报表可以用update(object, options)方法覆盖原有报表, 也可以用add(parentPath, object, options)方法在内容库content store 中新增一张报表.

完整的代码如下,EditReportSpec.java:

/**

* EditReportSpec *

* Copyright 2005 Cognos Incorporated. All Rights Reserved.

* Cognos and the Cognos logo are trademarks of Cognos Incorporated. *

* EditReportSpec class contains methods for modifying a simple list * report using the Cognos 8 SDK * */

import com.cognos.developer.schemas.bibus._3.AsynchDetailReportObject; import com.cognos.developer.schemas.bibus._3.AsynchReply;

import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum; import com.cognos.developer.schemas.bibus._3.Option;

import com.cognos.developer.schemas.bibus._3.ParameterValue;

import com.cognos.developer.schemas.bibus._3.ReportServiceQueryOptionBoolean; import com.cognos.developer.schemas.bibus._3.ReportServiceQueryOptionEnum; import

com.cognos.developer.schemas.bibus._3.ReportServiceQueryOptionSpecificationFormat;

import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject; import com.cognos.developer.schemas.bibus._3.SpecificationFormatEnum;

public class EditReportSpec {

// get the Report Spec

/**

* 得到报表定义 *

* @param connect Cognos 8 连接对象 * @param report 报表对象 */

public String getReportSpec(CRNConnect connect, BaseClassWrapper report) { String reportSpec = \ if ((connect.getReportService() != null) && (report != null) && (connect.getDefaultSavePath() != null)) { try { //从报表对象得到该报表的搜索路径 String reportPath =

report.getBaseClassObject().getSearchPath().getValue(); //查询选项 Option[] qOpts = new Option[2]; //是否更新报表定义 ReportServiceQueryOptionBoolean upgradeSpecFlag = new ReportServiceQueryOptionBoolean();

upgradeSpecFlag.setName(ReportServiceQueryOptionEnum.upgrade); upgradeSpecFlag.setValue(true); //报表定义格式 ReportServiceQueryOptionSpecificationFormat specFormat = new ReportServiceQueryOptionSpecificationFormat();

specFormat.setName(ReportServiceQueryOptionEnum.specificationFormat); specFormat.setValue(SpecificationFormatEnum.report); //设置查询选项 qOpts[0] = upgradeSpecFlag; qOpts[1] = specFormat; // sn_dg_sdk_method_reportService_query_start_1 //开始查询报表对象 AsynchReply qResult = connect.getReportService().query( new SearchPathSingleObject(reportPath), new ParameterValue[] {},

qOpts); // sn_dg_sdk_method_reportService_query_end_1 //如果查询没有执行完则一直等待 if ( (qResult.getStatus() == AsynchReplyStatusEnum.working) || (qResult.getStatus() == AsynchReplyStatusEnum.stillWorking) ) { while ( (qResult.getStatus() == AsynchReplyStatusEnum.working) || (qResult.getStatus() == AsynchReplyStatusEnum.stillWorking) ) { qResult =

connect.getReportService().wait(qResult.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {}); } } // sn_dg_sdk_method_reportService_query_start_2 // extract the report spec //从报表对象中得到报表定义 if (qResult.getDetails() != null) { for (int i = 0; i < qResult.getDetails().length; i++) { if (qResult.getDetails()[i] instanceof AsynchDetailReportObject) { reportSpec =

( (AsynchDetailReportObject)qResult.getDetails()[i]).getReport().getSpecification().getValue(); } } } // sn_dg_sdk_method_reportService_query_end_2 } catch (java.rmi.RemoteException remoteEx) {

Cognos 8 SDK简介 

reportSpec=((AsynchDetailReportObject)qResult.getDetails()[i]).getReport().getSpecification().getValue();}}}}2:将报表定义解析为XML对象树,此处用dom4j作为文档对象模型(DOM)解析器来修改报表定义P
推荐度:
点击下载文档文档为doc格式
6z9ym2zyen3pebe0iley
领取福利

微信扫码领取福利

微信扫码分享