ヘッダーをスキップ

Oracle Business Intelligence Publisherユーザーズ・ガイド
リリース10.1.3.2
E05037-01
目次へ
目次
前のページへ
前へ
次のページへ
次へ

BI Publisher APIの使用

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

概要

この章は、Application Programming Interfaceを介してBI Publisherと対話するプログラムまたはアプリケーションを作成する開発者を対象としています。この情報は、インストレーション・ファイルから入手できるJavadocをあわせて参照することを前提としています。

この項は、読者にJavaプログラミング、XMLおよびXSLテクノロジの知識があることを前提としています。

BI PublisherのコアAPI

BI Publisherは、次のコア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標準のBI Publisherによる実装であり、すべてのXSL-FOコンポーネントの完全な実装を表しているわけではありません。サポートされるXSL-FO要素のリストは、「サポートされているXSL-FO要素」を参照してください。

FOプロセッサは、次に示す2つの入力のいずれかから、PDF、RTF、HTMLまたはExcel(HTML)の出力を生成できます。

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

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

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

FOプロセッサの主な機能

双方向テキスト

BI Publisherでは、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つのレベルのフォント代替メカニズムがサポートされています。このメカニズムでは、指定したフォントまたは絵文字が検出されない場合に使用するデフォルト・フォントが制御されます。BI Publisherでは、適切なデフォルト代替フォントが自動的に提供され、構成は必要ありません。また、使用するデフォルト・フォントを指定するユーザー定義構成ファイルもサポートされています。絵文字の代替の場合、デフォルト・メカニズムでは絵文字のみが置換され、文字列全体は置換されません。

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

ヘッダーおよびフッターがテンプレートで定義されているより多くの領域を必要とする場合は、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;
    }
  }

PDFブック・バインダ・プロセッサ

PDFBookBinderプロセッサは、複数のPDF文書をマージして、章、項および節の階層構造と目次で構成された単一の文書にする場合に便利です。このプロセッサではPDFスタイルの「しおり」も生成され、アウトライン構造は章および項の階層によって決まります。非常に強力な機能を備えており、組み合された文書を完全に管理することができます。

使用方法

目次の書式設定とスタイルは、Microsoft Wordで作成されたRTFテンプレートを使用して作成されます。各章は独立したPDFファイル(1つの章、項または節が1つのPDFに対応します)としてプログラムに渡されます。テンプレートは、文書内への動的または静的コンテンツの挿入、ページ番号付けおよびハイパーリンクの配置のために章レベルで指定することもできます。

テンプレートの形式は、RTFまたはPDFのどちらでもかまいません。RTFテンプレートのほうが、BI Publisherの動的コンテンツのサポートを活用できるのでより柔軟性があります。PDFテンプレートは、柔軟性がはるかに低く、ページ番号やその他のタイプの動的コンテンツを挿入したときのテキスト領域の再構成といった必要な効果を得ることが難しくなります。

テンプレートは、(90度単位で)回転したり、透過にすることができます。PDFテンプレートは、ブック・レベルで指定してグローバルなページ番号付けや、その他、背景および透かしなどのコンテンツの指定を可能にすることもできます。表題ページも、各章や項ごとの中扉と同様にパラメータとして渡すことができます。

XML制御ファイル

ブックの章、項および節の構造は、XMLとして表され、コマンドライン・パラメータとして渡すことも、APIレベルで渡すこともできます。章および項のファイルは、すべてのテンプレート・ファイルおよびそのパラメータと同じように、すべてこのXML構造内に指定されます。したがって、必要なパラメータはXMLファイルとPDF出力ファイルの2つのみです。

また、ブック構造内に分冊の区切りを指定することもできます。これにより、内容が別々の出力ファイルに分割され、ファイルおよび印刷の管理が簡単になります。

次の図に、XML制御ファイルの構造を示します。

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

XML構造内でのテンプレートおよびコンテンツ・ファイルの位置を指定するには、ローカル・ファイル・システムへの相対パスまたはテンプレートやコンテンツの位置を指すURLを指定します。Secure HTTPプロトコルの他、特別に認識される次のようなBI Publisherプロトコルもサポートされています。

コマンドライン・オプション

コマンドラインの使用例を次に示します。

java oracle.apps.template.pdf.book.PDFBookBinder [-debug <true or false>] [-tmp <temp dir>] -xml <input xml> -pdf <output pdf>

