| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Apr | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||
JDeveloper is a great tool for writing your applications with the exception of lacking a usable reporting tool. For my projects I have been using Jasper Reports with a lot of success, however jasper is limited in some ways, so I am always looking for a new report tool. Oracle’s xmlpublisher / BI Publisher in it’s newest form looks like it might do the trick.
Like any Computer Geek I got excited when I demoed the new BIP ( I always love new toys), it was easy to configure and setup, the reports are easy to create using word templates and RTF, and it came with an API to use in your java programs. Being an Oracle tool, of course it would would just drop into JDEV and work right? Wrong? The APIs do not utilize the XDO report files that BIP creates, so in order to use it in JDEV you would have to create new data templates to exatract your data and then run it though the apis to generate your reports. Since the XDO report files are xml, I sat down and wrote a class that will exactract the the items I need to generate my reports in jdev using my BIP reports.
This code is quick and to the point, still needs some error handling and polishing, but you can get the idea of how it works. Since this is my first time using the xml parser, I am sure that I am doing things the hard way. I found idea for the XML reading routines from an article I found online, which outlined using Oracle’s DOM XML parser, I figured since I am in JDEV anyways might as well use the oracle clases when I can.
Here is the Code for the class:
package yourcompany.yourapp.model.custom;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This is a custom class to take a report from Business Intelligence Publisher and extract
//The needed data to utilize the APIs from BIP to render your reports.
//This class will take the XDO report file and extract the following items:
// The SQL Statement that generates the data XML File
// The Template File Name
// The Parameters used in the report
// these items can be then passed to the APIs to generate your reports
//
// This class still needs error handling to make it complete
// 29 Nov 2007 - Kelly Burton
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import oracle.xml.jaxp.JXDocumentBuilder;
import oracle.xml.jaxp.JXDocumentBuilderFactory;
import oracle.xml.parser.v2.XMLAttr;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.XMLElement;
import oracle.xml.parser.v2.XMLNode;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
public class parseXDO {
private String sqlData;
private String xdoFileName;
private ArrayList parameters = new ArrayList();
private String template;
public parseXDO() {
this.sqlData = null;
this.xdoFileName = null;
this.template = null;
}
public parseXDO(String xdoFile){
this.setReportFileName(xdoFile);
}
public void setTemplate(String template) {
this.template = template;
}
public String getTemplate() {
if (this.template == null ) this.processReport();
return template;
}
public void setSqlData(String sqlData) {
this.sqlData = sqlData;
}
public String getSqlData() {
if (this.sqlData == null ) this.processReport();
return sqlData;
}
public void setReportFileName(String xdoFileName) {
this.xdoFileName = xdoFileName;
if (xdoFileName !=null){
this.processReport();
}
}
public String getReportFileName() {
return xdoFileName;
}
public void setParameters(ArrayList parameters) {
this.parameters = parameters;
}
public ArrayList getParameters() {
return parameters;
}
private void processReport() {
try {
JXDocumentBuilderFactory factory = (JXDocumentBuilderFactory) JXDocumentBuilderFactory.newInstance();
JXDocumentBuilder documentBuilder = (JXDocumentBuilder) factory.newDocumentBuilder();
InputStream input = new FileInputStream(new File(this.xdoFileName));
XMLDocument xmlDocument = (XMLDocument) (documentBuilder.parse(input));
XMLElement rootElement = (XMLElement) (xmlDocument.getDocumentElement());
if (rootElement.hasChildNodes()) {
NodeList nodeList = rootElement.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
XMLNode node = (XMLNode) nodeList.item(i);
if (node.getNodeType() == XMLNode.ELEMENT_NODE) {
XMLElement element = (XMLElement) node;
// This is the start of the loop for getting the items from the report.
if (element.getTagName().compareTo(”templates”)== 0) {
if (element.hasChildNodes() ) {
NodeList nl = element.getChildNodes();
for (int j = 0; j < nl.getLength(); j++){
XMLNode cn = (XMLNode) nl.item(j);
if (cn.getLocalName() !=null && cn.getLocalName().compareTo(”template”)==0){
if (cn.hasAttributes ()){
NamedNodeMap xattributes = (NamedNodeMap) cn.getAttributes();
for (int l =0; l < xattributes.getLength(); l++){
XMLAttr xattribute = (XMLAttr) xattributes.item(l);
if (xattribute.getName().compareTo(”url”)==0){
this.template = xattribute.getValue().trim();
}
}
}
}
}
}
} //End if TEMPLATES
if (element.getTagName().compareTo(”dataModel”)== 0) {
if (element.hasChildNodes() ) {
NodeList nl = element.getChildNodes();
for (int j = 0; j < nl.getLength(); j++){
XMLNode cn = (XMLNode) nl.item(j);
if (cn.getLocalName() !=null &&
cn.getLocalName().compareTo(”dataSet”)==0 ){
this.sqlData = cn.getText().trim();
}
}
}
} //end if DATAMODEL
if (element.getTagName().compareTo(”parameters”)== 0) {
if (element.hasChildNodes() ) {
NodeList nl = element.getChildNodes();
for (int j = 0; j < nl.getLength(); j++){
XMLNode cn = (XMLNode) nl.item(j);
if (cn.getLocalName() !=null && cn.getLocalName().compareTo(”parameter”)==0){
if (cn.hasAttributes ()){
NamedNodeMap xattributes = (NamedNodeMap) cn.getAttributes();
for (int l =0; l < xattributes.getLength(); l++){
XMLAttr xattribute = (XMLAttr) xattributes.item(l);
if (xattribute.getName().compareTo(”id”)==0){
this.parameters.add(xattribute.getValue());
}
}
}
}
}
}
}//end if PARAMETERS
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
//Constructor file file name to create and process in one.
//Testing code
parseXDO parseXDO = new parseXDO(”c:/xmlwork/readmeFinal.xdo”);
System.out.println(parseXDO.getTemplate());
System.out.println(parseXDO.getReportFileName());
System.out.println(parseXDO.getSqlData());
//No Constructor Test
//parseXDO myXDO = new parseXDO();
//myXDO.setReportFileName(”c:/xmlwork/readmeFinal.xdo”);
//System.out.println(myXDO.getSqlData());
}
}
Using this class, you can take your XDO file and extract the SQL for the report, the parameters for your report, and the name of your template. Using this information you can pass it to the APIs to generate your reports using BIP/XMLPublisher and JDEV. Next Article I will show you how to use this class and the APIs to generate your reports for the user to download or view on the web page.
December 1, 2007 at 12:10 am
Hey JDevGuru
In the latest release 10.1.3.3.1 there are a set of web services that allow you to communicate wit hthe server and leave all of the definitions on the server and either ‘run now’ or schedule reports to be run. Worth a look.
Tim
December 1, 2007 at 6:25 am
Thanks Tim, I will take a look at that as well, whichever way is easiest for me to get my reports out, is the way for me
February 27, 2008 at 3:51 am
Looks interesting what you write. But because I never used reports I don’t know yet how I could use this in my ADF application.
Looking forowrd to your next article!! “how to use this class and the APIs to generate your reports for the user to download or view on the web page.”
Any idea when you will publish that?
March 3, 2008 at 11:38 am
“Next Article I will show you how to use this class and the APIs to generate your reports for the user to download or view on the web page.”
Hi, I really liked the above article. Have you posted the above article that you mentioned? Thank you.
March 25, 2008 at 1:47 pm
I still have to write the next article. Things at work got busy and no time to write. I have been using BPEL too and would like to write a few articles about it.