tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / scriptforge / SF_Session.xba
blob30d220d3be4c1a841567d2b9d1dfa51d68a5624b
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
194 &apos;&apos;&apos; - a string, a numeric value, a date or a boolean
195 &apos;&apos;&apos; - a 1D array, a 2D array or an array of arrays combining those types
196 &apos;&apos;&apos; - a com.sun.star.table.XCellRange UNO object
197 &apos;&apos;&apos; Returns:
198 &apos;&apos;&apos; The (string or numeric) value or the array of arrays returned by the call to the function
199 &apos;&apos;&apos; When the arguments contain arrays, the function is executed as an array function
200 &apos;&apos;&apos; Wrong arguments generate an error
201 &apos;&apos;&apos; Exceptions:
202 &apos;&apos;&apos; CALCFUNCERROR &apos; Execution error in calc function
203 &apos;&apos;&apos; Examples:
204 &apos;&apos;&apos; session.ExecuteCalcFunction(&quot;AVERAGE&quot;, 1, 5, 3, 7) returns 4
205 &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
206 &apos;&apos;&apos; session.ExecuteCalcFunction(&quot;LN&quot;, -3) generates an error
208 Dim oCalc As Object &apos; Give access to the com.sun.star.sheet.FunctionAccess service
209 Dim vReturn As Variant &apos; Returned value
210 Dim i As Long
211 Const cstThisSub = &quot;Session.ExecuteCalcFunction&quot;
212 Const cstSubArgs = &quot;CalcFunction, arg0[, arg1] ...&quot;
214 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
215 vReturn = Empty
217 Check:
218 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
219 If Not SF_Utils._Validate(CalcFunction, &quot;CalcFunction&quot;, V_STRING) Then GoTo Finally
220 End If
222 Try:
223 &apos; Execute function
224 Set oCalc = SF_Utils._GetUNOService(&quot;FunctionAccess&quot;)
225 &apos; Intercept calls from Python when no arguments. Example NOW()
226 If UBound(pvArgs) = 0 Then
227 If IsEmpty(pvArgs(0)) Then pvArgs = Array()
228 End If
229 &apos; Force suitable arguments
230 For i = 0 To UBound(pvArgs)
231 pvArgs(i) = SF_Array.ConvertToRange(pvArgs(i), Direction := &quot;V&quot;)
232 Next i
233 &apos; Error trapping and execution
234 If SF_Utils._ErrorHandling() Then On Local Error GoTo CatchCall
235 vReturn = oCalc.callFunction(UCase(CalcFunction), pvArgs())
237 Finally:
238 ExecuteCalcFunction = vReturn
239 SF_Utils._ExitFunction(cstThisSub)
240 Exit Function
241 Catch:
242 GoTo Finally
243 CatchCall:
244 SF_Exception.RaiseFatal(CALCFUNCERROR, CalcFunction)
245 GoTo Finally
246 End Function &apos; ScriptForge.SF_Session.ExecuteCalcFunction
248 REM -----------------------------------------------------------------------------
249 Public Function ExecutePythonScript(Optional ByVal Scope As Variant _
250 , Optional ByVal Script As Variant _
251 , ParamArray pvArgs As Variant _
252 ) As Variant
253 &apos;&apos;&apos; Execute the Python script given as a string and return the value returned by the script
254 &apos;&apos;&apos; Args:
255 &apos;&apos;&apos; Scope: one of the SCRIPTIS... public constants above (default = &quot;share&quot;)
256 &apos;&apos;&apos; Script: (Case sensitive)
257 &apos;&apos;&apos; &quot;library/module.py$method&quot;
258 &apos;&apos;&apos; or &quot;module.py$method&quot;
259 &apos;&apos;&apos; or &quot;myExtension.oxt|myScript|module.py$method&quot;
260 &apos;&apos;&apos; library =&gt; The library may be not loaded yet
261 &apos;&apos;&apos; myScript =&gt; The directory containing the python module
262 &apos;&apos;&apos; module.py =&gt; The python module
263 &apos;&apos;&apos; method =&gt; The python function
264 &apos;&apos;&apos; Read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
265 &apos;&apos;&apos; pvArgs: the arguments of the called script
266 &apos;&apos;&apos; Date arguments are converted to iso format. However dates in arrays are not converted
267 &apos;&apos;&apos; Returns:
268 &apos;&apos;&apos; The value(s) returned by the call to the script. If &gt;1 values, enclosed in an array
269 &apos;&apos;&apos; Exceptions:
270 &apos;&apos;&apos; NOSCRIPTERROR The script could not be found
271 &apos;&apos;&apos; Examples:
272 &apos;&apos;&apos; session.ExecutePythonScript(session.SCRIPTISSHARED, &quot;Capitalise.py$getNewString&quot;, &quot;Abc&quot;) returns &quot;abc&quot;
274 Dim oScript As Object &apos; Script to be invoked
275 Dim vArg As Variant &apos; Individual argument
276 Dim vReturn As Variant &apos; Returned value
277 Dim i As Long
279 Const cstThisSub = &quot;Session.ExecutePythonScript&quot;
280 Const cstSubArgs = &quot;[Scope], Script, arg0[, arg1] ...&quot;
282 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
284 vReturn = Empty
286 Check:
287 If IsError(Scope) Or IsMissing(Scope) Then Scope = SCRIPTISSHARED
288 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
289 If Not SF_Utils._Validate(Scope, &quot;Scope&quot;, V_STRING _
290 , Array(SCRIPTISSHARED, SCRIPTISEMBEDDED, SCRIPTISPERSONAL, SCRIPTISSHAROXT, SCRIPTISPERSOXT, SCRIPTISOXT) _
291 ) Then GoTo Finally
292 If Not SF_Utils._Validate(Script, &quot;Script&quot;, V_STRING) Then GoTo Finally
293 End If
295 Try:
296 &apos; Filter date arguments - NB: dates in arrays are not filtered
297 For i = 0 To UBound(pvArgs) &apos; pvArgs always zero-based
298 vArg = pvArgs(i)
299 If VarType(vArg) = V_DATE Then pvArgs(i) = SF_Utils._CDateToIso(vArg)
300 Next i
302 &apos; Intercept alternate Python helpers file when relevant
303 With _SF_
304 If SF_String.StartsWith(Script, .PythonHelper) And Len(.PythonHelper2) &gt; 0 Then
305 Scope = SCRIPTISPERSONAL
306 Script = .PythonHelper2 &amp; Mid(Script, Len(.PythonHelper) + 1)
307 End If
308 End With
309 &apos; Find script
310 Set oScript = SF_Session._GetScript(&quot;Python&quot;, Scope, Script)
312 &apos; Execute script
313 If Not IsNull(oScript) Then
314 vReturn = oScript.Invoke(pvArgs(), Array(), Array())
315 &apos; Remove surrounding array when single returned value
316 If IsArray(vReturn) Then
317 If UBound(vReturn) = 0 Then vReturn = vReturn(0)
318 End If
319 End If
321 Finally:
322 ExecutePythonScript = vReturn
323 SF_Utils._ExitFunction(cstThisSub)
324 Exit Function
325 Catch:
326 GoTo Finally
327 End Function &apos; ScriptForge.SF_Session.ExecutePythonScript
329 REM -----------------------------------------------------------------------------
330 Public Function GetPDFExportOptions() As Variant
331 &apos;&apos;&apos; Return the actual values of the PDF export options
332 &apos;&apos;&apos; The PDF options are described on https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export
333 &apos;&apos;&apos; PDF options are set at each use of the Export as ... PDF command by the user and kept
334 &apos;&apos;&apos; permanently until their reset by script or by a new export
335 &apos;&apos;&apos; Args:
336 &apos;&apos;&apos; Returns:
337 &apos;&apos;&apos; A ScriptForge dictionary instance listing the 40+ properties and their value
338 &apos;&apos;&apos; Examples:
339 &apos;&apos;&apos; Dim dict As Object
340 &apos;&apos;&apos; Set dict = session.GetPDFExportOptions()
341 &apos;&apos;&apos; MsgBox dict.Item(&quot;Quality&quot;)
343 Dim vDict As Variant &apos; Returned value
344 Dim oConfig As Object &apos; com.sun.star.configuration.ConfigurationProvider
345 Dim oNodePath As Object &apos; com.sun.star.beans.PropertyValue
346 Dim oOptions As Object &apos; configmgr.RootAccess
347 Dim vOptionNames As Variant &apos; Array of PDF options names
348 Dim vOptionValues As Variant &apos; Array of PDF options values
349 Dim i As Long
351 Const cstThisSub = &quot;Session.GetPDFExportOptions&quot;
352 Const cstSubArgs = &quot;&quot;
354 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
355 Set vDict = Nothing
357 Check:
358 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
360 Try:
361 &apos; Get the (read-only) internal PDF options
362 Set oConfig = SF_Utils._GetUNOService(&quot;ConfigurationProvider&quot;)
363 Set oNodePath = SF_Utils._MakePropertyValue(&quot;nodepath&quot;, &quot;/org.openoffice.Office.Common/Filter/PDF/Export/&quot;)
364 Set oOptions = oConfig.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, Array(oNodePath))
366 &apos; Copy the options into a ScriptForge dictionary with case-sensitive comparison of keys
367 Set vDict = CreateScriptService(&quot;Dictionary&quot;, True)
368 vOptionNames = oOptions.getElementNames()
369 vOptionValues = oOptions.getPropertyValues(vOptionNames)
370 &apos;
371 For i = 0 To UBound(vOptionNames)
372 vDict.Add(vOptionNames(i), vOptionValues(i))
373 Next i
376 Finally:
377 GetPDFExportOptions = vDict
378 SF_Utils._ExitFunction(cstThisSub)
379 Exit Function
380 Catch:
381 GoTo Finally
382 End Function &apos; ScriptForge.SF_Session.GetPDFExportOptions
384 REM -----------------------------------------------------------------------------
385 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
386 &apos;&apos;&apos; Return the actual value of the given property
387 &apos;&apos;&apos; Args:
388 &apos;&apos;&apos; PropertyName: the name of the property as a string
389 &apos;&apos;&apos; Returns:
390 &apos;&apos;&apos; The actual value of the property
391 &apos;&apos;&apos; Exceptions
392 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
394 Const cstThisSub = &quot;Session.GetProperty&quot;
395 Const cstSubArgs = &quot;PropertyName&quot;
397 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
398 GetProperty = Null
400 Check:
401 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
402 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
403 End If
405 Try:
406 Select Case UCase(PropertyName)
407 Case Else
408 End Select
410 Finally:
411 SF_Utils._ExitFunction(cstThisSub)
412 Exit Function
413 Catch:
414 GoTo Finally
415 End Function &apos; ScriptForge.SF_Session.GetProperty
417 REM -----------------------------------------------------------------------------
418 Public Function HasUnoMethod(Optional ByRef UnoObject As Variant _
419 , Optional ByVal MethodName As Variant _
420 ) As Boolean
421 &apos;&apos;&apos; Returns True if a UNO object contains the given method
422 &apos;&apos;&apos; Code-snippet derived from XRAY
423 &apos;&apos;&apos; Args:
424 &apos;&apos;&apos; UnoObject: the object to identify
425 &apos;&apos;&apos; MethodName: the name of the method as a string. The search is case-sensitive
426 &apos;&apos;&apos; Returns:
427 &apos;&apos;&apos; False when the method is not found or when an argument is invalid
429 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
430 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
431 Dim bMethod As Boolean &apos; Return value
432 Const cstThisSub = &quot;Session.HasUnoMethod&quot;
433 Const cstSubArgs = &quot;UnoObject, MethodName&quot;
435 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
437 Check:
438 bMethod = False
439 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
440 If IsNull(UnoObject) Then GoTo Finally
441 If VarType(MethodName) &lt;&gt; V_STRING Then GoTo Finally
442 If MethodName = Space(Len(MethodName)) Then GoTo Finally
444 Try:
445 On Local Error GoTo Catch
446 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
447 Set oInspect = oIntrospect.inspect(UnoObject)
448 bMethod = oInspect.hasMethod(MethodName, com.sun.star.beans.MethodConcept.ALL)
450 Finally:
451 HasUnoMethod = bMethod
452 SF_Utils._ExitFunction(cstThisSub)
453 Exit Function
454 Catch:
455 On Local Error GoTo 0
456 GoTo Finally
457 End Function &apos; ScriptForge.SF_Session.HasUnoMethod
459 REM -----------------------------------------------------------------------------
460 Public Function HasUnoProperty(Optional ByRef UnoObject As Variant _
461 , Optional ByVal PropertyName As Variant _
462 ) As Boolean
463 &apos;&apos;&apos; Returns True if a UNO object contains the given property
464 &apos;&apos;&apos; Code-snippet derived from XRAY
465 &apos;&apos;&apos; Args:
466 &apos;&apos;&apos; UnoObject: the object to identify
467 &apos;&apos;&apos; PropertyName: the name of the property as a string. The search is case-sensitive
468 &apos;&apos;&apos; Returns:
469 &apos;&apos;&apos; False when the property is not found or when an argument is invalid
471 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
472 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
473 Dim bProperty As Boolean &apos; Return value
474 Const cstThisSub = &quot;Session.HasUnoProperty&quot;
475 Const cstSubArgs = &quot;UnoObject, PropertyName&quot;
477 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
479 Check:
480 bProperty = False
481 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
482 If IsNull(UnoObject) Then GoTo Finally
483 If VarType(PropertyName) &lt;&gt; V_STRING Then GoTo Finally
484 If PropertyName = Space(Len(PropertyName)) Then GoTo Finally
486 Try:
487 On Local Error GoTo Catch
488 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
489 Set oInspect = oIntrospect.inspect(UnoObject)
490 bProperty = oInspect.hasProperty(PropertyName, com.sun.star.beans.PropertyConcept.ALL)
492 Finally:
493 HasUnoProperty = bProperty
494 SF_Utils._ExitFunction(cstThisSub)
495 Exit Function
496 Catch:
497 On Local Error GoTo 0
498 GoTo Finally
499 End Function &apos; ScriptForge.SF_Session.HasUnoProperty
501 REM -----------------------------------------------------------------------------
502 Public Function Methods() As Variant
503 &apos;&apos;&apos; Return the list of public methods of the Session service as an array
505 Methods = Array( _
506 &quot;ExecuteBasicScript&quot; _
507 , &quot;ExecuteCalcFunction&quot; _
508 , &quot;ExecutePythonScript&quot; _
509 , &quot;HasUnoMethod&quot; _
510 , &quot;HasUnoProperty&quot; _
511 , &quot;OpenURLInBrowser&quot; _
512 , &quot;RunApplication&quot; _
513 , &quot;SendMail&quot; _
514 , &quot;UnoMethods&quot; _
515 , &quot;UnoObjectType&quot; _
516 , &quot;UnoProperties&quot; _
517 , &quot;WebService&quot; _
520 End Function &apos; ScriptForge.SF_Session.Methods
522 REM -----------------------------------------------------------------------------
523 Public Sub OpenURLInBrowser(Optional ByVal URL As Variant)
524 &apos;&apos;&apos; Opens a URL in the default browser
525 &apos;&apos;&apos; Args:
526 &apos;&apos;&apos; URL: The URL to open in the browser
527 &apos;&apos;&apos; Examples:
528 &apos;&apos;&apos; session.OpenURLInBrowser(&quot;https://docs.python.org/3/library/webbrowser.html&quot;)
530 Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Session__OpenURLInBrowser&quot;
532 Const cstThisSub = &quot;Session.OpenURLInBrowser&quot;
533 Const cstSubArgs = &quot;URL&quot;
535 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
537 Check:
538 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
539 If Not SF_Utils._Validate(URL, &quot;URL&quot;, V_STRING) Then GoTo Finally
540 End If
542 Try:
543 ExecutePythonScript(SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper, URL)
545 Finally:
546 SF_Utils._ExitFunction(cstThisSub)
547 Exit Sub
548 Catch:
549 GoTo Finally
550 End Sub &apos; ScriptForge.SF_Session.OpenURLInBrowser
552 REM -----------------------------------------------------------------------------
553 Public Function Properties() As Variant
554 &apos;&apos;&apos; Return the list or properties as an array
556 Properties = Array( _
559 End Function &apos; ScriptForge.SF_Session.Properties
561 REM -----------------------------------------------------------------------------
562 Public Function RunApplication(Optional ByVal Command As Variant _
563 , Optional ByVal Parameters As Variant _
564 ) As Boolean
565 &apos;&apos;&apos; Executes an arbitrary system command
566 &apos;&apos;&apos; Args:
567 &apos;&apos;&apos; Command: The command to execute
568 &apos;&apos;&apos; This may be an executable file or a document which is registered with an application
569 &apos;&apos;&apos; so that the system knows what application to launch for that document
570 &apos;&apos;&apos; Parameters: a list of space separated parameters as a single string
571 &apos;&apos;&apos; The method does not validate the given parameters, but only passes them to the specified command
572 &apos;&apos;&apos; Returns:
573 &apos;&apos;&apos; True if success
574 &apos;&apos;&apos; Exceptions:
575 &apos;&apos;&apos; UNKNOWNFILEERROR Command could not be identified as a valid file
576 &apos;&apos;&apos; Examples:
577 &apos;&apos;&apos; session.RunApplication(&quot;Notepad.exe&quot;)
578 &apos;&apos;&apos; session.RunApplication(&quot;C:\myFolder\myDocument.odt&quot;)
579 &apos;&apos;&apos; session.RunApplication(&quot;kate&quot;) &apos; (Linux)
580 &apos;&apos;&apos; session.RunApplication(&quot;kate&quot;, &quot;/home/me/install.txt&quot;) &apos; (Linux)
582 Dim bReturn As Boolean &apos; Returned value
583 Dim oShell As Object &apos; com.sun.star.system.SystemShellExecute
584 Dim sCommand As String &apos; Command as an URL
585 Const cstThisSub = &quot;Session.RunApplication&quot;
586 Const cstSubArgs = &quot;Command, [Parameters]&quot;
588 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
589 bReturn = False
591 Check:
592 If IsMissing(Parameters) Then Parameters = &quot;&quot;
593 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
594 If Not SF_Utils._ValidateFile(Command, &quot;Command&quot;) Then GoTo Finally
595 If Not SF_Utils._Validate(Parameters, &quot;Parameters&quot;, V_STRING) Then GoTo Finally
596 End If
598 Try:
599 &apos; Cfr. discussion tdf#160222
600 &apos; 1) Try Shell(), always in not synchronized mode
601 &apos; 2) If failure - check command existence as a valid file
602 &apos; - try com.sun.star.system.SystemShellExecute
603 sCommand = SF_FileSystem._ConvertFromUrl(Command)
604 On Local Error GoTo Step2
605 Shell(sCommand, , Parameters, False)
606 Step2:
607 If Err &gt; 0 Then
608 On Error GoTo 0 &apos; Reset error status
609 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
610 If Not SF_FileSystem.FileExists(Command) Then GoTo CatchNotExists
611 Set oShell = SF_Utils._GetUNOService(&quot;SystemShellExecute&quot;)
612 sCommand = SF_FileSystem._ConvertToUrl(Command)
613 oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
614 End If
616 bReturn = True
618 Finally:
619 RunApplication = bReturn
620 SF_Utils._ExitFunction(cstThisSub)
621 Exit Function
622 Catch:
623 GoTo Finally
624 CatchNotExists:
625 SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;Command&quot;, Command)
626 GoTo Finally
627 End Function &apos; ScriptForge.SF_Session.RunApplication
629 REM -----------------------------------------------------------------------------
630 Public Sub SendMail(Optional ByVal Recipient As Variant _
631 , Optional ByRef Cc As Variant _
632 , Optional ByRef Bcc As Variant _
633 , Optional ByVal Subject As Variant _
634 , Optional ByRef Body As Variant _
635 , Optional ByVal FileNames As Variant _
636 , Optional ByVal EditMessage As Variant _
638 &apos;&apos;&apos; Send a message (with or without attachments) to recipients from the user&apos;s mail client
639 &apos;&apos;&apos; The message may be edited by the user before sending or, alternatively, be sent immediately
640 &apos;&apos;&apos; Args:
641 &apos;&apos;&apos; Recipient: an email addresses (To recipient)
642 &apos;&apos;&apos; Cc: a comma-delimited list of email addresses (carbon copy)
643 &apos;&apos;&apos; Bcc: a comma-delimited list of email addresses (blind carbon copy)
644 &apos;&apos;&apos; Subject: the header of the message
645 &apos;&apos;&apos; FileNames: a comma-separated list of filenames to attach to the mail. SF_FileSystem naming conventions apply
646 &apos;&apos;&apos; Body: the unformatted text of the message
647 &apos;&apos;&apos; EditMessage: when True (default) the message is editable before being sent
648 &apos;&apos;&apos; Exceptions:
649 &apos;&apos;&apos; UNKNOWNFILEERROR File does not exist
650 &apos;&apos;&apos; WRONGEMAILERROR String not recognized as an email address
651 &apos;&apos;&apos; SENDMAILERROR System error, probably no mail client
653 Dim sEmail As String &apos; An single email address
654 Dim sFile As String &apos; A single file name
655 Dim sArg As String &apos; Argument name
656 Dim vCc As Variant &apos; Array alias of Cc
657 Dim vBcc As Variant &apos; Array alias of Bcc
658 Dim vFileNames As Variant &apos; Array alias of FileNames
659 Dim oMailService As Object &apos; com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
660 Dim oMail As Object &apos; com.sun.star.system.XSimpleMailClient
661 Dim oMessage As Object &apos; com.sun.star.system.XSimpleMailMessage
662 Dim lFlag As Long &apos; com.sun.star.system.SimpleMailClientFlags.XXX
663 Dim ARR As Object : ARR = ScriptForge.SF_Array
664 Dim i As Long
665 Const cstComma = &quot;,&quot;, cstSemiColon = &quot;;&quot;
666 Const cstThisSub = &quot;Session.SendMail&quot;
667 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;
669 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
671 Check:
672 If IsMissing(Cc) Or IsEmpty(Cc) Then Cc = &quot;&quot;
673 If IsMissing(Bcc) Or IsEmpty(Bcc) Then Bcc = &quot;&quot;
674 If IsMissing(Subject) Or IsEmpty(Subject) Then Subject = &quot;&quot;
675 If IsMissing(FileNames) Or IsEmpty(FileNames) Then FileNames = &quot;&quot;
676 If IsMissing(Body) Or IsEmpty(Body) Then Body = &quot;&quot;
677 If IsMissing(EditMessage) Or IsEmpty(EditMessage) Then EditMessage = True
679 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
680 If Not SF_Utils._Validate(Recipient, &quot;Recipient&quot;, V_STRING) Then GoTo Finally
681 If Not SF_Utils._Validate(Cc, &quot;Cc&quot;, V_STRING) Then GoTo Finally
682 If Not SF_Utils._Validate(Bcc, &quot;Bcc&quot;, V_STRING) Then GoTo Finally
683 If Not SF_Utils._Validate(Subject, &quot;Subject&quot;, V_STRING) Then GoTo Finally
684 If Not SF_Utils._Validate(FileNames, &quot;FileNames&quot;, V_STRING) Then GoTo Finally
685 If Not SF_Utils._Validate(Body, &quot;Body&quot;, V_STRING) Then GoTo Finally
686 If Not SF_Utils._Validate(EditMessage, &quot;EditMessage&quot;, V_BOOLEAN) Then GoTo Finally
687 End If
689 &apos; Check email addresses
690 sArg = &quot;Recipient&quot; : sEmail = Recipient
691 If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
692 sArg = &quot;Cc&quot; : vCc = ARR.TrimArray(Split(Cc, cstComma))
693 For Each sEmail In vCc
694 If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
695 Next sEmail
696 sArg = &quot;Bcc&quot; : vBcc = ARR.TrimArray(Split(Bcc, cstComma))
697 For Each sEmail In vBcc
698 If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
699 Next sEmail
701 &apos; Check file existence
702 If Len(FileNames) &gt; 0 Then
703 vFileNames = ARR.TrimArray(Split(FileNames, cstComma))
704 For i = 0 To UBound(vFileNames)
705 sFile = vFileNames(i)
706 If Not SF_Utils._ValidateFile(sFile, &quot;FileNames&quot;) Then GoTo Finally
707 If Not SF_FileSystem.FileExists(sFile) Then GoTo CatchNotExists
708 vFileNames(i) = ConvertToUrl(sFile)
709 Next i
710 Else
711 vFileNames = Array()
712 End If
714 Try:
715 &apos; Initialize the mail service
716 Set oMailService = SF_Utils._GetUNOService(&quot;MailService&quot;)
717 If IsNull(oMailService) Then GoTo CatchMail
718 Set oMail = oMailService.querySimpleMailClient()
719 If IsNull(oMail) Then GoTo CatchMail
720 Set oMessage = oMail.createSimpleMailMessage()
721 If IsNull(oMessage) Then GoTo CatchMail
723 &apos; Feed the new mail message
724 With oMessage
725 .setRecipient(Recipient)
726 If Subject &lt;&gt; &quot;&quot; Then .setSubject(Subject)
727 If UBound(vCc) &gt;= 0 Then .setCcRecipient(vCc)
728 If UBound(vBcc) &gt;= 0 Then .setBccRecipient(vBcc)
729 .Body = Iif(Len(Body) = 0, &quot; &quot;, Body) &apos; Body must not be the empty string ??
730 .setAttachement(vFileNames)
731 End With
732 lFlag = Iif(EditMessage, com.sun.star.system.SimpleMailClientFlags.DEFAULTS, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE)
734 &apos; Send using the mail service
735 oMail.sendSimpleMailMessage(oMessage, lFlag)
737 Finally:
738 SF_Utils._ExitFunction(cstThisSub)
739 Exit Sub
740 Catch:
741 GoTo Finally
742 CatchEmail:
743 SF_Exception.RaiseFatal(WRONGEMAILERROR, sArg, sEmail)
744 GoTo Finally
745 CatchNotExists:
746 SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileNames&quot;, sFile)
747 GoTo Finally
748 CatchMail:
749 SF_Exception.RaiseFatal(SENDMAILERROR)
750 GoTo Finally
751 End Sub &apos; ScriptForge.SF_Session.SendMail
753 REM -----------------------------------------------------------------------------
754 Public Function SetPDFExportOptions(Optional ByRef PDFOptions As Variant) As Boolean
755 &apos;&apos;&apos; Modify the actual values of the PDF export options from an options dictionary
756 &apos;&apos;&apos; The PDF options are described on https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export
757 &apos;&apos;&apos; PDF options are set at each use of the Export as ... PDF command by the user and kept
758 &apos;&apos;&apos; permanently until their reset by script (like this one) or by a new export
759 &apos;&apos;&apos; The changed options are applicable on any subsequent ExportToPDF user command or to any SaveAsPDF script execution
760 &apos;&apos;&apos; Args:
761 &apos;&apos;&apos; PDFOptions: a ScriptForge dictionary object
762 &apos;&apos;&apos; Returns:
763 &apos;&apos;&apos; True when successful
764 &apos;&apos;&apos; Examples:
765 &apos;&apos;&apos; Dim dict As Object
766 &apos;&apos;&apos; Set dict = session.GetPDFExportOptions()
767 &apos;&apos;&apos; dict.ReplaceItem(&quot;Quality&quot;, 50)
768 &apos;&apos;&apos; session.SetPDFExportOptions(dict)
770 Dim bSetPDF As Boolean &apos; Returned value
771 Dim oConfig As Object &apos; com.sun.star.configuration.ConfigurationProvider
772 Dim oNodePath As Object &apos; com.sun.star.beans.PropertyValue
773 Dim oOptions As Object &apos; configmgr.RootAccess
774 Dim vOptionNames As Variant &apos; Array of PDF options names
775 Dim vOptionValues As Variant &apos; Array of PDF options values
776 Dim oDict As Object &apos; Alias of PDFOptions
777 Dim i As Long
779 Const cstThisSub = &quot;Session.SetPDFExportOptions&quot;
780 Const cstSubArgs = &quot;PDFOptions&quot;
782 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
783 bSetPDF = False
785 Check:
786 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
787 If Not SF_Utils._Validate(PDFOptions, &quot;PDFOptions&quot;, V_OBJECT, , , &quot;DICTIONARY&quot;) Then GoTo Finally
788 End If
790 Try:
791 &apos; Get the (updatable) internal PDF options
792 Set oConfig = SF_Utils._GetUNOService(&quot;ConfigurationProvider&quot;)
793 Set oNodePath = SF_Utils._MakePropertyValue(&quot;nodepath&quot;, &quot;/org.openoffice.Office.Common/Filter/PDF/Export/&quot;)
794 Set oOptions = oConfig.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;, Array(oNodePath))
796 &apos; Copy the options from the ScriptForge dictionary in argument to property values
797 Set oDict = PDFOptions
798 oOptions.setPropertyValues(oDict.Keys, oDict.Items)
799 oOptions.commitChanges()
801 bSetPDF = True
803 Finally:
804 SetPDFExportOptions = bSetPDF
805 SF_Utils._ExitFunction(cstThisSub)
806 Exit Function
807 Catch:
808 GoTo Finally
809 End Function &apos; ScriptForge.SF_Session.SetPDFExportOptions
811 REM -----------------------------------------------------------------------------
812 Public Function SetProperty(Optional ByVal PropertyName As Variant _
813 , Optional ByRef Value As Variant _
814 ) As Boolean
815 &apos;&apos;&apos; Set a new value to the given property
816 &apos;&apos;&apos; Args:
817 &apos;&apos;&apos; PropertyName: the name of the property as a string
818 &apos;&apos;&apos; Value: its new value
819 &apos;&apos;&apos; Exceptions
820 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
822 Const cstThisSub = &quot;Session.SetProperty&quot;
823 Const cstSubArgs = &quot;PropertyName, Value&quot;
825 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
826 SetProperty = False
828 Check:
829 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
830 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
831 End If
833 Try:
834 Select Case UCase(PropertyName)
835 Case Else
836 End Select
838 Finally:
839 SF_Utils._ExitFunction(cstThisSub)
840 Exit Function
841 Catch:
842 GoTo Finally
843 End Function &apos; ScriptForge.SF_Session.SetProperty
845 REM -----------------------------------------------------------------------------
846 Public Function UnoMethods(Optional ByRef UnoObject As Variant) As Variant
847 &apos;&apos;&apos; Returns a list of the methods callable from an UNO object
848 &apos;&apos;&apos; Code-snippet derived from XRAY
849 &apos;&apos;&apos; Args:
850 &apos;&apos;&apos; UnoObject: the object to identify
851 &apos;&apos;&apos; Returns:
852 &apos;&apos;&apos; A zero-based sorted array. May be empty
854 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
855 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
856 Dim vMethods As Variant &apos; Array of com.sun.star.reflection.XIdlMethod
857 Dim vMethod As Object &apos; com.sun.star.reflection.XIdlMethod
858 Dim lMax As Long &apos; UBounf of vMethods
859 Dim vMethodsList As Variant &apos; Return value
860 Dim i As Long
861 Const cstThisSub = &quot;Session.UnoMethods&quot;
862 Const cstSubArgs = &quot;UnoObject&quot;
864 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
866 Check:
867 vMethodsList = Array()
868 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
869 If IsNull(UnoObject) Then GoTo Finally
871 Try:
872 On Local Error GoTo Catch
873 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
874 Set oInspect = oIntrospect.inspect(UnoObject)
875 vMethods = oInspect.getMethods(com.sun.star.beans.MethodConcept.ALL)
877 &apos; The names must be extracted from com.sun.star.reflection.XIdlMethod structures
878 lMax = UBound(vMethods)
879 If lMax &gt;= 0 Then
880 ReDim vMethodsList(0 To lMax)
881 For i = 0 To lMax
882 vMethodsList(i) = vMethods(i).Name
883 Next i
884 vMethodsList = SF_Array.Sort(vMethodsList, CaseSensitive := True)
885 End If
887 Finally:
888 UnoMethods = vMethodsList
889 SF_Utils._ExitFunction(cstThisSub)
890 Exit Function
891 Catch:
892 On Local Error GoTo 0
893 GoTo Finally
894 End Function &apos; ScriptForge.SF_Session.UnoMethods
896 REM -----------------------------------------------------------------------------
897 Public Function UnoObjectType(Optional ByRef UnoObject As Variant) As String
898 &apos;&apos;&apos; Identify the UNO type of an UNO object
899 &apos;&apos;&apos; Code-snippet derived from XRAY
900 &apos;&apos;&apos; Args:
901 &apos;&apos;&apos; UnoObject: the object to identify
902 &apos;&apos;&apos; Returns:
903 &apos;&apos;&apos; com.sun.star. ... as a string
904 &apos;&apos;&apos; a zero-length string if identification was not successful
906 Dim oObjDesc As Object &apos; _ObjectDescriptor type
907 Dim sObjectType As String &apos; Return value
908 Const cstThisSub = &quot;Session.UnoObjectType&quot;
909 Const cstSubArgs = &quot;UnoObject&quot;
911 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
913 Check:
914 sObjectType = &quot;&quot;
915 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
916 If IsNull(UnoObject) Then GoTo Finally
918 Try:
919 Set oObjDesc = SF_Utils._VarTypeObj(UnoObject)
920 If oObjDesc.iVarType = V_UNOOBJECT Then sObjectType = oObjDesc.sObjectType
922 Finally:
923 UnoObjectType = sObjectType
924 SF_Utils._ExitFunction(cstThisSub)
925 Exit Function
926 End Function &apos; ScriptForge.SF_Session.UnoObjectType
928 REM -----------------------------------------------------------------------------
929 Public Function UnoProperties(Optional ByRef UnoObject As Variant) As Variant
930 &apos;&apos;&apos; Returns a list of the properties of an UNO object
931 &apos;&apos;&apos; Code-snippet derived from XRAY
932 &apos;&apos;&apos; Args:
933 &apos;&apos;&apos; UnoObject: the object to identify
934 &apos;&apos;&apos; Returns:
935 &apos;&apos;&apos; A zero-based sorted array. May be empty
937 Dim oIntrospect As Object &apos; com.sun.star.beans.Introspection
938 Dim oInspect As Object &apos; com.sun.star.beans.XIntrospectionAccess
939 Dim vProperties As Variant &apos; Array of com.sun.star.beans.Property
940 Dim vProperty As Object &apos; com.sun.star.beans.Property
941 Dim lMax As Long &apos; UBounf of vProperties
942 Dim vPropertiesList As Variant &apos; Return value
943 Dim i As Long
944 Const cstThisSub = &quot;Session.UnoProperties&quot;
945 Const cstSubArgs = &quot;UnoObject&quot;
947 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
949 Check:
950 vPropertiesList = Array()
951 If VarType(UnoObject) &lt;&gt; V_OBJECT Then GoTo Finally
952 If IsNull(UnoObject) Then GoTo Finally
954 Try:
955 On Local Error GoTo Catch
956 Set oIntrospect = SF_Utils._GetUNOService(&quot;Introspection&quot;)
957 Set oInspect = oIntrospect.inspect(UnoObject)
958 vProperties = oInspect.getProperties(com.sun.star.beans.PropertyConcept.ALL)
960 &apos; The names must be extracted from com.sun.star.beans.Property structures
961 lMax = UBound(vProperties)
962 If lMax &gt;= 0 Then
963 ReDim vPropertiesList(0 To lMax)
964 For i = 0 To lMax
965 vPropertiesList(i) = vProperties(i).Name
966 Next i
967 vPropertiesList = SF_Array.Sort(vPropertiesList, CaseSensitive := True)
968 End If
970 Finally:
971 UnoProperties = vPropertiesList
972 SF_Utils._ExitFunction(cstThisSub)
973 Exit Function
974 Catch:
975 On Local Error GoTo 0
976 GoTo Finally
977 End Function &apos; ScriptForge.SF_Session.UnoProperties
979 REM -----------------------------------------------------------------------------
980 Public Function WebService(Optional ByVal URI As Variant) As String
981 &apos;&apos;&apos; Get some web content from a URI
982 &apos;&apos;&apos; Args:
983 &apos;&apos;&apos; URI: URI text of the web service
984 &apos;&apos;&apos; Returns:
985 &apos;&apos;&apos; The web page content of the URI
986 &apos;&apos;&apos; Exceptions:
987 &apos;&apos;&apos; CALCFUNCERROR
988 &apos;&apos;&apos; Examples:
989 &apos;&apos;&apos; session.WebService(&quot;wiki.documentfoundation.org/api.php?&quot; _
990 &apos;&apos;&apos; &amp; &quot;hidebots=1&amp;days=7&amp;limit=50&amp;action=feedrecentchanges&amp;feedformat=rss&quot;)
992 Dim sReturn As String &apos; Returned value
993 Const cstThisSub = &quot;Session.WebService&quot;
994 Const cstSubArgs = &quot;URI&quot;
996 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
997 sReturn = &quot;&quot;
999 Check:
1000 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1001 If Not SF_Utils._Validate(URI, &quot;URI&quot;, V_STRING) Then GoTo Finally
1002 End If
1004 Try:
1005 sReturn = SF_Session.ExecuteCalcFunction(&quot;WEBSERVICE&quot;, URI)
1007 Finally:
1008 WebService = sReturn
1009 SF_Utils._ExitFunction(cstThisSub)
1010 Exit Function
1011 Catch:
1012 GoTo Finally
1013 End Function &apos; ScriptForge.SF_Session.WebService
1015 REM =========================================================== PRIVATE FUNCTIONS
1017 REM -----------------------------------------------------------------------------
1018 Private Function _ExecuteScript(ByVal psScript As String _
1019 , Optional ByRef pvArg As Variant _
1020 ) As Variant
1021 &apos;&apos;&apos; Execute the script expressed in the scripting framework_URI notation
1022 &apos;&apos;&apos; Args:
1023 &apos;&apos;&apos; psScript: read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
1024 &apos;&apos;&apos; pvArg: the unique argument to pass to the called script.
1025 &apos;&apos;&apos; It is often an event object that triggered the execution of the script.
1026 &apos;&apos;&apos; Returns:
1027 &apos;&apos;&apos; The return value after the script execution. May be ignored for events
1029 Dim sScope As String &apos; The scope part of the script URI
1030 Dim sLanguage As String &apos; The language part of the script URI
1031 Dim sScript As String &apos; The script part of the script URI
1032 Dim vStrings As Variant &apos; Array of strings: (script, language, scope)
1033 Const cstComma = &quot;,&quot;
1035 Try:
1036 If ScriptForge.SF_String.StartsWith(psScript, cstScript1) Then
1037 &apos; Parse script
1038 vStrings = Split( _
1039 Replace( _
1040 Replace(Mid(psScript, Len(cstScript1) + 1), cstScript2, cstComma) _
1041 , cstScript3, cstComma) _
1042 , cstComma)
1043 sScript = vStrings(0) : sLanguage = vStrings(1) : sScope = vStrings(2)
1044 &apos; Execute script
1045 If UCase(sLanguage) = &quot;BASIC&quot; Then
1046 _ExecuteScript = ExecuteBasicScript(sScope, sScript, pvArg)
1047 Else &apos; Python
1048 _ExecuteScript = ExecutePythonScript(sScope, sScript, pvArg)
1049 End If
1050 End If
1052 End Function &apos; ScriptForge.SF_Session._ExecuteScript
1054 REM -----------------------------------------------------------------------------
1055 Private Function _GetScript(ByVal psLanguage As String _
1056 , ByVal psScope As String _
1057 , ByVal psScript As String _
1058 ) As Object
1059 &apos;&apos;&apos; Get the adequate script provider and from there the requested script
1060 &apos;&apos;&apos; Called by ExecuteBasicScript() and ExecutePythonScript()
1061 &apos;&apos;&apos; The execution of the script is done by the caller
1062 &apos;&apos;&apos; Args:
1063 &apos;&apos;&apos; psLanguage: Basic or Python
1064 &apos;&apos;&apos; psScope: one of the SCRIPTISxxx constants
1065 &apos;&apos;&apos; The SCRIPTISOXT constant is an alias for 2 cases, extension either
1066 &apos;&apos;&apos; installed for one user only, or for all users
1067 &apos;&apos;&apos; Managed here by trial and error
1068 &apos;&apos;&apos; psScript: Read https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
1069 &apos;&apos;&apos; Returns:
1070 &apos;&apos;&apos; A com.sun.star.script.provider.XScript object
1072 Dim sScript As String &apos; The complete script string
1073 Dim oScriptProvider As Object &apos; Script provider singleton
1074 Dim oScript As Object &apos; Return value
1076 Try:
1077 &apos; Build script string
1078 sScript = cstScript1 &amp; psScript &amp; cstScript2 &amp; psLanguage &amp; cstScript3 &amp; LCase(psScope)
1080 &apos; Find script
1081 Set oScript = Nothing
1082 &apos; Python only: installation of extension is determined by user =&gt; unknown to script author
1083 If psScope = SCRIPTISOXT Then &apos; =&gt; Trial and error
1084 On Local Error GoTo ForAllUsers
1085 sScript = cstScript1 &amp; psScript &amp; cstScript2 &amp; psLanguage &amp; cstScript3 &amp; SCRIPTISPERSOXT
1086 Set oScriptProvider = SF_Utils._GetUNOService(&quot;ScriptProvider&quot;, SCRIPTISPERSOXT)
1087 Set oScript = oScriptProvider.getScript(sScript)
1088 End If
1089 ForAllUsers:
1090 On Local Error GoTo CatchNotFound
1091 If IsNull(oScript) Then
1092 If psScope = SCRIPTISOXT Then psScope = SCRIPTISSHAROXT
1093 Set oScriptProvider = SF_Utils._GetUNOService(&quot;ScriptProvider&quot;, psScope)
1094 Set oScript = oScriptProvider.getScript(sScript)
1095 End If
1097 Finally:
1098 _GetScript = oScript
1099 Exit Function
1100 CatchNotFound:
1101 SF_Exception.RaiseFatal(NOSCRIPTERROR, psLanguage, &quot;Scope&quot;, psScope, &quot;Script&quot;, psScript)
1102 GoTo Finally
1103 End Function &apos; ScriptForge.SF_Session._GetScript
1105 REM =============================================== END OF SCRIPTFORGE.SF_SESSION
1106 </script:module>