calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / wizards / source / scriptforge / SF_Session.xba
blob2bde313194b15b5c1acc9dcd2569964437a16caf
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_Session" 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 Compatible
9 Option Explicit
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_Session
13 &apos;&apos;&apos; ==========
14 &apos;&apos;&apos; Singleton class implementing the &quot;ScriptForge.Session&quot; service
15 &apos;&apos;&apos; Implemented as a usual Basic module
16 &apos;&apos;&apos;
17 &apos;&apos;&apos; Gathers diverse general-purpose properties and methods about :
18 &apos;&apos;&apos; - installation/execution environment
19 &apos;&apos;&apos; - UNO introspection utilities
20 &apos;&apos;&apos; - clipboard management
21 &apos;&apos;&apos; - invocation of external scripts or programs
22 &apos;&apos;&apos;
23 &apos;&apos;&apos; Service invocation example:
24 &apos;&apos;&apos; Dim session As Variant
25 &apos;&apos;&apos; session = CreateScriptService(&quot;Session&quot;)
26 &apos;&apos;&apos;
27 &apos;&apos;&apos; Detailed user documentation:
28 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_session.html?DbPAR=BASIC
29 &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;
31 REM ================================================================== EXCEPTIONS
33 Const CALCFUNCERROR = &quot;CALCFUNCERROR&quot; &apos; Calc function execution failed
34 Const NOSCRIPTERROR = &quot;NOSCRIPTERROR&quot; &apos; Script could not be located
35 Const SCRIPTEXECERROR = &quot;SCRIPTEXECERROR&quot; &apos; Exception during script execution
36 Const WRONGEMAILERROR = &quot;WRONGEMAILERROR&quot; &apos; Wrong email address
37 Const SENDMAILERROR = &quot;SENDMAILERROR&quot; &apos; Mail could not be sent
38 Const UNKNOWNFILEERROR = &quot;UNKNOWNFILEERROR&quot; &apos; Source file does not exist
40 REM ============================================================ MODULE CONSTANTS
42 &apos;&apos;&apos; Script locations
43 &apos;&apos;&apos; ================
44 &apos;&apos;&apos; Use next constants as Scope argument when invoking next methods:
45 &apos;&apos;&apos; ExecuteBasicScript()
46 &apos;&apos;&apos; ExecutePythonScript()
47 &apos;&apos;&apos; Example:
48 &apos;&apos;&apos; session.ExecuteBasicScript(session.SCRIPTISEMBEDDED, &quot;Standard.myModule.myFunc&quot;, etc)
50 Const cstSCRIPTISEMBEDDED = &quot;document&quot; &apos; a library of the document (BASIC + PYTHON)
51 Const cstSCRIPTISAPPLICATION = &quot;application&quot; &apos; a shared library (BASIC)
52 Const cstSCRIPTISPERSONAL = &quot;user&quot; &apos; a library of My Macros (PYTHON)
53 Const cstSCRIPTISPERSOXT = &quot;user:uno_packages&quot; &apos; an extension for the current user (PYTHON)
54 Const cstSCRIPTISSHARED = &quot;share&quot; &apos; a library of LibreOffice Macros (PYTHON)
55 Const cstSCRIPTISSHAROXT = &quot;share:uno_packages&quot; &apos; an extension for all users (PYTHON)
56 Const cstSCRIPTISOXT = &quot;uno_packages&quot; &apos; an extension but install params are unknown (PYTHON)
58 &apos;&apos;&apos; To build or to parse scripting framework URI&apos;s
59 Const cstScript1 = &quot;vnd.sun.star.script:&quot;
60 Const cstScript2 = &quot;?language=&quot;
61 Const cstScript3 = &quot;&amp;location=&quot;
63 REM ===================================================== CONSTRUCTOR/DESTRUCTOR
65 REM -----------------------------------------------------------------------------
66 Public Function Dispose() As Variant
67 Set Dispose = Nothing
68 End Function &apos; ScriptForge.SF_Array Explicit destructor
70 REM ================================================================== PROPERTIES
72 REM -----------------------------------------------------------------------------
73 Property Get ObjectType As String
74 &apos;&apos;&apos; Only to enable object representation
75 ObjectType = &quot;SF_Session&quot;
76 End Property &apos; ScriptForge.SF_Session.ObjectType
78 REM -----------------------------------------------------------------------------
79 Property Get ServiceName As String
80 &apos;&apos;&apos; Internal use
81 ServiceName = &quot;ScriptForge.Session&quot;
82 End Property &apos; ScriptForge.SF_Array.ServiceName
84 REM -----------------------------------------------------------------------------
85 Property Get SCRIPTISAPPLICATION As String
86 &apos;&apos;&apos; Convenient constants
87 SCRIPTISAPPLICATION = cstSCRIPTISAPPLICATION
88 End Property &apos; ScriptForge.SF_Session.SCRIPTISAPPLICATION
90 REM -----------------------------------------------------------------------------
91 Property Get SCRIPTISEMBEDDED As String
92 &apos;&apos;&apos; Convenient constants
93 SCRIPTISEMBEDDED = cstSCRIPTISEMBEDDED
94 End Property &apos; ScriptForge.SF_Session.SCRIPTISEMBEDDED
96 REM -----------------------------------------------------------------------------
97 Property Get SCRIPTISOXT As String
98 &apos;&apos;&apos; Convenient constants
99 SCRIPTISOXT = cstSCRIPTISOXT
100 End Property &apos; ScriptForge.SF_Session.SCRIPTISOXT
102 REM -----------------------------------------------------------------------------
103 Property Get SCRIPTISPERSONAL As String
104 &apos;&apos;&apos; Convenient constants
105 SCRIPTISPERSONAL = cstSCRIPTISPERSONAL
106 End Property &apos; ScriptForge.SF_Session.SCRIPTISPERSONAL
108 REM -----------------------------------------------------------------------------
109 Property Get SCRIPTISPERSOXT As String
110 &apos;&apos;&apos; Convenient constants
111 SCRIPTISPERSOXT = cstSCRIPTISPERSOXT
112 End Property &apos; ScriptForge.SF_Session.SCRIPTISPERSOXT
114 REM -----------------------------------------------------------------------------
115 Property Get SCRIPTISSHARED As String
116 &apos;&apos;&apos; Convenient constants
117 SCRIPTISSHARED = cstSCRIPTISSHARED
118 End Property &apos; ScriptForge.SF_Session.SCRIPTISSHARED
120 REM -----------------------------------------------------------------------------
121 Property Get SCRIPTISSHAROXT As String
122 &apos;&apos;&apos; Convenient constants
123 SCRIPTISSHAROXT = cstSCRIPTISSHAROXT
124 End Property &apos; ScriptForge.SF_Session.SCRIPTISSHAROXT
126 REM ============================================================== PUBLIC METHODS
128 REM -----------------------------------------------------------------------------
129 Public Function ExecuteBasicScript(Optional ByVal Scope As Variant _
130 , Optional ByVal Script As Variant _
131 , ParamArray pvArgs As Variant _
132 ) As Variant
133 &apos;&apos;&apos; Execute the Basic script given as a string and return the value returned by the script
134 &apos;&apos;&apos; Args:
135 &apos;&apos;&apos; Scope: &quot;Application&quot; (default) or &quot;Document&quot; (NOT case-sensitive)
136 &apos;&apos;&apos; (or use one of the SCRIPTIS... public constants above)
137 &apos;&apos;&apos; Script: library.module.method (Case sensitive)
138 &apos;&apos;&apos; library =&gt; The library may be not loaded yet
139 &apos;&apos;&apos; module =&gt; Must not be a class module
140 &apos;&apos;&apos; method =&gt; Sub or Function
141 &apos;&apos;&apos; Read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
142 &apos;&apos;&apos; pvArgs: the arguments of the called script
143 &apos;&apos;&apos; Returns:
144 &apos;&apos;&apos; The value returned by the call to the script
145 &apos;&apos;&apos; Exceptions:
146 &apos;&apos;&apos; NOSCRIPTERROR The script could not be found
147 &apos;&apos;&apos; Examples:
148 &apos;&apos;&apos; session.ExecuteBasicScript(, &quot;XrayTool._Main.Xray&quot;, someuno) &apos; Sub: no return expected
150 Dim oScript As Object &apos; Script to be invoked
151 Dim vReturn As Variant &apos; Returned value
153 Const cstThisSub = &quot;Session.ExecuteBasicScript&quot;
154 Const cstSubArgs = &quot;[Scope], Script, arg0[, arg1] ...&quot;
156 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
158 vReturn = Empty
160 Check:
161 If IsMissing(Scope) Or IsEmpty(Scope) Then Scope = SCRIPTISAPPLICATION
162 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
163 If Not SF_Utils._Validate(Scope, &quot;Scope&quot;, V_STRING _
164 , Array(SCRIPTISAPPLICATION, SCRIPTISEMBEDDED)) Then GoTo Finally
165 If Not SF_Utils._Validate(Script, &quot;Script&quot;, V_STRING) Then GoTo Finally
166 End If
168 Try:
169 &apos; Execute script
170 Set oScript = SF_Session._GetScript(&quot;Basic&quot;, Scope, Script)
171 On Local Error GoTo CatchExec
172 If Not IsNull(oScript) Then vReturn = oScript.Invoke(pvArgs, Array(), Array())
174 Finally:
175 ExecuteBasicScript = vReturn
176 SF_Utils._ExitFunction(cstThisSub)
177 Exit Function
178 Catch:
179 GoTo Finally
180 CatchExec:
181 SF_Exception.RaiseFatal(SCRIPTEXECERROR, &quot;Script&quot;, Script, Error$)
182 GoTo Finally
183 End Function &apos; ScriptForge.SF_Session.ExecuteBasicScript
185 REM -----------------------------------------------------------------------------
186 Public Function ExecuteCalcFunction(Optional ByVal CalcFunction As Variant _
187 , ParamArray pvArgs As Variant _
188 ) As Variant
189 &apos;&apos;&apos; Execute a Calc function by its (english) name and based on the given arguments
190 &apos;&apos;&apos; Args:
191 &apos;&apos;&apos; CalcFunction: the english name of the function to execute
192 &apos;&apos;&apos; pvArgs: the arguments of the called function
193 &apos;&apos;&apos; Each argument must be either a string, a numeric value
194 &apos;&apos;&apos; or an array of arrays combining those types
195 &apos;&apos;&apos; Returns:
196 &apos;&apos;&apos; The (string or numeric) value or the array of arrays returned by the call to the function
197 &apos;&apos;&apos; When the arguments contain arrays, the function is executed as an array function
198 &apos;&apos;&apos; Wrong arguments generate an error
199 &apos;&apos;&apos; Exceptions:
200 &apos;&apos;&apos; CALCFUNCERROR &apos; Execution error in calc function
201 &apos;&apos;&apos; Examples:
202 &apos;&apos;&apos; session.ExecuteCalcFunction(&quot;AVERAGE&quot;, 1, 5, 3, 7) returns 4
203 &apos;&apos;&apos; session.ExecuteCalcFunction(&quot;ABS&quot;, Array(Array(-1,2,3),Array(4,-5,6),Array(7,8,-9)))(2)(2) returns 9
204 &apos;&apos;&apos; session.ExecuteCalcFunction(&quot;LN&quot;, -3) generates an error
206 Dim oCalc As Object &apos; Give access to the com.sun.star.sheet.FunctionAccess service
207 Dim vReturn As Variant &apos; Returned value
208 Const cstThisSub = &quot;Session.ExecuteCalcFunction&quot;
209 Const cstSubArgs = &quot;CalcFunction, arg0[, arg1] ...&quot;
211 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
212 vReturn = Empty
214 Check:
215 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
216 If Not SF_Utils._Validate(CalcFunction, &quot;CalcFunction&quot;, V_STRING) Then GoTo Finally
217 End If
219 Try:
220 &apos; Execute function
221 Set oCalc = SF_Utils._GetUNOService(&quot;FunctionAccess&quot;)
222 &apos; Intercept calls from Python when no arguments. Example NOW()
223 If UBound(pvArgs) = 0 Then
224 If IsEmpty(pvArgs(0)) Then pvArgs = Array()
225 End If
226 On Local Error GoTo CatchCall
227 vReturn = oCalc.callFunction(UCase(CalcFunction), pvArgs())
229 Finally:
230 ExecuteCalcFunction = vReturn
231 SF_Utils._ExitFunction(cstThisSub)
232 Exit Function
233 Catch:
234 GoTo Finally
235 CatchCall:
236 SF_Exception.RaiseFatal(CALCFUNCERROR, CalcFunction)
237 GoTo Finally
238 End Function &apos; ScriptForge.SF_Session.ExecuteCalcFunction
240 REM -----------------------------------------------------------------------------
241 Public Function ExecutePythonScript(Optional ByVal Scope As Variant _
242 , Optional ByVal Script As Variant _
243 , ParamArray pvArgs As Variant _
244 ) As Variant
245 &apos;&apos;&apos; Execute the Python script given as a string and return the value returned by the script
246 &apos;&apos;&apos; Args:
247 &apos;&apos;&apos; Scope: one of the SCRIPTIS... public constants above (default = &quot;share&quot;)
248 &apos;&apos;&apos; Script: (Case sensitive)
249 &apos;&apos;&apos; &quot;library/module.py$method&quot;
250 &apos;&apos;&apos; or &quot;module.py$method&quot;
251 &apos;&apos;&apos; or &quot;myExtension.oxt|myScript|module.py$method&quot;
252 &apos;&apos;&apos; library =&gt; The library may be not loaded yet
253 &apos;&apos;&apos; myScript =&gt; The directory containing the python module
254 &apos;&apos;&apos; module.py =&gt; The python module
255 &apos;&apos;&apos; method =&gt; The python function
256 &apos;&apos;&apos; Read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
257 &apos;&apos;&apos; pvArgs: the arguments of the called script
258 &apos;&apos;&apos; Date arguments are converted to iso format. However dates in arrays are not converted
259 &apos;&apos;&apos; Returns:
260 &apos;&apos;&apos; The value(s) returned by the call to the script. If &gt;1 values, enclosed in an array
261 &apos;&apos;&apos; Exceptions:
262 &apos;&apos;&apos; NOSCRIPTERROR The script could not be found
263 &apos;&apos;&apos; Examples:
264 &apos;&apos;&apos; session.ExecutePythonScript(session.SCRIPTISSHARED, &quot;Capitalise.py$getNewString&quot;, &quot;Abc&quot;) returns &quot;abc&quot;
266 Dim oScript As Object &apos; Script to be invoked
267 Dim vArg As Variant &apos; Individual argument
268 Dim vReturn As Variant &apos; Returned value
269 Dim i As Long
271 Const cstThisSub = &quot;Session.ExecutePythonScript&quot;
272 Const cstSubArgs = &quot;[Scope], Script, arg0[, arg1] ...&quot;
274 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
276 vReturn = Empty
278 Check:
279 If IsError(Scope) Or IsMissing(Scope) Then Scope = SCRIPTISSHARED
280 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
281 If Not SF_Utils._Validate(Scope, &quot;Scope&quot;, V_STRING _
282 , Array(SCRIPTISSHARED, SCRIPTISEMBEDDED, SCRIPTISPERSONAL, SCRIPTISSHAROXT, SCRIPTISPERSOXT, SCRIPTISOXT) _
283 ) Then GoTo Finally
284 If Not SF_Utils._Validate(Script, &quot;Script&quot;, V_STRING) Then GoTo Finally
285 End If
287 Try:
288 &apos; Filter date arguments - NB: dates in arrays are not filtered
289 For i = 0 To UBound(pvArgs) &apos; pvArgs always zero-based
290 vArg = pvArgs(i)
291 If VarType(vArg) = V_DATE Then pvArgs(i) = SF_Utils._CDateToIso(vArg)
292 Next i
294 &apos; Intercept alternate Python helpers file when relevant
295 With _SF_
296 If SF_String.StartsWith(Script, .PythonHelper) And Len(.PythonHelper2) &gt; 0 Then
297 Scope = SCRIPTISPERSONAL
298 Script = .PythonHelper2 &amp; Mid(Script, Len(.PythonHelper) + 1)
299 End If
300 End With
301 &apos; Find script
302 Set oScript = SF_Session._GetScript(&quot;Python&quot;, Scope, Script)
304 &apos; Execute script
305 If Not IsNull(oScript) Then
306 vReturn = oScript.Invoke(pvArgs(), Array(), Array())
307 &apos; Remove surrounding array when single returned value
308 If IsArray(vReturn) Then
309 If UBound(vReturn) = 0 Then vReturn = vReturn(0)
310 End If
311 End If
313 Finally:
314 ExecutePythonScript = vReturn
315 SF_Utils._ExitFunction(cstThisSub)
316 Exit Function
317 Catch:
318 GoTo Finally
319 End Function &apos; ScriptForge.SF_Session.ExecutePythonScript
321 REM -----------------------------------------------------------------------------
322 Public Function GetPDFExportOptions() As Variant
323 &apos;&apos;&apos; Return the actual values of the PDF export options
324 &apos;&apos;&apos; The PDF options are described on https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export
325 &apos;&apos;&apos; PDF options are set at each use of the Export as ... PDF command by the user and kept
326 &apos;&apos;&apos; permanently until their reset by script or by a new export
327 &apos;&apos;&apos; Args:
328 &apos;&apos;&apos; Returns:
329 &apos;&apos;&apos; A ScriptForge dictionary instance listing the 40+ properties and their value
330 &apos;&apos;&apos; Examples:
331 &apos;&apos;&apos; Dim dict As Object
332 &apos;&apos;&apos; Set dict = session.GetPDFExportOptions()
333 &apos;&apos;&apos; MsgBox dict.Item(&quot;Quality&quot;)
335 Dim vDict As Variant &apos; Returned value
336 Dim oConfig As Object &apos; com.sun.star.configuration.ConfigurationProvider
337 Dim oNodePath As Object &apos; com.sun.star.beans.PropertyValue
338 Dim oOptions As Object &apos; configmgr.RootAccess
339 Dim vOptionNames As Variant &apos; Array of PDF options names
340 Dim vOptionValues As Variant &apos; Array of PDF options values
341 Dim i As Long
343 Const cstThisSub = &quot;Session.GetPDFExportOptions&quot;
344 Const cstSubArgs = &quot;&quot;
346 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
347 Set vDict = Nothing
349 Check:
350 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
352 Try:
353 &apos; Get the (read-only) internal PDF options
354 Set oConfig = SF_Utils._GetUNOService(&quot;ConfigurationProvider&quot;)
355 Set oNodePath = SF_Utils._MakePropertyValue(&quot;nodepath&quot;, &quot;/org.openoffice.Office.Common/Filter/PDF/Export/&quot;)
356 Set oOptions = oConfig.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, Array(oNodePath))
358 &apos; Copy the options into a ScriptForge dictionary
359 Set vDict = CreateScriptService(&quot;dictionary&quot;)
360 vOptionNames = oOptions.getElementNames()
361 vOptionValues = oOptions.getPropertyValues(vOptionNames)
362 &apos;
363 For i = 0 To UBound(vOptionNames)
364 vDict.Add(vOptionNames(i), vOptionValues(i))
365 Next i
368 Finally:
369 GetPDFExportOptions = vDict
370 SF_Utils._ExitFunction(cstThisSub)
371 Exit Function
372 Catch:
373 GoTo Finally
374 End Function &apos; ScriptForge.SF_Session.GetPDFExportOptions
376 REM -----------------------------------------------------------------------------
377 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
378 &apos;&apos;&apos; Return the actual value of the given property
379 &apos;&apos;&apos; Args:
380 &apos;&apos;&apos; PropertyName: the name of the property as a string
381 &apos;&apos;&apos; Returns:
382 &apos;&apos;&apos; The actual value of the property
383 &apos;&apos;&apos; Exceptions
384 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
386 Const cstThisSub = &quot;Session.GetProperty&quot;
387 Const cstSubArgs = &quot;PropertyName&quot;
389 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
390 GetProperty = Null
392 Check:
393 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
394 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
395 End If
397 Try:
398 Select Case UCase(PropertyName)
399 Case Else
400 End Select
402 Finally:
403 SF_Utils._ExitFunction(cstThisSub)
404 Exit Function
405 Catch:
406 GoTo Finally
407 End Function &apos; ScriptForge.SF_Session.GetProperty
409 REM -----------------------------------------------------------------------------
410 Public Function HasUnoMethod(Optional ByRef UnoObject As Variant _
411 , Optional ByVal MethodName As Variant _
412 ) As Boolean
413 &apos;&apos;&apos; Returns True if a UNO object contains the given method
414 &apos;&apos;&apos; Code-snippet derived from XRAY
415 &apos;&apos;&apos; Args:
416 &apos;&apos;&apos; UnoObject: the object to identify
417 &apos;&apos;&apos; MethodName: the name of the method as a string. The search is case-sensitive
418 &apos;&apos;&apos; Returns:
419 &apos;&apos;&apos; False when the method is not found or when an argument is invalid
421 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
422 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
423 Dim bMethod As Boolean &apos; Return value
424 Const cstThisSub = &quot;Session.HasUnoMethod&quot;
425 Const cstSubArgs = &quot;UnoObject, MethodName&quot;
427 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
429 Check:
430 bMethod = False
431 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
432 If IsNull(UnoObject) Then GoTo Finally
433 If VarType(MethodName) &lt;&gt; V_STRING Then GoTo Finally
434 If MethodName = Space(Len(MethodName)) Then GoTo Finally
436 Try:
437 On Local Error GoTo Catch
438 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
439 Set oInspect = oIntrospect.inspect(UnoObject)
440 bMethod = oInspect.hasMethod(MethodName, com.sun.star.beans.MethodConcept.ALL)
442 Finally:
443 HasUnoMethod = bMethod
444 SF_Utils._ExitFunction(cstThisSub)
445 Exit Function
446 Catch:
447 On Local Error GoTo 0
448 GoTo Finally
449 End Function &apos; ScriptForge.SF_Session.HasUnoMethod
451 REM -----------------------------------------------------------------------------
452 Public Function HasUnoProperty(Optional ByRef UnoObject As Variant _
453 , Optional ByVal PropertyName As Variant _
454 ) As Boolean
455 &apos;&apos;&apos; Returns True if a UNO object contains the given property
456 &apos;&apos;&apos; Code-snippet derived from XRAY
457 &apos;&apos;&apos; Args:
458 &apos;&apos;&apos; UnoObject: the object to identify
459 &apos;&apos;&apos; PropertyName: the name of the property as a string. The search is case-sensitive
460 &apos;&apos;&apos; Returns:
461 &apos;&apos;&apos; False when the property is not found or when an argument is invalid
463 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
464 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
465 Dim bProperty As Boolean &apos; Return value
466 Const cstThisSub = &quot;Session.HasUnoProperty&quot;
467 Const cstSubArgs = &quot;UnoObject, PropertyName&quot;
469 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
471 Check:
472 bProperty = False
473 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
474 If IsNull(UnoObject) Then GoTo Finally
475 If VarType(PropertyName) &lt;&gt; V_STRING Then GoTo Finally
476 If PropertyName = Space(Len(PropertyName)) Then GoTo Finally
478 Try:
479 On Local Error GoTo Catch
480 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
481 Set oInspect = oIntrospect.inspect(UnoObject)
482 bProperty = oInspect.hasProperty(PropertyName, com.sun.star.beans.PropertyConcept.ALL)
484 Finally:
485 HasUnoProperty = bProperty
486 SF_Utils._ExitFunction(cstThisSub)
487 Exit Function
488 Catch:
489 On Local Error GoTo 0
490 GoTo Finally
491 End Function &apos; ScriptForge.SF_Session.HasUnoProperty
493 REM -----------------------------------------------------------------------------
494 Public Function Methods() As Variant
495 &apos;&apos;&apos; Return the list of public methods of the Session service as an array
497 Methods = Array( _
498 &quot;ExecuteBasicScript&quot; _
499 , &quot;ExecuteCalcFunction&quot; _
500 , &quot;ExecutePythonScript&quot; _
501 , &quot;HasUnoMethod&quot; _
502 , &quot;HasUnoProperty&quot; _
503 , &quot;OpenURLInBrowser&quot; _
504 , &quot;RunApplication&quot; _
505 , &quot;SendMail&quot; _
506 , &quot;UnoMethods&quot; _
507 , &quot;UnoObjectType&quot; _
508 , &quot;UnoProperties&quot; _
509 , &quot;WebService&quot; _
512 End Function &apos; ScriptForge.SF_Session.Methods
514 REM -----------------------------------------------------------------------------
515 Public Sub OpenURLInBrowser(Optional ByVal URL As Variant)
516 &apos;&apos;&apos; Opens a URL in the default browser
517 &apos;&apos;&apos; Args:
518 &apos;&apos;&apos; URL: The URL to open in the browser
519 &apos;&apos;&apos; Examples:
520 &apos;&apos;&apos; session.OpenURLInBrowser(&quot;https://docs.python.org/3/library/webbrowser.html&quot;)
522 Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Session__OpenURLInBrowser&quot;
524 Const cstThisSub = &quot;Session.OpenURLInBrowser&quot;
525 Const cstSubArgs = &quot;URL&quot;
527 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
529 Check:
530 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
531 If Not SF_Utils._Validate(URL, &quot;URL&quot;, V_STRING) Then GoTo Finally
532 End If
534 Try:
535 ExecutePythonScript(SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper, URL)
537 Finally:
538 SF_Utils._ExitFunction(cstThisSub)
539 Exit Sub
540 Catch:
541 GoTo Finally
542 End Sub &apos; ScriptForge.SF_Session.OpenURLInBrowser
544 REM -----------------------------------------------------------------------------
545 Public Function Properties() As Variant
546 &apos;&apos;&apos; Return the list or properties as an array
548 Properties = Array( _
551 End Function &apos; ScriptForge.SF_Session.Properties
553 REM -----------------------------------------------------------------------------
554 Public Function RunApplication(Optional ByVal Command As Variant _
555 , Optional ByVal Parameters As Variant _
556 ) As Boolean
557 &apos;&apos;&apos; Executes an arbitrary system command
558 &apos;&apos;&apos; Args:
559 &apos;&apos;&apos; Command: The command to execute
560 &apos;&apos;&apos; This may be an executable file or a document which is registered with an application
561 &apos;&apos;&apos; so that the system knows what application to launch for that document
562 &apos;&apos;&apos; Parameters: a list of space separated parameters as a single string
563 &apos;&apos;&apos; The method does not validate the given parameters, but only passes them to the specified command
564 &apos;&apos;&apos; Returns:
565 &apos;&apos;&apos; True if success
566 &apos;&apos;&apos; Examples:
567 &apos;&apos;&apos; session.RunApplication(&quot;Notepad.exe&quot;)
568 &apos;&apos;&apos; session.RunApplication(&quot;C:\myFolder\myDocument.odt&quot;)
569 &apos;&apos;&apos; session.RunApplication(&quot;kate&quot;, &quot;/home/me/install.txt&quot;) &apos; (Linux)
571 Dim bReturn As Boolean &apos; Returned value
572 Dim oShell As Object &apos; com.sun.star.system.SystemShellExecute
573 Dim sCommand As String &apos; Command as an URL
574 Const cstThisSub = &quot;Session.RunApplication&quot;
575 Const cstSubArgs = &quot;Command, [Parameters]&quot;
577 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
578 bReturn = False
580 Check:
581 If IsMissing(Parameters) Then Parameters = &quot;&quot;
582 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
583 If Not SF_Utils._ValidateFile(Command, &quot;Command&quot;) Then GoTo Finally
584 If Not SF_Utils._Validate(Parameters, &quot;Parameters&quot;, V_STRING) Then GoTo Finally
585 End If
587 Try:
588 Set oShell = SF_Utils._GetUNOService(&quot;SystemShellExecute&quot;)
589 sCommand = SF_FileSystem._ConvertToUrl(Command)
590 oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.URIS_ONLY)
591 bReturn = True
593 Finally:
594 RunApplication = bReturn
595 SF_Utils._ExitFunction(cstThisSub)
596 Exit Function
597 Catch:
598 GoTo Finally
599 End Function &apos; ScriptForge.SF_Session.RunApplication
601 REM -----------------------------------------------------------------------------
602 Public Sub SendMail(Optional ByVal Recipient As Variant _
603 , Optional ByRef Cc As Variant _
604 , Optional ByRef Bcc As Variant _
605 , Optional ByVal Subject As Variant _
606 , Optional ByRef Body As Variant _
607 , Optional ByVal FileNames As Variant _
608 , Optional ByVal EditMessage As Variant _
610 &apos;&apos;&apos; Send a message (with or without attachments) to recipients from the user&apos;s mail client
611 &apos;&apos;&apos; The message may be edited by the user before sending or, alternatively, be sent immediately
612 &apos;&apos;&apos; Args:
613 &apos;&apos;&apos; Recipient: an email addresses (To recipient)
614 &apos;&apos;&apos; Cc: a comma-delimited list of email addresses (carbon copy)
615 &apos;&apos;&apos; Bcc: a comma-delimited list of email addresses (blind carbon copy)
616 &apos;&apos;&apos; Subject: the header of the message
617 &apos;&apos;&apos; FileNames: a comma-separated list of filenames to attach to the mail. SF_FileSystem naming conventions apply
618 &apos;&apos;&apos; Body: the unformatted text of the message
619 &apos;&apos;&apos; EditMessage: when True (default) the message is editable before being sent
620 &apos;&apos;&apos; Exceptions:
621 &apos;&apos;&apos; UNKNOWNFILEERROR File does not exist
622 &apos;&apos;&apos; WRONGEMAILERROR String not recognized as an email address
623 &apos;&apos;&apos; SENDMAILERROR System error, probably no mail client
625 Dim sEmail As String &apos; An single email address
626 Dim sFile As String &apos; A single file name
627 Dim sArg As String &apos; Argument name
628 Dim vCc As Variant &apos; Array alias of Cc
629 Dim vBcc As Variant &apos; Array alias of Bcc
630 Dim vFileNames As Variant &apos; Array alias of FileNames
631 Dim oMailService As Object &apos; com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
632 Dim oMail As Object &apos; com.sun.star.system.XSimpleMailClient
633 Dim oMessage As Object &apos; com.sun.star.system.XSimpleMailMessage
634 Dim lFlag As Long &apos; com.sun.star.system.SimpleMailClientFlags.XXX
635 Dim ARR As Object : ARR = ScriptForge.SF_Array
636 Dim i As Long
637 Const cstComma = &quot;,&quot;, cstSemiColon = &quot;;&quot;
638 Const cstThisSub = &quot;Session.SendMail&quot;
639 Const cstSubArgs = &quot;Recipient, [Cc=&quot;&quot;&quot;&quot;], [Bcc=&quot;&quot;&quot;&quot;], [Subject=&quot;&quot;&quot;&quot;], [FileNames=&quot;&quot;&quot;&quot;], [Body=&quot;&quot;&quot;&quot;], [EditMessage=True]&quot;
641 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
643 Check:
644 If IsMissing(Cc) Or IsEmpty(Cc) Then Cc = &quot;&quot;
645 If IsMissing(Bcc) Or IsEmpty(Bcc) Then Bcc = &quot;&quot;
646 If IsMissing(Subject) Or IsEmpty(Subject) Then Subject = &quot;&quot;
647 If IsMissing(FileNames) Or IsEmpty(FileNames) Then FileNames = &quot;&quot;
648 If IsMissing(Body) Or IsEmpty(Body) Then Body = &quot;&quot;
649 If IsMissing(EditMessage) Or IsEmpty(EditMessage) Then EditMessage = True
651 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
652 If Not SF_Utils._Validate(Cc, &quot;Recipient&quot;, V_STRING) Then GoTo Finally
653 If Not SF_Utils._Validate(Cc, &quot;Cc&quot;, V_STRING) Then GoTo Finally
654 If Not SF_Utils._Validate(Bcc, &quot;Bcc&quot;, V_STRING) Then GoTo Finally
655 If Not SF_Utils._Validate(Subject, &quot;Subject&quot;, V_STRING) Then GoTo Finally
656 If Not SF_Utils._Validate(FileNames, &quot;FileNames&quot;, V_STRING) Then GoTo Finally
657 If Not SF_Utils._Validate(Body, &quot;Body&quot;, V_STRING) Then GoTo Finally
658 If Not SF_Utils._Validate(EditMessage, &quot;EditMessage&quot;, V_BOOLEAN) Then GoTo Finally
659 End If
661 &apos; Check email addresses
662 sArg = &quot;Recipient&quot; : sEmail = Recipient
663 If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
664 sArg = &quot;Cc&quot; : vCc = ARR.TrimArray(Split(Cc, cstComma))
665 For Each sEmail In vCc
666 If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
667 Next sEmail
668 sArg = &quot;Bcc&quot; : vBcc = ARR.TrimArray(Split(Bcc, cstComma))
669 For Each sEmail In vBcc
670 If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
671 Next sEmail
673 &apos; Check file existence
674 If Len(FileNames) &gt; 0 Then
675 vFileNames = ARR.TrimArray(Split(FileNames, cstComma))
676 For i = 0 To UBound(vFileNames)
677 sFile = vFileNames(i)
678 If Not SF_Utils._ValidateFile(sFile, &quot;FileNames&quot;) Then GoTo Finally
679 If Not SF_FileSystem.FileExists(sFile) Then GoTo CatchNotExists
680 vFileNames(i) = ConvertToUrl(sFile)
681 Next i
682 Else
683 vFileNames = Array()
684 End If
686 Try:
687 &apos; Initialize the mail service
688 Set oMailService = SF_Utils._GetUNOService(&quot;MailService&quot;)
689 If IsNull(oMailService) Then GoTo CatchMail
690 Set oMail = oMailService.querySimpleMailClient()
691 If IsNull(oMail) Then GoTo CatchMail
692 Set oMessage = oMail.createSimpleMailMessage()
693 If IsNull(oMessage) Then GoTo CatchMail
695 &apos; Feed the new mail message
696 With oMessage
697 .setRecipient(Recipient)
698 If Subject &lt;&gt; &quot;&quot; Then .setSubject(Subject)
699 If UBound(vCc) &gt;= 0 Then .setCcRecipient(vCc)
700 If UBound(vBcc) &gt;= 0 Then .setBccRecipient(vBcc)
701 .Body = Iif(Len(Body) = 0, &quot; &quot;, Body) &apos; Body must not be the empty string ??
702 .setAttachement(vFileNames)
703 End With
704 lFlag = Iif(EditMessage, com.sun.star.system.SimpleMailClientFlags.DEFAULTS, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE)
706 &apos; Send using the mail service
707 oMail.sendSimpleMailMessage(oMessage, lFlag)
709 Finally:
710 SF_Utils._ExitFunction(cstThisSub)
711 Exit Sub
712 Catch:
713 GoTo Finally
714 CatchEmail:
715 SF_Exception.RaiseFatal(WRONGEMAILERROR, sArg, sEmail)
716 GoTo Finally
717 CatchNotExists:
718 SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileNames&quot;, sFile)
719 GoTo Finally
720 CatchMail:
721 SF_Exception.RaiseFatal(SENDMAILERROR)
722 GoTo Finally
723 End Sub &apos; ScriptForge.SF_Session.SendMail
725 REM -----------------------------------------------------------------------------
726 Public Function SetPDFExportOptions(Optional ByRef PDFOptions As Variant) As Boolean
727 &apos;&apos;&apos; Modify the actual values of the PDF export options from an options dictionary
728 &apos;&apos;&apos; The PDF options are described on https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export
729 &apos;&apos;&apos; PDF options are set at each use of the Export as ... PDF command by the user and kept
730 &apos;&apos;&apos; permanently until their reset by script (like this one) or by a new export
731 &apos;&apos;&apos; The changed options are applicable on any subsequent ExportToPDF user command or to any SaveAsPDF script execution
732 &apos;&apos;&apos; Args:
733 &apos;&apos;&apos; PDFOptions: a ScriptForge dictionary object
734 &apos;&apos;&apos; Returns:
735 &apos;&apos;&apos; True when successful
736 &apos;&apos;&apos; Examples:
737 &apos;&apos;&apos; Dim dict As Object
738 &apos;&apos;&apos; Set dict = session.GetPDFExportOptions()
739 &apos;&apos;&apos; dict.ReplaceItem(&quot;Quality&quot;, 50)
740 &apos;&apos;&apos; session.SetPDFExportOptions(dict)
742 Dim bSetPDF As Boolean &apos; Returned value
743 Dim oConfig As Object &apos; com.sun.star.configuration.ConfigurationProvider
744 Dim oNodePath As Object &apos; com.sun.star.beans.PropertyValue
745 Dim oOptions As Object &apos; configmgr.RootAccess
746 Dim vOptionNames As Variant &apos; Array of PDF options names
747 Dim vOptionValues As Variant &apos; Array of PDF options values
748 Dim oDict As Object &apos; Alias of PDFOptions
749 Dim i As Long
751 Const cstThisSub = &quot;Session.SetPDFExportOptions&quot;
752 Const cstSubArgs = &quot;PDFOptions&quot;
754 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
755 bSetPDF = False
757 Check:
758 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
759 If Not SF_Utils._Validate(PDFOptions, &quot;PDFOptions&quot;, V_OBJECT, , , &quot;DICTIONARY&quot;) Then GoTo Finally
760 End If
762 Try:
763 &apos; Get the (updatable) internal PDF options
764 Set oConfig = SF_Utils._GetUNOService(&quot;ConfigurationProvider&quot;)
765 Set oNodePath = SF_Utils._MakePropertyValue(&quot;nodepath&quot;, &quot;/org.openoffice.Office.Common/Filter/PDF/Export/&quot;)
766 Set oOptions = oConfig.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;, Array(oNodePath))
768 &apos; Copy the options from the ScriptForge dictionary in argument to property values
769 Set oDict = PDFOptions
770 oOptions.setPropertyValues(oDict.Keys, oDict.Items)
771 oOptions.commitChanges()
773 bSetPDF = True
775 Finally:
776 SetPDFExportOptions = bSetPDF
777 SF_Utils._ExitFunction(cstThisSub)
778 Exit Function
779 Catch:
780 GoTo Finally
781 End Function &apos; ScriptForge.SF_Session.SetPDFExportOptions
783 REM -----------------------------------------------------------------------------
784 Public Function SetProperty(Optional ByVal PropertyName As Variant _
785 , Optional ByRef Value As Variant _
786 ) As Boolean
787 &apos;&apos;&apos; Set a new value to the given property
788 &apos;&apos;&apos; Args:
789 &apos;&apos;&apos; PropertyName: the name of the property as a string
790 &apos;&apos;&apos; Value: its new value
791 &apos;&apos;&apos; Exceptions
792 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
794 Const cstThisSub = &quot;Session.SetProperty&quot;
795 Const cstSubArgs = &quot;PropertyName, Value&quot;
797 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
798 SetProperty = False
800 Check:
801 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
802 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
803 End If
805 Try:
806 Select Case UCase(PropertyName)
807 Case Else
808 End Select
810 Finally:
811 SF_Utils._ExitFunction(cstThisSub)
812 Exit Function
813 Catch:
814 GoTo Finally
815 End Function &apos; ScriptForge.SF_Session.SetProperty
817 REM -----------------------------------------------------------------------------
818 Public Function UnoMethods(Optional ByRef UnoObject As Variant) As Variant
819 &apos;&apos;&apos; Returns a list of the methods callable from an UNO object
820 &apos;&apos;&apos; Code-snippet derived from XRAY
821 &apos;&apos;&apos; Args:
822 &apos;&apos;&apos; UnoObject: the object to identify
823 &apos;&apos;&apos; Returns:
824 &apos;&apos;&apos; A zero-based sorted array. May be empty
826 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
827 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
828 Dim vMethods As Variant &apos; Array of com.sun.star.reflection.XIdlMethod
829 Dim vMethod As Object &apos; com.sun.star.reflection.XIdlMethod
830 Dim lMax As Long &apos; UBounf of vMethods
831 Dim vMethodsList As Variant &apos; Return value
832 Dim i As Long
833 Const cstThisSub = &quot;Session.UnoMethods&quot;
834 Const cstSubArgs = &quot;UnoObject&quot;
836 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
838 Check:
839 vMethodsList = Array()
840 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
841 If IsNull(UnoObject) Then GoTo Finally
843 Try:
844 On Local Error GoTo Catch
845 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
846 Set oInspect = oIntrospect.inspect(UnoObject)
847 vMethods = oInspect.getMethods(com.sun.star.beans.MethodConcept.ALL)
849 &apos; The names must be extracted from com.sun.star.reflection.XIdlMethod structures
850 lMax = UBound(vMethods)
851 If lMax &gt;= 0 Then
852 ReDim vMethodsList(0 To lMax)
853 For i = 0 To lMax
854 vMethodsList(i) = vMethods(i).Name
855 Next i
856 vMethodsList = SF_Array.Sort(vMethodsList, CaseSensitive := True)
857 End If
859 Finally:
860 UnoMethods = vMethodsList
861 SF_Utils._ExitFunction(cstThisSub)
862 Exit Function
863 Catch:
864 On Local Error GoTo 0
865 GoTo Finally
866 End Function &apos; ScriptForge.SF_Session.UnoMethods
868 REM -----------------------------------------------------------------------------
869 Public Function UnoObjectType(Optional ByRef UnoObject As Variant) As String
870 &apos;&apos;&apos; Identify the UNO type of an UNO object
871 &apos;&apos;&apos; Code-snippet derived from XRAY
872 &apos;&apos;&apos; Args:
873 &apos;&apos;&apos; UnoObject: the object to identify
874 &apos;&apos;&apos; Returns:
875 &apos;&apos;&apos; com.sun.star. ... as a string
876 &apos;&apos;&apos; a zero-length string if identification was not successful
878 Dim oObjDesc As Object &apos; _ObjectDescriptor type
879 Dim sObjectType As String &apos; Return value
880 Const cstThisSub = &quot;Session.UnoObjectType&quot;
881 Const cstSubArgs = &quot;UnoObject&quot;
883 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
885 Check:
886 sObjectType = &quot;&quot;
887 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
888 If IsNull(UnoObject) Then GoTo Finally
890 Try:
891 Set oObjDesc = SF_Utils._VarTypeObj(UnoObject)
892 If oObjDesc.iVarType = V_UNOOBJECT Then sObjectType = oObjDesc.sObjectType
894 Finally:
895 UnoObjectType = sObjectType
896 SF_Utils._ExitFunction(cstThisSub)
897 Exit Function
898 End Function &apos; ScriptForge.SF_Session.UnoObjectType
900 REM -----------------------------------------------------------------------------
901 Public Function UnoProperties(Optional ByRef UnoObject As Variant) As Variant
902 &apos;&apos;&apos; Returns a list of the properties of an UNO object
903 &apos;&apos;&apos; Code-snippet derived from XRAY
904 &apos;&apos;&apos; Args:
905 &apos;&apos;&apos; UnoObject: the object to identify
906 &apos;&apos;&apos; Returns:
907 &apos;&apos;&apos; A zero-based sorted array. May be empty
909 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
910 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
911 Dim vProperties As Variant &apos; Array of com.sun.star.beans.Property
912 Dim vProperty As Object &apos; com.sun.star.beans.Property
913 Dim lMax As Long &apos; UBounf of vProperties
914 Dim vPropertiesList As Variant &apos; Return value
915 Dim i As Long
916 Const cstThisSub = &quot;Session.UnoProperties&quot;
917 Const cstSubArgs = &quot;UnoObject&quot;
919 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
921 Check:
922 vPropertiesList = Array()
923 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
924 If IsNull(UnoObject) Then GoTo Finally
926 Try:
927 On Local Error GoTo Catch
928 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
929 Set oInspect = oIntrospect.inspect(UnoObject)
930 vProperties = oInspect.getProperties(com.sun.star.beans.PropertyConcept.ALL)
932 &apos; The names must be extracted from com.sun.star.beans.Property structures
933 lMax = UBound(vProperties)
934 If lMax &gt;= 0 Then
935 ReDim vPropertiesList(0 To lMax)
936 For i = 0 To lMax
937 vPropertiesList(i) = vProperties(i).Name
938 Next i
939 vPropertiesList = SF_Array.Sort(vPropertiesList, CaseSensitive := True)
940 End If
942 Finally:
943 UnoProperties = vPropertiesList
944 SF_Utils._ExitFunction(cstThisSub)
945 Exit Function
946 Catch:
947 On Local Error GoTo 0
948 GoTo Finally
949 End Function &apos; ScriptForge.SF_Session.UnoProperties
951 REM -----------------------------------------------------------------------------
952 Public Function WebService(Optional ByVal URI As Variant) As String
953 &apos;&apos;&apos; Get some web content from a URI
954 &apos;&apos;&apos; Args:
955 &apos;&apos;&apos; URI: URI text of the web service
956 &apos;&apos;&apos; Returns:
957 &apos;&apos;&apos; The web page content of the URI
958 &apos;&apos;&apos; Exceptions:
959 &apos;&apos;&apos; CALCFUNCERROR
960 &apos;&apos;&apos; Examples:
961 &apos;&apos;&apos; session.WebService(&quot;wiki.documentfoundation.org/api.php?&quot; _
962 &apos;&apos;&apos; &amp; &quot;hidebots=1&amp;days=7&amp;limit=50&amp;action=feedrecentchanges&amp;feedformat=rss&quot;)
964 Dim sReturn As String &apos; Returned value
965 Const cstThisSub = &quot;Session.WebService&quot;
966 Const cstSubArgs = &quot;URI&quot;
968 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
969 sReturn = &quot;&quot;
971 Check:
972 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
973 If Not SF_Utils._Validate(URI, &quot;URI&quot;, V_STRING) Then GoTo Finally
974 End If
976 Try:
977 sReturn = SF_Session.ExecuteCalcFunction(&quot;WEBSERVICE&quot;, URI)
979 Finally:
980 WebService = sReturn
981 SF_Utils._ExitFunction(cstThisSub)
982 Exit Function
983 Catch:
984 GoTo Finally
985 End Function &apos; ScriptForge.SF_Session.WebService
987 REM =========================================================== PRIVATE FUNCTIONS
989 REM -----------------------------------------------------------------------------
990 Private Function _ExecuteScript(ByVal psScript As String _
991 , Optional ByRef pvArg As Variant _
992 ) As Variant
993 &apos;&apos;&apos; Execute the script expressed in the scripting framework_URI notation
994 &apos;&apos;&apos; Args:
995 &apos;&apos;&apos; psScript: read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
996 &apos;&apos;&apos; pvArg: the unique argument to pass to the called script.
997 &apos;&apos;&apos; It is often an event object that triggered the execution of the script.
998 &apos;&apos;&apos; Returns:
999 &apos;&apos;&apos; The return value after the script execution. May be ignored for events
1001 Dim sScope As String &apos; The scope part of the script URI
1002 Dim sLanguage As String &apos; The language part of the script URI
1003 Dim sScript As String &apos; The script part of the script URI
1004 Dim vStrings As Variant &apos; Array of strings: (script, language, scope)
1005 Const cstComma = &quot;,&quot;
1007 Try:
1008 If ScriptForge.SF_String.StartsWith(psScript, cstScript1) Then
1009 &apos; Parse script
1010 vStrings = Split( _
1011 Replace( _
1012 Replace(Mid(psScript, Len(cstScript1) + 1), cstScript2, cstComma) _
1013 , cstScript3, cstComma) _
1014 , cstComma)
1015 sScript = vStrings(0) : sLanguage = vStrings(1) : sScope = vStrings(2)
1016 &apos; Execute script
1017 If UCase(sLanguage) = &quot;BASIC&quot; Then
1018 _ExecuteScript = ExecuteBasicScript(sScope, sScript, pvArg)
1019 Else &apos; Python
1020 _ExecuteScript = ExecutePythonScript(sScope, sScript, pvArg)
1021 End If
1022 End If
1024 End Function &apos; ScriptForge.SF_Session._ExecuteScript
1026 REM -----------------------------------------------------------------------------
1027 Private Function _GetScript(ByVal psLanguage As String _
1028 , ByVal psScope As String _
1029 , ByVal psScript As String _
1030 ) As Object
1031 &apos;&apos;&apos; Get the adequate script provider and from there the requested script
1032 &apos;&apos;&apos; Called by ExecuteBasicScript() and ExecutePythonScript()
1033 &apos;&apos;&apos; The execution of the script is done by the caller
1034 &apos;&apos;&apos; Args:
1035 &apos;&apos;&apos; psLanguage: Basic or Python
1036 &apos;&apos;&apos; psScope: one of the SCRIPTISxxx constants
1037 &apos;&apos;&apos; The SCRIPTISOXT constant is an alias for 2 cases, extension either
1038 &apos;&apos;&apos; installed for one user only, or for all users
1039 &apos;&apos;&apos; Managed here by trial and error
1040 &apos;&apos;&apos; psScript: Read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
1041 &apos;&apos;&apos; Returns:
1042 &apos;&apos;&apos; A com.sun.star.script.provider.XScript object
1044 Dim sScript As String &apos; The complete script string
1045 Dim oScriptProvider As Object &apos; Script provider singleton
1046 Dim oScript As Object &apos; Return value
1048 Try:
1049 &apos; Build script string
1050 sScript = cstScript1 &amp; psScript &amp; cstScript2 &amp; psLanguage &amp; cstScript3 &amp; LCase(psScope)
1052 &apos; Find script
1053 Set oScript = Nothing
1054 &apos; Python only: installation of extension is determined by user =&gt; unknown to script author
1055 If psScope = SCRIPTISOXT Then &apos; =&gt; Trial and error
1056 On Local Error GoTo ForAllUsers
1057 sScript = cstScript1 &amp; psScript &amp; cstScript2 &amp; psLanguage &amp; cstScript3 &amp; SCRIPTISPERSOXT
1058 Set oScriptProvider = SF_Utils._GetUNOService(&quot;ScriptProvider&quot;, SCRIPTISPERSOXT)
1059 Set oScript = oScriptProvider.getScript(sScript)
1060 End If
1061 ForAllUsers:
1062 On Local Error GoTo CatchNotFound
1063 If IsNull(oScript) Then
1064 If psScope = SCRIPTISOXT Then psScope = SCRIPTISSHAROXT
1065 Set oScriptProvider = SF_Utils._GetUNOService(&quot;ScriptProvider&quot;, psScope)
1066 Set oScript = oScriptProvider.getScript(sScript)
1067 End If
1069 Finally:
1070 _GetScript = oScript
1071 Exit Function
1072 CatchNotFound:
1073 SF_Exception.RaiseFatal(NOSCRIPTERROR, psLanguage, &quot;Scope&quot;, psScope, &quot;Script&quot;, psScript)
1074 GoTo Finally
1075 End Function &apos; ScriptForge.SF_Session._GetScript
1077 REM =============================================== END OF SCRIPTFORGE.SF_SESSION
1078 </script:module>