ヘッダーをスキップ

Oracle XML Publisherユーザーズ・ガイド
リリース11i
B25754-01
目次へ
目次
前のページへ
前へ
次のページへ
次へ

XMLパブリッシャAPIのコール

この章では、次のトピックについて説明します。

概要

この章は、Application Program Interfaceを介してXMLパブリッシャと対話するプログラムまたはアプリケーションを作成する開発者を対象としています。この情報は、OracleMetaLink Document 337999.1『About Oracle XML Publisher Release 5.6』から入手できるJavadocをあわせて参照することを前提としています。

XMLパブリッシャは、Java APIのコア層と、APIおよびUIのアプリケーション層の2つの層で構成されています。

この項は、読者にJavaプログラミング、XMLおよびXSLテクノロジの知識があることを前提としています。アプリケーション層については、テンプレート・マネージャの知識があることを前提としています。

XMLパブリッシャのコアAPI

XMLパブリッシャは、次のコアAPIコンポーネントで構成されています。

次の図は、各コア処理エンジンに対するテンプレート・タイプおよび出力タイプのオプションを示しています。

テキストで説明されている画像

PDFフォーム処理エンジン

PDFフォーム処理エンジンは、PDFテンプレートとXMLデータ・ファイルをマージしてPDF文書を作成します。これには、ファイル名、ストリームまたはXMLデータ文字列を使用します。

PDF処理エンジンの入力として、XMLベースのテンプレート・メタ情報(.xtm)ファイルを必要に応じて組み込むことができます。このファイルは、オーバーフロー・データの配置を定義する補足テンプレートです。

FO処理エンジンにも、PDFテンプレートに関する情報を提供するユーティリティが組み込まれています。これらのユーティリティでは、次の処理を実行できます。

PDFテンプレートとXMLデータのマージ

XMLデータをPDFテンプレートとマージしてPDF出力文書を作成するには、次の3つの方法があります。

必要に応じて、テンプレート内のオーバーフロー・データの配置を記述するメタデータXMLファイルを組み込むことができます。

入力/出力ファイル名を使用したXMLデータとPDFテンプレートのマージ

入力:

出力:

import oracle.apps.xdo.template.FormProcessor;
.
.
    FormProcessor fProcessor = new FormProcessor();

    fProcessor.setTemplate(args[0]);  // Input File (PDF) name
    fProcessor.setData(args[1]);     // Input XML data file name
    fProcessor.setOutput(args[2]);   // Output File (PDF) name
    fProcessor.setMetaInfo(args[3]);   // Metadata XML File name  You can omit this setting when you do not use Metadata.
    fProcessor.process();

入力/出力ストリームを使用したXMLデータとPDFテンプレートのマージ

入力:

出力:

import java.io.*;
import oracle.apps.xdo.template.FormProcessor;
.
.
.
  FormProcessor fProcessor = new FormProcessor();

  FileInputStream fIs = new FileInputStream(originalFilePath); // Input File
  FileInputStream fIs2 = new FileInputStream(dataFilePath); // Input Data
  FileInputStream fIs3 = new FileInputStream(metaData); // Metadata XML Data
  FileOutputStream fOs = new FileOutputStream(newFilePath); // Output File

  fProcessor.setTemplate(fIs);
  fProcessor.setData(fIs2);   // Input Data
  fProcessor.setOutput(fOs);
  fProcessor.setMetaInfo(fIs3);
  fProcessor.process();

  fIs.close();
  fOs.close();


XMLデータ文字列とPDFテンプレートのマージ

入力:

出力:

import oracle.apps.xdo.template.FormProcessor;
.
.
.
FormProcessor fProcessor = new FormProcessor();

fProcessor.setTemplate(originalFilePath);     // Input File (PDF) name
fProcessor.setDataString(xmlContents);       // Input XML string
fProcessor.setOutput(newFilePath);           // Output File (PDF) name
fProcessor.setMetaInfo(metaXml);        // Metadata XML File name    You can omit this setting when you do not use Metadata.
fProcessor.process();

フィールド名リストの取得

PDFテンプレートからフィールド名を取得するには、FormProcessor.getFieldNames() APIを使用します。このAPIでは、フィールド名が列挙オブジェクトに戻されます。

入力:

出力:

import java.util.Enumeration;
import oracle.apps.xdo.template.FormProcessor;
.
.
.
FormProcessor fProcessor = new FormProcessor();
fProcessor.setTemplate(filePath);        // Input File (PDF) name
Enumeration enum = fProcessor.getFieldNames();
while(enum.hasMoreElements()) {
  String formName = (String)enum.nextElement();
  System.out.println("name : " + formName + " , value : " + fProcessor.getFieldValue(formName));
}

XFDFデータの生成

XML Forms Data Format(XFDF)は、PDF文書内のフォーム・データと注釈を表すための形式です。XFDFは、Forms Data Format(FDF)のXMLバージョンであり、フォーム・データと注釈を表すためのPDFの簡易バージョンです。PDF文書内のフォーム・フィールドには、編集ボックス、ボタンおよびラジオ・ボタンが含まれます。

このクラスを使用してXFDFデータを生成します。このクラスのインスタンスを作成すると、内部XFDFツリーが初期化されます。append()メソッドを使用して、文字列の名前と値のペアを渡すことによって、FIELD要素をXFDFツリーに追加します。データは必要なだけ追加できます。

このクラスでは、appendXML()メソッドをコールしてXMLデータを追加することもできます。appendXML()メソッドをコールする前に、setStyleSheet()メソッドをコールして適切なXSLスタイルシートを設定する必要があることに注意してください。XMLデータは必要なだけ追加できます。

toString()、toReader()、toInputStream()またはtoXMLDocument()のいずれかのメソッドをコールすると、内部XFDF文書をいつでも取得できます。

次に、XFDFデータのサンプルを示します。

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>
 <field name="TITLE">
  <value>Purchase Order</value>
  </field>
 <field name="SUPPLIER_TITLE">
   <value>Supplie</value>
 </field>
  ...
 </fields>

次のコード例は、APIの使用方法を示しています。

import oracle.apps.xdo.template.FormProcessor;
import oracle.apps.xdo.template.pdf.xfdf.XFDFObject;
.
.
.
FormProcessor fProcessor = new FormProcessor();
fProcessor.setTemplate(filePath);      // Input File (PDF) name
XFDFObject xfdfObject = new XFDFObject(fProcessor.getFieldInfo());
System.out.println(xfdfObject.toString());

XSLTを使用したXMLデータのXFDF形式への変換

XSLスタイルシートを使用して、標準のXMLをXFDF形式に変換します。次に、サンプルのXMLデータをXFDFに変換する例を示します。

次のように、開始時のXMLはROWSET/ROW形式であるとします。

<ROWSET>
     <ROW num="0">
       <SUPPLIER>Supplier</SUPPLIER>
       <SUPPLIERNUMBER>Supplier Number</SUPPLIERNUMBER>
       <CURRCODE>Currency</CURRCODE>
     </ROW>
...
</ROWSET>

このXMLから次のXFDF形式を生成するとします。

 <fields>
  <field name="SUPPLIER1">
    <value>Supplier</value>
  </field>
  <field name="SUPPLIERNUMBER1">
    <value>Supplier Number</value>
  </field>
  <field name="CURRCODE1">
    <value>Currency</value>
  </field>
