Sei sulla pagina 1di 4

Integrate XML Publisher and OA Framework

The oracle applications is continuously evolving with the use of new technologies.
It is shifting from a traditional form based application to a self service web based application using Oracle
Applications Framework (OAF) .
Every application requires a seamless integration with the reporting tools.
OA Framework seamlessly integrates with XML Publisher to fulfill the Oracle Applications reporting
requirement.
In this article we will discuss in detail the integration of OA Framework and XML Publisher with an example.
It is assumed that the reader has basic understanding of OA Framework and XML Publisher.

The article has the following section
1) XML Publisher Architecture
2) Designing the OAF BC4J Data Model.
3) Designing the OAF Page and generating the Data XML
4) Designing the RTF Template using Data XML
5) Registering the Template with Oracle Applications.
6) Integrating the OAF page With XML Publisher.
7) Invoking the report from OAF

Step 1 : XML Publisher Reporting Architecture
An XML publisher report consist of a report template designed in RTF or PDF Formatand a Data XML file. The
template contains the report layout. During execution the Data XML File is merged with the template to
generate a PDF, HTML, EXCEL or RTF report.
Step 2: Designing the OAF BC4J Data Model.
Using jdeveloper create a ViewObject EmpVO using the below query and associate it to ApplicationModule
EmpAM.

SELECT empno,ename,job,mgr,hiredate,comm,deptno FROM emp

The Jdevloper should look like this
Step 3 : Generating the XML for Template Design
Design a OAF Page EmpPG with the Following Code in the Controller EmpCO.
EmpCO :

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAApplicationModuleImpl am= (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
am.invokeMethod("initEmpVO");
am.invokeMethod("getEmpDataXML");
}
EmpAMImpl :

public void initEmpVO()
{
EmpVOImpl vo = getEmpVO1();
if(vo == null)
{
MessageToken errTokens[] = {
new MessageToken("OBJECT_NAME", "EmpVO1")
};
throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
} else
{
vo.executeQuery();
}
}
public void getEmpDataXML()
{
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OAViewObject vo = (OAViewObject)findViewObject("EmpVO1");
((XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS)).print(outputStream);
System.out.println(outputStream.toString());
}
catch(Exception e)
{
throw new OAException (e.getMessage());
}
}
On running the page , the data xml file will be printed on the Jdeveloper Embeded OC4J Sever Log (since i
have used System.out.println). The XML file will be like
<EmpVO>
<EmpVORow>
<Empno>7369</Empno>
<Ename>SMITH</Ename>
<Job>CLERK</Job>
<Mgr>7902</Mgr>
<Hiredate>1980-12-17</Hiredate>
<Deptno>20</Deptno>
</EmpVORow>
<EmpVORow>
<Empno>7499</Empno>
<Ename>ALLEN</Ename>
<Job>SALESMAN</Job>
<Mgr>7698</Mgr>
<Hiredate>1981-02-20</Hiredate>
<Comm>300</Comm>
<Deptno>30</Deptno>
</EmpVORow>
<EmpVORow>
<Empno>7521</Empno>
<Ename>WARD</Ename>
<Job>SALESMAN</Job>
<Mgr>7698</Mgr>
<Hiredate>1981-02-22</Hiredate>
<Comm>500</Comm>
<Deptno>30</Deptno>
</EmpVORow>
</EmpVO>
Step 4 : Designing the Template

Install the Oracle XML Publisher Desktop available via patch 5887917. Open the Microsoft word. You should
be able to see the following menus and toolbars.
Using the menu Data -> Load XML Data... , load the XML File generated from Jdeveloper

If the XML files gets loaded successfully, then you should get the below confirmation.
Using the Table Wizard as below to create the 'Table Report Format' with all the columns of EMP.
The Table Report Format Template should be like
Save the document as Emp.rtf. Preview the report as PDF, XML, HTMl or RTF.
Step 5 : Registering the Template with Oracle Applications.
Login with a user having "XML Publisher Administrator" Responsibility.Navigate to Home --> Data Definition
and define the data definition.
Navigate to Home --> Template and Define the Template
Step 7 : Integrating the OAF page With XML Publisher
Design the EmpPG page to appear as shown below.
Set the Action Type and Event property of the Tourch Image Item to FireAction and GenerateReport
respectively. Modify the Controller and ApplicationModule as below

Imports :
import oracle.xml.parser.v2.XMLNode;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.xdo.XDOException;
import oracle.apps.xdo.oa.schema.server.TemplateHelper;
import oracle.cabo.ui.data.DataObject;
import oracle.jbo.XMLInterface;

EmpCO :
private static final int DEPTH = 4;
private static final int APP_ID = 20035;
private static final String APP_NAME = "XXIGS";
private static final String TEMPLATE_CODE = "Emp_Template";
private static final int BUFFER_SIZE = 32000;

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAApplicationModuleImpl am= (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
am.invokeMethod("initEmpVO");
}
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModuleImpl am= (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);

String event = pageContext.getParameter("event");
if("GenerateReport".equals(event))
{

// Get the HttpServletResponse object from the PageContext. The report output is written to
HttpServletResponse.
DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
HttpServletResponse response =
(HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
try {
ServletOutputStream os = response.getOutputStream();

// Set the Output Report File Name and Content Type
String contentDisposition = "attachment;filename=EmpReport.pdf";
response.setHeader("Content-Disposition",contentDisposition);
response.setContentType("application/pdf");

// Get the Data XML File as the XMLNode
XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xmlNode.print(outputStream);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();

//Generate the PDF Report.
TemplateHelper.processTemplate(
((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsConte
xt(),
APP_NAME,TEMPLATE_CODE,((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getO
ADBTransaction()).getUserLocale().getLanguage(),((OADBTransactionImpl)pageContext.getApplicationModul
e(webBean).getOADBTransaction()).getUserLocale().getCountry(),inputStream,TemplateHelper.OUTPUT_TY
PE_PDF,null,pdfFile);

// Write the PDF Report to the HttpServletResponse object and flush.
byte[] b = pdfFile.toByteArray();
response.setContentLength(b.length);
os.write(b, 0, b.length);
os.flush();
os.close();
}
catch(Exception e)
{
response.setContentType("text/html");
throw new OAException(e.getMessage(), OAException.ERROR);
}
pageContext.setDocumentRendered(false);
}
EMpAMImpl :

public void initEmpVO()
{ EmpVOImpl vo = getEmpVO1();
if(vo == null)
{ MessageToken errTokens[] = { new MessageToken("OBJECT_NAME", "EmpVO1") };
throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
} else { vo.executeQuery(); }
}
public XMLNode getEmpDataXML()
{
OAViewObject vo = (OAViewObject)findViewObject("EmpVO1");
XMLNode xmlNode = (XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
return xmlNode;
}
Run the EmpPG page and click on the tourch icon. The File Download window appear. Click on the Open
Button to view the report.

Potrebbero piacerti anche