tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / scriptforge / SF_Utils.xba
blob323978db2211b11023f9b867555cdd89103f5d5e
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Utils" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === Full documentation is available on https://help.libreoffice.org/ ===
6 REM =======================================================================================================================
8 Option Explicit
9 Option Private Module
11 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
12 &apos;&apos;&apos; SF_Utils
13 &apos;&apos;&apos; ========
14 &apos;&apos;&apos; FOR INTERNAL USE ONLY
15 &apos;&apos;&apos; Groups all private functions used by the official modules
16 &apos;&apos;&apos; Declares the Global variable _SF_
17 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
19 REM ===================================================================== GLOBALS
21 Global _SF_ As Variant &apos; SF_Root (Basic) object)
23 &apos;&apos;&apos; ScriptForge version
24 Const SF_Version = &quot;25.2&quot;
26 &apos;&apos;&apos; Standard symbolic names for VarTypes
27 &apos; V_EMPTY = 0
28 &apos; V_NULL = 1
29 &apos; V_INTEGER = 2
30 &apos; V_LONG = 3
31 &apos; V_SINGLE = 4
32 &apos; V_DOUBLE = 5
33 &apos; V_CURRENCY = 6
34 &apos; V_DATE = 7
35 &apos; V_STRING = 8
36 &apos;&apos;&apos; Additional symbolic names for VarTypes
37 Global Const V_OBJECT = 9
38 Global Const V_BOOLEAN = 11
39 Global Const V_VARIANT = 12
40 Global Const V_BYTE = 17
41 Global Const V_USHORT = 18
42 Global Const V_ULONG = 19
43 Global Const V_BIGINT = 35
44 Global Const V_DECIMAL = 37
45 Global Const V_ARRAY = 8192
46 &apos;&apos;&apos; Fictive VarTypes
47 Global Const V_NUMERIC = 99 &apos; Synonym of any numeric value [returned by _VarTypeExt()]
48 Global Const V_NOTHING = 101 &apos; Object categories [returned by _VarTypeObj()] Null object
49 Global Const V_UNOOBJECT = 102 &apos; Uno object or Uno structure
50 Global Const V_SFOBJECT = 103 &apos; ScriptForge object: has ObjectType and ServiceName properties
51 Global Const V_BASICOBJECT = 104 &apos; User Basic object
53 Type _ObjectDescriptor &apos; Returned by the _VarTypeObj() method
54 iVarType As Integer &apos; One of the V_NOTHING, V_xxxOBJECT constants
55 sObjectType As String &apos; Either &quot;&quot; or &quot;com.sun.star...&quot; or a ScriptForge object type (ex. &quot;SF_SESSION&quot; or &quot;DICTIONARY&quot;)
56 sServiceName As String &apos; Either &quot;&quot; or the service name of a ScriptForge object type (ex. &quot;ScriptForge.Exception&quot;-
57 End Type
59 REM ================================================================== EXCEPTIONS
61 Const MISSINGARGERROR = &quot;MISSINGARGERROR&quot; &apos; A mandatory argument is missing
62 Const ARGUMENTERROR = &quot;ARGUMENTERROR&quot; &apos; An argument does not pass the _Validate() validation
63 Const ARRAYERROR = &quot;ARRAYERROR&quot; &apos; An argument does not pass the _ValidateArray() validation
64 Const FILEERROR = &quot;FILEERROR&quot; &apos; An argument does not pass the _ValidateFile() validation
66 REM =========================================pvA==================== PRIVATE METHODS
68 REM -----------------------------------------------------------------------------
69 Public Function _CDateToIso(pvDate As Variant) As Variant
70 &apos;&apos;&apos; Returns a string representation of the given Basic date
71 &apos;&apos;&apos; Dates as strings are essential in property values, where Basic dates are evil
73 Dim sIsoDate As Variant &apos; Return value
75 If VarType(pvDate) = V_DATE Then
76 If Year(pvDate) &lt; 1900 Then &apos; Time only
77 sIsoDate = Right(&quot;0&quot; &amp; Hour(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Minute(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Second(pvDate), 2)
78 ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then &apos; Date only
79 sIsoDate = Year(pvDate) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Month(pvDate), 2) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Day(pvDate), 2)
80 Else
81 sIsoDate = Year(pvDate) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Month(pvDate), 2) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Day(pvDate), 2) _
82 &amp; &quot; &quot; &amp; Right(&quot;0&quot; &amp; Hour(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Minute(pvDate), 2) _
83 &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Second(pvDate), 2)
84 End If
85 Else
86 sIsoDate = pvDate
87 End If
89 _CDateToIso = sIsoDate
91 End Function &apos; ScriptForge.SF_Utils._CDateToIso
93 REM -----------------------------------------------------------------------------
94 Public Function _CDateToUnoDate(pvDate As Variant) As Variant
95 &apos;&apos;&apos; Returns a UNO com.sun.star.util.DateTime/Date/Time object depending on the given date
96 &apos;&apos;&apos; by using the appropriate CDateToUnoDateXxx builtin function
97 &apos;&apos;&apos; UNO dates are essential in property values, where Basic dates are evil
99 Dim vUnoDate As Variant &apos; Return value
101 If VarType(pvDate) = V_DATE Then
102 If Year(pvDate) &lt; 1900 Then
103 vUnoDate = CDateToUnoTime(pvDate)
104 ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then
105 vUnoDate = CDateToUnoDate(pvDate)
106 Else
107 vUnoDate = CDateToUnoDateTime(pvDate)
108 End If
109 Else
110 vUnoDate = pvDate
111 End If
113 _CDateToUnoDate = vUnoDate
115 End Function &apos; ScriptForge.SF_Utils._CDateToUnoDate
117 REM -----------------------------------------------------------------------------
118 Public Function _CPropertyValue(ByRef pvValue As Variant) As Variant
119 &apos;&apos;&apos; Set a value of a correct type in a com.sun.star.beans.PropertyValue
120 &apos;&apos;&apos; Date BASIC variables give error. Change them to UNO types
121 &apos;&apos;&apos; Empty arrays should be replaced by Null
123 Dim vValue As Variant &apos; Return value
125 If VarType(pvValue) = V_DATE Then
126 vValue = SF_Utils._CDateToUnoDate(pvValue)
127 ElseIf IsArray(pvValue) Then
128 If UBound(pvValue, 1) &lt; LBound(pvValue, 1) Then vValue = Null Else vValue = pvValue
129 Else
130 vValue = pvValue
131 End If
132 _CPropertyValue() = vValue
134 End Function &apos; ScriptForge.SF_Utils._CPropertyValue
136 REM -----------------------------------------------------------------------------
137 Public Function _CStrToDate(ByRef pvStr As String) As Date
138 &apos;&apos;&apos; Attempt to convert the input string to a Date variable with the CDate builtin function
139 &apos;&apos;&apos; If not successful, returns conventionally -1 (29/12/1899)
140 &apos;&apos;&apos; Date patterns: YYYY-MM-DD, HH:MM:DD and YYYY-MM-DD HH:MM:DD
142 Dim dDate As Date &apos; Return value
143 Const cstNoDate = -1
145 dDate = cstNoDate
146 Try:
147 On Local Error Resume Next
148 dDate = CDate(pvStr)
150 Finally:
151 _CStrToDate = dDate
152 Exit Function
153 End Function &apos; ScriptForge.SF_Utils._CStrToDate
155 REM -----------------------------------------------------------------------------
156 Public Function _EnterFunction(ByVal psSub As String, Optional ByVal psArgs As String) As Boolean
157 &apos;&apos;&apos; Called on top of each public function
158 &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
159 &apos;&apos;&apos; and to allow the explicit mention of the user call which caused an error
160 &apos;&apos;&apos; Args:
161 &apos;&apos;&apos; psSub = the called Sub/Function/Property, usually something like &quot;service.sub&quot;
162 &apos;&apos;&apos; Return: True when psSub is called from a user script
163 &apos;&apos;&apos; Used to bypass the validation of the arguments when unnecessary
165 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
166 If IsMissing(psArgs) Then psArgs = &quot;&quot;
167 With _SF_
168 If .StackLevel = 0 Then
169 .MainFunction = psSub
170 .MainFunctionArgs = psArgs
171 _EnterFunction = True
172 Else
173 _EnterFunction = False
174 End If
175 .StackLevel = .StackLevel + 1
176 If .DebugMode Then ._AddToConsole(&quot;==&gt; &quot; &amp; psSub &amp; &quot;(&quot; &amp; .StackLevel &amp; &quot;)&quot;)
177 End With
179 End Function &apos; ScriptForge.SF_Utils._EnterFunction
181 REM -----------------------------------------------------------------------------
182 Public Function _ErrorHandling(Optional ByVal pbErrorHandler As Boolean) As Boolean
183 &apos;&apos;&apos; Error handling is normally ON and can be set OFF for debugging purposes
184 &apos;&apos;&apos; Each user visible routine starts with a call to this function to enable/disable
185 &apos;&apos;&apos; standard handling of internal errors
186 &apos;&apos;&apos; Args:
187 &apos;&apos;&apos; pbErrorHandler = if present, set its value
188 &apos;&apos;&apos; Return: the current value of the error handler
190 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
191 If Not IsMissing(pbErrorHandler) Then _SF_.ErrorHandler = pbErrorHandler
192 _ErrorHandling = _SF_.ErrorHandler
194 End Function &apos; ScriptForge.SF_Utils._ErrorHandling
196 REM -----------------------------------------------------------------------------
197 Public Sub _ExitFunction(ByVal psSub As String)
198 &apos;&apos;&apos; Called in the Finally block of each public function
199 &apos;&apos;&apos; Manage ScriptForge internal aborts
200 &apos;&apos;&apos; Resets MainFunction (root) when exiting the method called by a user script
201 &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
202 &apos;&apos;&apos; Args:
203 &apos;&apos;&apos; psSub = the called Sub/Function/Property, usually something like &quot;service.sub&quot;
205 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; Useful only when current module has been recompiled
206 With _SF_
207 If Err &gt; 0 Then
208 SF_Exception.RaiseAbort(psSub)
209 End If
210 If .StackLevel = 1 Then
211 .MainFunction = &quot;&quot;
212 .MainFunctionArgs = &quot;&quot;
213 End If
214 If .DebugMode Then ._AddToConsole(&quot;&lt;== &quot; &amp; psSub &amp; &quot;(&quot; &amp; .StackLevel &amp; &quot;)&quot;)
215 If .StackLevel &gt; 0 Then .StackLevel = .StackLevel - 1
216 End With
218 End Sub &apos; ScriptForge.SF_Utils._ExitFunction
220 REM -----------------------------------------------------------------------------
221 Public Sub _ExportScriptForgePOTFile(ByVal FileName As String)
222 &apos;&apos;&apos; Export the ScriptForge POT file related to its own user interface
223 &apos;&apos;&apos; Should be called only before issuing new ScriptForge releases only
224 &apos;&apos;&apos; Args:
225 &apos;&apos;&apos; FileName: the resulting file. If it exists, is overwritten without warning
227 Dim sHeader As String &apos; The specific header to insert
229 sHeader = &quot;&quot; _
230 &amp; &quot;*********************************************************************\n&quot; _
231 &amp; &quot;*** The ScriptForge library and its associated libraries ***\n&quot; _
232 &amp; &quot;*** are part of the LibreOffice project. ***\n&quot; _
233 &amp; &quot;*********************************************************************\n&quot; _
234 &amp; &quot;\n&quot; _
235 &amp; &quot;ScriptForge Release &quot; &amp; SF_Version &amp; &quot;\n&quot; _
236 &amp; &quot;-----------------------&quot;
238 Try:
239 With _SF_
240 If Not IsNull(.LocalizedInterface) Then .LocalizedInterface.Dispose()
241 ._LoadLocalizedInterface(psMode := &quot;ADDTEXT&quot;) &apos; Force reload of labels from the code
242 .LocalizedInterface.ExportToPOTFile(FileName, Header := sHeader)
243 End With
245 Finally:
246 Exit Sub
247 End Sub &apos; ScriptForge.SF_Utils._ExportScriptForgePOTFile
249 REM -----------------------------------------------------------------------------
250 Public Function _GetPropertyValue(ByRef pvArgs As Variant, ByVal psName As String) As Variant
251 &apos;&apos;&apos; Returns the Value corresponding to the given name
252 &apos;&apos;&apos; Args
253 &apos;&apos;&apos; pvArgs: a zero_based array of PropertyValues
254 &apos;&apos;&apos; psName: the comparison is not case-sensitive
255 &apos;&apos;&apos; Returns:
256 &apos;&apos;&apos; Zero-length string if not found
258 Dim vValue As Variant &apos; Return value
259 Dim i As Long
261 vValue = &quot;&quot;
262 If IsArray(pvArgs) Then
263 For i = LBound(pvArgs) To UBound(pvArgs)
264 If UCase(psName) = UCase(pvArgs(i).Name) Then
265 vValue = pvArgs(i).Value
266 Exit For
267 End If
268 Next i
269 End If
270 _GetPropertyValue = vValue
272 End Function &apos; ScriptForge.SF_Utils._GetPropertyValue
274 REM -----------------------------------------------------------------------------
275 Public Function _GetRegistryKeyContent(ByVal psKeyName as string _
276 , Optional pbForUpdate as Boolean _
277 ) As Variant
278 &apos;&apos;&apos; Implement a ConfigurationProvider service
279 &apos;&apos;&apos; Derived from the Tools library
280 &apos;&apos;&apos; Args:
281 &apos;&apos;&apos; psKeyName: the name of the node in the configuration tree
282 &apos;&apos;&apos; pbForUpdate: default = False
284 Dim oConfigProvider as Object &apos; com.sun.star.configuration.ConfigurationProvider
285 Dim vNodePath(0) as New com.sun.star.beans.PropertyValue
286 Dim sConfig As String &apos; One of next 2 constants
287 Const cstConfig = &quot;com.sun.star.configuration.ConfigurationAccess&quot;
288 Const cstConfigUpdate = &quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;
290 Set oConfigProvider = _GetUNOService(&quot;ConfigurationProvider&quot;)
291 vNodePath(0).Name = &quot;nodepath&quot;
292 vNodePath(0).Value = psKeyName
294 If IsMissing(pbForUpdate) Then pbForUpdate = False
295 If pbForUpdate Then sConfig = cstConfigUpdate Else sConfig = cstConfig
297 Set _GetRegistryKeyContent = oConfigProvider.createInstanceWithArguments(sConfig, vNodePath())
299 End Function &apos; ScriptForge.SF_Utils._GetRegistryKeyContent
301 REM -----------------------------------------------------------------------------
302 Private Function _GetSetting(ByVal psPreference As String, psProperty As String) As Variant
303 &apos;&apos;&apos; Find in the configuration a specific setting based on its location in the
304 &apos;&apos;&apos; settings registry
306 Dim oConfigProvider As Object &apos; com.sun.star.configuration.ConfigurationProvider
307 Dim vNodePath As Variant &apos; Array of com.sun.star.beans.PropertyValue
309 &apos; Derived from the Tools library
310 Set oConfigProvider = createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
311 vNodePath = Array(SF_Utils._MakePropertyValue(&quot;nodepath&quot;, psPreference))
313 _GetSetting = oConfigProvider.createInstanceWithArguments( _
314 &quot;com.sun.star.configuration.ConfigurationAccess&quot;, vNodePath()).getByName(psProperty)
316 End Function &apos; ScriptForge.SF_Utils._GetSetting
318 REM -----------------------------------------------------------------------------
319 Public Function _GetUNOService(ByVal psService As String _
320 , Optional ByVal pvArg As Variant _
321 ) As Object
322 &apos;&apos;&apos; Create a UNO service
323 &apos;&apos;&apos; Each service is called only once
324 &apos;&apos;&apos; Args:
325 &apos;&apos;&apos; psService: shortcut to service
326 &apos;&apos;&apos; pvArg: some services might require an argument
328 Dim sLocale As String &apos; fr-BE f.i.
329 Dim oDefaultContext As Object
331 Set _GetUNOService = Nothing
332 With _SF_
333 Select Case psService
334 Case &quot;BrowseNodeFactory&quot;
335 Set oDefaultContext = GetDefaultContext()
336 If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName(&quot;/singletons/com.sun.star.script.browse.theBrowseNodeFactory&quot;)
337 Case &quot;CalendarImpl&quot;
338 If IsEmpty(.CalendarImpl) Or IsNull(.CalendarImpl) Then
339 Set .CalendarImpl = CreateUnoService(&quot;com.sun.star.i18n.CalendarImpl&quot;)
340 End If
341 Set _GetUNOService = .CalendarImpl
342 Case &quot;CharacterClass&quot;
343 If IsEmpty(.CharacterClass) Or IsNull(.CharacterClass) Then
344 Set .CharacterClass = CreateUnoService(&quot;com.sun.star.i18n.CharacterClassification&quot;)
345 End If
346 Set _GetUNOService = .CharacterClass
347 Case &quot;ConfigurationProvider&quot;
348 If IsEmpty(.ConfigurationProvider) Or IsNull(.ConfigurationProvider) Then
349 Set .ConfigurationProvider = CreateUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
350 End If
351 Set _GetUNOService = .ConfigurationProvider
352 Case &quot;CoreReflection&quot;
353 If IsEmpty(.CoreReflection) Or IsNull(.CoreReflection) Then
354 Set .CoreReflection = CreateUnoService(&quot;com.sun.star.reflection.CoreReflection&quot;)
355 End If
356 Set _GetUNOService = .CoreReflection
357 Case &quot;DatabaseContext&quot;
358 If IsEmpty(.DatabaseContext) Or IsNull(.DatabaseContext) Then
359 Set .DatabaseContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
360 End If
361 Set _GetUNOService = .DatabaseContext
362 Case &quot;DispatchHelper&quot;
363 If IsEmpty(.DispatchHelper) Or IsNull(.DispatchHelper) Then
364 Set .DispatchHelper = CreateUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
365 End If
366 Set _GetUNOService = .DispatchHelper
367 Case &quot;FileAccess&quot;
368 If IsEmpty(.FileAccess) Or IsNull(.FileAccess) Then
369 Set .FileAccess = CreateUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
370 End If
371 Set _GetUNOService = .FileAccess
372 Case &quot;FilePicker&quot;
373 Set .FilePicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;) &apos; Do not reuse an existing FilePicker: TDF#154462
374 Set _GetUNOService = .FilePicker
375 Case &quot;FilterFactory&quot;
376 If IsEmpty(.FilterFactory) Or IsNull(.FilterFactory) Then
377 Set .FilterFactory = CreateUnoService(&quot;com.sun.star.document.FilterFactory&quot;)
378 End If
379 Set _GetUNOService = .FilterFactory
380 Case &quot;FolderPicker&quot;
381 If IsEmpty(.FolderPicker) Or IsNull(.FolderPicker) Then
382 Set .FolderPicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
383 End If
384 Set _GetUNOService = .FolderPicker
385 Case &quot;FormatLocale&quot;
386 If IsEmpty(.FormatLocale) Or IsNull(.FormatLocale) Then
387 .FormatLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
388 &apos; 1st and 2nd chance
389 sLocale = SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, &quot;ooSetupSystemLocale&quot;)
390 If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;UILocale&quot;)
391 .FormatLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
392 .FormatLocale.Country = Right(sLocale, 2)
393 End If
394 Set _GetUNOService = .FormatLocale
395 Case &quot;FunctionAccess&quot;
396 If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then
397 Set .FunctionAccess = CreateUnoService(&quot;com.sun.star.sheet.FunctionAccess&quot;)
398 End If
399 Set _GetUNOService = .FunctionAccess
400 Case &quot;GraphicExportFilter&quot;
401 If IsEmpty(.GraphicExportFilter) Or IsNull(.GraphicExportFilter) Then
402 Set .GraphicExportFilter = CreateUnoService(&quot;com.sun.star.drawing.GraphicExportFilter&quot;)
403 End If
404 Set _GetUNOService = .GraphicExportFilter
405 Case &quot;Introspection&quot;
406 If IsEmpty(.Introspection) Or IsNull(.Introspection) Then
407 Set .Introspection = CreateUnoService(&quot;com.sun.star.beans.Introspection&quot;)
408 End If
409 Set _GetUNOService = .Introspection
410 Case &quot;LocaleData&quot;
411 If IsEmpty(.LocaleData) Or IsNull(.LocaleData) Then
412 Set .LocaleData = CreateUnoService(&quot;com.sun.star.i18n.LocaleData&quot;)
413 End If
414 Set _GetUNOService = .LocaleData
415 Case &quot;MacroExpander&quot;
416 Set oDefaultContext = GetDefaultContext()
417 If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName(&quot;/singletons/com.sun.star.util.theMacroExpander&quot;)
418 Case &quot;MailService&quot;
419 If IsEmpty(.MailService) Or IsNull(.MailService) Then
420 If GetGuiType = 1 Then &apos; Windows
421 Set .MailService = CreateUnoService(&quot;com.sun.star.system.SimpleSystemMail&quot;)
422 Else
423 Set .MailService = CreateUnoService(&quot;com.sun.star.system.SimpleCommandMail&quot;)
424 End If
425 End If
426 Set _GetUNOService = .MailService
427 Case &quot;ModuleUIConfigurationManagerSupplier&quot;
428 If IsEmpty(.ModuleUIConfigurationManagerSupplier) Or IsNull(.ModuleUIConfigurationManagerSupplier) Then
429 Set .ModuleUIConfigurationManagerSupplier = CreateUnoService(&quot;com.sun.star.ui.ModuleUIConfigurationManagerSupplier&quot;)
430 End If
431 Set _GetUNOService = .ModuleUIConfigurationManagerSupplier
432 Case &quot;Number2Text&quot;
433 If IsEmpty(.Number2Text) Or IsNull(.Number2Text) Then
434 Set .Number2Text = CreateUnoService(&quot;com.sun.star.linguistic2.NumberText&quot;)
435 End If
436 Set _GetUNOService = .Number2Text
437 Case &quot;OfficeLocale&quot;
438 If IsEmpty(.OfficeLocale) Or IsNull(.OfficeLocale) Then
439 .OfficeLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
440 &apos; 1st and 2nd chance
441 sLocale = SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, &quot;ooLocale&quot;)
442 If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;UILocale&quot;)
443 .OfficeLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
444 .OfficeLocale.Country = Right(sLocale, 2)
445 End If
446 Set _GetUNOService = .OfficeLocale
447 Case &quot;PackageInformationProvider&quot;
448 If IsEmpty(.PackageProvider) Or IsNull(.PackageProvider) Then
449 Set .PackageProvider = GetDefaultContext.getByName(&quot;/singletons/com.sun.star.deployment.PackageInformationProvider&quot;)
450 End If
451 Set _GetUNOService = .PackageProvider
452 Case &quot;PathSettings&quot;
453 If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then
454 Set .PathSettings = CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)
455 End If
456 Set _GetUNOService = .PathSettings
457 Case &quot;PathSubstitution&quot;
458 If IsEmpty(.PathSubstitution) Or IsNull(.PathSubstitution) Then
459 Set .PathSubstitution = CreateUnoService(&quot;com.sun.star.util.PathSubstitution&quot;)
460 End If
461 Set _GetUNOService = .PathSubstitution
462 Case &quot;PrinterServer&quot;
463 If IsEmpty(.PrinterServer) Or IsNull(.PrinterServer) Then
464 Set .PrinterServer = CreateUnoService(&quot;com.sun.star.awt.PrinterServer&quot;)
465 End If
466 Set _GetUNOService = .PrinterServer
467 Case &quot;ScriptProvider&quot;
468 If IsMissing(pvArg) Then pvArg = SF_Session.SCRIPTISAPPLICATION
469 Select Case LCase(pvArg)
470 Case SF_Session.SCRIPTISEMBEDDED &apos; Document
471 If Not IsNull(ThisComponent) Then Set _GetUNOService = ThisComponent.getScriptProvider()
472 Case Else
473 If IsEmpty(.ScriptProvider) Or IsNull(.ScriptProvider) Then
474 Set .ScriptProvider = _
475 CreateUnoService(&quot;com.sun.star.script.provider.MasterScriptProviderFactory&quot;).createScriptProvider(&quot;&quot;)
476 End If
477 Set _GetUNOService = .ScriptProvider
478 End Select
479 Case &quot;SearchOptions&quot;
480 If IsEmpty(.SearchOptions) Or IsNull(.SearchOptions) Then
481 Set .SearchOptions = New com.sun.star.util.SearchOptions
482 With .SearchOptions
483 .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
484 .searchFlag = 0
485 End With
486 End If
487 Set _GetUNOService = .SearchOptions
488 Case &quot;SystemLocale&quot;, &quot;Locale&quot;
489 If IsEmpty(.SystemLocale) Or IsNull(.SystemLocale) Then
490 .SystemLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
491 sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;SystemLocale&quot;)
492 .SystemLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
493 .SystemLocale.Country = Right(sLocale, 2)
494 End If
495 Set _GetUNOService = .SystemLocale
496 Case &quot;SystemShellExecute&quot;
497 If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then
498 Set .SystemShellExecute = CreateUnoService(&quot;com.sun.star.system.SystemShellExecute&quot;)
499 End If
500 Set _GetUNOService = .SystemShellExecute
501 Case &quot;TextSearch&quot;
502 If IsEmpty(.TextSearch) Or IsNull(.TextSearch) Then
503 Set .TextSearch = CreateUnoService(&quot;com.sun.star.util.TextSearch&quot;)
504 End If
505 Set _GetUNOService = .TextSearch
506 Case &quot;Toolkit&quot;
507 If IsEmpty(.Toolkit) Or IsNull(.Toolkit) Then
508 Set .Toolkit = CreateUnoService(&quot;com.sun.star.awt.Toolkit&quot;)
509 End If
510 Set _GetUNOService = .Toolkit
511 Case &quot;TransientDocumentFactory&quot;
512 If IsEmpty(.TransientDocument) Or IsNull(.TransientDocument) Then
513 Set .TransientDocument = CreateUnoService(&quot;com.sun.star.frame.TransientDocumentsDocumentContentFactory&quot;)
514 End If
515 Set _GetUNOService = .TransientDocument
516 Case &quot;URLTransformer&quot;
517 If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then
518 Set .URLTransformer = CreateUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
519 End If
520 Set _GetUNOService = .URLTransformer
521 Case Else
522 End Select
523 End With
525 End Function &apos; ScriptForge.SF_Utils._GetUNOService
527 REM -----------------------------------------------------------------------------
528 Public Sub _InitializeRoot(Optional ByVal pbForce As Boolean)
529 &apos;&apos;&apos; Initialize _SF_ as SF_Root basic object
530 &apos;&apos;&apos; Args:
531 &apos;&apos;&apos; pbForce = True forces the reinit (default = False)
533 If IsMissing(pbForce) Then pbForce = False
534 If pbForce Then Set _SF_ = Nothing
535 If IsEmpty(_SF_) Or IsNull(_SF_) Then
536 Set _SF_ = New SF_Root
537 Set _SF_.[Me] = _SF_
538 End If
540 End Sub &apos; ScriptForge.SF_Utils._InitializeRoot
542 REM -----------------------------------------------------------------------------
543 Public Function _MakePropertyValue(ByVal psName As String _
544 , ByRef pvValue As Variant _
545 ) As com.sun.star.beans.PropertyValue
546 &apos;&apos;&apos; Create and return a new com.sun.star.beans.PropertyValue
548 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
550 With oPropertyValue
551 .Name = psName
552 .Value = SF_Utils._CPropertyValue(pvValue)
553 End With
554 _MakePropertyValue() = oPropertyValue
556 End Function &apos; ScriptForge.SF_Utils._MakePropertyValue
558 REM -----------------------------------------------------------------------------
559 Public Function _Repr(ByVal pvArg As Variant, Optional ByVal plMax As Long) As String
560 &apos;&apos;&apos; Convert pvArg into a readable string (truncated if length &gt; plMax)
561 &apos;&apos;&apos; Args
562 &apos;&apos;&apos; pvArg: may be of any type
563 &apos;&apos;&apos; plMax: maximum length of the resulting string (default = 32K)
565 Dim sArg As String &apos; Return value
566 Dim oObject As Object &apos; Alias of argument to avoid &quot;Object variable not set&quot;
567 Dim oObjectDesc As Object &apos; Object descriptor
568 Dim sLength As String &apos; String length as a string
569 Dim i As Long
570 Const cstBasicObject = &quot;com.sun.star.script.NativeObjectWrapper&quot;
572 Const cstMaxLength = 2^15 - 1 &apos; 32767
573 Const cstByteLength = 25
574 Const cstEtc = &quot; … &quot;
576 If IsMissing(plMax) Then plMax = cstMaxLength
577 If plMax = 0 Then plMax = cstMaxLength
578 If IsArray(pvArg) Then
579 sArg = SF_Array._Repr(pvArg)
580 Else
581 Select Case VarType(pvArg)
582 Case V_EMPTY : sArg = &quot;[EMPTY]&quot;
583 Case V_NULL : sArg = &quot;[NULL]&quot;
584 Case V_OBJECT
585 Set oObjectDesc = SF_Utils._VarTypeObj(pvArg)
586 With oObjectDesc
587 Select Case .iVarType
588 Case V_NOTHING : sArg = &quot;[NOTHING]&quot;
589 Case V_OBJECT, V_BASICOBJECT
590 sArg = &quot;[OBJECT]&quot;
591 Case V_UNOOBJECT : sArg = &quot;[&quot; &amp; .sObjectType &amp; &quot;]&quot;
592 Case V_SFOBJECT
593 If Left(.sObjectType, 3) = &quot;SF_&quot; Then &apos; Standard module
594 sArg = &quot;[&quot; &amp; .sObjectType &amp; &quot;]&quot;
595 Else &apos; Class module must have a _Repr() method
596 Set oObject = pvArg
597 sArg = oObject._Repr()
598 End If
599 End Select
600 End With
601 Case V_VARIANT : sArg = &quot;[VARIANT]&quot;
602 Case V_STRING
603 sArg = SF_String._Repr(pvArg)
604 Case V_BOOLEAN : sArg = Iif(pvArg, &quot;[TRUE]&quot;, &quot;[FALSE]&quot;)
605 Case V_BYTE : sArg = Right(&quot;00&quot; &amp; Hex(pvArg), 2)
606 Case V_SINGLE, V_DOUBLE, V_CURRENCY
607 sArg = Format(pvArg)
608 If InStr(1, sArg, &quot;E&quot;, 1) = 0 Then sArg = Format(pvArg, &quot;##0.0##&quot;)
609 sArg = Replace(sArg, &quot;,&quot;, &quot;.&quot;) &apos;Force decimal point
610 Case V_BIGINT : sArg = CStr(CLng(pvArg))
611 Case V_DATE : sArg = _CDateToIso(pvArg)
612 Case Else : sArg = CStr(pvArg)
613 End Select
614 End If
615 If Len(sArg) &gt; plMax Then
616 sLength = &quot;(&quot; &amp; Len(sArg) &amp; &quot;)&quot;
617 sArg = Left(sArg, plMax - Len(cstEtc) - Len(slength)) &amp; cstEtc &amp; sLength
618 End If
619 _Repr = sArg
621 End Function &apos; ScriptForge.SF_Utils._Repr
623 REM -----------------------------------------------------------------------------
624 Private Function _ReprValues(Optional ByVal pvArgs As Variant _
625 , Optional ByVal plMax As Long _
626 ) As String
627 &apos;&apos;&apos; Convert an array of values to a comma-separated list of readable strings
629 Dim sValues As String &apos; Return value
630 Dim sValue As String &apos; A single value
631 Dim vValue As Variant &apos; A single item in the argument
632 Dim i As Long &apos; Items counter
633 Const cstMax = 20 &apos; Maximum length of single string
634 Const cstContinue = &quot;…&quot; &apos; Unicode continuation char U+2026
636 _ReprValues = &quot;&quot;
637 If IsMissing(pvArgs) Then Exit Function
638 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
639 sValues = &quot;&quot;
640 For i = 0 To UBound(pvArgs)
641 vValue = pvArgs(i)
642 If i &lt; plMax Then
643 If VarType(vValue) = V_STRING Then sValue = &quot;&quot;&quot;&quot; &amp; vValue &amp; &quot;&quot;&quot;&quot; Else sValue = SF_Utils._Repr(vValue, cstMax)
644 If Len(sValues) = 0 Then sValues = sValue Else sValues = sValues &amp; &quot;, &quot; &amp; sValue
645 ElseIf i &lt; UBound(pvArgs) Then
646 sValues = sValues &amp; &quot;, &quot; &amp; cstContinue
647 Exit For
648 End If
649 Next i
650 _ReprValues = sValues
652 End Function &apos; ScriptForge.SF_Utils._ReprValues
654 REM -----------------------------------------------------------------------------
655 Public Function _SetPropertyValue(ByVal pvPropertyValue As Variant _
656 , ByVal psName As String _
657 , ByRef pvValue As Variant _
658 ) As Variant
659 &apos;&apos;&apos; Return the 1st argument (passed by reference), which is an array of property values
660 &apos;&apos;&apos; If the property psName exists, update it with pvValue, otherwise create it on top of the returned array
662 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
663 Dim lIndex As Long &apos; Found entry
664 Dim vValue As Variant &apos; Alias of pvValue
665 Dim vProperties As Variant &apos; Alias of pvPropertyValue
666 Dim i As Long
668 lIndex = -1
669 vProperties = pvPropertyValue
670 For i = 0 To UBound(vProperties)
671 If vProperties(i).Name = psName Then
672 lIndex = i
673 Exit For
674 End If
675 Next i
676 If lIndex &lt; 0 Then &apos; Not found
677 lIndex = UBound(vProperties) + 1
678 ReDim Preserve vProperties(0 To lIndex)
679 Set oPropertyValue = SF_Utils._MakePropertyValue(psName, pvValue)
680 vProperties(lIndex) = oPropertyValue
681 vProperties = vProperties
682 Else &apos; psName exists already in array of property values
683 vProperties(lIndex).Value = SF_Utils._CPropertyValue(pvValue)
684 End If
686 _SetPropertyValue = vProperties
688 End Function &apos; ScriptForge.SF_Utils._SetPropertyValue
690 REM -----------------------------------------------------------------------------
691 Private Function _TypeNames(Optional ByVal pvArgs As Variant) As String
692 &apos;&apos;&apos; Converts the array of VarTypes to a comma-separated list of TypeNames
694 Dim sTypes As String &apos; Return value
695 Dim sType As String &apos; A single type
696 Dim iType As Integer &apos; A single item of the argument
698 _TypeNames = &quot;&quot;
699 If IsMissing(pvArgs) Then Exit Function
700 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
701 sTypes = &quot;&quot;
702 For Each iType In pvArgs
703 Select Case iType
704 Case V_EMPTY : sType = &quot;Empty&quot;
705 Case V_NULL : sType = &quot;Null&quot;
706 Case V_INTEGER : sType = &quot;Integer&quot;
707 Case V_LONG : sType = &quot;Long&quot;
708 Case V_SINGLE : sType = &quot;Single&quot;
709 Case V_DOUBLE : sType = &quot;Double&quot;
710 Case V_CURRENCY : sType = &quot;Currency&quot;
711 Case V_DATE : sType = &quot;Date&quot;
712 Case V_STRING : sType = &quot;String&quot;
713 Case V_OBJECT : sType = &quot;Object&quot;
714 Case V_BOOLEAN : sType = &quot;Boolean&quot;
715 Case V_VARIANT : sType = &quot;Variant&quot;
716 Case V_DECIMAL : sType = &quot;Decimal&quot;
717 Case &gt;= V_ARRAY : sType = &quot;Array&quot;
718 Case V_NUMERIC : sType = &quot;Numeric&quot;
719 End Select
720 If Len(sTypes) = 0 Then sTypes = sType Else sTypes = sTypes &amp; &quot;, &quot; &amp; sType
721 Next iType
722 _TypeNames = sTypes
724 End Function &apos; ScriptForge.SF_Utils._TypeNames
726 REM -----------------------------------------------------------------------------
727 Public Function _Validate(Optional ByRef pvArgument As Variant _
728 , ByVal psName As String _
729 , Optional ByVal pvTypes As Variant _
730 , Optional ByVal pvValues As Variant _
731 , Optional ByVal pvCaseSensitive As Variant _
732 , Optional ByVal pvObjectType As Variant _
733 ) As Boolean
734 &apos;&apos;&apos; Validate the arguments set by user scripts
735 &apos;&apos;&apos; The arguments of the function define the validation rules
736 &apos;&apos;&apos; This function ignores arrays. Use _ValidateArray instead
737 &apos;&apos;&apos; Args:
738 &apos;&apos;&apos; pvArgument: the argument to (in)validate
739 &apos;&apos;&apos; psName: the documented name of the argument (can be inserted in an error message)
740 &apos;&apos;&apos; pvTypes: array of allowed VarTypes
741 &apos;&apos;&apos; pvValues: array of allowed values
742 &apos;&apos;&apos; pvCaseSensitive: when True the comparison between strings is done case-sensitively
743 &apos;&apos;&apos; pvObjectType: mandatory Basic class
744 &apos;&apos;&apos; Return: True if validation OK
745 &apos;&apos;&apos; Otherwise an error is raised
746 &apos;&apos;&apos; Exceptions:
747 &apos;&apos;&apos; ARGUMENTERROR
749 Dim iVarType As Integer &apos; Extended VarType of argument
750 Dim bValid As Boolean &apos; Returned value
751 Dim oObjectDescriptor As Object &apos; _ObjectDescriptor type
752 Const cstMaxLength = 256 &apos; Maximum length of readable value
753 Const cstMaxValues = 10 &apos; Maximum number of allowed items to list in an error message
755 &apos; To avoid useless recursions, keep main function, only increase stack depth
756 _SF_.StackLevel = _SF_.StackLevel + 1
757 On Local Error GoTo Finally &apos; Do never interrupt
759 Try:
760 bValid = True
761 If IsMissing(pvArgument) Then GoTo CatchMissing
762 If IsMissing(pvCaseSensitive) Or IsEmpty(pvCaseSensitive) Then pvCaseSensitive = False
763 If IsMissing(pvObjectType) Or IsEmpty(pvObjectType) Then pvObjectType = &quot;&quot;
764 iVarType = SF_Utils._VarTypeExt(pvArgument)
766 &apos; Arrays NEVER pass validation
767 If iVarType &gt;= V_ARRAY Then
768 bValid = False
769 Else
770 &apos; Check existence of argument
771 bValid = iVarType &lt;&gt; V_NULL And iVarType &lt;&gt; V_EMPTY
772 &apos; Check if argument&apos;s VarType is valid
773 If bValid And Not IsMissing(pvTypes) Then
774 If Not IsArray(pvTypes) Then bValid = ( pvTypes = iVarType ) Else bValid = SF_Array.Contains(pvTypes, iVarType)
775 End If
776 &apos; Check if argument&apos;s value is valid
777 If bValid And Not IsMissing(pvValues) Then
778 If Not IsArray(pvValues) Then pvValues = Array(pvValues)
779 bValid = SF_Array.Contains(pvValues, pvArgument, CaseSensitive := pvCaseSensitive)
780 End If
781 &apos; Check instance types
782 If bValid And Len(pvObjectType) &gt; 0 And iVarType = V_OBJECT Then
783 &apos;Set oArgument = pvArgument
784 Set oObjectDescriptor = SF_Utils._VarTypeObj(pvArgument)
785 bValid = ( oObjectDescriptor.iVarType = V_SFOBJECT )
786 If bValid Then bValid = ( oObjectDescriptor.sObjectType = pvObjectType )
787 End If
788 End If
790 If Not bValid Then
791 &apos;&apos;&apos; Library: ScriptForge
792 &apos;&apos;&apos; Service: Array
793 &apos;&apos;&apos; Method: Contains
794 &apos;&apos;&apos; Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=&quot;&quot;]
795 &apos;&apos;&apos; A serious error has been detected on argument SortOrder
796 &apos;&apos;&apos; Rules: SortOrder is of type String
797 &apos;&apos;&apos; SortOrder must contain one of next values: &quot;ASC&quot;, &quot;DESC&quot;, &quot;&quot;
798 &apos;&apos;&apos; Actual value: &quot;Ascending&quot;
799 SF_Exception.RaiseFatal(ARGUMENTERROR _
800 , SF_Utils._Repr(pvArgument, cstMaxLength), psName, SF_Utils._TypeNames(pvTypes) _
801 , SF_Utils._ReprValues(pvValues, cstMaxValues), pvCaseSensitive, pvObjectType _
803 End If
805 Finally:
806 _Validate = bValid
807 _SF_.StackLevel = _SF_.StackLevel - 1
808 Exit Function
809 CatchMissing:
810 bValid = False
811 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
812 GoTo Finally
813 End Function &apos; ScriptForge.SF_Utils._Validate
815 REM -----------------------------------------------------------------------------
816 Public Function _ValidateArray(Optional ByRef pvArray As Variant _
817 , ByVal psName As String _
818 , Optional ByVal piDimensions As Integer _
819 , Optional ByVal piType As Integer _
820 , Optional ByVal pbNotNull As Boolean _
821 ) As Boolean
822 &apos;&apos;&apos; Validate the (array) arguments set by user scripts
823 &apos;&apos;&apos; The arguments of the function define the validation rules
824 &apos;&apos;&apos; This function ignores non-arrays. Use _Validate instead
825 &apos;&apos;&apos; Args:
826 &apos;&apos;&apos; pvArray: the argument to (in)validate
827 &apos;&apos;&apos; psName: the documented name of the array (can be inserted in an error message)
828 &apos;&apos;&apos; piDimensions: the # of dimensions the array must have. 0 = Any (default)
829 &apos;&apos;&apos; piType: (default = -1, i.e. not applicable)
830 &apos;&apos;&apos; For 2D arrays, the 1st column is checked
831 &apos;&apos;&apos; 0 =&gt; all items must be any out of next types: string, date or numeric,
832 &apos;&apos;&apos; but homogeneously: all strings or all dates or all numeric
833 &apos;&apos;&apos; V_STRING or V_DATE or V_NUMERIC =&gt; that specific type is required
834 &apos;&apos;&apos; pbNotNull: piType must be &gt;=0, otherwise ignored
835 &apos;&apos;&apos; If True: Empty, Null items are rejected
836 &apos;&apos;&apos; Return: True if validation OK
837 &apos;&apos;&apos; Otherwise an error is raised
838 &apos;&apos;&apos; Exceptions:
839 &apos;&apos;&apos; ARRAYERROR
841 Dim iVarType As Integer &apos; VarType of argument
842 Dim vItem As Variant &apos; Array item
843 Dim iItemType As Integer &apos; VarType of individual items of argument
844 Dim iDims As Integer &apos; Number of dimensions of the argument
845 Dim bValid As Boolean &apos; Returned value
846 Dim iArrayType As Integer &apos; Static array type
847 Dim iFirstItemType As Integer &apos; Type of 1st non-null/empty item
848 Dim sType As String &apos; Allowed item types as a string
849 Dim i As Long
850 Const cstMaxLength = 256 &apos; Maximum length of readable value
852 &apos; To avoid useless recursions, keep main function, only increase stack depth
854 _SF_.StackLevel = _SF_.StackLevel + 1
855 On Local Error GoTo Finally &apos; Do never interrupt
857 Try:
858 bValid = True
859 If IsMissing(pvArray) Then GoTo CatchMissing
860 If IsMissing(piDimensions) Then piDimensions = 0
861 If IsMissing(piType) Then piType = -1
862 If IsMissing(pbNotNull) Then pbNotNull = False
863 iVarType = VarType(pvArray)
865 &apos; Scalars NEVER pass validation
866 If iVarType &lt; V_ARRAY Then
867 bValid = False
868 Else
869 &apos; Check dimensions
870 iDims = SF_Array.CountDims(pvArray)
871 If iDims &gt; 2 Then bValid = False &apos; Only 1D and 2D arrays
872 If bValid And piDimensions &gt; 0 Then
873 bValid = ( iDims = piDimensions Or (iDims = 0 And piDimensions = 1) ) &apos; Allow empty vectors
874 End If
875 &apos; Check VarType and Empty/Null status of the array items
876 If bValid And iDims = 1 And piType &gt;= 0 Then
877 iArrayType = SF_Array._StaticType(pvArray)
878 If (piType = 0 And iArrayType &gt; 0) Or (piType &gt; 0 And iArrayType = piType) Then
879 &apos; If static array of the right VarType ..., OK
880 Else
881 &apos; Go through array and check individual items
882 iFirstItemType = -1
883 For i = LBound(pvArray, 1) To UBound(pvArray, 1)
884 If iDims = 1 Then vItem = pvArray(i) Else vItem = pvArray(i, LBound(pvArray, 2))
885 iItemType = SF_Utils._VarTypeExt(vItem)
886 If iItemType &gt; V_NULL Then &apos; Exclude Empty and Null
887 &apos; Initialization at first non-null item
888 If iFirstItemType &lt; 0 Then
889 iFirstItemType = iItemType
890 If piType &gt; 0 Then bValid = ( iFirstItemType = piType ) Else bValid = SF_Array.Contains(Array(V_STRING, V_DATE, V_NUMERIC), iFirstItemType)
891 Else
892 bValid = (iItemType = iFirstItemType)
893 End If
894 Else
895 bValid = Not pbNotNull
896 End If
897 If Not bValid Then Exit For
898 Next i
899 End If
900 End If
901 End If
903 If Not bValid Then
904 &apos;&apos;&apos; Library: ScriptForge
905 &apos;&apos;&apos; Service: Array
906 &apos;&apos;&apos; Method: Contains
907 &apos;&apos;&apos; Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=&quot;&quot;|&quot;ASC&quot;|&quot;DESC&quot;]
908 &apos;&apos;&apos; An error was detected on argument Array_1D
909 &apos;&apos;&apos; Rules: Array_1D is of type Array
910 &apos;&apos;&apos; Array_1D must have maximum 1 dimension
911 &apos;&apos;&apos; Array_1D must have all elements of the same type: either String, Date or Numeric
912 &apos;&apos;&apos; Actual value: (0:2, 0:3)
913 sType = &quot;&quot;
914 If piType = 0 Then
915 sType = &quot;String, Date, Numeric&quot;
916 ElseIf piType &gt; 0 Then
917 sType = SF_Utils._TypeNames(piType)
918 End If
919 SF_Exception.RaiseFatal(ARRAYERROR _
920 , SF_Utils._Repr(pvArray, cstMaxLength), psName, piDimensions, sType, pbNotNull)
921 End If
923 Finally:
924 _ValidateArray = bValid
925 _SF_.StackLevel = _SF_.StackLevel - 1
926 Exit Function
927 CatchMissing:
928 bValid = False
929 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
930 GoTo Finally
931 End Function &apos; ScriptForge.SF_Utils._ValidateArray
933 REM -----------------------------------------------------------------------------
934 Public Function _ValidateFile(Optional ByRef pvArgument As Variant _
935 , ByVal psName As String _
936 , Optional ByVal pbWildCards As Boolean _
937 , Optional ByVal pbSpace As Boolean _
939 &apos;&apos;&apos; Validate the argument as a valid FileName
940 &apos;&apos;&apos; Args:
941 &apos;&apos;&apos; pvArgument: the argument to (in)validate
942 &apos;&apos;&apos; pbWildCards: if True, wildcard characters are accepted in the last component of the 1st argument
943 &apos;&apos;&apos; pbSpace: if True, the argument may be an empty string. Default = False
944 &apos;&apos;&apos; Return: True if validation OK
945 &apos;&apos;&apos; Otherwise an error is raised
946 &apos;&apos;&apos; Exceptions:
947 &apos;&apos;&apos; ARGUMENTERROR
949 Dim iVarType As Integer &apos; VarType of argument
950 Dim sFile As String &apos; Alias for argument
951 Dim bValid As Boolean &apos; Returned value
952 Dim sFileNaming As String &apos; Alias of SF_FileSystem.FileNaming
953 Dim oArgument As Variant &apos; Workaround &quot;Object variable not set&quot; error on 1st executable statement
954 Const cstMaxLength = 256 &apos; Maximum length of readable value
955 Const DOCFILESYSTEM = &quot;vnd.sun.star.tdoc:/&quot;
957 &apos; To avoid useless recursions, keep main function, only increase stack depth
959 _SF_.StackLevel = _SF_.StackLevel + 1
960 On Local Error GoTo Finally &apos; Do never interrupt
962 Try:
963 bValid = True
964 If IsMissing(pvArgument) Then GoTo CatchMissing
965 If IsMissing(pbWildCards) Then pbWildCards = False
966 If IsMissing(pbSpace) Then pbSpace = False
967 iVarType = VarType(pvArgument)
969 &apos; Arrays NEVER pass validation
970 If iVarType &gt;= V_ARRAY Then
971 bValid = False
972 Else
973 &apos; Argument must be a string containing a valid file name
974 bValid = ( iVarType = V_STRING )
975 If bValid Then
976 bValid = ( Len(pvArgument) &gt; 0 Or pbSpace )
977 If bValid And Len(pvArgument) &gt; 0 Then
978 &apos; Wildcards are replaced by arbitrary alpha characters
979 If pbWildCards Then
980 sFile = Replace(Replace(pvArgument, &quot;?&quot;, &quot;Z&quot;), &quot;*&quot;, &quot;A&quot;)
981 Else
982 sFile = pvArgument
983 bValid = ( InStr(sFile, &quot;?&quot;) + InStr(sFile, &quot;*&quot;) = 0 )
984 End If
985 &apos; Check file format without wildcards
986 If bValid Then
987 With SF_FileSystem
988 sFileNaming = .FileNaming
989 If SF_String.StartsWith(sFile, DOCFILESYSTEM) Then sFileNaming = &quot;URL&quot;
990 Select Case sFileNaming
991 Case &quot;ANY&quot; : bValid = SF_String.IsUrl(ConvertToUrl(sFile))
992 Case &quot;URL&quot; : bValid = SF_String.IsUrl(sFile)
993 Case &quot;SYS&quot; : bValid = SF_String.IsFileName(sFile)
994 End Select
995 End With
996 End If
997 &apos; Check that wildcards are only present in last component
998 If bValid And pbWildCards Then
999 sFile = SF_FileSystem.GetParentFolderName(pvArgument)
1000 bValid = ( InStr(sFile, &quot;*&quot;) + InStr(sFile, &quot;?&quot;) + InStr(sFile,&quot;%3F&quot;) = 0 ) &apos; ConvertToUrl replaces ? by %3F
1001 End If
1002 End If
1003 End If
1004 End If
1006 If Not bValid Then
1007 &apos;&apos;&apos; Library: ScriptForge
1008 &apos;&apos;&apos; Service: FileSystem
1009 &apos;&apos;&apos; Method: CopyFile
1010 &apos;&apos;&apos; Arguments: Source, Destination
1011 &apos;&apos;&apos; A serious error has been detected on argument Source
1012 &apos;&apos;&apos; Rules: Source is of type String
1013 &apos;&apos;&apos; Source must be a valid file name expressed in operating system notation
1014 &apos;&apos;&apos; Source may contain one or more wildcard characters in its last component
1015 &apos;&apos;&apos; Actual value: /home/jean-*/SomeFile.odt
1016 SF_Exception.RaiseFatal(FILEERROR _
1017 , SF_Utils._Repr(pvArgument, cstMaxLength), psName, pbWildCards)
1018 End If
1020 Finally:
1021 _ValidateFile = bValid
1022 _SF_.StackLevel = _SF_.StackLevel - 1
1023 Exit Function
1024 CatchMissing:
1025 bValid = False
1026 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
1027 GoTo Finally
1028 End Function &apos; ScriptForge.SF_Utils._ValidateFile
1030 REM -----------------------------------------------------------------------------
1031 Public Function _VarTypeExt(ByRef pvValue As Variant) As Integer
1032 &apos;&apos;&apos; Return the VarType of the argument but all numeric types are aggregated into V_NUMERIC
1033 &apos;&apos;&apos; Args:
1034 &apos;&apos;&apos; pvValue: value to examine
1035 &apos;&apos;&apos; Return:
1036 &apos;&apos;&apos; The extended VarType
1038 Dim iType As Integer &apos; VarType of argument
1040 iType = VarType(pvValue)
1041 Select Case iType
1042 Case V_INTEGER, V_LONG, V_SINGLE, V_DOUBLE, V_CURRENCY, V_BIGINT, V_DECIMAL
1043 _VarTypeExt = V_NUMERIC
1044 Case Else : _VarTypeExt = iType
1045 End Select
1047 End Function &apos; ScriptForge.SF_Utils._VarTypeExt
1049 REM -----------------------------------------------------------------------------
1050 Public Function _VarTypeObj(ByRef pvValue As Variant) As Object
1051 &apos;&apos;&apos; Inspect the argument that is supposed to be an Object
1052 &apos;&apos;&apos; Return the internal type of object as one of the values
1053 &apos;&apos;&apos; V_NOTHING Null object
1054 &apos;&apos;&apos; V_UNOOBJECT Uno object or Uno structure
1055 &apos;&apos;&apos; V_SFOBJECT ScriptForge object: has ObjectType and ServiceName properties
1056 &apos;&apos;&apos; V_BASICOBJECT User Basic object
1057 &apos;&apos;&apos; coupled with object type as a string (&quot;com.sun.star...&quot; or &quot;SF_...&quot; or &quot;... ScriptForge class ...&quot;)
1058 &apos;&apos;&apos; When the argument is not an Object, return the usual VarType() of the argument
1060 Dim oObjDesc As _ObjectDescriptor &apos; Return value
1061 Dim oValue As Object &apos; Alias of pvValue used to avoid &quot;Object variable not set&quot; error
1062 Dim sObjType As String &apos; The type of object is first derived as a string
1063 Dim oReflection As Object &apos; com.sun.star.reflection.CoreReflection
1064 Dim vClass As Variant &apos; com.sun.star.reflection.XIdlClass
1065 Dim bUno As Boolean &apos; True when object recognized as UNO object
1067 Const cstBasicClass = &quot;com.sun.star.script.NativeObjectWrapper&quot; &apos; Way to recognize Basic objects
1069 On Local Error Resume Next &apos; Object type is established by trial and error
1071 Try:
1072 With oObjDesc
1073 .iVarType = VarType(pvValue)
1074 .sObjectType = &quot;&quot;
1075 .sServiceName = &quot;&quot;
1076 bUno = False
1077 If .iVarType = V_OBJECT Then
1078 If IsNull(pvValue) Then
1079 .iVarType = V_NOTHING
1080 Else
1081 Set oValue = pvValue
1082 &apos; Try UNO type with usual ImplementationName property
1083 .sObjectType = oValue.getImplementationName()
1084 If .sObjectType = &quot;&quot; Then
1085 &apos; Try UNO type with alternative CoreReflection trick
1086 Set oReflection = SF_Utils._GetUNOService(&quot;CoreReflection&quot;)
1087 vClass = oReflection.getType(oValue)
1088 If vClass.TypeClass &gt;= com.sun.star.uno.TypeClass.STRUCT Then
1089 .sObjectType = vClass.Name
1090 bUno = True
1091 End If
1092 Else
1093 bUno = True
1094 End If
1095 &apos; Identify Basic objects
1096 If .sObjectType = cstBasicClass Then
1097 bUno = False
1098 &apos; Try if the Basic object has an ObjectType property
1099 .sObjectType = oValue.ObjectType
1100 .sServiceName = oValue.ServiceName
1101 End If
1102 &apos; Derive the return value from the object type
1103 Select Case True
1104 Case Len(.sObjectType) = 0 &apos; Do nothing (return V_OBJECT)
1105 Case .sObjectType = cstBasicClass : .iVarType = V_BASICOBJECT
1106 Case bUno : .iVarType = V_UNOOBJECT
1107 Case Else : .iVarType = V_SFOBJECT
1108 End Select
1109 End If
1110 End If
1111 End With
1113 Finally:
1114 Set _VarTypeObj = oObjDesc
1115 Exit Function
1116 End Function &apos; ScriptForge.SF_Utils._VarTypeObj
1118 REM ================================================= END OF SCRIPTFORGE.SF_UTILS
1119 </script:module>