例: SetOutput method

  1. 次のエージェントは、文書 (note) コレクションの内容に基づいて DXL を生成します。
    Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CurrentDatabase
      
      REM Open xml file named after current database
      Dim stream As NotesStream
      Set stream = session.CreateStream
      filename$ = "c:¥dxl¥" & _
      Left(db.FileName, Len(db.FileName) - 3) & "xml"
      If Not stream.Open(filename$) Then
        Messagebox "Cannot open " & filename$,, "Error"
        Exit Sub
      End If
      Call stream.Truncate
      
      REM Create note collection for current database
      Dim nc As NotesNoteCollection
      Set nc = db.CreateNoteCollection(False)
      Call nc.SelectAllDesignElements(True)
      Call nc.BuildCollection
      
      REM Export note collection as DXL
      Dim exporter As NotesDXLExporter
      Set exporter = session.CreateDXLExporter(nc)
      Call exporter.SetOutput(stream)
      Call exporter.Process
    End Sub
  2. このコードはフォーム上にあります。2 つのフィールドには、入力ファイルのパス名と出力データベースの名前が指定されています。[Process] ボタンをクリックすると、NotesDXLImporter オブジェクトの入出力パラメータが設定され、その Process メソッドが呼び出されます。
    Dim session As NotesSession
    Dim ws As NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Dim importer As NotesDXLImporter
    Dim stream As NotesStream
    Dim db As NotesDatabase
    
    Sub Initialize
      Set session = New NotesSession
      Set ws = New NotesUIWorkspace
      Set importer = session.CreateDXLImporter
    End Sub
    
    Function SetInput As Boolean
      Set stream = session.CreateStream
      fileName$ = uidoc.FieldGetText("InputFile")
      If Not stream.Open(fileName$) Then
        Messagebox "Cannot open file",, fileName$
        SetInput = False
        Exit Function
      End If
      If stream.Bytes = 0 Then
        Messagebox "File did not exist or was empty",, fileName$
        SetInput = False
        Exit Function
      End If
      Call importer.SetInput(stream)
      SetInput = True
    End Function
    
    Function SetOutput As Boolean
      Set db = New NotesDatabase("", "")
      fileName$ = uidoc.FieldGetText("OutputDatabase")
      If Not db.Open("", fileName$) Then
        Call db.Create("", fileName$, True)
      End If
      Call importer.SetOutput(db)
      SetOutput = True
    End Function
    
    Sub Postopen(Source As Notesuidocument)
      Set uidoc = ws.CurrentDocument
    End Sub
    
    Sub Click(Source As Button)
    REM This is the "Process" button
      If Not SetInput Then Exit Sub
      If Not SetOutput Then Exit Sub
      Call importer.Process
    End Sub