使用java concurrent调用xmlp api生成pdf

目的:通过java concurrent调用XML Publisher API处理XML Data Definitionrtf 模板生成PDF报表。

环境:Oracle EBS R12.0.4

技术:Oracle, Java, XML Publisher

 

步骤:

 

1.创建XML数据定义文件(EmpDataTemplate.xml)并上传至服务器的/home/applprod/test4bip/目录:

<?xml version="1.0" encoding="UTF-8" ?> 
 <dataTemplate name="EmpData" description="Employee Details" Version="1.0">
	<parameters>
		<parameter name="p_DeptNo" dataType="character" /> 
	</parameters>
 <dataQuery>
	<sqlStatement name="Q1">
	<!--[CDATA[ 
	SELECT d.DEPTNO DEPTNO
		  ,d.DNAME DNAME
		  ,d.LOC LOC
		  ,e.EMPNO EMPNO
		  ,e.ENAME ENAME
		  ,e.JOB JOB
		  ,e.MGR MGR
		  ,e.HIREDATE HIREDATE
		  ,e.SAL SAL
		  ,nvl(e.COMM, 0) COMM
	  FROM scott.dept d
		  ,scott.emp  e
	 WHERE d.deptno = e.deptno
	   AND d.deptno = nvl( :p_DeptNo, d.deptno)
	]]--> 
	</sqlStatement>
  </dataQuery>
  <dataStructure>
	<group name="G_DEPT" source="Q1">
		<element name="DEPT_NUMBER"		value="DEPTNO" /> 
		<element name="DEPT_NAME"		value="DNAME" /> 
		<element name="LOCATION"		value="LOC" /> 
		<element name="EMPLOYEE_NUMBER" value="EMPNO" /> 
		<element name="NAME"			value="ENAME" /> 
		<element name="JOB"				value="JOB" /> 
		<element name="MANAGER"			value="MGR" /> 
		<element name="HIREDATE"		value="HIREDATE" /> 
		<element name="SALARY"			value="SAL" /> 
		<element name="COMMISSION"		value="COMM" /> 
	</group>
  </dataStructure>
 </dataTemplate>

 

2.创建rtf模板(EmpDataTemplate.rtf)并上传至服务器的/home/applprod/test4bip/目录:

使用java concurrent调用xmlp api生成pdf_第1张图片

 

3.创建java concurrent程序(EmpDataTemplate.java)。如果不能编译通过,需到服务器上的$JAVA_TOP目录下载相关类文件(可使用zip命令打包下载: zip -r ~/conclib ./oracle/apps/fnd/cp/*):

package oracle.apps.fnd.cp;

import java.sql.Connection;
import oracle.apps.fnd.cp.request.CpContext;
import oracle.apps.fnd.cp.request.JavaConcurrentProgram;
import oracle.apps.xdo.dataengine.DataProcessor;
import oracle.apps.fnd.util.ParameterList;
import oracle.apps.fnd.cp.request.ReqCompletion;
import oracle.apps.fnd.cp.request.OutFile;
import oracle.apps.fnd.cp.request.LogFile;
import oracle.apps.fnd.util.NameValueType;
import oracle.apps.xdo.template.RTFProcessor;
import oracle.apps.xdo.template.FOProcessor;
import com.sun.java.util.collections.Hashtable;
import java.io.File;

public class EmpDataTemplate implements JavaConcurrentProgram {

    String deptNo;

    public void runProgram(CpContext cpContext) {
        {

            ParameterList params = cpContext.getParameterList();
            ReqCompletion compl = cpContext.getReqCompletion();
            OutFile outFile = cpContext.getOutFile();
            LogFile logFile = cpContext.getLogFile();
            logFile.writeln(">>1 start ..", LogFile.STATEMENT);

            while (params.hasMoreElements()) {
                NameValueType val = params.nextParameter();
                if (val.getName().equals("P_DEPTNO"))
                    deptNo = val.getValue();

            }

            logFile.writeln(">>2 P_DEPTNO = " + deptNo, LogFile.STATEMENT);

            Connection jdbcConnection = cpContext.getJDBCConnection();

            try {

                //Initialization – instantiate the DataProcessor class//
                DataProcessor dataProcessor = new DataProcessor();

                //Set Data Template to be executed
                dataProcessor.setDataTemplate("/home/applprod/test4bip/EmpDataTemplate.xml");
                logFile.writeln(">>3 dataProcessor.setDataTemplate",
                                LogFile.STATEMENT);
				
				// Assign parameter
                Hashtable parameters = new Hashtable();
                parameters.put("p_DeptNo", deptNo);
                dataProcessor.setParameters(parameters);
                logFile.writeln(">>4 dataProcessor.setParameters",
                                LogFile.STATEMENT);

                // Set the jdbc connection
                dataProcessor.setConnection(jdbcConnection);
                logFile.writeln(">>5 dataProcessor.setConnection",
                                LogFile.STATEMENT);

                // Specify the output directory and file for the data file
                dataProcessor.setOutput("/home/applprod/test4bip/EmpDetails.xml");
                logFile.writeln(">>6 dataProcessor.setOutput",
                                LogFile.STATEMENT);

                // Process the data template
                dataProcessor.processData();
                logFile.writeln(">>6.1 dataProcessor.processData",
                                LogFile.STATEMENT);

                // Convert rtf to xsl
                RTFProcessor rtfProcessor =
                    new RTFProcessor("/home/applprod/test4bip/EmpDataTemplate.rtf");
                logFile.writeln(">>7 new RTFProcessor()", LogFile.STATEMENT);

                rtfProcessor.setOutput("/home/applprod/test4bip/EmpDataTemplate.xsl");
                rtfProcessor.process();

                logFile.writeln(">>8 rtfProcessor.process()",
                                LogFile.STATEMENT);

                // Geneate PDF
                FOProcessor foProcessor = new FOProcessor();
                foProcessor.setData("/home/applprod/test4bip/EmpDetails.xml");
                logFile.writeln(">>9 foProcessor.setData()",
                                LogFile.STATEMENT);

                foProcessor.setTemplate("/home/applprod/test4bip/EmpDataTemplate.xsl");
                logFile.writeln(">>10 foProcessor.setTemplate()",
                                LogFile.STATEMENT);

                foProcessor.setOutput("/home/applprod/test4bip/EmpDetails001.pdf");
                logFile.writeln(">>11 foProcessor.setOutput()",
                                LogFile.STATEMENT);
                foProcessor.setOutputFormat(FOProcessor.FORMAT_PDF);
                foProcessor.generate();
                logFile.writeln(">>12 foProcessor.generate() 001",
                                LogFile.STATEMENT);

                compl.setCompletion(ReqCompletion.NORMAL,
                                    "Concurrent Normal Completed!");

            } catch (Exception e) {
                compl.setCompletion(ReqCompletion.ERROR, e.toString());
            }
        }


    }
}

 

4.编译EmpDataTemplate.java,将EmpDataTemplate.class上传至服务器的$JAVA_TOP/oracle/apps/fnd/cp目录。

 

 

 

 

 

 

 

5.定义Executable:

Executable

Short Name

Application

Execution Method

Execution File Name

Execution File Path

XXFND_JAVAXMLP

XXFND_JAVAXMLP

Application Object Library

Java Concurrent Program

EmpDataTemplate

oracle.apps.fnd.cp

 

6.定义Program,挂请求,测试。

 

7.相关文档下载:

http://download.csdn.net/source/3209735

 

8.参考资料:

1http://blogs.oracle.com/xmlpublisher/2007/05/howto_java_concurrent_programs.html

 


原文链接: http://blog.csdn.net/t0nsha/article/details/6336872

你可能感兴趣的:(使用java concurrent调用xmlp api生成pdf)