IBM FileNet P8, バージョン 5.2.1            

ドキュメントの操作

以下のコード例は、ドキュメント関連の操作を示しています。 ドキュメント関連の他のタスクを以下に示します。

ドキュメントの作成

この例は、ドキュメントを作成し、オプションでプロパティー MimeType、DocumentTitle、および StorageArea を設定します。

Java™ の例

// ドキュメント・インスタンスを作成する
Document doc = Factory.Document.createInstance(os, ClassNames.DOCUMENT);

// ドキュメント・プロパティーを設定する
doc.getProperties().putValue("DocumentTitle", "New Document via Java API");
doc.set_MimeType("text/plain");

StorageArea sa = Factory.StorageArea.getInstance(os, new Id("{DE42374D-B04B-4F47-A62E-CAC9AC9A5719}") );
doc.set_StorageArea(sa);

doc.save(RefreshMode.NO_REFRESH );

// ドキュメントをチェックイン
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc.save(RefreshMode.NO_REFRESH);

// ドキュメントをファイリングする
Folder folder = Factory.Folder.getInstance(os, ClassNames.FOLDER,
        new Id("{42A3FC29-D635-4C37-8C86-84BAC73FFA3F}") );
ReferentialContainmentRelationship rcr = folder.file(doc,
        AutoUniqueName.AUTO_UNIQUE, "New Document via Java API",
        DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rcr.save(RefreshMode.NO_REFRESH);

C# の例

// ドキュメント・インスタンスを作成する
IDocument doc = Factory.Document.CreateInstance(os, ClassNames.DOCUMENT);

// ドキュメント・プロパティーを設定する
doc.Properties["DocumentTitle"] = "New Document via .NET API";
doc.MimeType = "text/plain";

IStorageArea sa = Factory.StorageArea.GetInstance(os, new Id("{DE42374D-B04B-4F47-A62E-CAC9AC9A5719}"));
doc.StorageArea = sa;

doc.Save(RefreshMode.NO_REFRESH);

// ドキュメントをチェックイン
doc.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc.Save(RefreshMode.NO_REFRESH);

// ドキュメントをフォルダーにファイリングする
IFolder folder = Factory.Folder.GetInstance(os, ClassNames.FOLDER,
        new Id("{42A3FC29-D635-4C37-8C86-84BAC73FFA3F}"));
IReferentialContainmentRelationship rcr = folder.File(doc,
        AutoUniqueName.AUTO_UNIQUE, "New Document via .NET API",
        DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rcr.Save(RefreshMode.NO_REFRESH);

統合されたドキュメントの所有権の獲得

この例では、ドキュメントを取得し、統合されたドキュメントの所有権を獲得する方法を示します。

Java の例

Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}") );
doc.takeFederatedOwnership();
doc.save(RefreshMode.NO_REFRESH);

C# の例

IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}"));
doc.TakeFederatedOwnership();
doc.Save(RefreshMode.NO_REFRESH);

ドキュメントの取得 (getInstance)

この例では、getInstance メソッドを使用してドキュメントを取得し、いくつかのプロパティーを返す方法を示します。getInstance メソッドはプロパティー・キャッシュにデータを格納しません。プロパティーを操作する場合は、fetchProperties メソッドを呼び出す必要があります。

Java の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null) );
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null) );
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}") );

// 選択したプロパティーをサーバーからフェッチする
doc.fetchProperties(pf);

// ドキュメント・プロパティーを返す
com.filenet.api.property.Properties props = doc.getProperties();

// プロパティー値の設定と出力を繰り返す
Iterator iter = props.iterator();
System.out.println("Property" +"¥t" + "Value");
System.out.println("------------------------");
while (iter.hasNext() )
{
    Property prop = (Property)iter.next();
    if (prop.getPropertyName().equals("DocumentTitle") )
      System.out.println(prop.getPropertyName() + "¥t" + prop.getStringValue() );
    else if (prop.getPropertyName().equals(PropertyNames.MIME_TYPE,) )
      System.out.println(prop.getPropertyName() + "¥t" + prop.getStringValue() );
}

C# の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null));
IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}") );

// 選択したプロパティーをサーバーからフェッチする
doc.FetchProperties(pf);

// ドキュメント・プロパティーを返す
IProperties props = doc.Properties;

// プロパティー値の設定と出力を繰り返す
System.Collections.IEnumerator propsIter = props.GetEnumerator();
System.Console.WriteLine("Property" +"¥t" + "Value");
System.Console.WriteLine("------------------------");
while (propsIter.MoveNext())
{
    IProperty prop = (IProperty)propsIter.Current;
    if (prop.GetPropertyName().Equals("DocumentTitle") )
        System.Console.WriteLine(prop.GetPropertyName() + "¥t" + prop.GetStringValue() );
    else if (prop.GetPropertyName().Equals(PropertyNames.MIME_TYPE) )
        System.Console.WriteLine(prop.GetPropertyName() + "¥t" + prop.GetStringValue() ); 
}

ドキュメントの取得 (fetchInstance)

この例では、fetchInstance メソッドを使用してドキュメントを取得し、いくつかのプロパティーを返す方法を示します。fetchInstance メソッドは、プロパティー・キャッシュに指定されたプロパティーを格納します。

Java の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();    
pf.addIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null) );
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null) );
Document doc = Factory.Document.fetchInstance(os, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}"),pf );

// ドキュメント・プロパティーを返す
com.filenet.api.property.Properties props = doc.getProperties();

// プロパティー値の設定と出力を繰り返す
Iterator iter = props.iterator();
System.out.println("Property" +"¥t" + "Value");
System.out.println("------------------------");
while (iter.hasNext() )
{
    Property prop = (Property)iter.next();
    if (prop.getPropertyName().equals("DocumentTitle") )
        System.out.println(prop.getPropertyName() + "¥t" + prop.getStringValue() );
    else if (prop.getPropertyName().equals(PropertyNames.MIME_TYPE) )
        System.out.println(prop.getPropertyName() + "¥t" + prop.getStringValue() );
}

C# の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null));
IDocument doc = Factory.Document.FetchInstance(os, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}"), pf);

// ドキュメント・プロパティーを返す
IProperties props = doc.Properties;

// プロパティー値の設定と出力を繰り返す
System.Collections.IEnumerator propsIter = props.GetEnumerator();
System.Console.WriteLine("Property" +"¥t" + "Value");
System.Console.WriteLine("------------------------");
while (propsIter.MoveNext())
{
    IProperty prop = (IProperty)propsIter.Current;
    if (prop.GetPropertyName().Equals("DocumentTitle") )
        System.Console.WriteLine(prop.GetPropertyName() + "¥t" + prop.GetStringValue() );
    else if (prop.GetPropertyName().Equals(PropertyNames.MIME_TYPE) )
        System.Console.WriteLine(prop.GetPropertyName() + "¥t" + prop.GetStringValue() );
}

ドキュメントの削除

この例では、ドキュメントの削除方法を示します。ドキュメントを削除すると、ドキュメント・オブジェクト自体のほか、関連付けられた内部コンテンツ、アノテーション、およびその他の依存オブジェクトも削除されます。削除処理は、処理全体で成功または失敗となります。例えば、ドキュメントのバージョンまたは依存オブジェクト (アノテーションなど) のいずれかを削除するのに必要な権限がない場合は、削除処理全体が失敗となります。 セキュリティー権限、複合ドキュメント関係によって課せられた制約、およびストレージ域の AllowsDelete プロパティーと RetentionPeriod プロパティーの使用により、ドキュメントの削除を防ぐことができます。

Java の例

Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{A26C3EF4-7C02-4D01-84CD-D3D7F1D5DA19}") );
doc.delete();
doc.save(RefreshMode.NO_REFRESH);

C# の例

IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{6B3E6E63-23B1-4D29-8E91-8632E30F10C5}"));
doc.Delete();
doc.Save(RefreshMode.NO_REFRESH);

ドキュメント・プロパティーの更新

この例では、DocumentTitle プロパティーを取得して値を変更し、プロパティー・キャッシュを更新する方法を示します。

Java の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
Document doc = Factory.Document.fetchInstance(os, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}"),pf );

// ドキュメント・プロパティーを返す
com.filenet.api.property.Properties props = doc.getProperties();

// プロパティー値を変更する
props.putValue("DocumentTitle", "Document with Updated Title via Java API");

// プロパティー・キャッシュを保存して更新する
doc.save(RefreshMode.REFRESH );

C# の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
IDocument doc = Factory.Document.FetchInstance(os, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}"), pf);

// ドキュメント・プロパティーを返す
IProperties props = doc.Properties;

// プロパティー値を変更する
doc.Properties["DocumentTitle"] = "Document with Updated Title via .NET API";

// プロパティー・キャッシュを保存して更新する
doc.Save(RefreshMode.REFRESH);

ドキュメント・コンテンツの設定

この例では、ドキュメント・コンテンツの設定方法を示します

Java の例

// ドキュメントを取得する
Document doc=Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{8FD91CF0-E991-426D-9BCB-B63F0E30E604}") );

// Document オブジェクトをチェックアウトして保存
doc.checkout(com.filenet.api.constants.ReservationType.EXCLUSIVE, null, doc.getClassName(), doc.getProperties());
doc.save(RefreshMode.REFRESH);

// Document オブジェクトから Reservation オブジェクトを取得する
Document reservation = (Document) doc.get_Reservation();

// 内部ファイルおよび外部ファイルを指定すると、コンテンツとして追加される
File internalFile = new File("C:¥¥docs¥mydoc.txt");
// non-Windows: File internalFile = new File("/tmp/docs/mydoc.txt");
String externalFile = "ftp://ftp.mycompany.com/docs/relnotes.txt";

// Reservation オブジェクトにコンテンツを追加する
try {
    // 最初に ContentTransfer オブジェクトを追加する
    ContentTransfer ctObject = Factory.ContentTransfer.createInstance();
    FileInputStream fileIS = new FileInputStream(internalFile.getAbsolutePath());
    ContentElementList contentList = Factory.ContentTransfer.createList();
    ctObject.setCaptureSource(fileIS);
    // ContentTransfer オブジェクトをリストに追加
    contentList.add(ctObject);

    // 次に ContentReference オブジェクトを追加する
    ContentReference crObject = Factory.ContentReference.createInstance(os);
    crObject.set_ContentLocation(externalFile);
    crObject.set_ContentType("text/plain"); // Must be set for ContentReference.
    // ContentReference オブジェクトをリストに追加する
    contentList.add(crObject);

    reservation.set_ContentElements(contentList);
    reservation.save(RefreshMode.REFRESH);
    }
catch (Exception e)
{
    System.out.println(e.getMessage() );
}

// Reservation オブジェクトにメジャー・バージョンとしてチェックインする
reservation.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
reservation.save(RefreshMode.REFRESH);

C# の例

// ドキュメントを取得する
IDocument doc=Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}") );

// Document オブジェクトをチェックアウトして保存
doc.Checkout(ReservationType.EXCLUSIVE, null, doc.GetClassName(), doc.Properties);
doc.Save(RefreshMode.REFRESH);

// Document オブジェクトから Reservation オブジェクトを取得する
IDocument reservation = (IDocument) doc.Reservation;

// 内部ファイルおよび外部ファイルを指定すると、コンテンツとして追加される
Stream internalFile = File.OpenRead(@"C:¥¥BootstrapConfigUtility.bat");
String externalFile = "file://C:¥¥BootstrapConfigUtility.bat";

// Reservation オブジェクトにコンテンツを追加する
try {
    // 最初に ContentTransfer オブジェクトを追加する
    IContentTransfer ctObject = Factory.ContentTransfer.CreateInstance();
    IContentElementList contentList = Factory.ContentTransfer.CreateList();
    ctObject.SetCaptureSource(internalFile);
    // ContentTransfer オブジェクトをリストに追加
    contentList.Add(ctObject);

    // 次に ContentReference オブジェクトを追加する
    IContentReference crObject = Factory.ContentReference.CreateInstance(os);
    crObject.ContentLocation = externalFile;
    crObject.ContentType = "text/plain";// Must be set for ContentReference.
    // ContentReference オブジェクトをリストに追加する
    contentList.Add(crObject);

    reservation.ContentElements = contentList;
    reservation.Save(RefreshMode.REFRESH);
}
catch (Exception e)
{
    System.Console.WriteLine(e.Message);
}

// Reservation オブジェクトにメジャー・バージョンとしてチェックインする
reservation.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
reservation.Save(RefreshMode.REFRESH);

ドキュメント・コンテンツの取得

この例では、ドキュメント・コンテンツに関する情報を表示し、コンテンツを印刷する方法を示します。最初に、コンテンツに関するドキュメント・プロパティーとして、ドキュメント内のコンテンツ・エレメントの数とドキュメントのサイズ (すべてのコンテンツ・エレメントの合計) を印刷します。次に、ドキュメントのコンテンツ・エレメント・リストを取得します。コンテンツ・エレメントごとに、いくつかのプロパティー値を印刷した後、コンテンツ自体を印刷します。

Java の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_SIZE, null) );
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_ELEMENTS, null) );
Document doc=Factory.Document.fetchInstance(os, "{9FEC3C69-57B2-4E29-872A-0EE452881555}", pf );

// コンテンツ・エレメントの情報を出力する
System.out.println("No. of document content elements: " + doc.get_ContentElements().size() + "¥n" +
 "Total size of content: " + doc.get_ContentSize() + "¥n");

// コンテンツ・エレメントを取得し、リストを反復処理する
ContentElementList docContentList = doc.get_ContentElements();
Iterator iter = docContentList.iterator();
while (iter.hasNext() )
{
    ContentTransfer ct = (ContentTransfer) iter.next();

    // エレメントのシーケンス番号とコンテンツ・タイプを出力する
    System.out.println("¥nElement Sequence number: " + ct.get_ElementSequenceNumber().intValue() + "¥n" +
     "Content type: " + ct.get_ContentType() + "¥n");

    // エレメントのコンテンツを取得して表示する
    InputStream stream = ct.accessContentStream();
    String readStr = "";
    try
    {
        int docLen = 1024;
        byte[] buf = new byte[docLen];
        int n = 1;
        while (n > 0)
        {
           n =  stream.read(buf, 0, docLen);
           readStr = readStr + new String(buf);
           buf = new byte[docLen];
        }
        System.out.println("Content:¥n " + readStr);
        stream.close();
    }
    catch(IOException ioe)
    {
        ioe.printStackTrace();
    }
}

C# の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_SIZE, null));
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_ELEMENTS, null));
IDocument doc = Factory.Document.FetchInstance(os, "{9FEC3C69-57B2-4E29-872A-0EE452881555}", pf);

// コンテンツ・エレメントの情報を出力する
System.Console.WriteLine("No. of document content elements: " + doc.ContentElements.Count + "¥n" +
 "Total size of content: " + doc.ContentSize + "¥n");

// コンテンツ・エレメントを取得し、リストを反復処理する
IContentElementList docContentList = doc.ContentElements;
System.Collections.IEnumerator iter = docContentList.GetEnumerator();
while (iter.MoveNext())
{
    IContentTransfer ct = (IContentTransfer)iter.Current;

    // エレメントのシーケンス番号とコンテンツ・タイプを出力する
    System.Console.WriteLine("¥nElement Sequence number: " + ct.ElementSequenceNumber.Value + "¥n" +
     "Content type: " + ct.ContentType + "¥n");

    // エレメントのコンテンツを取得して表示する
    String readStr = "";
    try
    {
        Stream stream = ct.AccessContentStream();
        int docLen = 1024;
        byte[] buf = new byte[docLen];
        int n = 1;
        while (n > 0)
        {
            n = stream.Read(buf, 0, docLen);
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            StringBuilder sb = new StringBuilder();
            sb.Append(enc.GetString(buf), 0, docLen);
            readStr=sb.ToString();
            buf = new byte[docLen];
        }
        System.Console.WriteLine("Content:¥n " + readStr);
        stream.Close();
    }
    catch(IOException ioe)
    {
        System.Console.WriteLine(ioe.Message);
    }
}

ストレージ域の割り当て

ストレージ域は、ドキュメントの作成時にのみ設定できます。「ドキュメントの作成」を参照してください。

保管ポリシーの割り当て

次の例では、ドキュメントに保管ポリシーを割り当てる方法を示します。 コードが有効になるのは、ポリシーに関連付けられているストレージ域がクローズされているか、いっぱいである場合のみです。 次回、ドキュメントがチェックアウトされてからチェックインされると、新しいポリシーは有効になります。

Java の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.STORAGE_POLICY, null));
Document doc=Factory.Document.fetchInstance(os, "{33074B6E-FD19-4C0D-96FC-D809633D35BE}", pf );

// 現在の保管ポリシー名を出力する
System.out.println("Current storage policy: " + doc.get_StoragePolicy().get_DisplayName() );

// 新しい保管ポリシーを設定して名前を出力する
StoragePolicy sp = Factory.StoragePolicy.getInstance(os, new Id("{BA065E85-7D01-48E3-9266-4EFDC8D8FAE3}") );
doc.set_StoragePolicy(sp);
doc.save(RefreshMode.REFRESH);
System.out.println("New storage policy: " + doc.get_StoragePolicy().get_DisplayName() );

C# の例

// ドキュメントを取得し、プロパティー・キャッシュを格納する
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.STORAGE_POLICY, null));
IDocument doc=Factory.Document.FetchInstance(os, "{61BA91F0-6639-4A12-A784-CD274AADF9AA}", pf );

// 現在の保管ポリシー名を出力する
System.Console.WriteLine("Current storage policy: " + doc.StoragePolicy.DisplayName);

// 新しい保管ポリシーを設定して名前を出力する
IStoragePolicy sp = Factory.StoragePolicy.GetInstance(os, new Id("{BA065E85-7D01-48E3-9266-4EFDC8D8FAE3}") );
doc.StoragePolicy = sp;
doc.Save(RefreshMode.REFRESH);
System.Console.WriteLine("New storage policy: " + doc.StoragePolicy.DisplayName);

ドキュメント・コンテンツの移動

これらの例では、ドキュメント・コンテンツを別のストレージ域に移動する方法を示します。2 番目の例では、ドキュメントのクラスを変更した後でドキュメントのコンテンツを移動する方法を示します。

以下の例では、ドキュメント・コンテンツを別のストレージ域に移動する方法を示します。この場合、コンテンツはデータベース・ストレージ域に移動されます。

Java の例

// ドキュメント・コンテンツの移動先となるストレージ域を取得
DatabaseStorageArea dsa = Factory.DatabaseStorageArea.fetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA75}"), null );

// コンテンツを移動する Document オブジェクトを取得する
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{33074B6E-FD19-4C0D-96FC-D809633D35BE}") );

// コンテンツを移動して Document オブジェクトを保存する
doc.moveContent(dsa);
doc.save(RefreshMode.REFRESH);

C# の例

// ドキュメント・コンテンツの移動先となるストレージ域を取得
IDatabaseStorageArea dsa = Factory.DatabaseStorageArea.FetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA75}"), null);

// コンテンツを移動する Document オブジェクトを取得する
IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{61BA91F0-6639-4A12-A784-CD274AADF9AA}"));

// コンテンツを移動して Document オブジェクトを保存する
doc.MoveContent(dsa);
doc.Save(RefreshMode.REFRESH);

以下の例では、ドキュメントのクラスを変更し、新規ドキュメント・クラスに関連付けられたストレージ域にドキュメント・コンテンツを移動する方法を示します。この場合、コンテンツはファイル・ストレージ域に移動されます。

Java の例

// 新規ドキュメント・クラスに関連付けられたストレージ域を取得する
FileStorageArea newDocClassFSA = Factory.FileStorageArea.fetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA77}"), null );

// コンテンツを移動する Document オブジェクトを取得する
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{33074B6E-FD19-4C0D-96FC-D809633D35BE}") );

// クラスを変更してコンテンツを移動する
// 対象の Document オブジェクトを取得する
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{33074B6E-FD19-4C0D-96FC-D809633D35BF}") );

// ドキュメント・クラスを変更する
doc.changeClass(“newDocClass”);

// 新規ドキュメント・クラスに関連付けられたストレージ域にコンテンツを移動し、
// Document オブジェクトを保存する
doc.moveContent(newDocClassFSA);
doc.save(RefreshMode.REFRESH);

C# の例

// 新規ドキュメント・クラスに関連付けられたストレージ域を取得する
IFileStorageArea newDocClassFSA = Factory.FileStorageArea.FetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA77}"), null);
 
// クラスを変更してコンテンツを移動する
// 対象の Document オブジェクトを取得する
IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{61BA91F0-6639-4A12-A784-CD274AADF9AB}"));
 
// ドキュメント・クラスを変更する
doc.ChangeClass("newDocClass");

// 新規ドキュメント・クラスに関連付けられたストレージ域にコンテンツを移動し、
// Document オブジェクトを保存する
doc.MoveContent(newDocClassFSA);
doc.Save(RefreshMode.REFRESH);

ドキュメントのファイリング解除

この例では、ドキュメントが含まれているフォルダーから、そのドキュメントをファイリング解除する 1つの方法を示します。この例が機能するためには、ファイリング解除するドキュメントを指す参照が必要です。

ドキュメントは、ReferentialContainmentRelationship (RCR) オブジェクトによって含有する側のフォルダーに接続されます。RCR の Head プロパティーはドキュメントを指し、RCR の Tail プロパティーは含有する側のフォルダーを指します。1 つのドキュメントは複数のフォルダーによって参照することができるため、この例ではドキュメントから RCR オブジェクトのセットを取得し、このセットを繰り返して、目的のフォルダーと一致する Tail プロパティーを持つ RCR オブジェクトを検出します。検出された RCR オブジェクトは削除されます。

Java の例

static PropertyFilter pf = new PropertyFilter(); 

pf.addIncludeProperty(new FilterElement(null, null, null, "Containers", null));
// ファイリング解除するドキュメントを取得
Document doc = Factory.Document.fetchInstance(os, new Id("{8854236F-02D6-40AB-B4B2-59B6756154D8}"), pf);

// 目的のフォルダーが検出されるまで、ドキュメントが含まれたすべてのフォルダーを繰り返す
ReferentialContainmentRelationshipSet rcrs = doc.get_Containers();
Iterator iter = rcrs.iterator();
while (iter.hasNext() )
{
   ReferentialContainmentRelationship rcr = (ReferentialContainmentRelationship)iter.next();
   Folder folder = (Folder)rcr.get_Tail();
   if (folder.get_Id().equals(new Id("{C40106FE-B510-4222-BB42-6D2FD5D21123}")))
   {
      rcr.delete();
      rcr.save(RefreshMode.REFRESH);
      break;
   }
}

C# の例

static PropertyFilter pf = new PropertyFilter();

pf.AddIncludeProperty(new FilterElement(null, null, null, "Containers", null));
// ファイリング解除するドキュメントを取得
IDocument doc = Factory.Document.FetchInstance(os, new Id("{8854236F-02D6-40AB-B4B2-59B6756154D8}"), pf);

// 目的のフォルダーが検出されるまで、ドキュメントが含まれたすべてのフォルダーを繰り返す
IReferentialContainmentRelationshipSet rcrs = doc.Containers;
foreach (IReferentialContainmentRelationship rcr in rcrs)
{
   IFolder folder = (IFolder)rcr.Tail;
   if (folder.Id.Equals(new Id("{C40106FE-B510-4222-BB42-6D2FD5D21123}")))
   {
      rcr.Delete();
      rcr.Save(RefreshMode.REFRESH);
      break;
   }
}

ドキュメント・クラスのカスタマイズ

この例では、新しいプロパティー (eMail 署名) をクラスに追加して Email クラスをカスタマイズする方法を示します。名前と説明のテキストには LocalizedString オブジェクトが必要です。これは getLocalizedString メソッドによって返されます。

Java の例

public void customizeClass()
{
    // 選択したクラス定義をサーバーからフェッチ
    ClassDefinition classDef = Factory.ClassDefinition.fetchInstance(os, "Email", null );

    // オブジェクト・プロパティーにオプションの値を設定して新しい PropertyTemplate を作成する
    PropertyTemplateObject newPropTemplate = Factory.PropertyTemplateObject.createInstance(os);
    newPropTemplate.set_Cardinality (Cardinality.SINGLE);
    newPropTemplate.set_IsValueRequired(Boolean.FALSE);

    // ロケール固有の文字列に必須プロパティーを設定
    LocalizedString locStr1 = getLocalizedString("eMail Signature", os.get_LocaleName() );
    // Create LocalizedString collection.
    newPropTemplate.set_DisplayNames (Factory.LocalizedString.createList() );
    newPropTemplate.get_DisplayNames().add(locStr1);

    LocalizedString locStr2 = getLocalizedString("Signature of sender",
       os.get_LocaleName() );
    newPropTemplate.set_DescriptiveTexts(Factory.LocalizedString.createList() );
    newPropTemplate.get_DescriptiveTexts().add(locStr2);

    // プロパティー・テンプレートをサーバーに保存
    newPropTemplate.save(RefreshMode.REFRESH);

    // プロパティー・テンプレートからプロパティー定義を作成
    PropertyDefinitionObject newPropDef = (PropertyDefinitionObject)newPropTemplate.createClassProperty();

    // E メール・アイテムに RequiredClass プロパティーを設定する
    newPropDef.set_RequiredClassId(new Id("{BFA64F40-5C45-45B1-B540-B5BA3CA08AAB}") );

    // PropertyDefinitions プロパティーをプロパティー・キャッシュから取得
    PropertyDefinitionList propDefs = classDef.get_PropertyDefinitions();

    // 新規プロパティー定義をクラス定義に追加
    propDefs.add(newPropDef);

    classDef.save(RefreshMode.REFRESH);
}

private LocalizedString getLocalizedString(String text, String locale)
{
    LocalizedString locStr = Factory.LocalizedString.createInstance ();
    locStr.set_LocalizedText(text);
    locStr.set_LocaleName (locale);
    return locStr;
}

C# の例

public void customizeClass()
{
    // 選択したクラス定義をサーバーからフェッチ
    IClassDefinition classDef = Factory.ClassDefinition.FetchInstance(os, "Email", null);

    // オブジェクト・プロパティーにオプションの値を設定して新しい PropertyTemplate を作成する
    IPropertyTemplateObject newPropTemplate = Factory.PropertyTemplateObject.CreateInstance(os);
    newPropTemplate.Cardinality = Cardinality.SINGLE;
    newPropTemplate.IsValueRequired = false;

    // ロケール固有の文字列に必須プロパティーを設定
    ILocalizedString locStr1 = getLocalizedString("eMail Signature", os.LocaleName);
    // LocalizedString コレクションを作成する
    newPropTemplate.DisplayNames = Factory.LocalizedString.CreateList();
    newPropTemplate.DisplayNames.Add(locStr1);

    ILocalizedString locStr2 = getLocalizedString("Signature of sender", os.LocaleName);
    newPropTemplate.DescriptiveTexts = Factory.LocalizedString.CreateList();
    newPropTemplate.DescriptiveTexts.Add(locStr2);

    // プロパティー・テンプレートをサーバーに保存
    newPropTemplate.Save(RefreshMode.REFRESH);

    // プロパティー・テンプレートからプロパティー定義を作成
    IPropertyDefinitionObject newPropDef = (IPropertyDefinitionObject)newPropTemplate.CreateClassProperty();

    // E メール・アイテムに RequiredClass プロパティーを設定する
    newPropDef.RequiredClassId = new Id("{BFA64F40-5C45-45B1-B540-B5BA3CA08AAB}");

    // PropertyDefinitions プロパティーをプロパティー・キャッシュから取得
    IPropertyDefinitionList propDefs = classDef.PropertyDefinitions;

    // 新規プロパティー定義をクラス定義に追加
    propDefs.Add(newPropDef);

    classDef.Save(RefreshMode.REFRESH);
}

private ILocalizedString getLocalizedString(String text, String locale)
{
    ILocalizedString locStr = Factory.LocalizedString.CreateInstance();
    locStr.LocalizedText = text;
    locStr.LocaleName = locale;
    return locStr;
}


最終更新日: 2015 年 10 月
document_procedures.htm

© Copyright IBM Corp. 2015.