在指定时间运行报表,参数为开始执行时间,搜索路径,报表参数,运行选项
? runSpecification(specification, parameterValues, options) 运行报表定义,参数为报表定义,报表参数,运行选项 此例我们用run(objectPath, parameterValues, options)方法 如果运行不带参数的报表,则parameterValues对象为空:
ParameterValue emptyParameterValues[]=new ParameterValue[] {}; reportParameterValues = emptyParameterValues;
如果运行带参数的报表,则设置参数如下:
//参数个数,数组
ParameterValue reportParameters[] = new ParameterValue[1]; reportParameters[0] = new ParameterValue(); //参数名称
reportParameters[0].setName(\//参数值也是数组
ParmValueItem pvi[] = new ParmValueItem[1];
SimpleParmValueItem item1 = new SimpleParmValueItem(); //参数值
item1.setUse(\pvi[0] = item1;
reportParameters[0].setValue(pvi);
设置运行选项:
//为option数组
Option runOptions[] = new Option[5]; //设置是否保存报表
RunOptionBoolean saveOutput = new RunOptionBoolean(); saveOutput.setName(RunOptionEnum.saveOutput); saveOutput.setValue(false); runOptions[0] = saveOutput;
//设置报表运行格式
RunOptionStringArray outputFormat = new RunOptionStringArray();
outputFormat.setName(RunOptionEnum.outputFormat);
//格式还可以为CSV , HTMLFragment, MHT, PDF, singleXLS, XHTML, XLS, XLWA, XML
outputFormat.setValue(new String[] { \runOptions[1] = outputFormat;
RunOptionOutputEncapsulation outputEncapsulation =
new RunOptionOutputEncapsulation();
outputEncapsulation.setName(RunOptionEnum.outputEncapsulation);
outputEncapsulation.setValue(OutputEncapsulationEnum.none); runOptions[2] = outputEncapsulation; //设置主要等待时间,单位秒
AsynchOptionInt primaryWait = new AsynchOptionInt();
primaryWait.setName(AsynchOptionEnum.primaryWaitThreshold); primaryWait.setValue(0); runOptions[3] = primaryWait; //次要等待时间,单位秒
AsynchOptionInt secondaryWait = new AsynchOptionInt();
secondaryWait.setName(AsynchOptionEnum.secondaryWaitThreshold); secondaryWait.setValue(0); runOptions[4] = secondaryWait;
运行报表:
AsynchReply res =
repService.run(new SearchPathSingleObject(reportPath), parameters, runOptions);
完整的类reportrunner.java如下:
/**
* reportrunner.java *
* Copyright 2005 Cognos Incorporated. All Rights Reserved.
* Cognos and the Cognos logo are trademarks of Cognos Incorporated. *
* Description: This code sample makes calls to Cognos 8 SDK methods. */
import java.io.FileOutputStream;
import java.net.MalformedURLException; import java.net.URL;
import javax.xml.rpc.ServiceException; import org.apache.axis.AxisFault; import org.apache.axis.client.Stub;
import com.cognos.developer.schemas.bibus._3.AsynchDetailReportOutput; import com.cognos.developer.schemas.bibus._3.AsynchOptionEnum; import com.cognos.developer.schemas.bibus._3.AsynchOptionInt; import com.cognos.developer.schemas.bibus._3.AsynchReply;
import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum; import com.cognos.developer.schemas.bibus._3.BiBusHeader; import com.cognos.developer.schemas.bibus._3.CAM;
import com.cognos.developer.schemas.bibus._3.FormFieldVar; import com.cognos.developer.schemas.bibus._3.FormatEnum; import com.cognos.developer.schemas.bibus._3.HdrSession;
import com.cognos.developer.schemas.bibus._3.OutputEncapsulationEnum; import com.cognos.developer.schemas.bibus._3.ParameterValue; import com.cognos.developer.schemas.bibus._3.Option;
import com.cognos.developer.schemas.bibus._3.ReportService_Port;
import com.cognos.developer.schemas.bibus._3.ReportService_ServiceLocator; import com.cognos.developer.schemas.bibus._3.RunOptionBoolean; import com.cognos.developer.schemas.bibus._3.RunOptionEnum;
import com.cognos.developer.schemas.bibus._3.RunOptionOutputEncapsulation; import com.cognos.developer.schemas.bibus._3.RunOptionStringArray; import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject; import com.cognos.developer.schemas.bibus._3.CAMPassport; import com.cognos.developer.schemas.bibus._3.*; /**
*运行报表并保存为HTML *
* Note that this application does no error handling; errors will cause * ugly exception stack traces to appear on the console, and the * application will exit ungracefully. */
public class reportrunner {
/**
* 此函数准备 biBusHeader *
* @param repService 一个初始化的report service 报表服务对象. * @param user 用户ID.
* @param pass 密码. * @param name 名称空间. */
static void setUpHeader(
ReportService_Port repService, String user, String pass, String name) {
// 净化头部移出对话上下文. BiBusHeader bibus =
(BiBusHeader) ((Stub)repService).getHeaderObject(\\
if (bibus != null) {
if (bibus.getTracking() != null) {
if
(bibus.getTracking().getConversationContext() != null) {
bibus.getTracking().setConversationContext(null); } }
return; }
// 为登陆设置一个新的biBusHeader. bibus = new BiBusHeader(); //此时用CAM方式进行登陆 bibus.setCAM(new CAM()); //设置登陆方式为logonAs
bibus.getCAM().setAction(\ //设置CAMPassport
bibus.getCAM().setCAMPassport(new CAMPassport()); // bibus.getCAM().getCAMPassport().setId(new String()); bibus.setHdrSession(new HdrSession()); //登陆信息数组
FormFieldVar ffs[] = new FormFieldVar[3];
//用户名
ffs[0] = new FormFieldVar();
ffs[0].setName(\ ffs[0].setValue(user);
ffs[0].setFormat(FormatEnum.not_encrypted); //密码
ffs[1] = new FormFieldVar();
ffs[1].setName(\ ffs[1].setValue(pass);
ffs[1].setFormat(FormatEnum.not_encrypted); //名称空间
ffs[2] = new FormFieldVar();
ffs[2].setName(\ ffs[2].setValue(name);
ffs[2].setFormat(FormatEnum.not_encrypted); //设置登陆信息
bibus.getHdrSession().setFormFieldVars(ffs);
//String passport = bibus.getCAM().getCAMPassport().getId(); //bibus.getCAM().setCAMPassport(new CAMPassport()); //bibus.getCAM().getCAMPassport().setId(new String()); //得到passport
String passport = bibus.getCAM().getCAMPassport().getId(); System.out.println(\
((Stub)repService).setHeader(\
}
/**
* Replace all occurrences of \ * 此处为把相对路径改变成绝对路径
* @param str The source string. 源字符串
* @param pattern The pattern to search for. 正则表达式
* @param replace The replacement for pattern. 要替换的字符串 *
* @return Identical to the original string with all instances * of \ */
public static String replaceSubstring(