Saturday 19 January 2013

Integrating XML Publisher and OAF


It is a very common requirement where we want to generate reports in PDF,
format from an OAF page itself without submitting any concurrent program.

To generate the output in PDF formats we need the following:

1 Design the OAF BC4J Object.
2) Design the OAF Page and generate the Data XML
3) Design the RTF Template using Data XML
4) Register the Template with Oracle Applications.
5) Integrating the OAF page With XML Publisher.
6) Invoking the report from OAF

//In Controller

import com.sun.java.util.collections.ArrayList;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.servlet.ServletOutputStream;
import oracle.apps.xdo.oa.schema.server.TemplateHelper;
import oracle.xml.parser.v2.XMLNode;
import java.lang.System;
import oracle.apps.fnd.framework.server.OADBTransactionImpl;
public class XXCO extends OAControllerImpl
{
private static final int DEPTH = 4;
private static final int APP_ID = 20003;
private static final String APP_NAME = "TPC";
private static final String TEMPLATE_CODE = "TPCFULLRUGTPEF"
private static final int BUFFER_SIZE = 32000;

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);


}


public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.invokeMethod("executeEdVO");

//Print Edward
if(pageContext.getParameter("edPrintBtn") != null)
{
// 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=TPCEdward.pdf";
response.setHeader("Content-Disposition",contentDisposition);
response.setContentType("application/pdf");

// Get the Data XML File as the XMLNode
XMLNode xmlNode = (XMLNode) am.invokeMethod("getEdwardDataXML");
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()).getAppsContext(),APP_NAME,TEMPLATE_CODE, ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(), ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),inputStream,TemplateHelper.OUTPUT_TYPE_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(true);

}

}

}





in AMImpl.java

public void executeEdVO()
{
OAViewObject vo = (OAViewObject)findViewObject("TpcEdwardVO1");
//OAViewObject vo = getTpcEdwardVO1();
if (vo.getFetchedRowCount() == 0)
{
// Setting the match fetch size to 0 for an in-memory VO
// prevents it from trying to query rows.
// Calling executeQuery() is a small workaround to a known
// BC4J issue that ensures that modified rows in this
// transient view object are not lost after commit. See
// View Objects in Detail for additional information about
// both of these calls.
vo.setMaxFetchSize(0);
vo.executeQuery();
vo.insertRow(vo.createRow());
}
}

public XMLNode getEdwardDataXML()
{
OAViewObject vo = (OAViewObject)findViewObject("TpcEdwardVO1");
XMLNode xmlNode = (XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
return xmlNode;
}

1 comment:

Anonymous said...

Can we use mutlipule VOs and Combine in to one XML