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