1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sw_SwXMailMerge" script:language="StarBasic">
3cdf0e10cSrcweir
4cdf0e10cSrcweir'*************************************************************************
5cdf0e10cSrcweir'
6*ce3cae9fSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
7*ce3cae9fSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
8*ce3cae9fSAndrew Rist'  distributed with this work for additional information
9*ce3cae9fSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
10*ce3cae9fSAndrew Rist'  to you under the Apache License, Version 2.0 (the
11*ce3cae9fSAndrew Rist'  "License"); you may not use this file except in compliance
12*ce3cae9fSAndrew Rist'  with the License.  You may obtain a copy of the License at
13*ce3cae9fSAndrew Rist'
14*ce3cae9fSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
15*ce3cae9fSAndrew Rist'
16*ce3cae9fSAndrew Rist'  Unless required by applicable law or agreed to in writing,
17*ce3cae9fSAndrew Rist'  software distributed under the License is distributed on an
18*ce3cae9fSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*ce3cae9fSAndrew Rist'  KIND, either express or implied.  See the License for the
20*ce3cae9fSAndrew Rist'  specific language governing permissions and limitations
21*ce3cae9fSAndrew Rist'  under the License.
22cdf0e10cSrcweir'
23cdf0e10cSrcweir'*************************************************************************
24cdf0e10cSrcweir
25*ce3cae9fSAndrew Rist
26*ce3cae9fSAndrew Rist
27cdf0e10cSrcweir' REQUIRED VARIABLES for interface/service tests:
28cdf0e10cSrcweir
29cdf0e10cSrcweir' com.sun.star.task.XJob:
30cdf0e10cSrcweirGlobal vXJobArgs(0 to 3) as Variant
31cdf0e10cSrcweir
32cdf0e10cSrcweir' com.sun.star.text.MailMerge
33cdf0e10cSrcweirGlobal cMailMerge_DocumentURL as String
34cdf0e10cSrcweir
35cdf0e10cSrcweirDim cDataSourceName  as String
36cdf0e10cSrcweirDim cDataCommand as String
37cdf0e10cSrcweirDim oXResultSet as Variant
38cdf0e10cSrcweir
39cdf0e10cSrcweir' Be sure that all variables are dimensioned:
40cdf0e10cSrcweiroption explicit
41cdf0e10cSrcweir
42cdf0e10cSrcweirSub CreateObj()
43cdf0e10cSrcweir
44cdf0e10cSrcweir'*************************************************************************
45cdf0e10cSrcweir' COMPONENT:
46cdf0e10cSrcweir' com.sun.star.sw.SwXMailMerge
47cdf0e10cSrcweir'*************************************************************************
48cdf0e10cSrcweirOn Error Goto ErrHndl
49cdf0e10cSrcweir
50cdf0e10cSrcweir	Dim vXJobArg0(0 to 7) as new com.sun.star.beans.NamedValue
51cdf0e10cSrcweir	Dim vXJobArg1(0 to 6) as new com.sun.star.beans.NamedValue
52cdf0e10cSrcweir	Dim vXJobArg2(0 to 9) as new com.sun.star.beans.NamedValue
53cdf0e10cSrcweir	Dim vXJobArg3(0) as new com.sun.star.beans.NamedValue
54cdf0e10cSrcweir	Dim cTestDoc as String
55cdf0e10cSrcweir	Dim cOutputURL as String
56cdf0e10cSrcweir    Dim oXConnection as Variant
57cdf0e10cSrcweir    Dim myBookMarks as Variant
58cdf0e10cSrcweir
59cdf0e10cSrcweir    oObj = createUnoService("com.sun.star.text.MailMerge")
60cdf0e10cSrcweir
61cdf0e10cSrcweir	cTestDoc = utils.Path2URL(cTestDocsDir + "/" + "MailMerge.sxw")
62cdf0e10cSrcweir    cMailMerge_DocumentURL = cTestDoc
63cdf0e10cSrcweir	cOutputURL = ConvertToURL(utils.getUserPath())
64cdf0e10cSrcweir    cDataSourceName  = "Bibliography"
65cdf0e10cSrcweir    cDataCommand = "biblio"
66cdf0e10cSrcweir    oXResultSet = getXResultSet()
67cdf0e10cSrcweir    oXConnection = oXResultSet.ActiveConnection
68cdf0e10cSrcweir
69cdf0e10cSrcweir	' create arguments for XJob:
70cdf0e10cSrcweir    myBookMarks = getMyBookMarks()
71cdf0e10cSrcweir
72cdf0e10cSrcweir    oObj.DataSourceName = cDataSourceName
73cdf0e10cSrcweir    oObj.Command = cDataCommand
74cdf0e10cSrcweir    oObj.CommandType = com.sun.star.sdb.CommandType.TABLE
75cdf0e10cSrcweir    oObj.OutputType = com.sun.star.text.MailMergeType.FILE
76cdf0e10cSrcweir    oObj.DocumentURL = cTestDoc
77cdf0e10cSrcweir    oObj.OutputURL = cOutputURL
78cdf0e10cSrcweir    oObj.FileNamePrefix = "Author"
79cdf0e10cSrcweir    oObj.FileNameFromColumn = TRUE
80cdf0e10cSrcweir    oObj.Selection = DimArray()
81cdf0e10cSrcweir
82cdf0e10cSrcweir	' use a simple DataBase with simple Table
83cdf0e10cSrcweir	vXJobArg0(0).Name = "DataSourceName" : vXJobArg0(0).Value = cDataSourceName
84cdf0e10cSrcweir	vXJobArg0(1).Name = "Command" : vXJobArg0(1).Value = cDataCommand
85cdf0e10cSrcweir	vXJobArg0(2).Name = "CommandType" : vXJobArg0(2).Value = com.sun.star.sdb.CommandType.TABLE
86cdf0e10cSrcweir	vXJobArg0(3).Name = "OutputType" : vXJobArg0(3).Value = com.sun.star.text.MailMergeType.FILE
87cdf0e10cSrcweir	vXJobArg0(4).Name = "DocumentURL" : vXJobArg0(4).Value = cTestDoc
88cdf0e10cSrcweir	vXJobArg0(5).Name = "OutputURL" : vXJobArg0(5).Value = cOutputURL
89cdf0e10cSrcweir	vXJobArg0(6).Name = "FileNamePrefix" : vXJobArg0(6).Value = "Identifier"
90cdf0e10cSrcweir	vXJobArg0(7).Name = "FileNameFromColumn" : vXJobArg0(7).Value = true
91cdf0e10cSrcweir
92cdf0e10cSrcweir	' use a simple DataBase with simple Table and write to printer
93cdf0e10cSrcweir	vXJobArg1(0).Name = "DataSourceName" : vXJobArg1(0).Value = cDataSourceName
94cdf0e10cSrcweir	vXJobArg1(1).Name = "Command" : vXJobArg1(1).Value = cDataCommand
95cdf0e10cSrcweir	vXJobArg1(2).Name = "CommandType" : vXJobArg1(2).Value = com.sun.star.sdb.CommandType.TABLE
96cdf0e10cSrcweir	vXJobArg1(3).Name = "OutputType" : vXJobArg1(3).Value = com.sun.star.text.MailMergeType.PRINTER
97cdf0e10cSrcweir	vXJobArg1(4).Name = "FileNamePrefix" : vXJobArg1(4).Value = "Author"
98cdf0e10cSrcweir	vXJobArg1(5).Name = "FileNameFromColumn" : vXJobArg1(5).Value = true
99cdf0e10cSrcweir	vXJobArg1(6).Name = "DocumentURL" : vXJobArg1(6).Value = cTestDoc
100cdf0e10cSrcweir
101cdf0e10cSrcweir	' use a XConnection
102cdf0e10cSrcweir	vXJobArg2(0).Name = "ActiveConnection" : vXJobArg2(0).Value = oXConnection
103cdf0e10cSrcweir	vXJobArg2(1).Name = "DataSourceName" : vXJobArg2(1).Value = cDataSourceName
104cdf0e10cSrcweir	vXJobArg2(2).Name = "Command" : vXJobArg2(2).Value = cDataCommand
105cdf0e10cSrcweir	vXJobArg2(3).Name = "CommandType" : vXJobArg2(3).Value = com.sun.star.sdb.CommandType.TABLE
106cdf0e10cSrcweir	vXJobArg2(4).Name = "OutputType" : vXJobArg2(4).Value = com.sun.star.text.MailMergeType.FILE
107cdf0e10cSrcweir	vXJobArg2(5).Name = "ResultSet" : vXJobArg2(5).Value = oXResultSet
108cdf0e10cSrcweir	vXJobArg2(6).Name = "OutputURL" : vXJobArg2(6).Value = cOutputURL
109cdf0e10cSrcweir	vXJobArg2(7).Name = "FileNamePrefix" : vXJobArg2(7).Value = "Identifier"
110cdf0e10cSrcweir	vXJobArg2(8).Name = "FileNameFromColumn" : vXJobArg2(8).Value = true
111cdf0e10cSrcweir	vXJobArg2(9).Name = "Selection" : vXJobArg2(9).Value = myBookMarks()
112cdf0e10cSrcweir
113cdf0e10cSrcweir	vXJobArgs(0) = vXJobArg0()
114cdf0e10cSrcweir	vXJobArgs(1) = vXJobArg1()
115cdf0e10cSrcweir	vXJobArgs(2) = vXJobArg2()
116cdf0e10cSrcweir	vXJobArgs(3) = DimArray()
117cdf0e10cSrcweir
118cdf0e10cSrcweir	out.log("com.sun.star.text.MailMerge created.")
119cdf0e10cSrcweir
120cdf0e10cSrcweirExit Sub
121cdf0e10cSrcweirErrHndl:
122cdf0e10cSrcweir    Test.Exception()
123cdf0e10cSrcweirEnd Sub
124cdf0e10cSrcweir
125cdf0e10cSrcweirSub XMailMergeEvent()
126cdf0e10cSrcweir    oObj.execute(vXJobArgs(2))
127cdf0e10cSrcweirend sub
128cdf0e10cSrcweir
129cdf0e10cSrcweirFunction getXResultSet() as Variant
130cdf0e10cSrcweir    Dim oRowSet as Object
131cdf0e10cSrcweir    oRowSet = createUnoService("com.sun.star.sdb.RowSet")
132cdf0e10cSrcweir    oRowSet.DataSourceName = cDataSourceName
133cdf0e10cSrcweir    oRowSet.Command = cDataCommand
134cdf0e10cSrcweir    oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE
135cdf0e10cSrcweir    oRowSet.execute()
136cdf0e10cSrcweir    wait(200)
137cdf0e10cSrcweir'    oRowSet.getFirst()
138cdf0e10cSrcweir    getXResultSet() = oRowSet
139cdf0e10cSrcweirend Function
140cdf0e10cSrcweir
141cdf0e10cSrcweirFunction getMyBookMarks() as Variant
142cdf0e10cSrcweir    Dim BookMarks(1) as Variant
143cdf0e10cSrcweir    oXResultSet.first()
144cdf0e10cSrcweir    BookMarks(0) = oXResultSet.getBookmark()
145cdf0e10cSrcweir    oXResultSet.next()
146cdf0e10cSrcweir    BookMarks(1) = oXResultSet.getBookmark()
147cdf0e10cSrcweir    getMyBookMarks() = BookMarks()
148cdf0e10cSrcweirend Function
149cdf0e10cSrcweir
150cdf0e10cSrcweir</script:module>
151