各項目は次のとおりです。

-xml <ファイル>: 目次XML構造を含む入力XMLファイルのファイル名です。

-pdf <ファイル>: 生成される最終のPDF出力ファイルです。

-tmp <ディレクトリ>: メモリー管理を向上させるための一時ディレクトリです(任意指定で、指定しない場合はシステムの環境変数“java.io.tmpdir”が使用されます)。

-log <ファイル>: 出力ログ・ファイルを設定します(任意指定で、デフォルトはSystem.outです)。

-debug <trueまたはfalse>: デバッグをオフまたはオンにします。

APIメソッド・コール

次に、APIメソッド・コールの例を示します。

String xmlInputPath = “c:\\tmp\\toc.xml”;
String pdfOutputPath = “c:\\tmp\\final_book.pdf”;
PDFBookBinder bookBinder = new PDFBookBinder(xmlInputPath,
 pdfOutputPath);

bookBinder.setConfig(new Properties());
bookBinder.process();

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

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

このソリューションを使用すると、BI Publisherを使用したバッチ印刷が可能になります。単一の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 N/A データおよびテンプレート処理定義が含まれる要素。
delivery N/A 生成された出力の送信先を定義します。
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属性には、複数の電子メール・アドレスをカンマで区切って指定できます。
attachmentの値はtrueまたはfalse(デフォルト)です。attachmentがtrueの場合、生成された文書は電子メールの送信時に添付されます。
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);
  }


バースト・エンジン

BI Publisherのバースト・エンジンは、データ・ストリームを受け入れて、複数の基準を基に分割し、テンプレートに基づいて出力を生成した後、一般的な配信チャネルを経由して個々の文書を配信します。このエンジンには、文書の生成および配信について幅広い選択肢が提供されています。次のような実装例があります。

使用方法

バースト・エンジンは文書プロセッサ・エンジンの拡張であり、起動のためにコールする独自のメソッドがあります。文書プロセッサのXML構造が、バースト・エンジンに必要な新しいコンポーネントの処理のために拡張されています。バースト・エンジンは、文書プロセッサがサポートするすべての配信機能を同一の形式を使用してサポートします。また、バーストするXMLデータおよび文書プロセッサXML形式(「文書プロセッサXMLファイルの階層と要素」を参照)の制御ファイルを受け入れます。

制御ファイル

制御ファイルは、次に示す2、3の拡張はありますが文書プロセッサXMLと同じ書式をとります。

動的配信先

データ内の要素を参照して、電子メール・アドレスやFAX番号などの特定の配信属性を導き出すことができます。次の書式で属性の値を入力します。

${ELEMENT}

ここで、ELEMENTはXMLデータの要素名で、この要素が属性の値を保持します。

次に例を示します。

<xapi:message id="123" to="${EMAIL}"/>

実行時に、属性の値は入力XMLファイルのEMAIL要素の値に設定されます。

属性の値は、Propertiesオブジェクトに入れてパラメータをAPIに渡すことでも設定できます。

動的配信コンテンツ

XMLデータ内の情報を参照して、配信コンテンツに含めることができます。これには、前述と同じ書式(${ELEMENT})を使用します。

たとえば、電子メール経由で従業員に文書をバーストし、件名の行にその従業員の名前を使用することで電子メールをパーソナライズする必要があるとします。従業員の名前がENAMEという要素に保持されていると仮定すると、次に示すように${ENAME}を使用して制御ファイルで従業員の名前を参照できます。

subject="Employee Details for ${ENAME}"

サンプル制御ファイル

次のサンプル制御ファイルは、EMPLOYEE要素を基にしてデータを分割し、各従業員にそれぞれのデータを含んだ電子メールを送信する制御ファイルの例を示したものです。サンプル・ファイルは注釈付きです。

<?xml version="1.0" encoding="UTF-8"?>
<xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi">
<xapi:request select="/EMPLOYEES/EMPLOYEE">
<! -  This sets the bursting element i.e., EMPLOYEE  - >
    <xapi:delivery>
      <xapi:email server="rgmamersmtp.oraclecorp.com" port="25"
       from="xmlpadmin1@oracle.com"  reply-to ="reply@oracle.com">
       <xapi:message id="123"  to="${EMAIL}"  cc="${EMAIL_ALL}"
        attachment="true" subject="Employee Details
        for ${ENAME}"> Mr. ${ENAME}, Please review the
        attached document</xapi:message>
