Monday, September 14, 2015

Oracle E-Business Suite R12.2.x | How to integrating OA Framework and BI Publisher



Controller Code
==============================
//Import below classes in controller

import oracle.xdo.XDOException;
import oracle.xdo.template.FOProcessor;
import oracle.xdo.template.RTFProcessor;
import oracle.cabo.ui.data.DataObject;
import oracle.xml.parser.v2.XMLNode;


/*
 * Handles functionality of Print button
 */

     if("printRpt".equals(pageContext.getParameter(EVENT_PARAM))) {

                DataObject sessionDictionary = pageContext.getNamedDataObject("_SessionParameters");
                HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");

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

                  try {
                     
                      ServletOutputStream os = response.getOutputStream();

                //Calling RTF Processor
                //RTF Processor generate XSL

                      RTFProcessor rtfProcessor = new RTFProcessor("/u01/oracle/ERPDEV/fs2/EBSapps/comn/java/classes/xxmoh/oracle/apps/per/selfservice/hrorder/template/TEMPLATE_SOURCE_PER_XXMOH_HR_SUSP_ORD_ar_SA_OAF.rtf");

                      ByteArrayOutputStream xlsOutputStream = new ByteArrayOutputStream();
                      rtfProcessor.setOutput(xlsOutputStream);
                      rtfProcessor.process();
                     
                       ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();

                             byte bufutf[] ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes();
                             localByteArrayOutputStream.write(bufutf);
                             byte buf[] = "<XXMainPG>".getBytes();
                             localByteArrayOutputStream.write(buf);
                           
                            Serializable[] params = {pageContext.getParameter("P_OrderSeq")};                         
                            XMLNode Nodes = (XMLNode)am.invokeMethod("getPrintDataXML", params);
                            
                             Nodes.print(localByteArrayOutputStream);
                            
                             byte buf2[] = "</XXMainPG>".getBytes();
                             localByteArrayOutputStream.write(buf2);

// To generate file

                      ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(localByteArrayOutputStream.toByteArray());
                     
                      System.out.println("XML : "+localByteArrayOutputStream.toString());
                    
//Calling FO Processor
//FO processor take XML data and RTF as XSL and generate PDF output
                      FOProcessor processor = new FOProcessor();
                     
                      ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();

                      processor.setData(xmlInputStream); //set xml input Stream
                      ByteArrayInputStream xlsInputStream = new ByteArrayInputStream(xlsOutputStream.toByteArray());
                      processor.setTemplate(xlsInputStream); //set xsl input file
                      processor.setOutput(pdfOutputStream);
                      processor.setOutputFormat(FOProcessor.FORMAT_PDF);
                     
                      processor.generate();
                     
     // Write the PDF Report to the HttpServletResponse object and flush.
                      byte[] b = pdfOutputStream.toByteArray();
                      response.setContentLength(b.length);
                      os.write(b, 0, b.length);
                      os.flush();
                      os.close();
                      pdfOutputStream.flush();
                      pdfOutputStream.close();
                     
                     
                  } catch (IOException e) {
                      // TODO
                      e.printStackTrace();
                  } catch (XDOException e) {
                        // TODO
                        e.printStackTrace();
                    }
                }



Application Module Code
==============================
import oracle.jbo.XMLInterface;
import oracle.xml.parser.v2.XMLNode;

    public XMLNode getPrintDataXML(String P_SeqNo) {

        try {

           OAViewObject vo = (OAViewObject)findViewObject("XxtstRptVO");

               vo.setWhereClause(null);
               vo.setWhereClause(" ORDER_SEQ = " + P_SeqNo);

             // Exceute VO
              vo.executeQuery();

              XMLNode xmlNode = (XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);

              return xmlNode;

             } catch (Exception e) {

               throw new OAException(e.getMessage() + "Custom Error in XML generation");
            }
 
      }



1 comment:

  1. Hi, where can i find "oracle.xdo.XDOException;" this file? I dont see this on unix. Is there a specific Jar i need to download?

    ReplyDelete