My Question: How do you run and download a report to text? In BusinessObjects, you can download reports as a plain text file. The documentation for the API indicates that you can download reports in various formats. How is this accomplished?
How to download them as PDF: In the documentation, they describe how to download them as a PDF file:
ViewSupport pdfViewSupport = new ViewSupport();
pdfViewSupport.setOutputFormat(OutputFormatType.PDF);
pdfViewSupport.setViewType(ViewType.BINARY);
pdfViewSupport.setViewMode(ViewModeType.DOCUMENT);
RetrieveBinaryView retBinView = new RetrieveBinaryView();
retBinView.setViewSupport(pdfViewSupport);
RetrieveData retBOData = new RetrieveData();
retBOData.setRetrieveView(retBinView);
DocumentInformation docInfo = boReportEngine.getDocumentInformation(struid, null, null, null, retBOData);
BinaryView myBOView = (BinaryView) boDocInfo.getView();
byte[] docContents = myBOView.getContent();
When I change:
pdfViewSupport.setOutputFormat(OutputFormatType.PDF);
pdfViewSupport.setViewType(ViewType.BINARY);
pdfViewSupport.setViewMode(ViewModeType.DOCUMENT);
to
pdfViewSupport.setOutputFormat(OutputFormatType.INT_HTML);
pdfViewSupport.setViewType(ViewType.INT_CHARACTER);
pdfViewSupport.setViewMode(ViewModeType.INT_REPORT_PAGE);
I get the following error:
org.apache.axis2.AxisFault: Binary view of such a document should be only requested with the use of ViewType.BINARY (WRE 01151)
The funny thing is that I set the ViewType to be INT_CHARACTER, not BINARY...
It breaks on the line:
DocumentInformation docInfo = boReportEngine.getDocumentInformation(struid, null, null, null, retBOData);
What I'm trying to do: It's really complicated, but I basically want to have a report which returns a single row and just prints that on the report (nothing else) and then download that report as text because the text is xml which I use in another program.
Any help would be great!
Note: I'm running on a 3.2 server, but we'll be upgrading to 4.0 pretty soon. So if the solution could work for both versions, that'd be awesome, otherwise a v4 and v3.x solution would be awesome as well :)
The problem this line:
RetrieveBinaryView retBinView = new RetrieveBinaryView();
So I don't know how this all works, but this is what you're looking for:
ViewSupport viewSupport = ViewSupport.Factory.newInstance();
viewSupport.setOutputFormat(OutputFormatType.INT_XML);
viewSupport.setViewType(ViewType.INT_CHARACTER);
viewSupport.setViewMode(ViewModeType.INT_REPORT_PAGE);
RetrieveData retBOData = RetrieveData.Factory.newInstance();
RetrieveXMLView retXMLView = RetrieveXMLView.Factory.newInstance();
retXMLView.setViewSupport(viewSupport);
retBOData.setRetrieveView(retXMLView);
DocumentInformation boDocInfo = getDocInfo(actions, retBOData);
XMLView bView = (XMLView) boDocInfo.getView();
ByteArrayOutputStream out = new ByteArrayOutputStream(bView.getContentLength());
bView.getContent().save(out);
byte[] reportBytes = out.toByteArray();
String reportInString = new String(reportBytes);
However, the reportInString
here is XML representing the report. So what I did was encapsulate what I want out of the report with a prefix and suffix. So, for example, let's say I encapsulate it with @#$ThisIsWhatYouWant-
and -End$#@
, then I would do the following:
Pattern patt = Pattern.compile("(?i)@#$ThisIsWhatYouWant-(.*?)-End$#@", Pattern.DOTALL);
Matcher match = patt.matcher(reportInString);
if (match.find()) {
return match.group(1);
}
return null;
P.S. This should work for both 3.x and 4.0 BO Servers.