<! - This assigns a delivery id of '123'. It also sets the e-mail
     address of the employee and a cc copy to a parameter value
     EMAIL_ALL; this might be a manager's e-mail. The employee's
     name (ENAME) can also be used in the subject/body
     of the email.  - >
</xapi:email>
   </xapi:delivery>
    <xapi:document output-type="pdf" delivery="123">
     <xapi:template type="rtf" location="/usr/tmp/empGeneric.rtf">
     <xapi:template type="rtf" location="/usr/tmp/empDet.rtf"
      filter=".//EMPLOYEE[ENAME='SMITH']" >
<! -  Employees with the name SMITH will have
      the empDet template applied  - >
      </xapi:template>
    </xapi:document>
  </xapi:request>
</xapi:requestset>

複数のバースト・オプション

バースト・エンジンは、複数のバースト基準および配信オプションをサポートできます。全従業員のデータをそれぞれの管理者情報とともに生成するレポートがある場合、次の動作を行う制御ファイルを作成できます。

各バースト・レベルごとに異なるテンプレートを提供できます。したがって、あるテンプレートを基に従業員レポートを生成し、別のテンプレートを基にして要約の管理者用レポートを生成するが、どちらも同じデータ・セットを使用するということが可能です。

このマルチバーストを実現するには、2つ目のrequest要素を制御ファイル構造に追加する必要があります。

マルチバーストの例

次のサンプルは、EMPLOYEEレベルおよびMANAGERレベルでバーストを実行する制御ファイルの作成方法を示したものです。

?xml version="1.0" encoding="UTF-8" ?>
<xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi">
<! -  First request to burst on employee  - >
 <xapi:request select="/EMPLOYEES/EMPLOYEE">
 <xapi:delivery>
 <xapi:email <<server details removed>> />
  <xapi:message id="123" <<message details removed>>
   </xapi:message>
  </xapi:email>
 <xapi:fax server="ipp://mycupsserver:631/printers/fax2">
  <xapi:number id="FAX1">916505069560</xapi:number>
  </xapi:fax>
  <xapi:print id="printer1"
   printer="ipp://mycupsserver:631/printers/printer1"
   copies="2" />
  </xapi:delivery>
 <xapi:document output-type="pdf" delivery="123">
  <xapi:template type="rtf" location="usr\tmp\empDet.rtf" />
  </xapi:document>
 </xapi:request>
<!Second request to burst on department  - >
<xapi:request select="/DATA/DEPT/MANAGER">
 <xapi:delivery>
 <xapi:email server="gmsmtp.oraclecorp.com" port=""
  from="XDOburstingTest@oracle.com" reply-to="reply@oracle.com">
  <xapi:message id="123" to="${MANAGER_EMAIL}"
   cc="${MANAGER_EMAIL}" attachment="true"
   subject="Department Summary for ${DEPTNO}">Please review
   the attached Department Summary for
   department ${DEPTNO}</xapi:message>
  </xapi:email>
  </xapi:delivery>
<xapi:document output-type="rtf" delivery="123">
  <xapi:template type="rtf"
   location="d:\burst_test\deptSummary.rtf" />
  </xapi:document>
  </xapi:request>
  </xapi:requestset>

バースト・リスナー

バースト・エンジンには、バースト・プロセスの様々な段階をリスニングできるリスニング・インタフェースが提供されています。サポートされている予約可能なモードは、次のとおりです。

これらのどのインタフェースに対しても、コール側のJavaクラスで予約できます。リスナーは、個々の文書の処理が正常に進んでいるかどうかを判断したり、要求の正常終了に基づいて別のプロセスを開始する場合に役に立ちます。

バーストAPIのコール

バーストAPIをコールするには、次のいずれかの書式を使用してDocumentProcessorクラスのインスタンスを作成します。

DocumentProcessor(xmlCtrlInput, xmlDataInput, tmpDir)

各項目は次のとおりです。

xmlCtrlInput: バースト・プロセスの制御ファイルです。ファイルへの文字列参照、inputStreamオブジェクトまたはReaderオブジェクトのいずれでもかまいません。

xmlDataInput: バーストするXMLデータです。ファイルへの文字列参照、inputStreamオブジェクトまたはReaderオブジェクトのいずれでもかまいません。

tmpDir: 一時作業ディレクトリです。Stringオブジェクトの書式を使用します。メインのBI Publisher一時ディレクトリが設定されているかぎり、これはオプションです。

簡単なJavaクラスの例

次に、サンプルJavaクラスを示します。

public class BurstingTest
{
  public BurstingTest()
  {
   try
   {
	DocumentProcessor dp = new DocumentProcessor
	("\burst\burstCtrl.xml", "\\burst\\empData.xml","\\burst");
 	dp.process();
	}
   }
   catch (Exception e)
   { System.out.println(e);

 public static void main(String[] args)
  {
    BurstingTest burst1 = new BurstingTest();
  }

}

リスナーを使用するJavaクラスの例

バースト・リスナーを活用するには、クラス宣言にインタフェースを追加してregisterListenerメソッドを使用します。その後、予約するリスナー用のコードを次のように追加します。

public class BurstingTest implements BurstingListener
{
  public BurstingTest()
  {
   try
   {
	DocumentProcessor dp = new DocumentProcessor
	("\burst\burstCtrl.xml", "\\burst\\empData.xml","\\burst");
	dp.registerListener(this);
 	dp.process();
	}
   }
   catch (Exception e)
   { System.out.println(e);

 public static void main(String[] args)
  {
    BurstingTest burst1 = new BurstingTest();
}

public void beforeProcess(){
  System.out.println("Start of Bursting Process");
  }
public void afterProcess()
  {
  System.out.println("End of Bursting Process");
  }

public void beforeProcessRequest(int requestIndex)
  {
  System.out.println("Start of Process Request ID"+requestIndex);
  }
  public void afterProcessRequest(int requestIndex)
  {
   System.out.println("End of Process Request ID"+requestIndex ");

  }
  public void beforeProcessDocument(int requestIndex,int
   documentIndex)
  {
  System.out.println("Start of Process Document");
  System.out.println("   Request Index "+requestIndex);
  System.out.println("   Document Index " +documentIndex);

  }
  public void afterProcessDocument(int requestIndex,int
   documentIndex,
  Vector documentOutputs)
  {
     System.out.println("   ========End of Process Document");
     System.out.println("   Outputs :"+documentOutputs);
  }
  public void beforeDocumentDelivery(int requestIndex,int
   documentIndex,
  String deliveryId)
  {
  System.out.println("   ========Start of  Delivery");
  System.out.println("   Request Index "+requestIndex);
  System.out.println("   Document Index " +documentIndex);
  System.out.println("   DeliveryId  " +deliveryId);
  }
  public void afterDocumentDelivery(int requestIndex,int documentIndex,
  String deliveryId,Object deliveryObject,Vector attachments)
  {
    System.out.println("   ========End of  Delivery");
    System.out.println("  Attachments : "+attachments);

   }

}

パラメータの渡し方

制御ファイルで配信用に使用する値を保持したパラメータを渡すには、次のコードを追加します。

…
Properties prop= new Properties();
prop.put("user-variable:ADMIN_EMAIL","jo.smith@company.com");
dp.setConfig(prop);
dp.process();
…

バースト制御ファイルの例

この項のすべての例で、次のXMLデータソースが使用されます。

<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<DEPTS>
 <DEPT>
  <DEPTNO>20</DEPTNO>
  <NAME>Accounting</NAME>
  <MANAGER_EMAIL>tdexter@mycomp.com</MANAGER_EMAIL>
  <EMPLOYEES>
   <EMPLOYEE>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>1980-12-17T00:00:00.000-08:00</HIREDATE>
    <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
    <EMAIL>jsmith@mycomp.com</EMAIL>
   </EMPLOYEE>
   <EMPLOYEE>
    <EMPNO>7566</EMPNO>
    <ENAME>JONES</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>1981-04-02T00:00:00.000-08:00</HIREDATE>
    <SAL>2975</SAL>
    <DEPTNO>20</DEPTNO>
    <EMAIL>jjones@mycomp.com</EMAIL>
   </EMPLOYEE>
  </EMPLOYEES>
 </DEPT>
 <DEPT>
  <DEPTNO>30</DEPTNO>
  <NAME>Sales</NAME>
  <MANAGER_EMAIL>dsmith@mycomp.com</MANAGER_EMAIL>
  <EMPLOYEES>
   <EMPLOYEE>
    <EMPNO>7788</EMPNO>
    <ENAME>SCOTT</ENAME>
    <JOB>ANALYST</JOB>
    <MGR>7566</MGR>
    <HIREDATE>1982-12-09T00:00:00.000-08:00</HIREDATE>
    <SAL>3000</SAL>
    <DEPTNO>20</DEPTNO>
    <EMAIL>jscott@mycomp.com</EMAIL>
   </EMPLOYEE>
   <EMPLOYEE>
    <EMPNO>7876</EMPNO>
    <ENAME>ADAMS</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7788</MGR>
    <HIREDATE>1983-01-12T00:00:00.000-08:00</HIREDATE>
    <SAL>1100</SAL>
    <EMAIL>jadams@mycomp.com</EMAIL>
   </EMPLOYEE>
  </EMPLOYEES>
 </DEPT>
</DEPTS>
</DATA>

例1: 従業員データを電子メール経由で従業員にバーストする

次のサンプルでは、各従業員のデータにテンプレート(empDet.rtf)を適用し、PDF文書を生成して、その文書を電子メールで各従業員に配信する方法を示します。

<?xml version="1.0" encoding="UTF-8"?>
<xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi">
<xapi:request select="/DATA/DEPTS/DEPT/EMPLOYEES/EMPLOYEE">
 <! -  Burst on employee element  - >
    <xapi:delivery>
      <xapi:email server="my.smtp.server" port="25"
       from="xmlpadmin@mycomp.com" reply-to ="">
       <xapi:message id="123"  to="${EMAIL}"
<! -  Set the id for the delivery method  - >
<! -  Use the employees EMAIL element to email the document to
      the employee  - >
cc="${ADMIN_EMAIL}"
<! -  Use the ADMIN_EMAIL parameter to CC the document
      to the administrator  - >
 attachment="true" subject="Employee Details for ${ENAME}">
 Mr. ${ENAME}, Please review the attached document</xapi:message>
<! -  Embed the employees name into the email message  - >
</xapi:email>
   </xapi:delivery>
    <xapi:document output-type="pdf" delivery="123">
<!Specify the delivery method id to be used  - >
     <xapi:template type="rtf"
      location="\usr\empDet.rtf"></xapi:template>
    </xapi:document>
  </xapi:request>
</xapi:requestset>

例2: 従業員データを、複数の配信チャネルを経由して、条件に応じてレイアウト・テンプレートを使用して従業員にバーストする

このサンプルでは、バーストを実行し、従業員名を確認し、テンプレートを使用してPDFを生成する方法を示します。文書はさらに電子メールで送信され印刷されます。

<?xml version="1.0" encoding="UTF-8"?>
<xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi" >
 <xapi:globalData location="stream">
 </xapi:globalData >
  <xapi:request select="/DATA/DEPTS/DEPT/EMPLOYEES/EMPLOYEE">
    <xapi:delivery>
      <xapi:email server="my.smtp.server" port=""
       from="xmlpserver@oracle.com"
       reply-to ="reply@oracle.com">
     <xapi:message id="123"  to="${EMAIL}" cc="" attachment="true"
       subject="Employee Details for ${ENAME}"> Mr. ${ENAME},
       Please review the attached document</xapi:message>
</xapi:email>
<xapi:print id="printer1"
  printer="ipp://ipgpc1:631/printers/printer1" copies="2" />
<! -  Add an id for this delivery method i.e. printer1  - >
     </xapi:delivery>
    <xapi:document output-type="pdf" delivery="printer1,123">
<! -  Deliver to printer and email  - >
     <xapi:template type="rtf" location="/usr/empDetSmith.rtf"
      filter=".//EMPLOYEE[ENAME='SMITH']">
<!- Specify template to be used for employees called SMITH  - >
      </xapi:template>
     <xapi:template type="rtf" location="/usr/empSummary.rtf">
<! -  Default template to be used  - >
      </xapi:template>
    </xapi:document>
  </xapi:request>
</xapi:requestset>

例3: 従業員データを従業員およびその管理者にバーストする

このサンプルでは、PDFが添付された電子メールをempDetテンプレートを使用して全従業員にバーストする方法を示します。また、従業員の要約PDFを電子メール経由で各部門の管理者にバーストします。

<?xml version="1.0" encoding="UTF-8"?>
<xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi">
  <xapi:request select="/DATA/DEPTS/DEPT/EMPLOYEES/EMPLOYEE">
    <xapi:delivery>
      <xapi:email server="my.smtp.server" port=""
       from="xmlpserver@oracle.com" reply-to ="">
      <xapi:message id="123"  to="${EMAIL}" cc="${EMAIL}"
       attachment="true"
       subject="Employee Details for ${ENAME}"> Mr. ${ENAME},
       Please review the attached document</xapi:message>
</xapi:email>
    </xapi:delivery>
    <xapi:document output-type="pdf" delivery="123">
     <xapi:template type="rtf"
      location="/usr/empDet.rtf"</xapi:template>
    </xapi:document>
  </xapi:request>
<xapi:request select="/DATA/DEPTS/DEPT">
<! -  Second request created to burst the same dataset to the
      manager based on the DEPT element  - >
    <xapi:delivery>
       <xapi:email  server="my.smtp.server" port=""
        from="xmlpserver@oracle.com" reply-to ="">
<xapi:message id="456"  to="${MANAGER_EMAIL}"
 cc="${MANAGER_EMAIL}" attachment="true" subject="Department
 Summary for ${DEPTNO}"> Please review the attached
 Department Summary for department ${DEPTNO}</xapi:message>
</xapi:email>
    </xapi:delivery>
    <xapi:document output-type="rtf" delivery="456">
     <xapi:template type="rtf"
      location="\usr\deptSumm.rtf"></xapi:template>
  </xapi:document>
  </xapi:request>
</xapi:requestset>

BI Publisherのプロパティ

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

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

プロパティの全リストは、「ランタイム・プロパティの設定」を参照してください。

プロパティの設定

プロパティは、次の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();
    /* PDF Security control: */
    prop.put("pdf-security", "true");
    /* Permissions password: */
    prop.put("pdf-permissions-password", "abc");
    /* Encryption level: */
    prop.put("pdf-encription-level", "0");
    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();
      /* PDF Security control: */
      prop.put("pdf-security", "true");
      /* Permissions password: */
      prop.put("pdf-permissions-password", "abc");
      /* encryption level: */
      prop.put("pdf-encription-level", "0");
      processor.setConfig(prop);
      docProcessor.process();
    }
    catch(Exception e)
    {
	e.printStackTrace();
       System.exit(1);
    }
    System.exit(0);
  }

拡張バーコード・フォント書式設定の実装

テンプレートで拡張書式設定が機能するには、実行時にデータの書式を設定する適切なメソッドをJavaクラスに提供する必要があります。多くのフォント・ベンダーは、書式設定を実行するために、フォントとともにコードを提供しています。これらのコードは、実行時にBI Publisherの書式設定ライブラリで使用可能なクラスにメソッドとして組み込む必要があります。エンコーディングに対して正しいメソッドをコールするために、ライブラリのクラスに固有のインタフェースを用意する必要があります。

注意: RTFテンプレートに必要は設定は、「バーコードの拡張書式設定」を参照してください。

このクラスには、次の3つのメソッドを実装する必要があります。

/**
 * Return a unique ID for this bacode encoder
 * @return the id as a string
 */
  public String getVendorID();

/**
 * Return true if this encoder support a specific type of barcode
 * @param type the type of the barcode
 * @return true if supported
 */
  public boolean isSupported(String type);

/**
 * Encode a barcode string by given a specific type
 * @param data the original data for the barcode
 * @param type the type of the barcode
 * @return the formatted data
 */
  public String encode(String data, String type);

このクラスをBI Publisherが動作している中間層JVMのクラスパスに配置してください。

注意: E-Business Suiteユーザーは、中間層および存在しているコンカレント・ノードのクラスパスに、クラスを配置する必要があります。

register-barcode-vendorコマンドにbarcode_vendor_idが指定されていない場合、BI PublisherはgetVendorID()をコールして、このメソッドの結果をベンダーIDとして使用します。

次に、code128a、code128bおよびcode128cエンコーディングをサポートするクラスの例を示します。

重要: 次のコード・サンプルは、コピー・アンド・ペーストしてシステムで使用できます。公開上の制約のため、改行を修正し、スマート引用符として表示される引用符を削除して単純な引用符に置換する必要があります。

package oracle.apps.xdo.template.rtf.util.barcoder;

import java.util.Hashtable;
import java.lang.reflect.Method;
import oracle.apps.xdo.template.rtf.util.XDOBarcodeEncoder;
import oracle.apps.xdo.common.log.Logger;
// This class name will be used in the register vendor
// field in the template.

public class BarcodeUtil  implements XDOBarcodeEncoder
// The class implements the XDOBarcodeEncoder interface
{
// This is the barcode vendor id that is used in the
// register vendor field and format-barcode fields
  public static final String BARCODE_VENDOR_ID = "XMLPBarVendor";
// The hashtable is used to store references to
// the encoding methods
  public static final Hashtable ENCODERS = new Hashtable(10);
// The BarcodeUtil class needs to be instantiated
  public static final BarcodeUtil mUtility = new BarcodeUtil();
// This is the main code that is executed in the class,
// it is loading the methods for the encoding into the hashtable.
// In this case we are loading the three code128 encoding
// methods we have created.
  static {
    try {
      Class[] clazz = new Class[] { "".getClass() };

      ENCODERS.put("code128a",mUtility.getClass().getMethod("code128a", clazz));
      ENCODERS.put("code128b",mUtility.getClass().getMethod("code128b", clazz));
      ENCODERS.put("code128c",mUtility.getClass().getMethod("code128c", clazz));
     } catch (Exception e) {
// This is using the BI Publisher logging class to push
// errors to the XMLP log file.
      Logger.log(e,5);
    }
  }
// The getVendorID method is called from the template layer
// at runtime to ensure the correct encoding method are used
    public final String getVendorID()
    {
        return BARCODE_VENDOR_ID;
    }
//The isSupported method is called to ensure that the
// encoding method called from the template is actually
//  present in this class.
// If not then XMLP will report this in the log.
    public final boolean isSupported(String s)
    {
        if(s != null)
            return ENCODERS.containsKey(s.trim().toLowerCase());
        else
            return false;
    }

// The encode method is called to then call the appropriate
// encoding method, in this example the code128a/b/c methods.

   public final String encode(String s, String s1)
    {
        if(s != null && s1 != null)
        {
            try
            {
                Method method = (Method)ENCODERS.get(s1.trim().toLowerCase());
                if(method != null)
                    return (String)method.invoke(this, new Object[] {
                        s
                    });
                else
                    return s;
            }
            catch(Exception exception)
            {
                  Logger.log(exception,5);
            }
            return s;
        } else
        {
            return s;
        }
    }

  /** This is the complete method for Code128a */

  public static final String code128a( String DataToEncode )
  {
    char C128_Start = (char)203;
    char C128_Stop = (char)206;
    String Printable_string = "";
    char CurrentChar;
    int CurrentValue=0;
    int weightedTotal=0;
    int CheckDigitValue=0;
    char C128_CheckDigit='w';

    DataToEncode = DataToEncode.trim();
    weightedTotal = ((int)C128_Start) - 100;
    for( int i = 1; i <= DataToEncode.length(); i++ )
      {
      //get the value of each character
      CurrentChar = DataToEncode.charAt(i-1);
      if( ((int)CurrentChar) < 135 )
	CurrentValue = ((int)CurrentChar) - 32;
      if( ((int)CurrentChar) > 134 )
	CurrentValue = ((int)CurrentChar) - 100;

      CurrentValue = CurrentValue * i;
      weightedTotal = weightedTotal + CurrentValue;
      }
    //divide the WeightedTotal by 103 and get the remainder,
    //this is the CheckDigitValue
    CheckDigitValue = weightedTotal % 103;
    if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )
      C128_CheckDigit = (char)(CheckDigitValue + 32);
    if( CheckDigitValue > 94 )
      C128_CheckDigit = (char)(CheckDigitValue + 100);
    if( CheckDigitValue == 0 ){
      C128_CheckDigit = (char)194;
    }

    Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";
    return Printable_string;
  }
/** This is the complete method for Code128b ***/

  public static final String code128b( String DataToEncode )
  {
    char C128_Start = (char)204;
    char C128_Stop = (char)206;
    String Printable_string = "";
    char CurrentChar;
    int CurrentValue=0;
    int weightedTotal=0;
    int CheckDigitValue=0;
    char C128_CheckDigit='w';

    DataToEncode = DataToEncode.trim();
    weightedTotal = ((int)C128_Start) - 100;
    for( int i = 1; i <= DataToEncode.length(); i++ )
      {
      //get the value of each character
      CurrentChar = DataToEncode.charAt(i-1);
      if( ((int)CurrentChar) < 135 )
        CurrentValue = ((int)CurrentChar) - 32;
      if( ((int)CurrentChar) > 134 )
        CurrentValue = ((int)CurrentChar) - 100;

      CurrentValue = CurrentValue * i;
      weightedTotal = weightedTotal + CurrentValue;
      }
    //divide the WeightedTotal by 103 and get the remainder,
    //this is the CheckDigitValue
    CheckDigitValue = weightedTotal % 103;
    if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )
      C128_CheckDigit = (char)(CheckDigitValue + 32);
    if( CheckDigitValue > 94 )
      C128_CheckDigit = (char)(CheckDigitValue + 100);
    if( CheckDigitValue == 0 ){
      C128_CheckDigit = (char)194;
    }

    Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";
    return Printable_string;
  }


  /** This is the complete method for Code128c **/

  public static final String code128c( String s )
  {
    char C128_Start = (char)205;
    char C128_Stop = (char)206;
    String Printable_string = "";
    String DataToPrint = "";
    String OnlyCorrectData = "";
    int i=1;
    int CurrentChar=0;
    int CurrentValue=0;
    int weightedTotal=0;
    int CheckDigitValue=0;
    char C128_CheckDigit='w';
    DataToPrint = "";
    s = s.trim();
    for(i = 1; i <= s.length(); i++ )
      {
      //Add only numbers to OnlyCorrectData string
      CurrentChar = (int)s.charAt(i-1);
      if((CurrentChar < 58) && (CurrentChar > 47))
	{
	  OnlyCorrectData = OnlyCorrectData + (char)s.charAt(i-1);
	}
      }
    s = OnlyCorrectData;
    //Check for an even number of digits, add 0 if not even
    if( (s.length() % 2) == 1 )
      {
	s = "0" + s;
      }
    //<<<< Calculate Modulo 103 Check Digit and generate
    // DataToPrint >>>>
    //Set WeightedTotal to the Code 128 value of
// the start character
    weightedTotal = ((int)C128_Start) - 100;
    int WeightValue = 1;
    for( i = 1; i <= s.length(); i += 2 )
      {
	//Get the value of each number pair (ex: 5 and 6 = 5*10+6 =56)
	//And assign the ASCII values to DataToPrint
	CurrentChar = ((((int)s.charAt(i-1))-48)*10) + (((int)s.charAt(i))-48);
	if((CurrentChar < 95) && (CurrentChar  > 0))
	  DataToPrint = DataToPrint + (char)(CurrentChar + 32);
	if( CurrentChar > 94 )
	  DataToPrint = DataToPrint + (char)(CurrentChar + 100);
	if( CurrentChar == 0)
	  DataToPrint = DataToPrint + (char)194;
	//multiply by the weighting character
	//add the values together to get the weighted total
	weightedTotal = weightedTotal + (CurrentChar * WeightValue);
	WeightValue = WeightValue + 1;
      }
    //divide the WeightedTotal by 103 and get the remainder,
    //this is the CheckDigitValue
    CheckDigitValue = weightedTotal % 103;
    if((CheckDigitValue < 95) && (CheckDigitValue > 0))
      C128_CheckDigit = (char)(CheckDigitValue + 32);
    if( CheckDigitValue > 94 )
      C128_CheckDigit = (char)(CheckDigitValue + 100);
    if( CheckDigitValue == 0 ){
      C128_CheckDigit = (char)194;
    }
    Printable_string = C128_Start + DataToPrint + C128_CheckDigit + C128_Stop + " ";
    Logger.log(Printable_string,5);
    return Printable_string;
  }
}

クラスを作成して正しいクラスパスに配置すると、テンプレート作成者は、そのクラスを使用してバーコードのデータを書式設定できるようになります。テンプレート・コマンドに次の情報を指定することをテンプレート作成者に伝える必要があります。

テンプレート作成者は、この情報を使用してバーコード出力用データを正しくエンコーディングできます。