...
</fields>

次のXSLTによって変換が実行されます。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<fields>
<xsl:apply-templates/>
</fields>
</xsl:template>
   <!-- Count how many ROWs(rows) are in the source XML file. -->
   <xsl:variable name="cnt" select="count(//row|//ROW)" />
   <!-- Try to match ROW (or row) element.
   <xsl:template match="ROW/*|row/*">
      <field>
         <!-- Set "name" attribute in "field" element. -->
         <xsl:attribute name="name">
            <!-- Set the name of the current element (column name)as a value of the current name attribute. -->
            <xsl:value-of select="name(.)" />
            <!-- Add the number at the end of the name attribute value if more than 1 rows found in the source XML file.-->
            <xsl:if test="$cnt > 1">
               <xsl:number count="ROW|row" level="single" format="1"/>
            </xsl:if>
         </xsl:attribute>
         <value>
            <!--Set the text data set in the current column data as a text of the "value" element. -->
            <xsl:value-of select="." />
         </value>
      </field>
   </xsl:template>
</xsl:stylesheet>          

この結果、次のようにXSLTを使用すると、XFDFObjectを使用してXMLをXFDF形式に変換できます。

import java.io.*;
import oracle.apps.xdo.template.pdf.xfdf.XFDFObject;
.
.
.
XFDFObject xfdfObject  = new XFDFObject();

xfdfObject .setStylesheet(new BufferedInputStream(new FileInputStream(xslPath)));   // XSL file name
xfdfObject .appendXML( new File(xmlPath1));   // XML data file name
xfdfObject .appendXML( new File(xmlPath2));   // XML data file name

System.out.print(xfdfObject .toString());

RTFプロセッサ・エンジン

XSLの生成

RTFプロセッサ・エンジンは、入力としてRTFテンプレートを使用します。プロセッサは、テンプレートを解析し、XSL-FOテンプレートを作成します。このテンプレートをデータ・ソース(XMLファイル)とともにFOエンジンに渡すと、PDF、HTML、RTFまたはExcel(HTML)の出力を作成できます。

次の例に示すように、入力/出力ファイル名または入力/出力ストリームのいずれかを使用します。

入力/出力ファイル名を使用したXSLの生成

入力:

出力:

import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args)
  {
RTFProcessor rtfProcessor = new RTFProcessor(args[0]); //input template
rtfProcessor.setOutput(args[1]);  // output file
rtfProcessor.process();
    System.exit(0);
  }

入力/出力ストリームを使用したXSLの生成

入力:

出力:

import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args)
  {
    FileInputStream   fIs  = new FileInputStream(args[0]);  //input template
    FileOutputStream  fOs  = new FileOutputStream(args[1]); // output

    RTFProcessor rtfProcessor = new RTFProcessor(fIs);
    rtfProcessor.setOutput(fOs);
    rtfProcessor.process();
    // Closes inputStreams outputStream
    System.exit(0);
  }

FOプロセッサ・エンジン

XMLファイルおよびXSLファイルからの出力の生成

FOプロセッサ・エンジンは、W3C XSL-FO標準のXMLパブリッシャによる実装であり、すべてのXSL-FOコンポーネントの完全な実装を表しているわけではありません。FOプロセッサは、次に示す2つの入力のいずれかから、PDF、RTF、HTMLまたはExcel(HTML)の出力を生成できます。

両方の入力タイプをファイル名、ストリームまたは配列で渡すことができます。setOutputFormatメソッドを次のいずれかに設定して出力形式を設定します。

次の入力からXSL-FOを作成するXSL-FOユーティリティも提供されています。

XSL-FOユーティリティからのFOオブジェクト出力は、FOプロセッサの入力として使用できます。

FOプロセッサの主な機能

双方向テキスト

XMLパブリッシャでは、BiDiレイアウトに関してUnicode BiDiアルゴリズムを利用します。FOプロセッサでは、プロパティwriting-mode、directionおよびunicode bidiに対する特定の値に基づいてBiDiレイアウトがサポートされます。

writing-modeプロパティでは、テキストにおける行の語順、および行の順序が定義されます。つまり、right-to-left, top-to-bottom(右から左、上から下)またはleft-to-right, top-to-bottom(左から右、上から下)のいずれかを指定します。directionプロパティでは、テキスト文字列の書込み方法が決まります。つまり、right-to-left(右から左)またはleft-to-right(左から右)などの方向を指定します。unicode bidiでは、上書き動作が制御および管理されます。

フォント代替メカニズム

FOプロセッサでは、2つのレベルのフォント代替メカニズムがサポートされています。このメカニズムでは、指定したフォントまたは絵文字が検出されない場合に使用するデフォルト・フォントが制御されます。XMLパブリッシャでは、適切なデフォルト代替フォントが自動的に提供され、構成は必要ありません。また、使用するデフォルト・フォントを指定するユーザー定義の構成ファイルもサポートされています。絵文字の代替の場合、デフォルト・メカニズムでは絵文字のみが置換され、文字列全体は置換されません。

詳細は、「XMLパブリッシャ構成ファイル」を参照してください。

可変ヘッダーおよびフッター

ヘッダーおよびフッターがテンプレートで定義されているより多くの領域を必要とする場合は、FOプロセッサによって、ページのヘッダーおよびフッターの値と本文領域余白の値との差異に基づいて、ヘッダーおよびフッターの領域が拡張され、本文の領域が縮小されます。

水平方向の表区切り

この機能では、Zスタイルの水平方向の表区切りがサポートされます。水平方向の表区切りは列の拡張に影響されないため、拡張された列のセルがページ(または領域の幅)を超えた場合は、FOプロセッサによってセルが分割され、分割セルに対してインテリジェント書式設定は適用されません。

次の図は、幅が広すぎるために1ページに表示できない表を示しています。

テキストで説明されている画像

次の図は、幅の広い表を水平方向の表区切りで処理する方法の1つのオプションを示しています。この例では、3列目の後で水平方向の表区切りが行われます。

テキストで説明されている画像

次の図は、別のオプションを示しています。3列目の後で表が区切られますが、新しい各ページに1列目が表示されます。

テキストで説明されている画像

ファイル名を使用した出力の生成

次の例は、FOプロセッサでファイル名を使用して出力ファイルを作成する方法を示しています。

入力:

出力:

import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args)
  {

    FOProcessor processor = new FOProcessor();
    processor.setData(args[0]);     // set XML input file
    processor.setTemplate(args[1]); // set XSL input file
    processor.setOutput(args[2]);  //set output file
    processor.setOutputFormat(FOProcessor.FORMAT_PDF);
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }

    System.exit(0);
  }

ストリームを使用した出力の生成

次の例に示すように、入力/出力ストリームを指定してプロセッサを使用することもできます。

入力:

出力:

import java.io.InputStream;
import java.io.OutputStream;
import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public void runFOProcessor(InputStream xmlInputStream,
                             InputStream xslInputStream,
                             OutputStream pdfOutputStream)
  {

    FOProcessor processor = new FOProcessor();
    processor.setData(xmlInputStream);
    processor.setTemplate(xslInputStream);
    processor.setOutput(pdfOutputStream);
    // Set output format (for PDF generation)
    processor.setOutputFormat(FOProcessor.FORMAT_PDF);
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }

    System.exit(0);

  }

XSLテンプレートおよびXMLデータの配列からの出力の生成

データとテンプレートの配列の組合せを処理して、複数の入力から1つの出力ファイルを生成できます。入力データ・ソースの数は、データに適用されるテンプレートの数と一致する必要があります。たとえば、File1.xml、File2.xml、File3.xmlとFile1.xsl、File2.xsl、File3.xslの入力から単一のFile1_File2_File3.pdfが作成されます。

入力:

出力:

import java.io.InputStream;
import java.io.OutputStream;
import oracle.apps.xdo.template.FOProcessor;
.
.
.
   public static void main(String[] args)
  {

    String[] xmlInput = {"first.xml", "second.xml", "third.xml"};
    String[] xslInput = {"first.xsl", "second.xsl", "third.xsl"};


    FOProcessor processor = new FOProcessor();
    processor.setData(xmlInput);
    processor.setTemplate(xslInput);

    processor.setOutput("/tmp/output.pdf);          //set (PDF) output file
    processor.setOutputFormat(FOProcessor.FORMAT_PDF); processor.process();
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }

  }
    

XSL-FOユーティリティの使用

入力XMLおよびXSLファイルからXSL-FO出力ファイルを作成するか、または2つのXSL-FOファイルをマージするには、XSL-FOユーティリティを使用します。このユーティリティで作成される出力は、最終出力の生成に使用できます。「FOファイルからの出力の生成」を参照してください。

XMLファイルおよびXSLファイルからのXSL-FOの作成

入力:

出力:

import oracle.apps.xdo.template.fo.util.FOUtility;
.
.
.
  public static void main(String[] args)
  {
    InputStream foStream;

    // creates XSL-FO InputStream from XML(arg[0])
    // and XSL(arg[1]) filepath String
    foStream = FOUtility.createFO(args[0], args[1]);
    if (mergedFOStream == null)
    {
      System.out.println("Merge failed.");
      System.exit(1);
    }

    System.exit(0);
  }

2つのXMLファイルおよび2つのXSLファイルからのXSL-FOの作成

入力:

出力:

import oracle.apps.xdo.template.fo.util.FOUtility;
.
.
.
  public static void main(String[] args)
  {
    InputStream firstFOStream, secondFOStream, mergedFOStream;
    InputStream[] input = InputStream[2];

    // creates XSL-FO from arguments
    firstFOStream = FOUtility.createFO(args[0], args[1]);

    // creates another XSL-FO from arguments
    secondFOStream = FOUtility.createFO(args[2], args[3]);

    // set each InputStream into the InputStream Array
    Array.set(input, 0, firstFOStream);
    Array.set(input, 1, secondFOStream);

    // merges two XSL-FOs
    mergedFOStream = FOUtility.mergeFOs(input);

    if (mergedFOStream == null)
    {
      System.out.println("Merge failed.");
      System.exit(1);
    }
    System.exit(0);
  }

2つのXSL-FOファイルのマージ

入力:

出力:

import oracle.apps.xdo.template.fo.util.FOUtility;
.
.
.
  public static void main(String[] args)
  {
    InputStream mergedFOStream;

    // creates Array
    String[] input = {args[0], args[1]};

    // merges two FO files
    mergedFOStream = FOUtility.mergeFOs(input);
    if (mergedFOStream == null)
    {
      System.out.println("Merge failed.");
      System.exit(1);
    }
    System.exit(0);
  }

FOファイルからの出力の生成

FOプロセッサは、FOオブジェクトを処理して最終出力を生成するためにも使用できます。FOオブジェクトは、XMLデータにXSL-FOスタイルシートを適用した結果です。これらのオブジェクトは、サード・パーティのアプリケーションから生成でき、FOプロセッサの入力として使用できます。

プロセッサのコール方法は前述の方法と同じですが、書式設定の指示はFOに含まれているため、テンプレートは必要ありません。

ファイル名を使用した出力の生成

入力:

出力:

import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args) {

    FOProcessor processor = new FOProcessor();
    processor.setData(args[0]);     // set XSL-FO input file
    processor.setTemplate((String)null);
    processor.setOutput(args[2]);  //set (PDF) output file
    processor.setOutputFormat(FOProcessor.FORMAT_PDF);
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }

    System.exit(0);
  }

ストリームを使用した出力の生成

入力:

出力:

import java.io.InputStream;
import java.io.OutputStream;
import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public void runFOProcessor(InputStream xmlfoInputStream,
                             OutputStream pdfOutputStream)
  {

    FOProcessor processor = new FOProcessor();
    processor.setData(xmlfoInputStream);
    processor.setTemplate((String)null);

    processor.setOutput(pdfOutputStream);
    // Set output format (for PDF generation)
    processor.setOutputFormat(FOProcessor.FORMAT_PDF);
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }
  }

FOデータの配列を使用した出力の生成

複数のFO入力を配列として渡して単一の出力ファイルを生成できます。テンプレートは必要でないため、次の例に示すように、テンプレート配列のメンバーはnullに設定します。

入力:

出力:

import java.lang.reflect.Array;
import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args)
  {

    String[] xmlInput = {"first.fo", "second.fo", "third.fo"};
    String[] xslInput = {null, null, null};   // null needs for xsl-fo input

    FOProcessor processor = new FOProcessor();
    processor.setData(xmlInput);
    processor.setTemplate(xslInput);

    processor.setOutput("/tmp/output.pdf);          //set (PDF) output file
    processor.setOutputFormat(FOProcessor.FORMAT_PDF); processor.process();
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }

  }

PDF文書マージ機能

PDF文書マージ機能クラスでは、PDF文書を操作するための一連のユーティリティが提供されます。これらのユーティリティを使用すると、文書のマージ、ページ番号の追加、背景の設定および透かしの追加を実行できます。

PDF文書のマージ

多くのビジネス文書が、最終的に1つの文書にマージする必要がある別個の複数の文書で構成されています。PDFDocMergerクラスでは、複数文書をマージして単一のPDF文書を作成する機能がサポートされています。また、作成した文書をさらに操作して、ページ番号、透かしまたはその他の背景イメージを追加できます。

入力/出力ファイル名を使用したマージ

次のコードは、物理ファイルを使用して2つのPDF文書をマージ(連結)して、単一の出力文書を生成する方法を示しています。

入力:

出力:

import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
.
.
.
  public static void main(String[] args)
  {
    try
    {
      // Last argument is PDF file name for output
      int inputNumbers = args.length - 1;

      // Initialize inputStreams
      FileInputStream[] inputStreams = new FileInputStream[inputNumbers];
      inputStreams[0] = new FileInputStream(args[0]);
      inputStreams[1] = new FileInputStream(args[1]);

      // Initialize outputStream
      FileOutputStream outputStream = new FileOutputStream(args[2]);

      // Initialize PDFDocMerger
      PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);

      // Merge PDF Documents and generates new PDF Document
      docMerger.mergePDFDocs();
      docMerger = null;

      // Closes inputStreams and outputStream
    }
    catch(Exception exc)
    {
      exc.printStackTrace();
    }
  }

入力/出力ストリームを使用したマージ

入力:

出力:

import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
.
.
.
  public boolean mergeDocs(InputStream[] inputStreams, OutputStream outputStream)
  {
    try
    {
      // Initialize PDFDocMerger
      PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);

      // Merge PDF Documents and generates new PDF Document
      docMerger.mergePDFDocs();
      docMerger = null;

      return true;
    }
    catch(Exception exc)
    {
      exc.printStackTrace();
      return false;
    }
  }

ページ番号を配置するための背景とのマージ

次のコードは、入力ストリームを使用して2つのPDF文書をマージし、単一のマージ出力ストリームを生成する方法を示しています。

ページ番号を追加する手順は、次のとおりです。

  1. 最終出力PDF文書でページ番号を表示する位置にPDFフォーム・フィールドを組み込んだ背景用のPDFテンプレート文書を作成します。

  2. フォーム・フィールドに@pagenum@という名前を設定します。

  3. フィールドに、ページ番号の開始番号を入力します。フィールドに値を入力しない場合、開始ページ番号はデフォルトで1に設定されます。

入力:

出力:

import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
.
.
.
 public static boolean mergeDocs(InputStream[] inputStreams, InputStream backgroundStream, OutputStream outputStream)

 {
    try
    {
      // Initialize PDFDocMerger
      PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);

      // Set Background
      docMerger.setBackground(backgroundStream);

      // Merge PDF Documents and generates new PDF Document
      docMerger.mergePDFDocs();
      docMerger = null;

      return true;
    }
    catch(Exception exc)
    {
      exc.printStackTrace();
      return false;
    }
  }

マージ文書へのページ番号の追加

FOプロセッサでは、XSL-FOテンプレートによってページ番号がネイティブでサポートされていますが、複数の文書をマージしている場合、完成した文書に最初から最後まで番号を付けるにはこのクラスを使用する必要があります。

次に示すコード例では、次のメソッドを使用して、ページ上の特定位置へのページ番号配置、番号の書式設定、および開始値の設定が実行されます。

入力:

出力:

import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
.
.
.
  public boolean mergeDocs(InputStream[] inputStreams, OutputStream outputStream)
  {
    try
    {
      // Initialize PDFDocMerger
      PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);

      // Calls several methods to specify Page Number

      // Calling setPageNumberCoordinates() method is necessary to set Page Numbering
      // Please refer to javadoc for more information
      docMerger.setPageNumberCoordinates(300, 20);


      // If this method is not called, then the default font"(Helvetica, 8)" is used.
      docMerger.setPageNumberFontInfo("Courier", 8);

      // If this method is not called, then the default initial value "(1, 1)" is used.
      docMerger.setPageNumberValue(1, 1);

      // Merge PDF Documents and generates new PDF Document
      docMerger.mergePDFDocs();
      docMerger = null;

      return true;
    }
    catch(Exception exc)
    {
      exc.printStackTrace();
      return false;
    }
  }

テキストまたはイメージの透かしの設定

草案段階の一部の文書では、文書全体に「DRAFT」という透かしが表示される必要があります。また、文書に背景イメージが必要な場合もあります。次のコード例は、PDFDocMergerクラスを使用して透かしを設定する方法を示しています。

テキストの透かしの設定

SetTextDefaultWatermark( )メソッドを使用して、次の属性でテキストの透かしを設定します。

または、SetTextWatermark( )メソッドを使用して、各属性を別々に設定する方法もあります。SetTextWatermark()メソッドを次のように使用します。

次の例は、これらのプロパティを設定し、PDFDocMergerをコールする方法を示しています。

入力:

出力:

import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
.
.
.
  public boolean mergeDocs(InputStream inputStreams, OutputStream outputStream)
  {
    try
    {
      // Initialize PDFDocMerger
      PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);

      // You can use setTextDefaultWatermark() without these detailed setting
      docMerger.setTextWatermark("DRAFT", 200f, 200f); //set text and place
      docMerger.setTextWatermarkAngle(80);                //set angle
      docMerger.setTextWatermarkColor(1.0f, 0.3f, 0.5f);  // set RGB Color

      // Merge PDF Documents and generates new PDF Document
      docMerger.mergePDFDocs();
      docMerger = null;

      return true;
    }
    catch(Exception exc)
    {
      exc.printStackTrace();
      return false;
    }
  }

イメージの透かしの設定

イメージの透かしは、文書の背景全体または特定の領域(例: ロゴ表示領域)に表示されるように設定できます。次のように、長方形の座標を使用して、イメージの配置とサイズを指定します。

float[ ] rct = {左下X, 左下Y, 右上X, 右上Y}

例:

float[ ] rct = {100f, 100f, 200f, 200f}

イメージは、定義された長方形の領域にあわせてサイズが変更されます。

サイズを変更せずに実際のイメージ・サイズを使用するには、左下Xと左下Yの位置で配置を定義し、右上Xと右上Yの座標は-1fと指定します。次に例を示します。

float[ ] rct = {100f, 100f, -1f, -1f}

入力:

出力:

import java.io.*;
import oracle.apps.xdo.common.pdf.util.PDFDocMerger;
.
.
.
  public boolean mergeDocs(InputStream inputStreams, OutputStream outputStream, String imageFilePath)
  {
    try
    {
      // Initialize PDFDocMerger
      PDFDocMerger docMerger = new PDFDocMerger(inputStreams, outputStream);

      FileInputStream wmStream = new FileInputStream(imageFilePath);
      float[] rct = {100f, 100f, -1f, -1f};
      pdfMerger.setImageWatermark(wmStream, rct);

      // Merge PDF Documents and generates new PDF Document
      docMerger.mergePDFDocs();
      docMerger = null;

      // Closes inputStreams
      return true;
    }
    catch(Exception exc)
    {
      exc.printStackTrace();
      return false;
    }
  }

文書プロセッサ・エンジン

文書プロセッサ・エンジンは、テンプレート名、データ・ソース、言語、出力タイプ、出力名および出力先を指定する単一のXMLインスタンス文書を渡すことによって、単一のAPIまたは複数のAPIにアクセスするバッチ処理機能を提供します。

このソリューションを使用すると、XMLパブリッシャを使用したバッチ印刷が可能になります。単一のXML文書を使用して、複数の顧客に対する一連の請求書について、顧客ごとの優先出力形式や配信チャネルなども含めて定義できます。XML形式は非常に柔軟性があり、複数文書の作成または単一のマスター文書の作成が可能です。

この項の内容は、次のとおりです。

文書プロセッサXMLファイルの階層と要素

文書プロセッサXMLファイルの要素の階層は、次のとおりです。

Requestset
   request
      delivery
         filesystem
         print
         fax
            number
         email
            message
      document
         background
            text
         pagenumber
         template
            data

この階層を図に表すと、次のようになります。

テキストで説明されている画像

次の表で、各要素について説明します。

要素 属性 説明
requestset xmlns
version
ルート要素には、[xmlns:xapi="http://xmlns.oracle.com/oxp/xapi/"]ブロックが含まれている必要があります。
versionは必須ではありませんが、デフォルトで"1.0"に設定されます。
request 該当なし データおよびテンプレート処理定義が含まれる要素。
delivery 該当なし 生成された出力の送信先を定義します。
document output-type 出力を1つ指定します。この出力には複数のテンプレート要素を設定できます。output-type属性はオプションです。有効な値は、次のとおりです。
pdf(デフォルト)
rtf
html
excel
text
filesystem output 出力をファイル・システムに保存する場合はこの要素を指定します。output属性にディレクトリ・パスを定義します。
print
  • printer

  • server-alias

print要素は、1つの文書を複数のプリンタに印刷するために、deliveryの下に複数回記述できます。printer属性をURI(例:"ipp://myprintserver:631/printers/printername")で指定します。
fax
  • server

  • server-alias

server属性にURIを指定します。例: "ipp://myfaxserver1:631/printers/myfaxmachine"。
number   number要素は、複数のFAX番号をリストするために複数回記述できます。各要素に1つの番号のみ記述する必要があります。
email
  • server

  • port

  • from

  • reply-to

  • server-alias

server属性に送信メール・サーバー(SMTP)を指定します。
port属性にメール・サーバーのポートを指定します。
message
  • to

  • cc

  • bcc

  • attachment

  • subject

message要素は、email要素の下に複数回配置できます。message要素には文字データを指定できます。
to、ccおよびbcc属性には、複数のEメール・アドレスをカンマで区切って指定できます。
attachmentの値はtrueまたはfalse(デフォルト)です。attachmentがtrueの場合、生成された文書はEメールの送信時に添付されます。
subject属性はオプションです。
background where 特定のページに背景テキストが必要な場合は、where値に必要なページ番号を設定します。ページ索引は1から始まります。デフォルト値は0(ゼロ)で、この場合はすべてのページに背景が配置されます。
text
  • title

  • default

titleの値に透かしテキストを指定します。
defaultの値がyesの場合は、スラッシュ付きの透かしが自動的に描画されます。デフォルト値はyesです。
pagenumber
  • initial-page-index

  • initial-value

  • x-pos

  • y-pos

initial-page-indexのデフォルト値は0(ゼロ)です。
initial-valueのデフォルト値は1です。
ページ番号のフォントにはHelveticaが使用されます。
x-posは、左下のx位置を示します。
y-posは、左下のy位置を示します。
template
  • locale

  • location

  • type

テンプレート情報が記述されます。
type属性の有効な値は、次のとおりです。
pdf
rtf
xsl-fo
etext
デフォルト値はpdfです。
data location location属性を定義して、データの格納場所を指定するか、またはサブ要素を含む実際のXMLデータを添付します。locationのデフォルト値はinlineです。locationがXMLファイルまたはURLのいずれかを指し示す場合、データには正しいエンコーディングのXML宣言が含まれている必要があります。
location属性が指定されない場合は、データ要素に実際のデータのサブ要素が含まれている必要があります。これにはXML宣言を含めないでください。

XMLファイルのサンプル

この項では、次の例を示す各サンプルXMLファイルを提供します。

単純なXMLのサンプル

次のサンプルは、1つのテンプレート(template1.pdf)と1つのデータ・ソース(data1)から、ファイル・システムに送信される1つの出力ファイル(outfile.pdf)を作成する定義を示す単純な例です。

<?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>

2つのデータ・セットの定義

次の例は、2つのデータ・ソースを定義して1つのテンプレートとマージし、ファイル・システムに送信される1つの出力ファイルを作成する方法を示しています。

<?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>

複数のテンプレートおよびデータの定義

次の例は、前述の例を基に、2つのデータ・ソースを1つのテンプレートに、さらに2つのデータ・ソースを2番目のテンプレートに適用し、これら2つを1つの出力ファイルにマージする方法を示しています。文書をマージするときは、output-typeが"pdf"であることが必要です。

<?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>

HTTPを介したテンプレートの取得

このサンプルは、前述の例とほぼ同じですが、2つのテンプレートが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>

HTTPを介したデータの取得

このサンプルは、前述の例を基に、2つのデータ・ソースを使用する1つのテンプレートを示しています。これらはすべてHTTPを介して取得されます。さらに、HTTPを介して取得される2番目のテンプレートと、XMLに埋め込まれた2つのデータ・ソースが示されています。

<?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>

複数出力の生成

次のサンプルは、2つの出力out_1.pdfとout_2.pdfの生成を示しています。各出力に対してrequest要素が定義されていることに注意してください。

<?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>

ページ番号の定義

次のサンプルは、PDF出力文書にページ番号を定義するpagenumber要素の使用方法を示しています。生成される最初の文書は、初期ページ番号値1で始まります。2番目の出力文書は、初期ページ番号値3で始まります。pagenumber要素は、document要素タグ内の任意の場所に配置できます。

pagenumber要素を使用して適用されるページ番号は、テンプレートで定義されているページ番号を置換しません。

<?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>

プロセッサの起動

次のコード例は、入力ファイル名と入力ストリームを使用して文書プロセッサ・エンジンを起動する方法を示しています。

入力ファイル名を使用したプロセッサの起動

入力:

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);
  }

入力ストリームを使用したプロセッサの起動

入力:

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);
  }


XMLパブリッシャのプロパティ

FOプロセッサでは、最終的な文書に適用可能なPDFセキュリティおよびその他のプロパティがサポートされています。セキュリティ・プロパティには、文書を印刷不可にする機能、および暗号化文書にパスワード・セキュリティを適用する機能があります。

その他のプロパティでは、フォントのサブセット化および埋込みを定義できます。テンプレートで、通常XMLパブリッシャで実行時に使用できないフォントが使用されている場合は、フォント・プロパティを使用してフォントの格納場所を指定できます。XMLパブリッシャは、実行時にフォントを取得し、最終的な文書で使用します。たとえば、このプロパティは、小切手の口座番号と銀行支店コードにMICRフォントを使用している場合に、その小切手の印刷に使用される場合があります。

プロパティの全リストは、「XMLパブリッシャのプロパティ」を参照してください。

プロパティの設定

プロパティは、次の2つの方法で設定できます。

FOエンジンへのプロパティの受渡し

プロパティをプロパティ・オブジェクトとして渡すには、FOプロセッサをコールする前にプロパティの名前/値のペアを設定します。次に例を示します。

入力:

出力:

import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args)
  {

    FOProcessor processor = new FOProcessor();
    processor.setData(args[0]);     // set XML input file
    processor.setTemplate(args[1]); // set XSL input file
    processor.setOutput(args[2]);  //set (PDF) output file
    processor.setOutputFormat(FOProcessor.FORMAT_PDF);
    Properties prop = new Properties();
    prop.put("pdf-security", "true");             // PDF security control
    prop.put("pdf-permissions-password", "abc");  // permissions password
    prop.put("pdf-encription-level", "0");        // encryption level
    processor.setConfig(prop);
    // Start processing
    try
    {
       processor.generate();
    }
    catch (XDOException e)
    {
       e.printStackTrace();
       System.exit(1);
    }

    System.exit(0);
  }

FOプロセッサへの構成ファイルの受渡し

次のコードは、構成ファイルの格納場所を渡す例を示しています。

入力:

出力:

import oracle.apps.xdo.template.FOProcessor;
.
.
.
  public static void main(String[] args)
  {
    FOProcessor processor = new FOProcessor();
    processor.setData(args[0]);     // set XML input file
                 processor.setTemplate(args[1]); // set XSL input file
    processor.setOutput(args[2]);  //set (PDF) output file
    processor.setOutputFormat(FOProcessor.FORMAT_PDF);
    processor.setConfig(“/tmp/xmlpconfig.xml”);
    // Start processing
    try
    {
       processor.generate();
    }    catch (XDOException e)
    {       e.printStackTrace();
            System.exit(1);
    }
      System.exit(0);
  }

文書プロセッサへのプロパティの受渡し

入力:

出力:

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);
      Properties prop = new Properties();
      prop.put("pdf-security", "true");         // PDF security control
      prop.put("pdf-permissions-password", "abc");  // permissions password
      prop.put("pdf-encription-level", "0");   // encryption level
      processor.setConfig(prop);
      docProcessor.process();
    }
    catch(Exception e)
    {
        e.printStackTrace();
       System.exit(1);
    }
    System.exit(0);
  }

アプリケーション層のAPI

XMLパブリッシャのアプリケーション層では、「XMLパブリッシャ管理者」職責を使用して、テンプレート・マネージャのユーザー・インタフェースを介してデータ・ソースとテンプレートを格納し、管理できます。また、Application Program Interfaceを介してこれらのオブジェクトにアクセスし、操作することもできます。この項では、プログラマが使用できるAPIについて説明します。

データ・ソースとテンプレートはデータベースに格納されます。この中には、オブジェクトについて記述するメタデータおよび物理オブジェクト自体(例: RTFファイル)が含まれます。これらのAPIを使用すると、データ・ソースとテンプレートに関する情報を登録、更新および取得できます。また、XMLパブリッシャをコールし、テンプレートをデータ・ソースに適用して出力文書を(コンカレント・マネージャを経由せずに)直接生成するためにAPIを使用することもできます。

XMLパブリッシャ・スキーマでは、各データ・ソースに複数のテンプレートを割り当てることができます。ただし、テンプレートはデータ・ソースなしに存在することはできません。次の図は、この関係を表しています。

テキストで説明されている画像

データ・ソースのAPI

プログラムでデータ定義にアクセスして操作するために、次のAPIが用意されています。

DataSourceクラス

データ・ソースは、テンプレートの登録対象のプレースホルダ・オブジェクトとして機能します。DataSourceクラスは、単一のデータ・ソース定義エントリを表します。このクラスでは、データ・ソースのプロパティの設定およびデータ・ソースからのプロパティの取得を実行するために、次に示すメソッドが提供されます。

DataSourceHelperクラス

このクラスは、テンプレート・マネージャ・リポジトリ内のデータ・ソース定義エントリの管理に使用できるユーティリティ・クラスです。

データ・ソース定義エントリは、テンプレートのデータ・ソースを表す論理単位です。各データ・ソース定義エントリには、XSD(XMLスキーマ定義)形式の1つのデータ定義、およびXMLの1つのサンプル・データ・ファイルを設定できます。また、言語ごとに1つ以上の表示名と摘要を設定できます。ユーザーのセッション言語に基づいて、適切な名称と摘要が抽出され、ユーザーに表示されます。

AppsContextの取得

すべてのメソッドに、Applicationsデータベースと通信するためのAppsContextインスタンスが必要です。次のいずれかのメソッドを使用して、コードにAppsContextインスタンスを取得してください。

  1. このクラスをOAフレームワークで使用している場合、AppsContextを取得するには次をコールします。

    ((OADBTransactionImpl)am.getOADBTransaction()).getAppsContext()

    amは使用しているOA ApplicationModuleです。

  2. このクラスをJavaコンカレント・プログラムで使用している場合は、CpContextをAppsContextとして渡します。

  3. それ以外の場合は、DBCファイルからAppsContextを作成します。Applicationsでサーブレット/JSPを実行している場合、DBCファイルのフルパスを取得するには次をコールします。

    System.getProperty("JTFDBCFILE")またはSystem.getProperty("BNEDBCFILE")

データ・ソース定義エントリの作成

新規データ・ソース定義エントリをテンプレート・マネージャ・リポジトリに追加する手順は、次のとおりです。

  1. DataSource.createInstance()メソッドをコールして、DataSourceクラスのインスタンスを作成します。

  2. インスタンスの属性を設定します。

  3. インスタンスをDataSourceHelper.createDataSource()メソッドに渡します。

// Create an instance
 DataSource d = DataSource.createInstance(ctx, "XDO", "TestDataSource");
 // Set properties
 d.setDescription("This is the test data source entry.");
 d.setStartDate(new java.sql.Date(System.currentTimeMillis()));
 d.setName("Test Data Source !");
 d.setStatus(TypeDefinitions.DATA_SOURCE_STATUS_ENABLED);
 // Call createDataSource() to create an entry into the repository
 DataSourceHelper.createDataSource(ctx, d);

データ・ソース定義エントリの取得と更新

リポジトリのデータ・ソース定義エントリを更新するには、DataSourceHelper.getDataSource()メソッドをコールします。このメソッドでは、DataSourceインスタンスの配列が戻されます。データ・ソースのsetメソッドを使用してこれらのインスタンスを更新します。

 // Get data source definition entries
 DataSource[] d = DataSourceHelper.getDataSource(ctx, "XDO", "%XDO%");

 // Update properties
 d.setDescription("New data source entry.");
 d.setStartDate(new java.sql.Date(System.currentTimeMillis()));
 d.setName("New Data Source name");
 d.setStatus(TypeDefinitions.DATA_SOURCE_STATUS_ENABLED);
 // Call updateDataSource() to commit the update in the repository
 DataSourceHelper.updateDataSource(ctx, d);

データ・ソース定義エントリの削除

データ・ソース定義エントリを削除するには、DataSource.deleteDataSource()メソッドをコールします。この関数では、レコードはリポジトリから実際には削除されず、今後の使用に備えて無効のマークが付けられます。このステータスは、DataSource.updateDataSourceStatus()メソッドをコールしていつでも変更できます。

スキーマ・ファイルとサンプル・ファイルの追加、更新および削除

データ・ソース・スキーマ定義ファイルとサンプルXMLファイルを追加、更新および削除するには、DataSourceHelperクラスに定義されているメソッドをコールします。前述のdeleteDataSource()メソッドとは異なり、これらのメソッドではスキーマ・ファイルとサンプル・レコードがリポジトリから実際に削除されることに注意してください。

 // Add a schema definition file
 DataSourceHelper.addSchemaFile(ctx, "XDO", "TestDataSource",
   "schema.xsd", new FileInputStream("/path/to/schema.xsd"));
 // Add a sample xml data file
 DataSourceHelper.addSampleFile(ctx, "XDO", "TestDataSource",
   "sample.xml", new FileInputStream("/path/to/sample.xml"));

 // Update a schema definition file
 DataSourceHelper.addSchemaFile(ctx, "XDO", "TestDataSource",
   new FileInputStream("/path/to/new_schema.xsd"));
 // Update a sample xml data file
 DataSourceHelper.addSampleFile(ctx, "XDO", "TestDataSource",
   new FileInputStream("/path/to/new_sample.xml"));

 // Delete a schema definition file
 DataSourceHelper.deleteSchemaFile(ctx, "XDO", "TestDataSource");
 // Delete a sample xml data file
 DataSourceHelper.deleteSampleFile(ctx, "XDO", "TestDataSource");

スキーマ・ファイルとサンプル・ファイルのリポジトリからの取得

スキーマ・ファイルまたはサンプル・ファイルをリポジトリからダウンロードするには、getSchemaFile()またはgetSampleFile()メソッドをコールします。これらのメソッドでは、戻り値として、ファイルの内容に接続される入力ストリームが戻されます。

コード例は、次のとおりです。

// Download the schema definition file from the repository
 InputStream schemaFile =
   DataSourceHelper.getSchemaFile(ctx, "XDO", "TestDataSource", );

 // Download the XML sample data file from the repository
 InputStream sampleFile =
   DataSourceHelper.getSampleFile(ctx, "XDO", "TestDataSource", );

テンプレートのAPI

複数のテンプレート・オブジェクトを単一のデータ・ソースに関連付けることができます。Templateクラスは、単一のテンプレート・インスタンスを表します。TemplateHelperクラスは、テンプレート・マネージャのテンプレート・オブジェクトを作成および更新するために使用されるユーティリティ・クラスです。

Templateクラス

Templateクラスは、テンプレート・マネージャ内の単一のテンプレート・オブジェクトを表します。テンプレート・オブジェクトはデータ・ソース・オブジェクトと関連付けられます。このクラスには、テンプレート・オブジェクトを操作するためのgetおよびsetメソッドがいくつかあります。

TemplateHelperクラス

TemplateHelperクラスは、テンプレート・マネージャ内のテンプレート・エントリを管理するユーティリティ・クラスです。一連の静的なユーティリティ・メソッドで構成されます。

テンプレート・エントリは、単一のテンプレートを表す論理単位です。各テンプレート・エントリには対応するデータ・ソース定義エントリがあり、このテンプレートに対するデータの表示方法が定義されています。また、言語ごとに1つの物理テンプレート・ファイルがあります。ロケール固有のテンプレート・ファイルは別々にアップロードされます。テンプレートに関連付けられている各翻訳済XLIFFについては、XMLパブリッシャによって別々のXSLファイルが作成および格納されます。

各テンプレート・エントリには、言語ごとに1つの表示名と摘要があります。これらの名称は、テンプレート・マネージャのユーザー・インタフェースでテンプレート・エントリ名が表示されるときに抽出され、使用されます。

AppsContextインスタンスの取得

一部のメソッドには、Applicationsデータベースと通信するためのAppsContextインスタンスが必要です。次のいずれかのオプションを使用して、コードにAppsContextインスタンスを取得してください。

  1. このクラスをOAフレームワークで使用している場合、AppsContextを取得するには、((OADBTransactionImpl)am.getOADBTransaction()).getAppsContext()をコールします。

    amは使用しているOAApplicationModuleです。

  2. このクラスをJavaコンカレント・プログラムで使用している場合は、CpContextをAppsContextとして渡します。

  3. それ以外の場合は、DBCファイルからAppsContextを作成します。Applicationsでサーブレット/JSPを実行している場合、DBCファイルのフルパスを取得するには次をコールします。

    System.getProperty("JTFDBCFILE")またはSystem.getProperty("BNEDBCFILE")

OAApplicationModuleインスタンスの取得

一部のメソッドには、Applicationsデータベースと通信するためのOAApplicationModuleインスタンスが必要です。次の方法で、コードにOAApplicationModuleインスタンスを取得してください。

  1. OAフレームワークでTemplateHelperを使用している場合、OAApplicationModuleインスタンスはすでに取得されています。

  2. AppsContextをすでに取得している場合は、oracle.apps.fnd.framework.server.OAApplicationModuleUtilを使用してOAApplicationModuleインスタンスを作成できます。

最新の開発はAppsContextを使用するAPIに基づいているため、AppsContextを使用してAPIをコールすることをお薦めします。OAApplicationModuleを使用するAPIも使用できますが、内部的にはAppsContextを使用する、対応のAPIがコールされます。

テンプレート・エントリの作成

テンプレート・マネージャ・リポジトリに新規テンプレート・エントリを追加する手順は、次のとおりです。

  1. Template.createInstance()メソッドをコールして、Templateクラスのインスタンスを作成します。

  2. インスタンスの属性を設定します。

  3. インスタンスをTemplateHelper.createTemplate()メソッドに渡します。

// Create an instance
 Template t = Template.createInstance(appsContext, "XDO", "TestTemplate",
   TypeDefinitions.TEMPLATE_TYPE_PDF, "XDO", "TestTemplate");

 // Set properties
 t.setDescription("This is the test template entry.");
 t.setStartDate(new java.sql.Date(System.currentTimeMillis()));
 t.setName("Test template !");
 t.setStatus(TypeDefinitions.TEMPLATE_STATUS_ENABLED);
 // Call createTemplate() to create an entry into the repository
 TemplateHelper.createTemplate(am, t);


テンプレート・エントリの取得と更新

リポジトリからテンプレート・エントリを取得するには、TemplateHelper.getTemplate()メソッドまたはgetTemplates()メソッドをコールします。これらのインスタンスを使用してエントリ情報を更新します。

// Get active template entries
 Template[] t = TemplateHelper.getTemplates(appsContext, "XDO", "XDO%", true);

 // Update properties
 t[0].setDescription("updated template entry.");
 t[0].setStartDate(new java.sql.Date(System.currentTimeMillis()));
 t[0].setName("updated template entry name");
 t[0].setStatus(TypeDefinitions.TEMPLATE_STATUS_ENABLED);

 // Call updateTemplate() to commit the update in the repository
 TemplateHelper.updateTemplate(appsContext, t[0]);

テンプレート・エントリの削除

テンプレート・エントリを削除するには、Template.deleteTemplate()メソッドをコールします。このメソッドでは、レコードはリポジトリから実際には削除されず、今後の使用に備えて無効のマークが付けられます。このステータスは、Template.updateTemplateStatus()メソッドをコールしていつでも変更できます。

テンプレート・ファイルの追加、更新および削除

テンプレート・ファイルを追加、更新および削除するには、TemplateHelperクラスに定義されているメソッドをコールします。テンプレート・エントリとは異なり、テンプレート・ファイルを削除すると、レコードがリポジトリから実際に削除されることに注意してください。

次のコード例は、テンプレート・ファイルを追加、削除および更新する方法を示しています。

 // Add English template file to the template entry
 TemplateHelper.addTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "en",                  // ISO language code of the template
  "US",                  // ISO territory code of the template
  Template.TEMPLATE_TYPE_PDF, // Type of the template file
  "us.pdf",              // Filename of the template file
  new FileInputStream("/path/to/us.pdf")); // Template file

 // Add Japanese template file to the template entry
 TemplateHelper.addTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "ja",                  // ISO language code of the template
  "JP",                  // ISO territory code of the template
  Template.TEMPLATE_TYPE_PDF, // Type of the template file
  "ja.pdf",              // Filename of the template file
  new FileInputStream("/path/to/ja.pdf")); // Template file

 // Update English template file to the template entry
 TemplateHelper.updateTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "en",                  // ISO language code of the template
  "US",                  // ISO territory code of the template
  Template.TEMPLATE_TYPE_PDF, // Type of the template file
  "us.pdf",              // Filename of the template file
  new FileInputStream("/path/to/new/us.pdf")); // Template file

 // Delete Japanese template file to the template entry
 TemplateHelper.deleteTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "ja",                  // ISO language code of the template
  "JP");                 // ISO territory code of the template

