COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => SDK => Topic started by: Galaxy on 20 Jul 2011 01:42:39 PM

Title: How to read or import reports and its contents
Post by: Galaxy on 20 Jul 2011 01:42:39 PM

Hi All,

Have one question on cognos SDK.  I need to read  the report contents and save as a html file OR  need to import the report as a pdf file / htm file.

How to achieve this ?  please share your ideas.   and i am able to connect to the content store and able to list the reports
Title: Re: How to read or import reports and its contents
Post by: jdzurek on 06 Oct 2011 12:47:53 PM
You can access the report specification content XML through the use of CMService Query method. This might help you out.

ex:

public void setReportSpecs(String ReportPath) throws Exception{
        String sReportSpec = null;
        PropEnum props[] = new PropEnum[]{PropEnum.searchPath, PropEnum.defaultName, PropEnum.specification};
        SearchPathMultipleObject spMulti = new SearchPathMultipleObject();
        spMulti.set_value(ReportPath);

        try {
            BaseClass[] repPth = cognosConnection.getCmService().query(spMulti, props, new Sort[]{}, new QueryOptions());
           
            // There should be only one report with the specified searchPath
            if (repPth != null && repPth.length > 0)
            {
                // extract the report spec
                sReportSpec = (((Report) repPth[0]).getSpecification().getValue());
                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = builderFactory.newDocumentBuilder();
                InputStream is = new ByteArrayInputStream(sReportSpec.getBytes("UTF-8"));
                this.xmlDoc = builder.parse(is);
            }
            else
                this.xmlDoc = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }