変更プリプロセッサーの操作
変更プリプロセッサーの概要については、『変更プリプロセッサー』 を参照してください。
変更プリプロセッサー・ハンドラーの作成
変更プリプロセッサー・ハンドラーを作成するには、Java™ ChangePreprocessor インターフェースの preprocessObjectChange メソッドを実装する必要があります。Java による実装と JavaScript による実装の例を以下に示します。それぞれ、ユーザー定義クラスのインスタンスが Mime タイプの要件を満たすことを確認します。MimeType プロパティーはチェックイン時にのみ設定できることに注意してください。
- Windows: C:¥Program Files¥Filenet¥Content Engine¥samples
- Windows 以外: /opt/IBM/FileNet/ContentEngine/samples
Java の例
/* AccountsReceivable クラスに、Mime タイプの要件「application/x-transactionmanager」
を適用します。 */
package sample.actionhandler;
import com.filenet.api.action.*;
import com.filenet.api.core.IndependentlyPersistableObject;
import com.filenet.api.constants.PropertyNames;
import com.filenet.api.exception.*;
public class ChangePreprocessorHandler implements com.filenet.api.engine.ChangePreprocessor
{
public boolean preprocessObjectChange(IndependentlyPersistableObject sourceObj)
{
try {
boolean checkMimeType = false;
// 作成アクションおよびチェックイン・アクションの場合にのみ MimeType プロパティーをチェック
PendingAction actions[] = sourceObj.getPendingActions();
for ( int i = 0; i < actions.length && !checkMimeType; i++ )
{
if ( actions[i] instanceof Create || actions[i] instanceof Checkin )
checkMimeType = true;
}
if ( !checkMimeType ) return false;
// 取得を試みる前に MimeType プロパティーがコレクション内にあることを確認
if (sourceObj.getProperties().isPropertyPresent(PropertyNames.MIME_TYPE) )
{
// MimeType 値が要件に準拠していない場合に値を変更
String mimeType = sourceObj.getProperties().get(PropertyNames.MIME_TYPE).getStringValue();
if (mimeType == null ||!mimeType.equalsIgnoreCase("application/x-transactionmanager") )
{
sourceObj.getProperties().putValue("MimeType", "application/x-transactionmanager");
return true;
}
}
return false;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}
JavaScript の例
/* AccountsReceivable クラスに、Mime タイプの要件「application/x-transactionmanager」
を適用します。 */
importPackage(java.lang);
importPackage(Packages.com.filenet.api.action);
importClass(Packages.com.filenet.api.core.IndependentlyPersistableObject);
importClass(Packages.com.filenet.api.constants.PropertyNames);
function preprocessObjectChange(sourceObj)
{
try {
var checkMimeType = false;
// 作成アクションおよびチェックイン・アクションの場合にのみ MimeType プロパティーをチェック
var actions = sourceObj.getPendingActions();
for ( var i = 0; i < actions.length && !checkMimeType; i++ )
{
if ( actions[i] instanceof Create || actions[i] instanceof Checkin )
checkMimeType = true;
}
if ( !checkMimeType ) return false;
// 取得を試みる前に MimeType プロパティーがコレクション内にあることを確認
if (sourceObj.getProperties().isPropertyPresent(PropertyNames.MIME_TYPE) )
{
// MimeType 値が要件に準拠していない場合に値を変更
var mimeType = sourceObj.getProperties().get(PropertyNames.MIME_TYPE).getStringValue();
if (mimeType == null ||!mimeType.equalsIgnoreCase("application/x-transactionmanager") )
{
sourceObj.getProperties().putValue("MimeType", "application/x-transactionmanager");
return true;
}
}
return false;
}
catch (e) {
throw new RuntimeException(e);
}
}
ChangePreprocessorAction オブジェクトの作成
CmChangePreprocessorAction オブジェクトは、変更プリプロセッサーに関連付けられたクラスのインスタンスで開始する変更プリプロセッサー・ハンドラーを識別します。2 つの CmChangePreprocessorAction オブジェクト (1 つは Java で実装されたハンドラーを参照し、もう 1 つは JavaScript で実装されたハンドラーを参照する) の作成方法を示す Java と C# の例を次に示します。
作成される 1 つ目の CmChangePreprocessorAction オブジェクトでは、Java で実装されたハンドラーはコード・モジュール内に含まれるため、CodeModule オブジェクトを取得し、それを CmChangePreprocessorAction オブジェクトの CodeModule プロパティーに設定する必要があります。
作成される 2 つ目の CmChangePreprocessorAction オブジェクトでは、変更プリプロセッサー・ハンドラーは JavaScript で実装されるため、そのスクリプトをオブジェクトの ScriptText プロパティーに設定する必要があります。
Java の例
// Java ハンドラーの変更プリプロセッサー・アクションを作成
CmChangePreprocessorAction cpaJava = Factory.CmChangePreprocessorAction.createInstance(os, "CmChangePreprocessorAction");
// Java コンポーネントを持つ CodeModule オブジェクトの取得
CodeModule cm = Factory.CodeModule.getInstance(os, "CodeModule",
new Id("{1DFCEDCC-B734-45AD-93D6-03874E8F1288}") );
// CodeModule プロパティーの設定
cpaJava.set_CodeModule(cm);
// ハンドラー・クラスの完全修飾名を指定して ProgId プロパティーを設定する
cpaJava.set_ProgId("sample.actionhandler.ChangePreprocessorHandler");
// その他のプロパティーを設定および保存
cpaJava.set_IsEnabled(false);
cpaJava.set_DisplayName("MimeType validation");
cpaJava.save(RefreshMode.REFRESH);
// JavaScript ハンドラーの変更プリプロセッサー・アクションを作成
CmChangePreprocessorAction cpaJavascript = Factory.CmChangePreprocessorAction.createInstance(os, "CmChangePreprocessorAction");
// ProgId プロパティーをスクリプト・タイプ ID に設定
cpaJavascript.set_ProgId("Javascript");
// ファイルからスクリプトを読み取るメソッドを呼び出し、スクリプト・テキストをアクション・オブジェクトに設定
String inputScript = readScriptText();
cpaJavascript.set_ScriptText(inputScript);
// その他のプロパティーを設定および保存
cpaJavascript.set_IsEnabled(true);
cpaJavascript.set_DisplayName("MimeType validation");
cpaJavascript.save(RefreshMode.REFRESH);
C# の例
// Java ハンドラーの変更プリプロセッサー・アクションを作成
ICmChangePreprocessorAction cpaJava = Factory.CmChangePreprocessorAction.CreateInstance(os, "CmChangePreprocessorAction");
// Java コンポーネントを持つ CodeModule オブジェクトの取得
ICodeModule cm = Factory.CodeModule.GetInstance(os, "CodeModule",
new Id("{1DFCEDCC-B734-45AD-93D6-03874E8F1288}") );
// CodeModule プロパティーの設定
cpaJava.CodeModule = cm;
// ハンドラー・クラスの完全修飾名を指定して ProgId プロパティーを設定する
cpaJava.ProgId = "sample.actionhandler.ChangePreprocessorHandler";
// その他のプロパティーを設定および保存
cpaJava.IsEnabled = false;
cpaJava.DisplayName = "MimeType validation";
cpaJava.Save(RefreshMode.REFRESH);
// JavaScript ハンドラーの変更プリプロセッサー・アクションを作成
ICmChangePreprocessorAction cpaJavascript = Factory.CmChangePreprocessorAction.CreateInstance(os, "CmChangePreprocessorAction");
// ProgId プロパティーをスクリプトのタイプに設定
cpaJavascript.ProgId = "Javascript";
// ファイルからスクリプトを読み取るメソッドを呼び出し、スクリプト・テキストをアクション・オブジェクトに設定
String inputScript = readScriptText();
cpaJavascript.ScriptText = inputScript;
// その他のプロパティーを設定および保存
cpaJavascript.IsEnabled = true;
cpaJavascript.DisplayName = "MimeType validation";
cpaJavascript.Save(RefreshMode.REFRESH);
ChangePreprocessorDefinition オブジェクトの作成
変更プリプロセッサー・ハンドラーおよび CmChangePreprocessorAction オブジェクトを作成し終えたら、CmChangePreprocessorDefinition オブジェクトを作成する準備ができています。以下の Java および C# の例では、ユーザー定義の AccountsReceivable クラスを表す SubscribableClassDefinition オブジェクトに CmChangePreprocessorDefinition オブジェクトが設定されます。
Java の例
// 変更プリプロセッサー定義オブジェクトの作成
CmChangePreprocessorDefinition cpDef = Factory.CmChangePreprocessorDefinition.createInstance(os);
cpDef.set_DisplayName("Accounts Receivable - MimeType validation");
cpDef.set_IsEnabled(true);
// CmChangePreprocessorAction を取得し、定義オブジェクトに設定
CmChangePreprocessorAction action = Factory.CmChangePreprocessorAction.getInstance(os, "CmChangePreprocessorAction",
new Id("{45A990F2-1B0D-4CF2-AB3E-9B6B06A5410E}") );
cpDef.set_ChangePreprocessorAction(action);
// 変更プリプロセッサー定義リスト・オブジェクトを作成し、定義オブジェクトを追加
CmChangePreprocessorDefinitionList cpdList=Factory.CmChangePreprocessorDefinition.createList();
cpdList.add(cpDef);
// AccountsReceivable クラス定義を取得し、それに定義リスト・オブジェクトを設定
SubscribableClassDefinition objClassDef = Factory.SubscribableClassDefinition.getInstance(os, new Id("3ADC7781-ED70-43E4-97C3-40CF7DE2D565}") );
objClassDef.set_ChangePreprocessorDefinitions(cpdList);
objClassDef.save(RefreshMode.NO_REFRESH);
C# の例
// 変更プリプロセッサー定義オブジェクトの作成
ICmChangePreprocessorDefinition cpDef = Factory.CmChangePreprocessorDefinition.CreateInstance(os);
cpDef.DisplayName = "Accounts Receivable - MimeType validation";
cpDef.IsEnabled = true;
// ICmChangePreprocessorAction を取得し、定義オブジェクトに設定
ICmChangePreprocessorAction action = Factory.CmChangePreprocessorAction.GetInstance(os, "CmChangePreprocessorAction"
new Id("{0551C740-3502-46D1-9DB0-98CBDBD70232}") );
cpDef.ChangePreprocessorAction=action;
// 変更プリプロセッサー定義リスト・オブジェクトを作成し、定義オブジェクトを追加
ICmChangePreprocessorDefinitionList cpdList=Factory.CmChangePreprocessorDefinition.CreateList();
cpdList.Add(cpDef);
// AccountsReceivable クラス定義を取得し、それに定義リスト・オブジェクトを設定
ISubscribableClassDefinition objClassDef = Factory.SubscribableClassDefinition.GetInstance(os, new Id("3ADC7781-ED70-43E4-97C3-40CF7DE2D565}") );
objClassDef.ChangePreprocessorDefinitions = cpdList;
objClassDef.Save(RefreshMode.NO_REFRESH);
変更プリプロセッサー・アクションの取得
オブジェクト・ストアから CmChangePreprocessorAction オブジェクトのコレクションを取得する方法を、次の Java および C# の例に示します。
Java の例
// オブジェクト・ストアから変更プリプロセッサー・アクションを取得
FilterElement fe = new FilterElement(null, null, null, PropertyNames.CHANGE_PREPROCESSOR_ACTIONS, null);
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(fe);
os.fetchProperties(pf);
CmChangePreprocessorActionSet cpActionSet = os.get_ChangePreprocessorActions();
// アクション・セットを反復処理
Iterator iter = cpActionSet.iterator();
while (iter.hasNext() )
{
CmChangePreprocessorAction cpAction = (CmChangePreprocessorAction)iter.next();
System.out.println("Action: " + cpAction.get_DisplayName() + " | IsEnabled: " + cpAction.get_IsEnabled() );
}
C# の例
// オブジェクト・ストアから変更プリプロセッサー・アクションを取得
FilterElement fe = new FilterElement(null, null, null, PropertyNames.CHANGE_PREPROCESSOR_ACTIONS, null);
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(fe);
os.FetchProperties(pf);
ICmChangePreprocessorActionSet cpActionSet = os.ChangePreprocessorActions;
// アクション・セットを反復処理
foreach (ICmChangePreprocessorAction cpAction in cpActionSet)
{
System.Console.WriteLine("Action: " + cpAction.DisplayName + " | IsEnabled: " + cpAction.IsEnabled );
}
変更プリプロセッサー定義の取得
クラス定義から CmChangePreprocessorDefinition オブジェクトのリストを取得する方法を、次の Java および C# の例に示します。
Java の例
// AccountsReceivable クラス定義をフェッチし、CmChangePreprocessorDefinition オブジェクトのリストを取得
SubscribableClassDefinition scd = Factory.SubscribableClassDefinition.fetchInstance(os, new Id("3ADC7781-ED70-43E4-97C3-40CF7DE2D565}"), null);
CmChangePreprocessorDefinitionList cpdList = scd.get_ChangePreprocessorDefinitions();
// 定義リストを反復処理
Iterator iter = cpdList.iterator();
while (iter.hasNext() )
{
CmChangePreprocessorDefinition cpDef = (CmChangePreprocessorDefinition)iter.next();
System.out.println("Definition: " + cpDef.get_DisplayName() + " | IsEnabled: " + cpDef.get_IsEnabled() );
}
C# の例
// AccountsReceivable クラス定義をフェッチし、CmChangePreprocessorDefinition オブジェクトのリストを取得
ISubscribableClassDefinition scd = Factory.SubscribableClassDefinition.FetchInstance(os, new Id("3ADC7781-ED70-43E4-97C3-40CF7DE2D565}"), null);
ICmChangePreprocessorDefinitionList cpdList = scd.ChangePreprocessorDefinitions;
// 定義リストを反復処理
foreach (ICmChangePreprocessorDefinition cpDef in cpdList)
{
System.Console.WriteLine("Definition: " + cpDef.DisplayName + " | IsEnabled: " + cpDef.IsEnabled );
}