Document Processor Engine
The Document Processor Engine provides batch processing functionality to access a single API or multiple APIs by passing a single XML instance document to specify template names, data sources, languages, output type, output names, and destinations.
This solution enables batch printing with XML Publisher, in which a single XML document can be used to define a set of invoices for customers, including the preferred output format and delivery channel for those customers. The XML format is very flexible allowing multiple documents to be created or a single master document.
This section:
Describes the hierarchy and elements of the Document Processor XML file
Provides sample XML files to demonstrate specific processing options
Provides example code to invoke the processors
Hierarchy and Elements of the Document Processor XML File
The Document Processor XML file has the following element hierarchy:
Requestset request delivery filesystem print fax number email message document background text pagenumber template data
This hierarchy is displayed in the following illustration:
The following table describes each of the elements:
Element | Attributes | Description |
---|---|---|
requestset | xmlns version | Root element must contain [xmlns:xapi="http://xmlns.oracle.com/oxp/xapi/"] block The version is not required, but defaults to "1.0". |
request | N/A | Element that contains the data and template processing definitions. |
delivery | N/A | Defines where the generated output is sent. |
document | output-type | Specify one output that can have several template elements. The output-type attribute is optional. Valid values are: pdf (Default) rtf html excel text |
filesystem | output | Specify this element to save the output to the file system. Define the directory path in the output attribute. |
| The print element can occur multiple times under delivery to print one document to several printers. Specify the printer attribute as a URI, such as:"ipp://myprintserver:631/printers/printername" | |
fax |
| Specify a URI in the server attribute, for example: "ipp://myfaxserver1:631/printers/myfaxmachine" |
number | The number element can occur multiple times to list multiple fax numbers. Each element occurrence must contain only one number. | |
| Specify the outgoing mail server (SMTP) in the server attribute. Specify the mail server port in the port attribute. | |
message |
| The message element can be placed several times under the email element. You can specify character data in the message element. You can specify multiple e-mail addresses in the to, cc and bcc attributes separated by a comma. The attachment value is either true or false (default). If attachment is true, then a generated document will be attached when the e-mail is sent. The subject attribute is optional. |
background | where | If the background text is required on a specific page, then set the where value to the page numbers required. The page index starts at 1. The default value is 0, which places the background on all pages. |
text |
| Specify the watermark text in the title value. A default value of "yes" automatically draws the watermark with forward slash type. The default value is yes. |
pagenumber |
| The initial-page-index default value is 0. The initial-value default value is 1. "Helvetica" is used for the page number font. The x-pos provides lower left x position. The y-pos provides lower left y position. |
template |
| Contains template information. Valid values for the type attribute are rtf xsl-fo etext The default value is "pdf". |
data | location | Define the location attribute to specify the location of the data, or attach the actual XML data with subelements. The default value of location is "inline". It the location points to either an XML file or a URL, then the data should contain an XML declaration with the proper encoding. If the location attribute is not specified, the data element should contain the subelements for the actual data. This must not include an XML declaration. |
XML File Samples
Following are sample XML files that show:
Simple XML shape
Defining two data sets
Defining multiple templates and data
Retrieving templates over HTTP
Retrieving data over HTTP
Generating more than one output
Defining page numbers
Simple XML sample
The following sample is a simple example that shows the definition of one template (template1.pdf) and one data source (data1) to produce one output file (outfile.pdf) delivered to the file system:
Example
<?xml version="1.0" encoding="UTF-8" ?> <xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\tmp\outfile.pdf" /> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="d:\mywork\template1.pdf"> <xapi:data> <field1>data1</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request> </xapi:requestset>
Defining two data sets
The following example shows how to define two data sources to merge with one template to produce one output file delivered to the file system:
Example
<?xml version="1.0" encoding="UTF-8"?><xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\tmp\outfile.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="d:\mywork\template1.pdf"> <xapi:data> <field1>The first set of data</field1> </xapi:data> <xapi:data> <field1>The second set of data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request></xapi:requestset>
Defining multiple templates and data
The following example builds on the previous examples by applying two data sources to one template and two data sources to a second template, and then merging the two into a single output file. Note that when merging documents, the output-type must be "pdf".
Example
<?xml version="1.0" encoding="UTF-8"?><xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\tmp\outfile3.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="d:\mywork\template1.pdf"> <xapi:data> <field1>The first set of data</field1> </xapi:data> <xapi:data> <field1>The second set of data</field1> </xapi:data> </xapi:template> <xapi:template type="pdf" location="d:\mywork\template2.pdf"> <xapi:data> <field1>The third set of data</field1> </xapi:data> <xapi:data> <field1>The fourth set of data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request></xapi:requestset>
Retrieving templates over HTTP
This sample is identical to the previous example, except in this case the two templates are retrieved over HTTP:
<?xml version="1.0" encoding="UTF-8"?><xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\temp\out4.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="http://your.server:9999/templates/template1.pdf"> <xapi:data> <field1>The first page data</field1> </xapi:data> <xapi:data> <field1>The second page data</field1> </xapi:data> </xapi:template> <xapi:template type="pdf" location="http://your.server:9999/templates/template2.pdf"> <xapi:data> <field1>The third page data</field1> </xapi:data> <xapi:data> <field1>The fourth page data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request></xapi:requestset>
Retrieving data over HTTP
This sample builds on the previous example and shows one template with two data sources, all retrieved via HTTP; and a second template retrieved via HTTP with its two data sources embedded in the XML:
Example
<?xml version="1.0" encoding="UTF-8"?><xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\temp\out5.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="http://your.server:9999/templates/template1.pdf"> <xapi:data location="http://your.server:9999/data/data_1.xml"/> <xapi:data location="http://your.server:9999/data/data_2.xml"/> </xapi:template> <xapi:template type="pdf" location="http://your.server:9999/templates/template2.pdf"> <xapi:data> <field1>The third page data</field1> </xapi:data> <xapi:data> <field1>The fourth page data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request></xapi:requestset>
Generating more than one output
The following sample shows the generation of two outputs: out_1.pdf and out_2.pdf. Note that a request element is defined for each output.
Example
<?xml version="1.0" encoding="UTF-8"?><xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\temp\out_1.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="d:\mywork\template1.pdf"> <xapi:data> <field1>The first set of data</field1> </xapi:data> <xapi:data> <field1>The second set of data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\temp\out_2.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="d:mywork\template2.pdf"> <xapi:data> <field1>The third set of data</field1> </xapi:data> <xapi:data> <field1>The fourth set of data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request></xapi:requestset>
Defining page numbers
The following sample shows the use of the pagenumber element to define page numbers on a PDF output document. The first document that is generated will begin with an initial page number value of 1. The second output document will begin with an initial page number value of 3. The pagenumber element can reside anywhere within the document element tags.
Note that page numbering that is applied using the pagenumber element will not replace page numbers that are defined in the template.
<?xml version="1.0" encoding="UTF-8"?><xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi"> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\temp\out7-1.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:pagenumber initial-value="1" initial-page-index="1" x-pos="300" y-pos="20" /> <xapi:template type="pdf" location="d:\mywork\template1.pdf"> <xapi:data> <field1>The first page data</field1> </xapi:data> <xapi:data> <field1>The second page data</field1> </xapi:data> </xapi:template> </xapi:document> </xapi:request> <xapi:request> <xapi:delivery> <xapi:filesystem output="d:\temp\out7-2.pdf"/> </xapi:delivery> <xapi:document output-type="pdf"> <xapi:template type="pdf" location="d:\mywork\template2.pdf"> <xapi:data> <field1>The third page data</field1> </xapi:data> <xapi:data> <field1>The fourth page data</field1> </xapi:data> </xapi:template> <xapi:pagenumber initial-value="3" initial-page-index="1" x-pos="300" y-pos="20" /> </xapi:document> </xapi:request></xapi:requestset>
Invoke Processors
The following code samples show how to invoke the document processor engine using an input file name and an input stream.
Invoke Processors with Input File Name
Input:
Data file name (String)
Directory for Temporary Files (String)
Example
import oracle.apps.xdo.batch.DocumentProcessor;... public static void main(String[] args) {... try { // dataFile --- File path of the Document Processor XML // tempDir --- Temporary Directory path DocumentProcessor docProcessor = new DocumentProcessor(dataFile, tempDir); docProcessor.process(); } catch(Exception e) {e.printStackTrace(); System.exit(1); } System.exit(0); }
Invoke Processors with InputStream
Input:
Data file (InputStream)
Directory for Temporary Files (String)
Example
import oracle.apps.xdo.batch.DocumentProcessor;import java.io.InputStream;... public static void main(String[] args) {... try { // dataFile --- File path of the Document Processor XML // tempDir --- Temporary Directory path FileInputStream fIs = new FileInputStream(dataFile); DocumentProcessor docProcessor = new DocumentProcessor(fIs, tempDir); docProcessor.process(); fIs.close(); } catch(Exception e) {e.printStackTrace(); System.exit(1); } System.exit(0); }