1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Correspondence" script:
language=
"StarBasic">Option Explicit
22 Public msgNoTextmark$, msgError$
25 Public sCompany$, sFirstName$, sLastName$, sStreet$, sPostalCode$, sCity$, sState$, sInitials$, sPosition$
27 Public oDocument, oText, oBookMarks, oBookMark, oBookMarkCursor, oBookText as Object
28 Public bTemplate, bDBFields as Boolean
32 BasicLibraries.LoadLibrary(
"Tools
")
33 TemplateDialog = LoadDialog(
"Template
",
"TemplateDialog
")
34 DialogModel = TemplateDialog.Model
36 DialogModel.Optmerge.State = True
37 LoadLanguageCorrespondence()
38 TemplateDialog.Execute
39 TemplateDialog.Dispose()
45 BasicLibraries.LoadLibrary(
"Tools
")
46 LoadLanguageCorrespondence()
54 BasicLibraries.LoadLibrary(
"Tools
")
55 LoadLanguageCorrespondence()
61 Function LoadLanguageCorrespondence() as Boolean
62 If InitResources(
"'Template
'",
"tpl
") Then
63 msgNoTextmark$ = GetResText(
1303)
& Chr(
13)
& Chr(
10)
& GetResText(
1301)
64 msgError$ = GetResText(
1302)
66 DialogModel.Title = GetResText(
1303+
3)
67 DialogModel.CmdCancel.Label = GetResText(
1102)
68 DialogModel.CmdCorrGoOn.Label = GetResText(
1103)
69 DialogModel.OptSingle.Label = GetResText(
1303 +
1)
70 DialogModel.Optmerge.Label = GetResText(
1303 +
2)
71 DialogModel.FrmLetter.Label = GetResText(
1303)
73 LoadLanguageCorrespondence() = True
75 msgbox(
"Warning: Resource could not be loaded!
")
80 Function GetFieldName(oFieldKnot as Object, GeneralFieldName as String)
81 If oFieldKnot.HasByName(GeneralFieldName) Then
82 GetFieldName = oFieldKnot.GetByName(GeneralFieldName).AssignedFieldName
84 GetFieldName =
""
91 Dim sDocLang as String
92 Dim oSearchDesc as Object
93 Dim oFoundAll as Object
95 Dim sFoundContent as String
96 Dim sFoundString as String
97 Dim sDBField as String
99 Dim oDBAccess as Object
100 Dim oAddressDialog as Object
101 Dim oAddressPilot as Object
102 Dim oFields as Object
103 Dim oDocSettings as Object
104 Dim oContext as Object
105 Dim bDBvalid as Boolean
106 'On Local Error Goto GENERALERROR
109 bDBFields = DialogModel.Optmerge.State
'database or placeholder
110 TemplateDialog.EndExecute()
115 oDBAccess = GetRegistryKeyContent(
"org.openoffice.Office.DataAccess/AddressBook/
")
116 sAddressbook = oDBAccess.DataSourceName
119 oContext = createUnoService(
"com.sun.star.sdb.DatabaseContext
" )
121 If (not isNull(oContext)) Then
122 'Is the previously assigned address data source still valid?
123 bDBvalid = oContext.hasByName(sAddressbook)
126 If (bDBvalid = false) Then
127 oAddressPilot = createUnoService(
"com.sun.star.ui.dialogs.AddressBookSourcePilot
")
128 oAddressPilot.execute
130 oDBAccess = GetRegistryKeyContent(
"org.openoffice.Office.DataAccess/AddressBook/
")
131 sAddressbook = oDBAccess.DataSourceName
132 If sAddressbook =
"" Then
133 MsgBox(GetResText(
1301))
137 oFields = oDBAccess.GetByName(
"Fields
")
138 Table = oDBAccess.GetByName(
"Command
")
141 ParaBreak = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
142 oDocument = ThisComponent
144 'set the address db as current db at the document
145 oDocSettings = oDocument.createInstance(
"com.sun.star.document.Settings
")
146 oDocSettings.CurrentDatabaseDataSource = sAddressbook
147 oDocSettings.CurrentDatabaseCommand = Table
148 oDocSettings.CurrentDatabaseCommandType =
0
150 oBookmarks = oDocument.Bookmarks
151 oText = oDocument.Text
153 oSearchDesc = oDocument.createsearchDescriptor()
154 oSearchDesc.SearchRegularExpression = True
155 oSearchDesc.SearchWords = True
156 oSearchDesc.SearchString =
"<[^
>]+
>"
157 oFoundall = oDocument.FindAll(oSearchDesc)
159 'Loop over the foundings
160 For i = oFoundAll.Count -
1 To
0 Step -
1
161 oFound = oFoundAll.GetByIndex(i)
162 sFoundString = oFound.String
163 'Extract the string inside the brackets
164 sFoundContent = FindPartString(sFoundString,
"<",
">",
1)
165 sFoundContent = LTrim(sFoundContent)
166 ' Define the Cursor and place it on the founding
167 oBookmarkCursor = oFound.Text.CreateTextCursorbyRange(oFound)
168 oBookText = oFound.Text
170 sDBField = GetFieldname(oFields, sFoundContent)
171 If sDBField
<> "" Then
172 InsertDBField(sAddressbook, Table, sDBField)
174 InsertPlaceholder(sFoundContent)
177 InsertPlaceholder(sFoundContent)
181 'Open the DB beamer with the right DB
184 Dim aURL as new com.sun.star.util.URL
185 aURL.complete =
".component:DB/DataSourceBrowser
"
186 oTransformer = createUnoService(
"com.sun.star.util.URLTransformer
")
187 oTransformer.parseStrict(aURL)
188 oDisp = oDocument.getCurrentController.getFrame.queryDispatch(aURL,
"_beamer
", com.sun.star.frame.FrameSearchFlag.CHILDREN + com.sun.star.frame.FrameSearchFlag.CREATE)
189 Dim aArgs(
3) as new com.sun.star.beans.PropertyValue
190 aArgs(
1).Name =
"DataSourceName
"
191 aArgs(
1).Value = sAddressbook
192 aArgs(
2).Name =
"CommandType
"
193 aArgs(
2).Value = com.sun.star.sdb.CommandType.TABLE
194 aArgs(
3).Name =
"Command
"
195 aArgs(
3).Value = Table
196 oDisp.dispatch(aURL, aArgs())
200 If Err
<> 0 Then
201 Msgbox(msgError$,
16, GetProductName())
209 Sub InsertDBField(sDBName as String, sTableName as String, sColName as String)
210 Dim oFieldMaster, oField as Object
211 If sColname
<> "" Then
212 oFieldMaster = oDocument.createInstance(
"com.sun.star.text.FieldMaster.Database
")
213 oField = oDocument.createInstance(
"com.sun.star.text.TextField.Database
")
214 oFieldMaster.DataBaseName = sDBName
215 oFieldMaster.DataBaseName = sDBName
216 oFieldMaster.DataTableName = sTableName
217 oFieldMaster.DataColumnName = sColName
218 oField.AttachTextfieldmaster (oFieldMaster)
219 oBookText.InsertTextContent(oBookMarkCursor, oField, True)
220 oField.Content =
"<" & sColName
& ">"
225 Sub InsertPlaceholder(sColName as String)
226 Dim oFieldMaster as Object
227 Dim bCorrectField as Boolean
228 If sColname
<> "" Then
230 oFieldMaster = oDocument.createInstance(
"com.sun.star.text.TextField.JumpEdit
")
232 Case
"Company
"
233 oFieldMaster.PlaceHolder = getResText(
1350+
1)
234 Case
"Department
"
235 oFieldMaster.PlaceHolder = getResText(
1350+
2)
236 Case
"FirstName
"
237 oFieldMaster.PlaceHolder = getResText(
1350+
3)
238 Case
"LastName
"
239 oFieldMaster.PlaceHolder = getResText(
1350+
4)
240 Case
"Street
"
241 oFieldMaster.PlaceHolder = getResText(
1350+
5)
242 Case
"Country
"
243 oFieldMaster.PlaceHolder = getResText(
1350+
6)
245 oFieldMaster.PlaceHolder = getResText(
1350+
7)
246 Case
"City
"
247 oFieldMaster.PlaceHolder = getResText(
1350+
8)
248 Case
"Title
"
249 oFieldMaster.PlaceHolder = getResText(
1350+
9)
250 Case
"Position
"
251 oFieldMaster.PlaceHolder = getResText(
1350+
10)
252 Case
"AddrForm
"
253 oFieldMaster.PlaceHolder = getResText(
1350+
11)
254 Case
"Code
"
255 oFieldMaster.PlaceHolder = getResText(
1350+
12)
256 Case
"AddrFormMail
"
257 oFieldMaster.PlaceHolder = getResText(
1350+
13)
258 Case
"PhonePriv
"
259 oFieldMaster.PlaceHolder = getResText(
1350+
14)
260 Case
"PhoneComp
"
261 oFieldMaster.PlaceHolder = getResText(
1350+
15)
263 oFieldMaster.PlaceHolder = getResText(
1350+
16)
264 Case
"EMail
"
265 oFieldMaster.PlaceHolder = getResText(
1350+
17)
267 oFieldMaster.PlaceHolder = getResText(
1350+
18)
268 Case
"Note
"
269 oFieldMaster.PlaceHolder = getResText(
1350+
19)
270 Case
"Altfield1
"
271 oFieldMaster.PlaceHolder = getResText(
1350+
20)
272 Case
"Altfield2
"
273 oFieldMaster.PlaceHolder = getResText(
1350+
21)
274 Case
"Altfield3
"
275 oFieldMaster.PlaceHolder = getResText(
1350+
22)
276 Case
"Altfield4
"
277 oFieldMaster.PlaceHolder = getResText(
1350+
23)
279 oFieldMaster.PlaceHolder = getResText(
1350+
24)
280 Case
"State
"
281 oFieldMaster.PlaceHolder = getResText(
1350+
25)
282 Case
"PhoneOffice
"
283 oFieldMaster.PlaceHolder = getResText(
1350+
26)
284 Case
"Pager
"
285 oFieldMaster.PlaceHolder = getResText(
1350+
27)
286 Case
"PhoneCell
"
287 oFieldMaster.PlaceHolder = getResText(
1350+
28)
288 Case
"PhoneOther
"
289 oFieldMaster.PlaceHolder = getResText(
1350+
29)
290 Case
"CalendarURL
"
291 oFieldMaster.PlaceHolder = getResText(
1350+
30)
292 Case
"InviteParticipant
"
293 oFieldMaster.PlaceHolder = getResText(
1350+
31)
295 bCorrectField = False
297 If bCorrectField Then
298 oFieldMaster.Hint = getResText(
1350)
299 oBookText.InsertTextContent(oBookMarkCursor, oFieldMaster, True)