テンプレート・ファイルの取得

テンプレート・ファイルの内容をリポジトリからダウンロードするには、getTemplateFile()メソッドをコールします。これらのメソッドでは、戻り値として、テンプレート・ファイルに接続される入力ストリームが戻されます。

// Download the English template file from the repository
 InputStream in = TemplateHelper.getTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "en",                  // ISO language code of the template
  "US");                 // ISO territory code of the template

テンプレートの処理

テンプレート・マネージャに格納されているテンプレートをXMLデータ・ソースに適用するには、いずれかのprocessTemplate()メソッドをコールします。処理された文書の送信先の出力ストリーム・オブジェクトを渡す必要があります。

// Process template
 TemplateHelper.processTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "en",                  // ISO language code of the template
  "US",                  // ISO territory code of the template
  dataInputStream,       // XML data for the template
  TemplateHelper.OUTPUT_TYPE_PDF,  // Output type of the procesed document
  properties,            // Properties for the template processing
  docOutputStream)       // OutputStream where the processed document goes.

Propertiesオブジェクトを渡して、テンプレート処理に関するプロパティを渡します。XMLパブリッシャ・プロセッサに渡すプロパティがない場合は、nullを渡します。

RTF/FOテンプレートへのXSLパラメータの受渡し

  1. Propertiesオブジェクトにパラメータ名と値を設定します。

    RTF/XSLテンプレートに対するプロパティ名はすべてxsltで始まる必要があります。

    パラメータ値は一重引用符で囲む必要があります。

    String <parameter_name> = "name";
    String <parameter_value> = "value";
    Properties props = new Properties();
    ...
    props.put("xslt.<parameter_name>", "'<parameter_value>'");
    ...

    String <parameter_name> = "name";

  2. TemplateHelper.processTemplate()メソッドのコール時にこのプロパティ・オブジェクトを設定します。

    TemplateHelper.processTemplate(appsContext, "OKC", "OKCTERMS", "en", "US", pData, props, pOutput);
  3. 次の構文を使用してRTF/FOテンプレートにXSLパラメータを定義します。

    <xsl:param name="parameter_name" select "default_value" xdofo:ctx="begin"/>
    

設定したプロパティを渡す以外に、TemplateHelperクラスでは、次の場所が検索され、使用可能な場合はシステム・レベルのプロパティが取得されます。

  1. OA_MEDIAの場所など、OA固有のプロパティに対するJavaシステム・プロパティ

  2. {java.home}/lib/xdo.cfgにあるシステム構成ファイル

システム・レベル・プロパティと、渡したユーザー・レベル・プロパティが競合する場合は、ユーザー・レベル・プロパティが優先されます。

EFT/EDIテンプレートの作成および処理

TemplateHelperクラスではEFT/EDIテンプレートがサポートされます。Template.TEMPLATE_TYPE_ETEXTテンプレート・タイプでEFT/EDIテンプレート・エントリを作成できます。また、TemplateHelper内のprocessTemplate()メソッドを使用して、EFT/EDIテンプレートを処理することもできます。EFT/EDIテンプレートの処理時にOUTPUT_TYPE_ETEXT出力タイプを割り当てることができます。EFT/EDI処理エンジンにパラメータを渡す必要がある場合は、processTemplate()メソッドのコール時に、これらのパラメータをPropertiesオブジェクトとして渡すことができます。

// Process EFT/EDI template
 TemplateHelper.processTemplateFile(
  appsContext,           // AppsContext
  "XDO",                 // Application short name of the template
  "TestTemplate",        // Template code of the template
  "en",                  // ISO language code of the template
  "US",                  // ISO territory code of the template
  dataInputStream,       // XML data for the template
  TemplateHelper.OUTPUT_TYPE_ETEXT,  // Output type of the procesed document
  properties,            // Properties for the template processing.
                         // All properties will be passed to EFT/EDI engine
  docOutputStream)       // OutputStream where the processed document goes.

EFT/EDIテンプレートの処理をさらに制御する必要がある場合(EFT/EDI処理エンジン用のコンテキスト・パラメータの取得/設定など)は、EFTGeneratorをコールしてテンプレートを処理できます。

import oracle.apps.xdo.template.eft.EFTGenerator;

  …

  // Process EFT/EDI template with EFTGenerator class
  EFTGenerator generator = new EFTGenerator();
  // Get the template file from template manager repository
  // and set it.
  generator.loadXSL(
    TemplateHelper.getTemplateFile(ctx, "XDO", "TestTemplate", "en", "US"));
  // Set the data XML
  generator.loadXML(dataInputStream);
  // Set context param
  generator.setContextParam(PARAM1, PARAM1_VALUE);
  // Process the template
  generator.process(resultOutputStream);
  // Get context param
  String param2 = generator.getContextParam(PARAM2);


言語代替メカニズム

getTemplateFile()およびprocessTemplate()メソッドの両方で、言語代替メカニズムがサポートされています。このメカニズムでは、言語基準と一致するテンプレート・ファイルがない場合でも、最も適切な入力ストリームが提供されます。言語代替の優先順位は、次のとおりです。

  1. 特定の言語および地域と一致するテンプレート・ファイルを戻します。

  2. 特定の言語と一致するテンプレート・ファイルを戻し、地域に依存しません(地域の値が00)。

  3. デフォルト・テンプレートを戻します。デフォルト・テンプレート・ファイルの割当て方法の詳細は、「デフォルト・テンプレート」を参照してください。

たとえば、次の表のようなテンプレートのサンプルがテンプレート・マネージャ・リポジトリにあるとします。

テンプレート・ファイル ISO言語コード ISO地域コード デフォルト/非デフォルト
A en US 非デフォルト
B en 00 非デフォルト
C fr FR デフォルト
D ja JP 非デフォルト

次の表に、特定のISO言語/地域コードの組合せを渡した場合に戻されるテンプレートを示します。

ISO言語コード ISO地域コード 戻されるテンプレート
en US A
en GB B
en null B
fr FR C
ja JP D
de DE C

最も適切なターゲット・テンプレート・ファイルを取得するために、ISO言語コードと地域コードの両方を明示的に渡すことをお薦めします。

テンプレート検証

getTemplateFile()またはprocessTemplate()をコールすると、デフォルトで、XMLパブリッシャによって、テンプレート・エントリに設定されているSTART_DATE、END_DATEおよびTEMPLATE_STATUSに対して検証ロジックが実行されます。無効なエントリが検出された場合は、その内容に応じて、TemplateExpiredException、TemplateNotYetValidException、StatusDisabledExceptionの各例外が戻されます。これらの例外はoracle.apps.xdo.XDOExceptionのサブクラスであるため、これらの例外をすべて1度に取得する場合はXDOExceptionを取得できます。この検証モードをオフにするには、Javaシステム・プロパティxdo.TemplateValidationをfalseに設定します。デフォルト・モードはtrueに設定されています。

翻訳可能テンプレート

各テンプレート・コードに対して翻訳可能テンプレートを定義できます。getXLIFF()およびuploadXLIFF()メソッドを使用すると、テンプレート・ファイル内のテキストをXLIFF形式で取得して翻訳した後、ファイルにマージしなおすことができます。