Amazon Contextual Product Ads

Tuesday, 4 February 2014

Show BI Publisher Report in Oracle ADF page – with Java API only


The following was developed with Jdeveloper 11g R2 ( and BI Publisher 10g.

My task was to allow user to download some data from the web - site in the “Power Point” format. The data is dynamically generated so PPT file need to be created each time user click the “download” button.

Oracle Bi Publisher  (OBP) is the obvious choice about what is the framework for PPT file generation. OBP can take XML source data , apply it over RTF template (which OBP knows how to convert to XSL-FO) and create different output types (PDF,Power Point,HTML…).

   First step was to generate the XML file. Actually we could do it with extracting XML from VO, but I will show how can we avoid this.

   OBP has something called “Data Template”, which is also the XML file. The purpose of this XML file is to define the SQL that will be used to extract the data and to define the structure of the XML file that is later used as a Data Source.

First of all we need to obtain the JDBC connection. We will get it from the web-logic Data Source


Now create some data in the database

Journal VARCHAR(25), Publisher VARCHAR(25),
Edition VARCHAR(25), Title Varchar(45), Author Varchar(25));
INSERT INTO Catalog VALUES('catalog1', 'Oracle Magazine', 'Oracle Publishing', 
'March-April 2006', 'Commanding ASM', 'Arup Nanda');
INSERT INTO Catalog VALUES('catalog2', 'Oracle Magazine', 'Oracle Publishing', 
'May-June 2006', 'Tuning Your View Objects', 'Steve Muench');
INSERT INTO Catalog VALUES('catalog3', 'Oracle Magazine', 'Oracle Publishing', 
'May-June 2006', 'Managing Oracle Portal', 'Aradhana Puri');

Get the connection from the Web Logic

 javax.naming.Context initialContext = new javax.naming.InitialContext();
 javax.sql.DataSource dataSource =  (javax.sql.DataSource)initialContext.lookup("jdbc/Conn");
 Connection          connection = dataSource.getConnection();

Create XML data from “Data Template”

DataProcessor dataProcessor = new DataProcessor();
ByteArrayOutputStream out  = new ByteArrayOutputStream();
byte[] data = out.toByteArray();
ByteArrayInputStream istream = new ByteArrayInputStream(data);
System.out.println("Done data template");

Convert RTF file to XSL-FO

 RTFProcessor rtf = new RTFProcessor("C:\\Users\\Unitask\\Doc1.rtf");
 ByteArrayOutputStream outXslFo  = new ByteArrayOutputStream();
 byte[] dataXslFo = outXslFo.toByteArray();
 ByteArrayInputStream inXslFo = new ByteArrayInputStream(dataXslFo);

Merge XML Data and XSL-FO to generate a power point

FOProcessor processor = new FOProcessor();
 System.out.println("Done power point");

Now to make all this working in Jdeveloper, you first of all need to add a lot of jar to the CLASSPATH. To get the jar files you need to download “Oracle BI Publisher for Desktop” from Oracle web site and install it. After installation go to (I didn’t change the default installation folder) C:\Program Files (x86)\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\jlib and the following jars to your ADF application


Note: You actually don’t need the ojdbc6.jar file

Build a web page with a button that has “fileDownloadListener”

<af:commandButton text="Export" id="cb1">
     <af:fileDownloadActionListener contentType="application/"

“sendPtt” is the method in the managed bean that is executing exactly the same code I posted above.

This method out of the box gets OutputStream

 public void sendPtt(FacesContext context, OutputStream outParam) throws IOException

and it is used to write the the request output stream. You can see that we use it in this line of code


Now what is you also want to display the data to the user before he/she performing the actual “download”? Not a problem. You cannot present power point in the borwser, but who said it should be a “Power Point”. User only want to see it and doesn’t cares about the format. So you can generate the same output in HTML or PDF and embed into your page.

I created the servlet (called it “report”) and used the same code, but this time I asked to create a PDF output.

In my ADF page I used “Inline Frame” component that I pointed to “report” servlet


Now when user starts the page , he can see the data and also to download it as “Power Point”


You can download the workspace and RTF and Data Template bellow


OBP Files

No comments:

Post a Comment