例: SetInput method

  1. 次のエージェントは、データベースの内容に基づいて 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 Export current database as DXL
      Dim exporter As NotesDXLExporter
      Set exporter = session.CreateDXLExporter
      Call exporter.SetInput(db)
      Call exporter.SetOutput(stream)
      Call exporter.Process
    End Sub
  2. 次のエージェントは、文書コレクションの内容に基づいて 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) - 4) & "_dc.xml"
      If Not stream.Open(filename$) Then
        Messagebox "Cannot open " & filename$,, "Error"
        Exit Sub
      End If
      Call stream.Truncate
      
      REM Create document collection
      Dim dc As NotesDocumentCollection
      Set dc = db.AllDocuments
      If dc.Count = 0 Then
        Messagebox "No document in database",, "No document"
        Exit Sub
      End If
      
      REM Export document collection as DXL
      Dim exporter As NotesDXLExporter
      Set exporter = session.CreateDXLExporter
      Call exporter.SetInput(dc)
      Call exporter.SetOutput(stream)
      Call exporter.Process
    End Sub
  3. 次のエージェントは、文書の内容に基づいて 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) - 4) & "_doc.xml"
      If Not stream.Open(filename$) Then
        Messagebox "Cannot open " & filename$,, "Error"
        Exit Sub
      End If
      Call stream.Truncate
      
      REM Get selected or first selected document
      Dim dc As NotesDocumentCollection
      Set dc = db.UnprocessedDocuments
      If dc.Count = 0 Then
        Messagebox "No document selected",, "No document"
        Exit Sub
      End If
      Dim doc As NotesDocument
      Set doc = dc.GetFirstDocument
      
      REM Export document as DXL
      Dim exporter As NotesDXLExporter
      Set exporter = session.CreateDXLExporter
      Call exporter.SetInput(doc)
      Call exporter.SetOutput(stream)
      Call exporter.Process
    End Sub
  4. このコードはフォーム上にあります。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