nss: upgrade to release 3.73
[LibreOffice.git] / wizards / source / scriptforge / SF_Utils.xba
blob67aa32f29c775e9c765dd5fd2a04c22bdd3e1545
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;7.1&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 Global Const V_NUMERIC = 99 &apos; Fictive VarType synonym of any numeric value
48 REM ================================================================== EXCEPTIONS
50 Const MISSINGARGERROR = &quot;MISSINGARGERROR&quot; &apos; A mandatory argument is missing
51 Const ARGUMENTERROR = &quot;ARGUMENTERROR&quot; &apos; An argument does not pass the _Validate() validation
52 Const ARRAYERROR = &quot;ARRAYERROR&quot; &apos; An argument does not pass the _ValidateArray() validation
53 Const FILEERROR = &quot;FILEERROR&quot; &apos; An argument does not pass the _ValidateFile() validation
55 REM =========================================pvA==================== PRIVATE METHODS
57 REM -----------------------------------------------------------------------------
58 Public Function _CDateToIso(pvDate As Variant) As Variant
59 &apos;&apos;&apos; Returns a string representation of the given Basic date
60 &apos;&apos;&apos; Dates as strings are essential in property values, where Basic dates are evil
62 Dim sIsoDate As Variant &apos; Return value
64 If VarType(pvDate) = V_DATE Then
65 If Year(pvDate) &lt; 1900 Then &apos; Time only
66 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)
67 ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then &apos; Date only
68 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)
69 Else
70 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) _
71 &amp; &quot; &quot; &amp; Right(&quot;0&quot; &amp; Hour(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Minute(pvDate), 2) _
72 &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Second(pvDate), 2)
73 End If
74 Else
75 sIsoDate = pvDate
76 End If
78 _CDateToIso = sIsoDate
80 End Function &apos; ScriptForge.SF_Utils._CDateToIso
82 REM -----------------------------------------------------------------------------
83 Public Function _CDateToUnoDate(pvDate As Variant) As Variant
84 &apos;&apos;&apos; Returns a UNO com.sun.star.util.DateTime/Date/Time object depending on the given date
85 &apos;&apos;&apos; by using the appropriate CDateToUnoDateXxx builtin function
86 &apos;&apos;&apos; UNO dates are essential in property values, where Basic dates are evil
88 Dim vUnoDate As Variant &apos; Return value
90 If VarType(pvDate) = V_DATE Then
91 If Year(pvDate) &lt; 1900 Then
92 vUnoDate = CDateToUnoTime(pvDate)
93 ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then
94 vUnoDate = CDateToUnoDate(pvDate)
95 Else
96 vUnoDate = CDateToUnoDateTime(pvDate)
97 End If
98 Else
99 vUnoDate = pvDate
100 End If
102 _CDateToUnoDate = vUnoDate
104 End Function &apos; ScriptForge.SF_Utils._CDateToUnoDate
106 REM -----------------------------------------------------------------------------
107 Public Function _CPropertyValue(ByRef pvValue As Variant) As Variant
108 &apos;&apos;&apos; Set a value of a correct type in a com.sun.star.beans.PropertyValue
109 &apos;&apos;&apos; Date BASIC variables give error. Change them to UNO types
110 &apos;&apos;&apos; Empty arrays should be replaced by Null
112 Dim vValue As Variant &apos; Return value
114 If VarType(pvValue) = V_DATE Then
115 vValue = SF_Utils._CDateToUnoDate(pvValue)
116 ElseIf IsArray(pvValue) Then
117 If UBound(pvValue, 1) &lt; LBound(pvValue, 1) Then vValue = Null Else vValue = pvValue
118 Else
119 vValue = pvValue
120 End If
121 _CPropertyValue() = vValue
123 End Function &apos; ScriptForge.SF_Utils._CPropertyValue
125 REM -----------------------------------------------------------------------------
126 Public Function _CStrToDate(ByRef pvStr As String) As Date
127 &apos;&apos;&apos; Attempt to convert the input string to a Date variable with the CDate builtin function
128 &apos;&apos;&apos; If not successful, returns conventionally -1 (29/12/1899)
129 &apos;&apos;&apos; Date patterns: YYYY-MM-DD, HH:MM:DD and YYYY-MM-DD HH:MM:DD
131 Dim dDate As Date &apos; Return value
132 Const cstNoDate = -1
134 dDate = cstNoDate
135 Try:
136 On Local Error Resume Next
137 dDate = CDate(pvStr)
139 Finally:
140 _CStrToDate = dDate
141 Exit Function
142 End Function &apos; ScriptForge.SF_Utils._CStrToDate
144 REM -----------------------------------------------------------------------------
145 Public Function _EnterFunction(ByVal psSub As String, Optional ByVal psArgs As String)
146 &apos;&apos;&apos; Called on top of each public function
147 &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
148 &apos;&apos;&apos; and to allow the explicit mention of the user call which caused an error
149 &apos;&apos;&apos; Args:
150 &apos;&apos;&apos; psSub = the called Sub/Function/Property, usually something like &quot;service.sub&quot;
151 &apos;&apos;&apos; Return: True when psSub is called from a user script
152 &apos;&apos;&apos; Used to bypass the validation of the arguments when unnecessary
154 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
155 If IsMissing(psArgs) Then psArgs = &quot;&quot;
156 With _SF_
157 If .StackLevel = 0 Then
158 .MainFunction = psSub
159 .MainFunctionArgs = psArgs
160 _EnterFunction = True
161 Else
162 _EnterFunction = False
163 End If
164 .StackLevel = .StackLevel + 1
165 If .DebugMode Then ._AddToConsole(&quot;==&gt; &quot; &amp; psSub &amp; &quot;(&quot; &amp; .StackLevel &amp; &quot;)&quot;)
166 End With
168 End Function &apos; ScriptForge.SF_Utils._EnterFunction
170 REM -----------------------------------------------------------------------------
171 Public Function _ErrorHandling(Optional ByVal pbErrorHandler As Boolean) As Boolean
172 &apos;&apos;&apos; Error handling is normally ON and can be set OFF for debugging purposes
173 &apos;&apos;&apos; Each user visible routine starts with a call to this function to enable/disable
174 &apos;&apos;&apos; standard handling of internal errors
175 &apos;&apos;&apos; Args:
176 &apos;&apos;&apos; pbErrorHandler = if present, set its value
177 &apos;&apos;&apos; Return: the current value of the error handler
179 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
180 If Not IsMissing(pbErrorHandler) Then _SF_.ErrorHandler = pbErrorHandler
181 _ErrorHandling = _SF_.ErrorHandler
183 End Function &apos; ScriptForge.SF_Utils._ErrorHandling
185 REM -----------------------------------------------------------------------------
186 Public Sub _ExitFunction(ByVal psSub As String)
187 &apos;&apos;&apos; Called in the Finally block of each public function
188 &apos;&apos;&apos; Manage ScriptForge internal aborts
189 &apos;&apos;&apos; Resets MainFunction (root) when exiting the method called by a user script
190 &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
191 &apos;&apos;&apos; Args:
192 &apos;&apos;&apos; psSub = the called Sub/Function/Property, usually something like &quot;service.sub&quot;
194 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; Useful only when current module has been recompiled
195 With _SF_
196 If Err &gt; 0 Then
197 SF_Exception.RaiseAbort(psSub)
198 End If
199 If .StackLevel = 1 Then
200 .MainFunction = &quot;&quot;
201 .MainFunctionArgs = &quot;&quot;
202 End If
203 If .DebugMode Then ._AddToConsole(&quot;&lt;== &quot; &amp; psSub &amp; &quot;(&quot; &amp; .StackLevel &amp; &quot;)&quot;)
204 If .StackLevel &gt; 0 Then .StackLevel = .StackLevel - 1
205 End With
207 End Sub &apos; ScriptForge.SF_Utils._ExitFunction
209 REM -----------------------------------------------------------------------------
210 Public Sub _ExportScriptForgePOTFile(ByVal FileName As String)
211 &apos;&apos;&apos; Export the ScriptForge POT file related to its own user interface
212 &apos;&apos;&apos; Should be called only before issuing new ScriptForge releases only
213 &apos;&apos;&apos; Args:
214 &apos;&apos;&apos; FileName: the resulting file. If it exists, is overwritten without warning
216 Dim sHeader As String &apos; The specific header to insert
218 sHeader = &quot;&quot; _
219 &amp; &quot;*********************************************************************\n&quot; _
220 &amp; &quot;*** The ScriptForge library and its associated libraries ***\n&quot; _
221 &amp; &quot;*** are part of the LibreOffice project. ***\n&quot; _
222 &amp; &quot;*********************************************************************\n&quot; _
223 &amp; &quot;\n&quot; _
224 &amp; &quot;ScriptForge Release &quot; &amp; SF_Version &amp; &quot;\n&quot; _
225 &amp; &quot;-----------------------&quot;
227 Try:
228 With _SF_
229 .Interface.ExportToPOTFile(FileName, Header := sHeader)
230 End With
232 Finally:
233 Exit Sub
234 End Sub &apos; ScriptForge.SF_Utils._ExportScriptForgePOTFile
236 REM -----------------------------------------------------------------------------
237 Public Function _GetPropertyValue(ByRef pvArgs As Variant, ByVal psName As String) As Variant
238 &apos;&apos;&apos; Returns the Value corresponding to the given name
239 &apos;&apos;&apos; Args
240 &apos;&apos;&apos; pvArgs: a zero_based array of PropertyValues
241 &apos;&apos;&apos; psName: the comparison is not case-sensitive
242 &apos;&apos;&apos; Returns:
243 &apos;&apos;&apos; Zero-length string if not found
245 Dim vValue As Variant &apos; Return value
246 Dim i As Long
248 vValue = &quot;&quot;
249 If IsArray(pvArgs) Then
250 For i = LBound(pvArgs) To UBound(pvArgs)
251 If UCase(psName) = UCase(pvArgs(i).Name) Then
252 vValue = pvArgs(i).Value
253 Exit For
254 End If
255 Next i
256 End If
257 _GetPropertyValue = vValue
259 End Function &apos; ScriptForge.SF_Utils._GetPropertyValue
261 REM -----------------------------------------------------------------------------
262 Public Function _GetRegistryKeyContent(ByVal psKeyName as string _
263 , Optional pbForUpdate as Boolean _
264 ) As Variant
265 &apos;&apos;&apos; Implement a ConfigurationProvider service
266 &apos;&apos;&apos; Derived from the Tools library
267 &apos;&apos;&apos; Args:
268 &apos;&apos;&apos; psKeyName: the name of the node in the configuration tree
269 &apos;&apos;&apos; pbForUpdate: default = False
271 Dim oConfigProvider as Object &apos; com.sun.star.configuration.ConfigurationProvider
272 Dim vNodePath(0) as New com.sun.star.beans.PropertyValue
273 Dim sConfig As String &apos; One of next 2 constants
274 Const cstConfig = &quot;com.sun.star.configuration.ConfigurationAccess&quot;
275 Const cstConfigUpdate = &quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;
277 Set oConfigProvider = _GetUNOService(&quot;ConfigurationProvider&quot;)
278 vNodePath(0).Name = &quot;nodepath&quot;
279 vNodePath(0).Value = psKeyName
281 If IsMissing(pbForUpdate) Then pbForUpdate = False
282 If pbForUpdate Then sConfig = cstConfigUpdate Else sConfig = cstConfig
284 Set _GetRegistryKeyContent = oConfigProvider.createInstanceWithArguments(sConfig, vNodePath())
286 End Function &apos; ScriptForge.SF_Utils._GetRegistryKeyContent
288 REM -----------------------------------------------------------------------------
289 Public Function _GetUNOService(ByVal psService As String _
290 , Optional ByVal pvArg As Variant _
291 ) As Object
292 &apos;&apos;&apos; Create a UNO service
293 &apos;&apos;&apos; Each service is called only once
294 &apos;&apos;&apos; Args:
295 &apos;&apos;&apos; psService: shortcut to service
296 &apos;&apos;&apos; pvArg: some services might require an argument
298 Dim sLocale As String &apos; fr-BE f.i.
299 Dim oConfigProvider As Object
300 Dim oDefaultContext As Object
301 Dim vNodePath As Variant
303 Set _GetUNOService = Nothing
304 With _SF_
305 Select Case psService
306 Case &quot;BrowseNodeFactory&quot;
307 Set oDefaultContext = GetDefaultContext()
308 If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName(&quot;/singletons/com.sun.star.script.browse.theBrowseNodeFactory&quot;)
309 Case &quot;CharacterClass&quot;
310 If IsEmpty(.CharacterClass) Or IsNull(.CharacterClass) Then
311 Set .CharacterClass = CreateUnoService(&quot;com.sun.star.i18n.CharacterClassification&quot;)
312 End If
313 Set _GetUNOService = .CharacterClass
314 Case &quot;ConfigurationProvider&quot;
315 If IsEmpty(.ConfigurationProvider) Or IsNull(.ConfigurationProvider) Then
316 Set .ConfigurationProvider = CreateUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
317 End If
318 Set _GetUNOService = .ConfigurationProvider
319 Case &quot;CoreReflection&quot;
320 If IsEmpty(.CoreReflection) Or IsNull(.CoreReflection) Then
321 Set .CoreReflection = CreateUnoService(&quot;com.sun.star.reflection.CoreReflection&quot;)
322 End If
323 Set _GetUNOService = .CoreReflection
324 Case &quot;DatabaseContext&quot;
325 If IsEmpty(.DatabaseContext) Or IsNull(.DatabaseContext) Then
326 Set .DatabaseContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
327 End If
328 Set _GetUNOService = .DatabaseContext
329 Case &quot;DispatchHelper&quot;
330 If IsEmpty(.DispatchHelper) Or IsNull(.DispatchHelper) Then
331 Set .DispatchHelper = CreateUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
332 End If
333 Set _GetUNOService = .DispatchHelper
334 Case &quot;FileAccess&quot;
335 If IsEmpty(.FileAccess) Or IsNull(.FileAccess) Then
336 Set .FileAccess = CreateUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
337 End If
338 Set _GetUNOService = .FileAccess
339 Case &quot;FilePicker&quot;
340 If IsEmpty(.FilePicker) Or IsNull(.FilePicker) Then
341 Set .FilePicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
342 End If
343 Set _GetUNOService = .FilePicker
344 Case &quot;FilterFactory&quot;
345 If IsEmpty(.FilterFactory) Or IsNull(.FilterFactory) Then
346 Set .FilterFactory = CreateUnoService(&quot;com.sun.star.document.FilterFactory&quot;)
347 End If
348 Set _GetUNOService = .FilterFactory
349 Case &quot;FolderPicker&quot;
350 If IsEmpty(.FolderPicker) Or IsNull(.FolderPicker) Then
351 Set .FolderPicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
352 End If
353 Set _GetUNOService = .FolderPicker
354 Case &quot;FunctionAccess&quot;
355 If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then
356 Set .FunctionAccess = CreateUnoService(&quot;com.sun.star.sheet.FunctionAccess&quot;)
357 End If
358 Set _GetUNOService = .FunctionAccess
359 Case &quot;Introspection&quot;
360 If IsEmpty(.Introspection) Or IsNull(.Introspection) Then
361 Set .Introspection = CreateUnoService(&quot;com.sun.star.beans.Introspection&quot;)
362 End If
363 Set _GetUNOService = .Introspection
364 Case &quot;Locale&quot;
365 If IsEmpty(.Locale) Or IsNull(.Locale) Then
366 .Locale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
367 &apos; Derived from the Tools library
368 Set oConfigProvider = createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
369 vNodePath = Array() : ReDim vNodePath(0)
370 vNodePath(0) = New com.sun.star.beans.PropertyValue
371 vNodePath(0).Name = &quot;nodepath&quot; : vNodePath(0).Value = &quot;org.openoffice.Setup/L10N&quot;
372 sLocale = oConfigProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, vNodePath()).getByName(&quot;ooLocale&quot;)
373 .Locale.Language = Left(sLocale, 2)
374 .Locale.Country = Right(sLocale, 2)
375 End If
376 Set _GetUNOService = .Locale
377 Case &quot;MacroExpander&quot;
378 Set oDefaultContext = GetDefaultContext()
379 If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName(&quot;/singletons/com.sun.star.util.theMacroExpander&quot;)
380 Case &quot;MailService&quot;
381 If IsEmpty(.MailService) Or IsNull(.MailService) Then
382 If GetGuiType = 1 Then &apos; Windows
383 Set .MailService = CreateUnoService(&quot;com.sun.star.system.SimpleSystemMail&quot;)
384 Else
385 Set .MailService = CreateUnoService(&quot;com.sun.star.system.SimpleCommandMail&quot;)
386 End If
387 End If
388 Set _GetUNOService = .MailService
389 Case &quot;PathSettings&quot;
390 If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then
391 Set .PathSettings = CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)
392 End If
393 Set _GetUNOService = .PathSettings
394 Case &quot;PathSubstitution&quot;
395 If IsEmpty(.PathSubstitution) Or IsNull(.PathSubstitution) Then
396 Set .PathSubstitution = CreateUnoService(&quot;com.sun.star.util.PathSubstitution&quot;)
397 End If
398 Set _GetUNOService = .PathSubstitution
399 Case &quot;ScriptProvider&quot;
400 If IsMissing(pvArg) Then pvArg = SF_Session.SCRIPTISAPPLICATION
401 Select Case LCase(pvArg)
402 Case SF_Session.SCRIPTISEMBEDDED &apos; Document
403 If Not IsNull(ThisComponent) Then Set _GetUNOService = ThisComponent.getScriptProvider()
404 Case Else
405 If IsEmpty(.ScriptProvider) Or IsNull(.ScriptProvider) Then
406 Set .ScriptProvider = _
407 CreateUnoService(&quot;com.sun.star.script.provider.MasterScriptProviderFactory&quot;).createScriptProvider(&quot;&quot;)
408 End If
409 Set _GetUNOService = .ScriptProvider
410 End Select
411 Case &quot;SearchOptions&quot;
412 If IsEmpty(.SearchOptions) Or IsNull(.SearchOptions) Then
413 Set .SearchOptions = New com.sun.star.util.SearchOptions
414 With .SearchOptions
415 .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
416 .searchFlag = 0
417 End With
418 End If
419 Set _GetUNOService = .SearchOptions
420 Case &quot;SystemShellExecute&quot;
421 If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then
422 Set .SystemShellExecute = CreateUnoService(&quot;com.sun.star.system.SystemShellExecute&quot;)
423 End If
424 Set _GetUNOService = .SystemShellExecute
425 Case &quot;TextSearch&quot;
426 If IsEmpty(.TextSearch) Or IsNull(.TextSearch) Then
427 Set .TextSearch = CreateUnoService(&quot;com.sun.star.util.TextSearch&quot;)
428 End If
429 Set _GetUNOService = .TextSearch
430 Case &quot;URLTransformer&quot;
431 If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then
432 Set .URLTransformer = CreateUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
433 End If
434 Set _GetUNOService = .URLTransformer
435 Case Else
436 End Select
437 End With
439 End Function &apos; ScriptForge.SF_Utils._GetUNOService
441 REM -----------------------------------------------------------------------------
442 Public Sub _InitializeRoot(Optional ByVal pbForce As Boolean)
443 &apos;&apos;&apos; Initialize _SF_ as SF_Root basic object
444 &apos;&apos;&apos; Args:
445 &apos;&apos;&apos; pbForce = True forces the reinit (default = False)
447 If IsMissing(pbForce) Then pbForce = False
448 If pbForce Then Set _SF_ = Nothing
449 If IsEmpty(_SF_) Or IsNull(_SF_) Then
450 Set _SF_ = New SF_Root
451 Set _SF_.[Me] = _SF_
452 &apos; Localization
453 _SF_._LoadLocalizedInterface()
454 End If
456 End Sub &apos; ScriptForge.SF_Utils._InitializeRoot
458 REM -----------------------------------------------------------------------------
459 Public Function _MakePropertyValue(ByVal psName As String _
460 , ByRef pvValue As Variant _
461 ) As com.sun.star.beans.PropertyValue
462 &apos;&apos;&apos; Create and return a new com.sun.star.beans.PropertyValue
464 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
466 With oPropertyValue
467 .Name = psName
468 .Value = SF_Utils._CPropertyValue(pvValue)
469 End With
470 _MakePropertyValue() = oPropertyValue
472 End Function &apos; ScriptForge.SF_Utils._MakePropertyValue
474 REM -----------------------------------------------------------------------------
475 Public Function _Repr(ByVal pvArg As Variant, Optional ByVal plMax As Long) As String
476 &apos;&apos;&apos; Convert pvArg into a readable string (truncated if length &gt; plMax)
477 &apos;&apos;&apos; Args
478 &apos;&apos;&apos; pvArg: may be of any type
479 &apos;&apos;&apos; plMax: maximum length of the resulting string (default = 32K)
481 Dim sArg As String &apos; Return value
482 Dim oObject As Object &apos; Alias of argument to avoid &quot;Object variable not set&quot;
483 Dim sObject As String &apos; Object representation
484 Dim sObjectType As String &apos; ObjectType attribute of Basic objects
485 Dim sLength As String &apos; String length as a string
486 Dim i As Long
487 Const cstBasicObject = &quot;com.sun.star.script.NativeObjectWrapper&quot;
489 Const cstMaxLength = 2^15 - 1 &apos; 32767
490 Const cstByteLength = 25
491 Const cstEtc = &quot; … &quot;
493 If IsMissing(plMax) Or plMax = 0 Then plMax = cstMaxLength
494 If IsArray(pvArg) Then
495 sArg = SF_Array._Repr(pvArg)
496 Else
497 Select Case VarType(pvArg)
498 Case V_EMPTY : sArg = &quot;[EMPTY]&quot;
499 Case V_NULL : sArg = &quot;[NULL]&quot;
500 Case V_OBJECT
501 If IsNull(pvArg) Then
502 sArg = &quot;[NULL]&quot;
503 Else
504 sObject = SF_Session.UnoObjectType(pvArg)
505 If sObject = &quot;&quot; Or sObject = cstBasicObject Then &apos; Not a UNO object
506 &apos; Test if argument is a ScriptForge object
507 sObjectType = &quot;&quot;
508 On Local Error Resume Next
509 Set oObject = pvArg
510 sObjectType = oObject.ObjectType
511 On Error GoTo 0
512 If sObjectType = &quot;&quot; Then
513 sArg = &quot;[OBJECT]&quot;
514 ElseIf Left(sObjectType, 3) = &quot;SF_&quot; Then
515 sArg = &quot;[&quot; &amp; sObjectType &amp; &quot;]&quot;
516 Else
517 sArg = oObject._Repr()
518 End If
519 Else
520 sArg = &quot;[&quot; &amp; sObject &amp; &quot;]&quot;
521 End If
522 End If
523 Case V_VARIANT : sArg = &quot;[VARIANT]&quot;
524 Case V_STRING
525 sArg = SF_String._Repr(pvArg)
526 Case V_BOOLEAN : sArg = Iif(pvArg, &quot;[TRUE]&quot;, &quot;[FALSE]&quot;)
527 Case V_BYTE : sArg = Right(&quot;00&quot; &amp; Hex(pvArg), 2)
528 Case V_SINGLE, V_DOUBLE, V_CURRENCY
529 sArg = Format(pvArg)
530 If InStr(1, sArg, &quot;E&quot;, 1) = 0 Then sArg = Format(pvArg, &quot;##0.0##&quot;)
531 sArg = Replace(sArg, &quot;,&quot;, &quot;.&quot;) &apos;Force decimal point
532 Case V_BIGINT : sArg = CStr(CLng(pvArg))
533 Case V_DATE : sArg = _CDateToIso(pvArg)
534 Case Else : sArg = CStr(pvArg)
535 End Select
536 End If
537 If Len(sArg) &gt; plMax Then
538 sLength = &quot;(&quot; &amp; Len(sArg) &amp; &quot;)&quot;
539 sArg = Left(sArg, plMax - Len(cstEtc) - Len(slength)) &amp; cstEtc &amp; sLength
540 End If
541 _Repr = sArg
543 End Function &apos; ScriptForge.SF_Utils._Repr
545 REM -----------------------------------------------------------------------------
546 Private Function _ReprValues(Optional ByVal pvArgs As Variant _
547 , Optional ByVal plMax As Long _
548 ) As String
549 &apos;&apos;&apos; Convert an array of values to a comma-separated list of readable strings
551 Dim sValues As String &apos; Return value
552 Dim sValue As String &apos; A single value
553 Dim vValue As Variant &apos; A single item in the argument
554 Dim i As Long &apos; Items counter
555 Const cstMax = 20 &apos; Maximum length of single string
556 Const cstContinue = &quot;…&quot; &apos; Unicode continuation char U+2026
558 _ReprValues = &quot;&quot;
559 If IsMissing(pvArgs) Then Exit Function
560 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
561 sValues = &quot;&quot;
562 For i = 0 To UBound(pvArgs)
563 vValue = pvArgs(i)
564 If i &lt; plMax Then
565 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)
566 If Len(sValues) = 0 Then sValues = sValue Else sValues = sValues &amp; &quot;, &quot; &amp; sValue
567 ElseIf i &lt; UBound(pvArgs) Then
568 sValues = sValues &amp; &quot;, &quot; &amp; cstContinue
569 Exit For
570 End If
571 Next i
572 _ReprValues = sValues
574 End Function &apos; ScriptForge.SF_Utils._ReprValues
576 REM -----------------------------------------------------------------------------
577 Public Sub _SetPropertyValue(ByRef pvPropertyValue As Variant _
578 , ByVal psName As String _
579 , ByRef pvValue As Variant _
581 &apos;&apos;&apos; Update the 1st argument (passed by reference), which is an array of property values
582 &apos;&apos;&apos; If the property psName exists, update it with pvValue, otherwise create it on top of the array
584 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
585 Dim lIndex As Long &apos; Found entry
586 Dim vValue As Variant &apos; Alias of pvValue
587 Dim i As Long
589 lIndex = -1
590 For i = 0 To UBound(pvPropertyValue)
591 If pvPropertyValue(i).Name = psName Then
592 lIndex = i
593 Exit For
594 End If
595 Next i
596 If lIndex &lt; 0 Then &apos; Not found
597 lIndex = UBound(pvPropertyValue) + 1
598 ReDim Preserve pvPropertyValue(0 To lIndex)
599 Set oPropertyValue = SF_Utils._MakePropertyValue(psName, pvValue)
600 pvPropertyValue(lIndex) = oPropertyValue
601 Else &apos; psName exists already in array of property values
602 pvPropertyValue(lIndex).Value = SF_Utils._CPropertyValue(pvValue)
603 End If
605 End Sub &apos; ScriptForge.SF_Utils._SetPropertyValue
607 REM -----------------------------------------------------------------------------
608 Private Function _TypeNames(Optional ByVal pvArgs As Variant) As String
609 &apos;&apos;&apos; Converts the array of VarTypes to a comma-separated list of TypeNames
611 Dim sTypes As String &apos; Return value
612 Dim sType As String &apos; A single type
613 Dim iType As Integer &apos; A single item of the argument
615 _TypeNames = &quot;&quot;
616 If IsMissing(pvArgs) Then Exit Function
617 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
618 sTypes = &quot;&quot;
619 For Each iType In pvArgs
620 Select Case iType
621 Case V_EMPTY : sType = &quot;Empty&quot;
622 Case V_NULL : sType = &quot;Null&quot;
623 Case V_INTEGER : sType = &quot;Integer&quot;
624 Case V_LONG : sType = &quot;Long&quot;
625 Case V_SINGLE : sType = &quot;Single&quot;
626 Case V_DOUBLE : sType = &quot;Double&quot;
627 Case V_CURRENCY : sType = &quot;Currency&quot;
628 Case V_DATE : sType = &quot;Date&quot;
629 Case V_STRING : sType = &quot;String&quot;
630 Case V_OBJECT : sType = &quot;Object&quot;
631 Case V_BOOLEAN : sType = &quot;Boolean&quot;
632 Case V_VARIANT : sType = &quot;Variant&quot;
633 Case V_DECIMAL : sType = &quot;Decimal&quot;
634 Case &gt;= V_ARRAY : sType = &quot;Array&quot;
635 Case V_NUMERIC : sType = &quot;Numeric&quot;
636 End Select
637 If Len(sTypes) = 0 Then sTypes = sType Else sTypes = sTypes &amp; &quot;, &quot; &amp; sType
638 Next iType
639 _TypeNames = sTypes
641 End Function &apos; ScriptForge.SF_Utils._TypeNames
643 REM -----------------------------------------------------------------------------
644 Public Function _Validate(Optional ByRef pvArgument As Variant _
645 , ByVal psName As String _
646 , Optional ByVal pvTypes As Variant _
647 , Optional ByVal pvValues As Variant _
648 , Optional ByVal pvRegex As Variant _
649 , Optional ByVal pvObjectType As Variant _
650 ) As Boolean
651 &apos;&apos;&apos; Validate the arguments set by user scripts
652 &apos;&apos;&apos; The arguments of the function define the validation rules
653 &apos;&apos;&apos; This function ignores arrays. Use _ValidateArray instead
654 &apos;&apos;&apos; Args:
655 &apos;&apos;&apos; pvArgument: the argument to (in)validate
656 &apos;&apos;&apos; psName: the documented name of the argument (can be inserted in an error message)
657 &apos;&apos;&apos; pvTypes: array of allowed VarTypes
658 &apos;&apos;&apos; pvValues: array of allowed values
659 &apos;&apos;&apos; pvRegex: regular expression to comply with
660 &apos;&apos;&apos; pvObjectType: mandatory Basic class
661 &apos;&apos;&apos; Return: True if validation OK
662 &apos;&apos;&apos; Otherwise an error is raised
663 &apos;&apos;&apos; Exceptions:
664 &apos;&apos;&apos; ARGUMENTERROR
666 Dim iVarType As Integer &apos; Extended VarType of argument
667 Dim bValid As Boolean &apos; Returned value
668 Dim oArgument As Variant &apos; Workaround &quot;Object variable not set&quot; error on 1st executable statement
669 Const cstMaxLength = 256 &apos; Maximum length of readable value
670 Const cstMaxValues = 10 &apos; Maximum number of allowed items to list in an error message
672 &apos; To avoid useless recursions, keep main function, only increase stack depth
673 _SF_.StackLevel = _SF_.StackLevel + 1
674 On Local Error GoTo Finally &apos; Do never interrupt
676 Try:
677 bValid = True
678 If IsMissing(pvArgument) Then GoTo CatchMissing
679 If IsMissing(pvRegex) Or IsEmpty(pvRegex) Then pvRegex = &quot;&quot;
680 If IsMissing(pvObjectType) Or IsEmpty(pvObjectType) Then pvObjectType = &quot;&quot;
681 iVarType = SF_Utils._VarTypeExt(pvArgument)
683 &apos; Arrays NEVER pass validation
684 If iVarType &gt;= V_ARRAY Then
685 bValid = False
686 Else
687 &apos; Check existence of argument
688 bValid = iVarType &lt;&gt; V_NULL And iVarType &lt;&gt; V_EMPTY
689 &apos; Check if argument&apos;s VarType is valid
690 If bValid And Not IsMissing(pvTypes) Then
691 If Not IsArray(pvTypes) Then bValid = ( pvTypes = iVarType ) Else bValid = SF_Array.Contains(pvTypes, iVarType)
692 End If
693 &apos; Check if argument&apos;s value is valid
694 If bValid And Not IsMissing(pvValues) Then
695 If Not IsArray(pvValues) Then pvValues = Array(pvValues)
696 bValid = SF_Array.Contains(pvValues, pvArgument, CaseSensitive := False)
697 End If
698 &apos; Check regular expression
699 If bValid And Len(pvRegex) &gt; 0 And iVarType = V_STRING Then
700 If Len(pvArgument) &gt; 0 Then bValid = SF_String.IsRegex(pvArgument, pvRegex, CaseSensitive := False)
701 End If
702 &apos; Check instance types
703 If bValid And Len(pvObjectType) &gt; 0 And iVarType = V_OBJECT Then
704 Set oArgument = pvArgument
705 bValid = ( pvObjectType = oArgument.ObjectType )
706 End If
707 End If
709 If Not bValid Then
710 &apos;&apos;&apos; Library: ScriptForge
711 &apos;&apos;&apos; Service: Array
712 &apos;&apos;&apos; Method: Contains
713 &apos;&apos;&apos; Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=&quot;&quot;]
714 &apos;&apos;&apos; A serious error has been detected on argument SortOrder
715 &apos;&apos;&apos; Rules: SortOrder is of type String
716 &apos;&apos;&apos; SortOrder must contain one of next values: &quot;ASC&quot;, &quot;DESC&quot;, &quot;&quot;
717 &apos;&apos;&apos; Actual value: &quot;Ascending&quot;
718 SF_Exception.RaiseFatal(ARGUMENTERROR _
719 , SF_Utils._Repr(pvArgument, cstMaxLength), psName, SF_Utils._TypeNames(pvTypes) _
720 , SF_Utils._ReprValues(pvValues, cstMaxValues), pvRegex, pvObjectType _
722 End If
724 Finally:
725 _Validate = bValid
726 _SF_.StackLevel = _SF_.StackLevel - 1
727 Exit Function
728 CatchMissing:
729 bValid = False
730 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
731 GoTo Finally
732 End Function &apos; ScriptForge.SF_Utils._Validate
734 REM -----------------------------------------------------------------------------
735 Public Function _ValidateArray(Optional ByRef pvArray As Variant _
736 , ByVal psName As String _
737 , Optional ByVal piDimensions As Integer _
738 , Optional ByVal piType As Integer _
739 , Optional ByVal pbNotNull As Boolean _
740 ) As Boolean
741 &apos;&apos;&apos; Validate the (array) arguments set by user scripts
742 &apos;&apos;&apos; The arguments of the function define the validation rules
743 &apos;&apos;&apos; This function ignores non-arrays. Use _Validate instead
744 &apos;&apos;&apos; Args:
745 &apos;&apos;&apos; pvArray: the argument to (in)validate
746 &apos;&apos;&apos; psName: the documented name of the array (can be inserted in an error message)
747 &apos;&apos;&apos; piDimensions: the # of dimensions the array must have. 0 = Any (default)
748 &apos;&apos;&apos; piType: (default = -1, i.e. not applicable)
749 &apos;&apos;&apos; For 2D arrays, the 1st column is checked
750 &apos;&apos;&apos; 0 =&gt; all items must be any out of next types: string, date or numeric,
751 &apos;&apos;&apos; but homogeneously: all strings or all dates or all numeric
752 &apos;&apos;&apos; V_STRING or V_DATE or V_NUMERIC =&gt; that specific type is required
753 &apos;&apos;&apos; pbNotNull: piType must be &gt;=0, otherwise ignored
754 &apos;&apos;&apos; If True: Empty, Null items are rejected
755 &apos;&apos;&apos; Return: True if validation OK
756 &apos;&apos;&apos; Otherwise an error is raised
757 &apos;&apos;&apos; Exceptions:
758 &apos;&apos;&apos; ARRAYERROR
760 Dim iVarType As Integer &apos; VarType of argument
761 Dim vItem As Variant &apos; Array item
762 Dim iItemType As Integer &apos; VarType of individual items of argument
763 Dim iDims As Integer &apos; Number of dimensions of the argument
764 Dim bValid As Boolean &apos; Returned value
765 Dim iArrayType As Integer &apos; Static array type
766 Dim iFirstItemType As Integer &apos; Type of 1st non-null/empty item
767 Dim sType As String &apos; Allowed item types as a string
768 Dim i As Long
769 Const cstMaxLength = 256 &apos; Maximum length of readable value
771 &apos; To avoid useless recursions, keep main function, only increase stack depth
773 _SF_.StackLevel = _SF_.StackLevel + 1
774 On Local Error GoTo Finally &apos; Do never interrupt
776 Try:
777 bValid = True
778 If IsMissing(pvArray) Then GoTo CatchMissing
779 If IsMissing(piDimensions) Then piDimensions = 0
780 If IsMissing(piType) Then piType = -1
781 If IsMissing(pbNotNull) Then pbNotNull = False
782 iVarType = VarType(pvArray)
784 &apos; Scalars NEVER pass validation
785 If iVarType &lt; V_ARRAY Then
786 bValid = False
787 Else
788 &apos; Check dimensions
789 iDims = SF_Array.CountDims(pvArray)
790 If iDims &gt; 2 Then bValid = False &apos; Only 1D and 2D arrays
791 If bValid And piDimensions &gt; 0 Then
792 bValid = ( iDims = piDimensions Or (iDims = 0 And piDimensions = 1) ) &apos; Allow empty vectors
793 End If
794 &apos; Check VarType and Empty/Null status of the array items
795 If bValid And iDims = 1 And piType &gt;= 0 Then
796 iArrayType = SF_Array._StaticType(pvArray)
797 If (piType = 0 And iArrayType &gt; 0) Or (piType &gt; 0 And iArrayType = piType) Then
798 &apos; If static array of the right VarType ..., OK
799 Else
800 &apos; Go through array and check individual items
801 iFirstItemType = -1
802 For i = LBound(pvArray, 1) To UBound(pvArray, 1)
803 If iDims = 1 Then vItem = pvArray(i) Else vItem = pvArray(i, LBound(pvArray, 2))
804 iItemType = SF_Utils._VarTypeExt(vItem)
805 If iItemType &gt; V_NULL Then &apos; Exclude Empty and Null
806 &apos; Initialization at first non-null item
807 If iFirstItemType &lt; 0 Then
808 iFirstItemType = iItemType
809 If piType &gt; 0 Then bValid = ( iFirstItemType = piType ) Else bValid = SF_Array.Contains(Array(V_STRING, V_DATE, V_NUMERIC), iFirstItemType)
810 Else
811 bValid = (iItemType = iFirstItemType)
812 End If
813 Else
814 bValid = Not pbNotNull
815 End If
816 If Not bValid Then Exit For
817 Next i
818 End If
819 End If
820 End If
822 If Not bValid Then
823 &apos;&apos;&apos; Library: ScriptForge
824 &apos;&apos;&apos; Service: Array
825 &apos;&apos;&apos; Method: Contains
826 &apos;&apos;&apos; Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=&quot;&quot;|&quot;ASC&quot;|&quot;DESC&quot;]
827 &apos;&apos;&apos; An error was detected on argument Array_1D
828 &apos;&apos;&apos; Rules: Array_1D is of type Array
829 &apos;&apos;&apos; Array_1D must have maximum 1 dimension
830 &apos;&apos;&apos; Array_1D must have all elements of the same type: either String, Date or Numeric
831 &apos;&apos;&apos; Actual value: (0:2, 0:3)
832 sType = &quot;&quot;
833 If piType = 0 Then
834 sType = &quot;String, Date, Numeric&quot;
835 ElseIf piType &gt; 0 Then
836 sType = SF_Utils._TypeNames(piType)
837 End If
838 SF_Exception.RaiseFatal(ARRAYERROR _
839 , SF_Utils._Repr(pvArray, cstMaxLength), psName, piDimensions, sType, pbNotNull)
840 End If
842 Finally:
843 _ValidateArray = bValid
844 _SF_.StackLevel = _SF_.StackLevel - 1
845 Exit Function
846 CatchMissing:
847 bValid = False
848 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
849 GoTo Finally
850 End Function &apos; ScriptForge.SF_Utils._ValidateArray
852 REM -----------------------------------------------------------------------------
853 Public Function _ValidateFile(Optional ByRef pvArgument As Variant _
854 , ByVal psName As String _
855 , Optional ByVal pbWildCards As Boolean _
856 , Optional ByVal pbSpace As Boolean _
858 &apos;&apos;&apos; Validate the argument as a valid FileName
859 &apos;&apos;&apos; Args:
860 &apos;&apos;&apos; pvArgument: the argument to (in)validate
861 &apos;&apos;&apos; pbWildCards: if True, wildcard characters are accepted in the last component of the 1st argument
862 &apos;&apos;&apos; pbSpace: if True, the argument may be an empty string. Default = False
863 &apos;&apos;&apos; Return: True if validation OK
864 &apos;&apos;&apos; Otherwise an error is raised
865 &apos;&apos;&apos; Exceptions:
866 &apos;&apos;&apos; ARGUMENTERROR
868 Dim iVarType As Integer &apos; VarType of argument
869 Dim sFile As String &apos; Alias for argument
870 Dim bValid As Boolean &apos; Returned value
871 Dim sFileNaming As String &apos; Alias of SF_FileSystem.FileNaming
872 Dim oArgument As Variant &apos; Workaround &quot;Object variable not set&quot; error on 1st executable statement
873 Const cstMaxLength = 256 &apos; Maximum length of readable value
875 &apos; To avoid useless recursions, keep main function, only increase stack depth
877 _SF_.StackLevel = _SF_.StackLevel + 1
878 On Local Error GoTo Finally &apos; Do never interrupt
880 Try:
881 bValid = True
882 If IsMissing(pvArgument) Then GoTo CatchMissing
883 If IsMissing(pbWildCards) Then pbWildCards = False
884 If IsMissing(pbSpace) Then pbSpace = False
885 iVarType = VarType(pvArgument)
887 &apos; Arrays NEVER pass validation
888 If iVarType &gt;= V_ARRAY Then
889 bValid = False
890 Else
891 &apos; Argument must be a string containing a valid file name
892 bValid = ( iVarType = V_STRING )
893 If bValid Then
894 bValid = ( Len(pvArgument) &gt; 0 Or pbSpace )
895 If bValid And Len(pvArgument) &gt; 0 Then
896 &apos; Wildcards are replaced by arbitrary alpha characters
897 If pbWildCards Then
898 sFile = Replace(Replace(pvArgument, &quot;?&quot;, &quot;Z&quot;), &quot;*&quot;, &quot;A&quot;)
899 Else
900 sFile = pvArgument
901 bValid = ( InStr(sFile, &quot;?&quot;) + InStr(sFile, &quot;*&quot;) = 0 )
902 End If
903 &apos; Check file format without wildcards
904 If bValid Then
905 With SF_FileSystem
906 sFileNaming = .FileNaming
907 Select Case sFileNaming
908 Case &quot;ANY&quot; : bValid = SF_String.IsUrl(ConvertToUrl(sFile))
909 Case &quot;URL&quot; : bValid = SF_String.IsUrl(sFile)
910 Case &quot;SYS&quot; : bValid = SF_String.IsFileName(sFile)
911 End Select
912 End With
913 End If
914 &apos; Check that wildcards are only present in last component
915 If bValid And pbWildCards Then
916 sFile = SF_FileSystem.GetParentFolderName(pvArgument)
917 bValid = ( InStr(sFile, &quot;*&quot;) + InStr(sFile, &quot;?&quot;) + InStr(sFile,&quot;%3F&quot;) = 0 ) &apos; ConvertToUrl replaces ? by %3F
918 End If
919 End If
920 End If
921 End If
923 If Not bValid Then
924 &apos;&apos;&apos; Library: ScriptForge
925 &apos;&apos;&apos; Service: FileSystem
926 &apos;&apos;&apos; Method: CopyFile
927 &apos;&apos;&apos; Arguments: Source, Destination
928 &apos;&apos;&apos; A serious error has been detected on argument Source
929 &apos;&apos;&apos; Rules: Source is of type String
930 &apos;&apos;&apos; Source must be a valid file name expressed in operating system notation
931 &apos;&apos;&apos; Source may contain one or more wildcard characters in its last component
932 &apos;&apos;&apos; Actual value: /home/jean-*/SomeFile.odt
933 SF_Exception.RaiseFatal(FILEERROR _
934 , SF_Utils._Repr(pvArgument, cstMaxLength), psName, pbWildCards)
935 End If
937 Finally:
938 _ValidateFile = bValid
939 _SF_.StackLevel = _SF_.StackLevel - 1
940 Exit Function
941 CatchMissing:
942 bValid = False
943 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
944 GoTo Finally
945 End Function &apos; ScriptForge.SF_Utils._ValidateFile
947 REM -----------------------------------------------------------------------------
948 Public Function _VarTypeExt(ByRef pvValue As Variant) As Integer
949 &apos;&apos;&apos; Return the VarType of the argument but all numeric types are aggregated into V_NUMERIC
950 &apos;&apos;&apos; Args:
951 &apos;&apos;&apos; pvValue: value to examine
952 &apos;&apos;&apos; Return:
953 &apos;&apos;&apos; The extended VarType
955 Dim iType As Integer &apos; VarType of argument
957 iType = VarType(pvValue)
958 Select Case iType
959 Case V_INTEGER, V_LONG, V_SINGLE, V_DOUBLE, V_CURRENCY, V_BIGINT, V_DECIMAL
960 _VarTypeExt = V_NUMERIC
961 Case Else : _VarTypeExt = iType
962 End Select
964 End Function &apos; ScriptForge.SF_Utils._VarTypeExt
966 REM ================================================= END OF SCRIPTFORGE.SF_UTILS
967 </script:module>