mirror of
https://github.com/kekingcn/kkFileView.git
synced 2026-04-20 05:18:39 +00:00
移除office-plugin, 使用新版jodconverter
This commit is contained in:
2549
server/windows-office/share/basic/ScriptForge/SF_Array.xba
Normal file
2549
server/windows-office/share/basic/ScriptForge/SF_Array.xba
Normal file
File diff suppressed because it is too large
Load Diff
952
server/windows-office/share/basic/ScriptForge/SF_Dictionary.xba
Normal file
952
server/windows-office/share/basic/ScriptForge/SF_Dictionary.xba
Normal file
@@ -0,0 +1,952 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Dictionary" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Dictionary
|
||||
''' =============
|
||||
''' Class for management of dictionaries
|
||||
''' A dictionary is a collection of key-item pairs
|
||||
''' The key is a not case-sensitive string
|
||||
''' Items may be of any type
|
||||
''' Keys, items can be retrieved, counted, etc.
|
||||
'''
|
||||
''' The implementation is based on
|
||||
''' - one collection mapping keys and entries in the array
|
||||
''' - one 1-column array: key + data
|
||||
'''
|
||||
''' Why a Dictionary class beside the builtin Collection class ?
|
||||
''' A standard Basic collection does not support the retrieval of the keys
|
||||
''' Additionally it may contain only simple data (strings, numbers, ...)
|
||||
'''
|
||||
''' Service instantiation example:
|
||||
''' Dim myDict As Variant
|
||||
''' myDict = CreateScriptService("Dictionary") ' Once per dictionary
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Const DUPLICATEKEYERROR = "DUPLICATEKEYERROR" ' Key exists already
|
||||
Const UNKNOWNKEYERROR = "UNKNOWNKEYERROR" ' Key not found
|
||||
Const INVALIDKEYERROR = "INVALIDKEYERROR" ' Key contains only spaces
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
' Defines an entry in the MapItems array
|
||||
Type ItemMap
|
||||
Key As String
|
||||
Value As Variant
|
||||
End Type
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private ObjectType As String ' Must be "DICTIONARY"
|
||||
Private ServiceName As String
|
||||
Private MapKeys As Variant ' To retain the original keys
|
||||
Private MapItems As Variant ' Array of ItemMaps
|
||||
Private _MapSize As Long ' Total number of entries in the dictionary
|
||||
Private _MapRemoved As Long ' Number of inactive entries in the dictionary
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "DICTIONARY"
|
||||
ServiceName = "ScriptForge.Dictionary"
|
||||
Set MapKeys = New Collection
|
||||
Set MapItems = Array()
|
||||
_MapSize = 0
|
||||
_MapRemoved = 0
|
||||
End Sub ' ScriptForge.SF_Dictionary Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' ScriptForge.SF_Dictionary Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
RemoveAll()
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_Dictionary Explicit destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Count() As Long
|
||||
''' Actual number of entries in the dictionary
|
||||
''' Example:
|
||||
''' myDict.Count
|
||||
|
||||
Count = _PropertyGet("Count")
|
||||
|
||||
End Property ' ScriptForge.SF_Dictionary.Count
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Item(Optional ByVal Key As Variant) As Variant
|
||||
''' Return the value of the item related to Key
|
||||
''' Args:
|
||||
''' Key: the key value (string)
|
||||
''' Returns:
|
||||
''' Empty if not found, otherwise the found value
|
||||
''' Example:
|
||||
''' myDict.Item("ThisKey")
|
||||
''' NB: defined as a function to not disrupt the Basic IDE debugger
|
||||
|
||||
Item = _PropertyGet("Item", Key)
|
||||
|
||||
End Function ' ScriptForge.SF_Dictionary.Item
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Items() as Variant
|
||||
''' Return the list of Items as a 1D array
|
||||
''' The Items and Keys properties return their respective contents in the same order
|
||||
''' The order is however not necessarily identical to the creation sequence
|
||||
''' Returns:
|
||||
''' The array is empty if the dictionary is empty
|
||||
''' Examples
|
||||
''' a = myDict.Items
|
||||
''' For Each b In a ...
|
||||
|
||||
Items = _PropertyGet("Items")
|
||||
|
||||
End Property ' ScriptForge.SF_Dictionary.Items
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Keys() as Variant
|
||||
''' Return the list of keys as a 1D array
|
||||
''' The Keys and Items properties return their respective contents in the same order
|
||||
''' The order is however not necessarily identical to the creation sequence
|
||||
''' Returns:
|
||||
''' The array is empty if the dictionary is empty
|
||||
''' Examples
|
||||
''' a = myDict.Keys
|
||||
''' For each b In a ...
|
||||
|
||||
Keys = _PropertyGet("Keys")
|
||||
|
||||
End Property ' ScriptForge.SF_Dictionary.Keys
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Add(Optional ByVal Key As Variant _
|
||||
, Optional ByVal Item As Variant _
|
||||
) As Boolean
|
||||
''' Add a new key-item pair into the dictionary
|
||||
''' Args:
|
||||
''' Key: must not yet exist in the dictionary
|
||||
''' Item: any value, including an array, a Basic object, a UNO object, ...
|
||||
''' Returns: True if successful
|
||||
''' Exceptions:
|
||||
''' DUPLICATEKEYERROR: such a key exists already
|
||||
''' INVALIDKEYERROR: zero-length string or only spaces
|
||||
''' Examples:
|
||||
''' myDict.Add("NewKey", NewValue)
|
||||
|
||||
Dim oItemMap As ItemMap ' New entry in the MapItems array
|
||||
Const cstThisSub = "Dictionary.Add"
|
||||
Const cstSubArgs = "Key, Item"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
Add = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Key, "Key", V_STRING) Then GoTo Catch
|
||||
If IsArray(Item) Then
|
||||
If Not SF_Utils._ValidateArray(Item, "Item") Then GoTo Catch
|
||||
Else
|
||||
If Not SF_Utils._Validate(Item, "Item") Then GoTo Catch
|
||||
End If
|
||||
End If
|
||||
If Key = Space(Len(Key)) Then GoTo CatchInvalid
|
||||
If Exists(Key) Then GoTo CatchDuplicate
|
||||
|
||||
Try:
|
||||
_MapSize = _MapSize + 1
|
||||
MapKeys.Add(_MapSize, Key)
|
||||
oItemMap.Key = Key
|
||||
oItemMap.Value = Item
|
||||
ReDim Preserve MapItems(1 To _MapSize)
|
||||
MapItems(_MapSize) = oItemMap
|
||||
Add = True
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchDuplicate:
|
||||
SF_Exception.RaiseFatal(DUPLICATEKEYERROR, "Key", Key)
|
||||
GoTo Finally
|
||||
CatchInvalid:
|
||||
SF_Exception.RaiseFatal(INVALIDKEYERROR, "Key")
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.Add
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ConvertToArray() As Variant
|
||||
''' Store the content of the dictionary in a 2-columns array:
|
||||
''' Key stored in 1st column, Item stored in 2nd
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' a zero-based 2D array(0:Count - 1, 0:1)
|
||||
''' an empty array if the dictionary is empty
|
||||
|
||||
Dim vArray As Variant ' Return value
|
||||
Dim sKey As String ' Tempry key
|
||||
Dim vKeys As Variant ' Array of keys
|
||||
Dim lCount As Long ' Counter
|
||||
Const cstThisSub = "Dictionary.ConvertToArray"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
vArray = Array()
|
||||
If Count = 0 Then
|
||||
Else
|
||||
ReDim vArray(0 To Count - 1, 0 To 1)
|
||||
lCount = -1
|
||||
vKeys = Keys
|
||||
For Each sKey in vKeys
|
||||
lCount = lCount + 1
|
||||
vArray(lCount, 0) = sKey
|
||||
vArray(lCount, 1) = Item(sKey)
|
||||
Next sKey
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ConvertToArray = vArray()
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ConvertToArray
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ConvertToJson(ByVal Optional Indent As Variant) As Variant
|
||||
''' Convert the content of the dictionary to a JSON string
|
||||
''' JSON = JavaScript Object Notation: https://en.wikipedia.org/wiki/JSON
|
||||
''' Limitations
|
||||
''' Allowed item types: String, Boolean, numbers, Null and Empty
|
||||
''' Arrays containing above types are allowed
|
||||
''' Dates are converted into strings (not within arrays)
|
||||
''' Other types are converted to their string representation (cfr. SF_String.Represent)
|
||||
''' Args:
|
||||
''' Indent:
|
||||
''' If indent is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level.
|
||||
''' An indent level <= 0 will only insert newlines.
|
||||
''' "", (the default) selects the most compact representation.
|
||||
''' Using a positive integer indent indents that many spaces per level.
|
||||
''' If indent is a string (such as Chr(9)), that string is used to indent each level.
|
||||
''' Returns:
|
||||
''' the JSON string
|
||||
''' Example:
|
||||
''' myDict.Add("p0", 12.5)
|
||||
''' myDict.Add("p1", "a string àé""ê")
|
||||
''' myDict.Add("p2", DateSerial(2020,9,28))
|
||||
''' myDict.Add("p3", True)
|
||||
''' myDict.Add("p4", Array(1,2,3))
|
||||
''' MsgBox a.ConvertToJson() ' {"p0": 12.5, "p1": "a string \u00e0\u00e9\"\u00ea", "p2": "2020-09-28", "p3": true, "p4": [1, 2, 3]}
|
||||
|
||||
Dim sJson As String ' Return value
|
||||
Dim vArray As Variant ' Array of property values
|
||||
Dim oPropertyValue As Object ' com.sun.star.beans.PropertyValue
|
||||
Dim sKey As String ' Tempry key
|
||||
Dim vKeys As Variant ' Array of keys
|
||||
Dim vItem As Variant ' Tempry item
|
||||
Dim iVarType As Integer ' Extended VarType
|
||||
Dim lCount As Long ' Counter
|
||||
Dim vIndent As Variant ' Python alias of Indent
|
||||
Const cstPyHelper = "$" & "_SF_Dictionary__ConvertToJson"
|
||||
|
||||
Const cstThisSub = "Dictionary.ConvertToJson"
|
||||
Const cstSubArgs = "[Indent=Null]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(Indent) Or IsEmpty(INDENT) Then Indent = ""
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Indent, "Indent", Array(V_STRING, V_NUMERIC)) Then GoTo Finally
|
||||
End If
|
||||
sJson = ""
|
||||
|
||||
Try:
|
||||
vArray = Array()
|
||||
If Count = 0 Then
|
||||
Else
|
||||
ReDim vArray(0 To Count - 1)
|
||||
lCount = -1
|
||||
vKeys = Keys
|
||||
For Each sKey in vKeys
|
||||
' Check item type
|
||||
vItem = Item(sKey)
|
||||
iVarType = SF_Utils._VarTypeExt(vItem)
|
||||
Select Case iVarType
|
||||
Case V_STRING, V_BOOLEAN, V_NUMERIC, V_NULL, V_EMPTY
|
||||
Case V_DATE
|
||||
vItem = SF_Utils._CDateToIso(vItem)
|
||||
Case >= V_ARRAY
|
||||
Case Else
|
||||
vItem = SF_Utils._Repr(vItem)
|
||||
End Select
|
||||
' Build in each array entry a (Name, Value) pair
|
||||
Set oPropertyValue = SF_Utils._MakePropertyValue(sKey, vItem)
|
||||
lCount = lCount + 1
|
||||
Set vArray(lCount) = oPropertyValue
|
||||
Next sKey
|
||||
End If
|
||||
|
||||
'Pass array to Python script for the JSON conversion
|
||||
With ScriptForge.SF_Session
|
||||
vIndent = Indent
|
||||
If VarType(Indent) = V_STRING Then
|
||||
If Len(Indent) = 0 Then vIndent = Null
|
||||
End If
|
||||
sJson = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, vArray, vIndent)
|
||||
End With
|
||||
|
||||
Finally:
|
||||
ConvertToJson = sJson
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ConvertToJson
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ConvertToPropertyValues() As Variant
|
||||
''' Store the content of the dictionary in an array of PropertyValues
|
||||
''' Key stored in Name, Item stored in Value
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' a zero-based 1D array(0:Count - 1). Each entry is a com.sun.star.beans.PropertyValue
|
||||
''' Name: the key in the dictionary
|
||||
''' Value:
|
||||
''' Dates are converted to UNO dates
|
||||
''' Empty arrays are replaced by Null
|
||||
''' an empty array if the dictionary is empty
|
||||
|
||||
Dim vArray As Variant ' Return value
|
||||
Dim oPropertyValue As Object ' com.sun.star.beans.PropertyValue
|
||||
Dim sKey As String ' Tempry key
|
||||
Dim vKeys As Variant ' Array of keys
|
||||
Dim lCount As Long ' Counter
|
||||
Const cstThisSub = "Dictionary.ConvertToPropertyValues"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
vArray = Array()
|
||||
If Count = 0 Then
|
||||
Else
|
||||
ReDim vArray(0 To Count - 1)
|
||||
lCount = -1
|
||||
vKeys = Keys
|
||||
For Each sKey in vKeys
|
||||
' Build in each array entry a (Name, Value) pair
|
||||
Set oPropertyValue = SF_Utils._MakePropertyValue(sKey, Item(sKey))
|
||||
lCount = lCount + 1
|
||||
Set vArray(lCount) = oPropertyValue
|
||||
Next sKey
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ConvertToPropertyValues = vArray()
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ConvertToPropertyValues
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Exists(Optional ByVal Key As Variant) As Boolean
|
||||
''' Determine if a key exists in the dictionary
|
||||
''' Args:
|
||||
''' Key: the key value (string)
|
||||
''' Returns: True if key exists
|
||||
''' Examples:
|
||||
''' If myDict.Exists("SomeKey") Then ' don't add again
|
||||
|
||||
Dim vItem As Variant ' Item part in MapKeys
|
||||
Const cstThisSub = "Dictionary.Exists"
|
||||
Const cstSubArgs = "Key"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
Exists = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Key, "Key", V_STRING) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Dirty but preferred to go through whole collection
|
||||
On Local Error GoTo NotFound
|
||||
vItem = MapKeys(Key)
|
||||
NotFound:
|
||||
Exists = ( Not ( Err = 5 ) And vItem > 0 )
|
||||
On Local Error GoTo 0
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.Exists
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByVal Key As Variant _
|
||||
) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Key: mandatory if PropertyName = "Item", ignored otherwise
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
''' Examples:
|
||||
''' myDict.GetProperty("Count")
|
||||
|
||||
Const cstThisSub = "Dictionary.GetProperty"
|
||||
Const cstSubArgs = "PropertyName, [Key]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If IsMissing(Key) Or IsEmpty(Key) Then Key = ""
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName, Key)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ImportFromJson(Optional ByVal InputStr As Variant _
|
||||
, Optional Byval Overwrite As Variant _
|
||||
) As Boolean
|
||||
''' Adds the content of a Json string into the current dictionary
|
||||
''' JSON = JavaScript Object Notation: https://en.wikipedia.org/wiki/JSON
|
||||
''' Limitations
|
||||
''' The JSON string may contain numbers, strings, booleans, null values and arrays containing those types
|
||||
''' It must not contain JSON objects, i.e. sub-dictionaries
|
||||
''' An attempt is made to convert strings to dates if they fit one of next patterns:
|
||||
''' YYYY-MM-DD, HH:MM:SS or YYYY-MM-DD HH:MM:SS
|
||||
''' Args:
|
||||
''' InputStr: the json string to import
|
||||
''' Overwrite: when True entries with same name may exist in the dictionary and their values are overwritten
|
||||
''' Default = False
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
''' Exceptions:
|
||||
''' DUPLICATEKEYERROR: such a key exists already
|
||||
''' INVALIDKEYERROR: zero-length string or only spaces
|
||||
''' Example:
|
||||
''' Dim s As String
|
||||
''' s = "{'firstName': 'John','lastName': 'Smith','isAlive': true,'age': 66, 'birth': '1954-09-28 20:15:00'" _
|
||||
''' & ",'address': {'streetAddress': '21 2nd Street','city': 'New York','state': 'NY','postalCode': '10021-3100'}" _
|
||||
''' & ",'phoneNumbers': [{'type': 'home','number': '212 555-1234'},{'type': 'office','number': '646 555-4567'}]" _
|
||||
''' & ",'children': ['Q','M','G','T'],'spouse': null}"
|
||||
''' s = Replace(s, "'", """")
|
||||
''' myDict.ImportFromJson(s, OverWrite := True)
|
||||
''' ' The (sub)-dictionaries "address" and "phoneNumbers(0) and (1) are reduced to Empty
|
||||
|
||||
Dim bImport As Boolean ' Return value
|
||||
Dim vArray As Variant ' JSON string converted to array
|
||||
Dim vArrayEntry As Variant ' A single entry in vArray
|
||||
Dim vKey As Variant ' Tempry key
|
||||
Dim vItem As Variant ' Tempry item
|
||||
Dim bExists As Boolean ' True when an entry exists
|
||||
Dim dDate As Date ' String converted to Date
|
||||
Const cstPyHelper = "$" & "_SF_Dictionary__ImportFromJson"
|
||||
|
||||
Const cstThisSub = "Dictionary.ImportFromJson"
|
||||
Const cstSubArgs = "InputStr, [Overwrite=False]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bImport = False
|
||||
|
||||
Check:
|
||||
If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(InputStr, "InputStr", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Overwrite, "Overwrite", V_BOOLEAN) Then GoYo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
With ScriptForge.SF_Session
|
||||
vArray = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, InputStr)
|
||||
End With
|
||||
If Not IsArray(vArray) Then GoTo Finally ' Conversion error or nothing to do
|
||||
|
||||
' vArray = Array of subarrays = 2D DataArray (cfr. Calc)
|
||||
For Each vArrayEntry In vArray
|
||||
vKey = vArrayEntry(0)
|
||||
If VarType(vKey) = V_STRING Then ' Else skip
|
||||
vItem = vArrayEntry(1)
|
||||
If Overwrite Then bExists = Exists(vKey) Else bExists = False
|
||||
' When the item matches a date pattern, convert it to a date
|
||||
If VarType(vItem) = V_STRING Then
|
||||
dDate = SF_Utils._CStrToDate(vItem)
|
||||
If dDate > -1 Then vItem = dDate
|
||||
End If
|
||||
If bExists Then
|
||||
ReplaceItem(vKey, vItem)
|
||||
Else
|
||||
Add(vKey, vItem) ' Key controls are done in Add
|
||||
End If
|
||||
End If
|
||||
Next vArrayEntry
|
||||
|
||||
bImport = True
|
||||
|
||||
Finally:
|
||||
ImportFromJson = bImport
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ImportFromJson
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ImportFromPropertyValues(Optional ByVal PropertyValues As Variant _
|
||||
, Optional Byval Overwrite As Variant _
|
||||
) As Boolean
|
||||
''' Adds the content of an array of PropertyValues into the current dictionary
|
||||
''' Names contain Keys, Values contain Items
|
||||
''' UNO dates are replaced by Basic dates
|
||||
''' Args:
|
||||
''' PropertyValues: a zero-based 1D array. Each entry is a com.sun.star.beans.PropertyValue
|
||||
''' Overwrite: when True entries with same name may exist in the dictionary and their values are overwritten
|
||||
''' Default = False
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
''' Exceptions:
|
||||
''' DUPLICATEKEYERROR: such a key exists already
|
||||
''' INVALIDKEYERROR: zero-length string or only spaces
|
||||
|
||||
Dim bImport As Boolean ' Return value
|
||||
Dim oPropertyValue As Object ' com.sun.star.beans.PropertyValue
|
||||
Dim vItem As Variant ' Tempry item
|
||||
Dim sObjectType As String ' UNO object type of dates
|
||||
Dim bExists As Boolean ' True when an entry exists
|
||||
Const cstThisSub = "Dictionary.ImportFromPropertyValues"
|
||||
Const cstSubArgs = "PropertyValues, [Overwrite=False]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bImport = False
|
||||
|
||||
Check:
|
||||
If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If IsArray(PropertyValues) Then
|
||||
If Not SF_Utils._ValidateArray(PropertyValues, "PropertyValues", 1, V_OBJECT, True) Then GoTo Finally
|
||||
Else
|
||||
If Not SF_Utils._Validate(PropertyValues, "PropertyValues", V_OBJECT) Then GoTo Finally
|
||||
End If
|
||||
If Not SF_Utils._Validate(Overwrite, "Overwrite", V_BOOLEAN) Then GoYo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
If Not IsArray(PropertyValues) Then PropertyValues = Array(PropertyValues)
|
||||
With oPropertyValue
|
||||
For Each oPropertyValue In PropertyValues
|
||||
If Overwrite Then bExists = Exists(.Name) Else bExists = False
|
||||
If SF_Session.UnoObjectType(oPropertyValue) = "com.sun.star.beans.PropertyValue" Then
|
||||
If IsUnoStruct(.Value) Then
|
||||
sObjectType = SF_Session.UnoObjectType(.Value)
|
||||
Select Case sObjectType
|
||||
Case "com.sun.star.util.DateTime" : vItem = CDateFromUnoDateTime(.Value)
|
||||
Case "com.sun.star.util.Date" : vItem = CDateFromUnoDate(.Value)
|
||||
Case "com.sun.star.util.Time" : vItem = CDateFromUnoTime(.Value)
|
||||
Case Else : vItem = .Value
|
||||
End Select
|
||||
Else
|
||||
vItem = .Value
|
||||
End If
|
||||
If bExists Then
|
||||
ReplaceItem(.Name, vItem)
|
||||
Else
|
||||
Add(.Name, vItem) ' Key controls are done in Add
|
||||
End If
|
||||
End If
|
||||
Next oPropertyValue
|
||||
End With
|
||||
bImport = True
|
||||
|
||||
Finally:
|
||||
ImportFromPropertyValues = bImport
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ImportFromPropertyValues
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list or methods of the Dictionary class as an array
|
||||
|
||||
Methods = Array( _
|
||||
"Add" _
|
||||
, "ConvertToArray" _
|
||||
, "ConvertToJson" _
|
||||
, "ConvertToPropertyValues" _
|
||||
, "Exists" _
|
||||
, "ImportFromJson" _
|
||||
, "ImportFromPropertyValues" _
|
||||
, "Remove" _
|
||||
, "RemoveAll" _
|
||||
, "ReplaceItem" _
|
||||
, "ReplaceKey" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Dictionary.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Dictionary class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"Count" _
|
||||
, "Item" _
|
||||
, "Items" _
|
||||
, "Keys" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Dictionary.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Remove(Optional ByVal Key As Variant) As Boolean
|
||||
''' Remove an existing dictionary entry based on its key
|
||||
''' Args:
|
||||
''' Key: must exist in the dictionary
|
||||
''' Returns: True if successful
|
||||
''' Exceptions:
|
||||
''' UNKNOWNKEYERROR: the key does not exist
|
||||
''' Examples:
|
||||
''' myDict.Remove("OldKey")
|
||||
|
||||
Dim lIndex As Long ' To remove entry in the MapItems array
|
||||
Const cstThisSub = "Dictionary.Remove"
|
||||
Const cstSubArgs = "Key"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
Remove = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Key, "Key", V_STRING) Then GoTo Catch
|
||||
End If
|
||||
If Not Exists(Key) Then GoTo CatchUnknown
|
||||
|
||||
Try:
|
||||
lIndex = MapKeys.Item(Key)
|
||||
MapKeys.Remove(Key)
|
||||
Erase MapItems(lIndex) ' Is now Empty
|
||||
_MapRemoved = _MapRemoved + 1
|
||||
Remove = True
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchUnknown:
|
||||
SF_Exception.RaiseFatal(UNKNOWNKEYERROR, "Key", Key)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.Remove
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function RemoveAll() As Boolean
|
||||
''' Remove all the entries from the dictionary
|
||||
''' Args:
|
||||
''' Returns: True if successful
|
||||
''' Examples:
|
||||
''' myDict.RemoveAll()
|
||||
|
||||
Dim vKeys As Variant ' Array of keys
|
||||
Dim sColl As String ' A collection key in MapKeys
|
||||
Const cstThisSub = "Dictionary.RemoveAll"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
RemoveAll = False
|
||||
|
||||
Check:
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
vKeys = Keys
|
||||
For Each sColl In vKeys
|
||||
MapKeys.Remove(sColl)
|
||||
Next sColl
|
||||
Erase MapKeys
|
||||
Erase MapItems
|
||||
' Make dictionary ready to receive new entries
|
||||
Call Class_Initialize()
|
||||
RemoveAll = True
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.RemoveAll
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ReplaceItem(Optional ByVal Key As Variant _
|
||||
, Optional ByVal Value As Variant _
|
||||
) As Boolean
|
||||
''' Replace the item value
|
||||
''' Args:
|
||||
''' Key: must exist in the dictionary
|
||||
''' Returns: True if successful
|
||||
''' Exceptions:
|
||||
''' UNKNOWNKEYERROR: the old key does not exist
|
||||
''' Examples:
|
||||
''' myDict.ReplaceItem("Key", NewValue)
|
||||
|
||||
Dim oItemMap As ItemMap ' Content to update in the MapItems array
|
||||
Dim lIndex As Long ' Entry in the MapItems array
|
||||
Const cstThisSub = "Dictionary.ReplaceItem"
|
||||
Const cstSubArgs = "Key, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
ReplaceItem = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Key, "Key", V_STRING) Then GoTo Catch
|
||||
If Not SF_Utils._Validate(Value, "Value") Then GoTo Catch
|
||||
End If
|
||||
If Not Exists(Key) Then GoTo CatchUnknown
|
||||
|
||||
Try:
|
||||
' Find entry in MapItems and update it with the new value
|
||||
lIndex = MapKeys.Item(Key)
|
||||
oItemMap = MapItems(lIndex)
|
||||
oItemMap.Value = Value
|
||||
ReplaceItem = True
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchUnknown:
|
||||
SF_Exception.RaiseFatal(UNKNOWNKEYERROR, "Key", Key)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ReplaceItem
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ReplaceKey(Optional ByVal Key As Variant _
|
||||
, Optional ByVal Value As Variant _
|
||||
) As Boolean
|
||||
''' Replace existing key
|
||||
''' Args:
|
||||
''' Key: must exist in the dictionary
|
||||
''' Value: must not exist in the dictionary
|
||||
''' Returns: True if successful
|
||||
''' Exceptions:
|
||||
''' UNKNOWNKEYERROR: the old key does not exist
|
||||
''' DUPLICATEKEYERROR: the new key exists
|
||||
''' Examples:
|
||||
''' myDict.ReplaceKey("OldKey", "NewKey")
|
||||
|
||||
Dim oItemMap As ItemMap ' Content to update in the MapItems array
|
||||
Dim lIndex As Long ' Entry in the MapItems array
|
||||
Const cstThisSub = "Dictionary.ReplaceKey"
|
||||
Const cstSubArgs = "Key, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
ReplaceKey = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Key, "Key", V_STRING) Then GoTo Catch
|
||||
If Not SF_Utils._Validate(Value, "Value", V_STRING) Then GoTo Catch
|
||||
End If
|
||||
If Not Exists(Key) Then GoTo CatchUnknown
|
||||
If Value = Space(Len(Value)) Then GoTo CatchInvalid
|
||||
If Exists(Value) Then GoTo CatchDuplicate
|
||||
|
||||
Try:
|
||||
' Remove the Key entry and create a new one in MapKeys
|
||||
With MapKeys
|
||||
lIndex = .Item(Key)
|
||||
.Remove(Key)
|
||||
.Add(lIndex, Value)
|
||||
End With
|
||||
oItemMap = MapItems(lIndex)
|
||||
oItemMap.Key = Value
|
||||
ReplaceKey = True
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchUnknown:
|
||||
SF_Exception.RaiseFatal(UNKNOWNKEYERROR, "Key", Key)
|
||||
GoTo Finally
|
||||
CatchDuplicate:
|
||||
SF_Exception.RaiseFatal(DUPLICATEKEYERROR, "Value", Value)
|
||||
GoTo Finally
|
||||
CatchInvalid:
|
||||
SF_Exception.RaiseFatal(INVALIDKEYERROR, "Key")
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.ReplaceKey
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "Dictionary.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
SetProperty = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary.SetProperty
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String _
|
||||
, Optional pvKey As Variant _
|
||||
)
|
||||
''' Return the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
''' pvKey: the key to retrieve, numeric or string
|
||||
|
||||
Dim vItemMap As Variant ' Entry in the MapItems array
|
||||
Dim vArray As Variant ' To get Keys or Values
|
||||
Dim i As Long
|
||||
Dim cstThisSub As String
|
||||
Dim cstSubArgs As String
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
cstThisSub = "SF_Dictionary.get" & psProperty
|
||||
If IsMissing(pvKey) Then cstSubArgs = "" Else cstSubArgs = "[Key]"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("Count")
|
||||
_PropertyGet = _MapSize - _MapRemoved
|
||||
Case UCase("Item")
|
||||
If Not SF_Utils._Validate(pvKey, "Key", V_STRING) Then GoTo Catch
|
||||
If Exists(pvKey) Then _PropertyGet = MapItems(MapKeys(pvKey)).Value Else _PropertyGet = Empty
|
||||
Case UCase("Keys"), UCase("Items")
|
||||
vArray = Array()
|
||||
If _MapSize - _MapRemoved - 1 >= 0 Then
|
||||
ReDim vArray(0 To (_MapSize - _MapRemoved - 1))
|
||||
i = -1
|
||||
For each vItemMap In MapItems()
|
||||
If Not IsEmpty(vItemMap) Then
|
||||
i = i + 1
|
||||
If UCase(psProperty) = "KEYS" Then vArray(i) = vItemMap.Key Else vArray(i) = vItemMap.Value
|
||||
End If
|
||||
Next vItemMap
|
||||
End If
|
||||
_PropertyGet = vArray
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Dictionary._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the Dictionary instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[Dictionary] (key1:value1, key2:value2, ...)
|
||||
|
||||
Dim sDict As String ' Return value
|
||||
Dim vKeys As Variant ' Array of keys
|
||||
Dim sKey As String ' Tempry key
|
||||
Dim vItem As Variant ' Tempry item
|
||||
Const cstDictEmpty = "[Dictionary] ()"
|
||||
Const cstDict = "[Dictionary]"
|
||||
Const cstMaxLength = 50 ' Maximum length for items
|
||||
Const cstSeparator = ", "
|
||||
|
||||
_Repr = ""
|
||||
|
||||
If Count = 0 Then
|
||||
sDict = cstDictEmpty
|
||||
Else
|
||||
sDict = cstDict & " ("
|
||||
vKeys = Keys
|
||||
For Each sKey in vKeys
|
||||
vItem = Item(sKey)
|
||||
sDict = sDict & sKey & ":" & SF_Utils._Repr(vItem, cstMaxLength) & cstSeparator
|
||||
Next sKey
|
||||
sDict = Left(sDict, Len(sDict) - Len(cstSeparator)) & ")" ' Suppress last comma
|
||||
End If
|
||||
|
||||
_Repr = sDict
|
||||
|
||||
End Function ' ScriptForge.SF_Dictionary._Repr
|
||||
|
||||
REM ============================================ END OF SCRIPTFORGE.SF_DICTIONARY
|
||||
</script:module>
|
||||
1107
server/windows-office/share/basic/ScriptForge/SF_Exception.xba
Normal file
1107
server/windows-office/share/basic/ScriptForge/SF_Exception.xba
Normal file
File diff suppressed because it is too large
Load Diff
2084
server/windows-office/share/basic/ScriptForge/SF_FileSystem.xba
Normal file
2084
server/windows-office/share/basic/ScriptForge/SF_FileSystem.xba
Normal file
File diff suppressed because it is too large
Load Diff
696
server/windows-office/share/basic/ScriptForge/SF_L10N.xba
Normal file
696
server/windows-office/share/basic/ScriptForge/SF_L10N.xba
Normal file
@@ -0,0 +1,696 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_L10N" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
'Option Private Module
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' L10N (aka SF_L10N)
|
||||
''' ====
|
||||
''' Implementation of a Basic class for providing a number of services
|
||||
''' related to the translation of user interfaces into a huge number of languages
|
||||
''' with a minimal impact on the program code itself
|
||||
'''
|
||||
''' The design choices of this module are based on so-called PO-files
|
||||
''' PO-files (portable object files) have long been promoted in the free software industry
|
||||
''' as a mean of providing multilingual UIs. This is accomplished through the use of human-readable
|
||||
''' text files with a well defined structure that specifies, for any given language,
|
||||
''' the source language string and the localized string
|
||||
'''
|
||||
''' To read more about the PO format and its ecosystem of associated toolsets:
|
||||
''' https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html#PO-Files
|
||||
''' and, IMHO, a very good tutorial:
|
||||
''' http://pology.nedohodnik.net/doc/user/en_US/ch-about.html
|
||||
'''
|
||||
''' The main advantage of the PO format is the complete dissociation between the two
|
||||
''' very different profiles, i.e. the programmer and the translator(s).
|
||||
''' Being independent text files, one per language to support, the programmer may give away
|
||||
''' pristine PO template files (known as POT-files) for a translator to process.
|
||||
'''
|
||||
''' This class implements mainly 3 mechanisms:
|
||||
''' - AddText: for the programmer to build a set of words or sentences
|
||||
''' meant for being translated later
|
||||
''' - ExportToPOTFile: All the above texts are exported into a pristine POT-file
|
||||
''' - GetText: At runtime get the text in the user language
|
||||
''' Note that the first two are optional: POT and PO-files may be built with a simple text editor
|
||||
'''
|
||||
''' Several instances of the L10N class may coexist
|
||||
' The constraint however is that each instance should find its PO-files
|
||||
''' in a separate directory
|
||||
''' PO-files must be named with the targeted locale: f.i. "en-US.po" or "fr-BE.po"
|
||||
'''
|
||||
''' Service invocation syntax
|
||||
''' CreateScriptService("L10N"[, FolderName[, Locale]])
|
||||
''' FolderName: the folder containing the PO-files (in SF_FileSystem.FileNaming notation)
|
||||
''' Locale: in the form la-CO (language-COUNTRY)
|
||||
''' Service invocation examples:
|
||||
''' Dim myPO As Variant
|
||||
''' myPO = CreateScriptService("L10N") ' AddText and ExportToPOTFile are allowed
|
||||
''' myPO = CreateScriptService("L10N", "C:\myPOFiles\", "fr-BE")
|
||||
''' 'All functionalities are available
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM =============================================================== PRIVATE TYPES
|
||||
|
||||
''' The recognized elements of an entry in a PO file are (other elements are ignored) :
|
||||
''' #. Extracted comments (given by the programmer to the translator)
|
||||
''' #, flag (the kde-format flag when the string contains tokens)
|
||||
''' msgctxt Context (to store an acronym associated with the message, this is a distortion of the norm)
|
||||
''' msgid untranslated-string
|
||||
''' msgstr translated-string
|
||||
''' NB: plural forms are not supported
|
||||
|
||||
Type POEntry
|
||||
Comment As String
|
||||
Flag As String
|
||||
Context As String
|
||||
MsgId As String
|
||||
MsgStr As String
|
||||
End Type
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Const DUPLICATEKEYERROR = "DUPLICATEKEYERROR"
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private ObjectType As String ' Must be "L10N"
|
||||
Private ServiceName As String
|
||||
Private _POFolder As String ' PO files container
|
||||
Private _Locale As String ' la-CO
|
||||
Private _POFile As String ' PO file in URL format
|
||||
Private _Encoding As String ' Used to open the PO file, default = UTF-8
|
||||
Private _Dictionary As Object ' SF_Dictionary
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "L10N"
|
||||
ServiceName = "ScriptForge.L10N"
|
||||
_POFolder = ""
|
||||
_Locale = ""
|
||||
_POFile = ""
|
||||
Set _Dictionary = Nothing
|
||||
End Sub ' ScriptForge.SF_L10N Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
|
||||
If Not IsNull(_Dictionary) Then Set _Dictionary = _Dictionary.Dispose()
|
||||
Call Class_Initialize()
|
||||
End Sub ' ScriptForge.SF_L10N Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_L10N Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Folder() As String
|
||||
''' Returns the FolderName containing the PO-files expressed as given by the current FileNaming
|
||||
''' property of the SF_FileSystem service. Default = URL format
|
||||
''' May be empty
|
||||
''' Example:
|
||||
''' myPO.Folder
|
||||
|
||||
Folder = _PropertyGet("Folder")
|
||||
|
||||
End Property ' ScriptForge.SF_L10N.Folder
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Languages() As Variant
|
||||
''' Returns a zero-based array listing all the BaseNames of the PO-files found in Folder,
|
||||
''' Example:
|
||||
''' myPO.Languages
|
||||
|
||||
Languages = _PropertyGet("Languages")
|
||||
|
||||
End Property ' ScriptForge.SF_L10N.Languages
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Locale() As String
|
||||
''' Returns the currently active language-COUNTRY combination. May be empty
|
||||
''' Example:
|
||||
''' myPO.Locale
|
||||
|
||||
Locale = _PropertyGet("Locale")
|
||||
|
||||
End Property ' ScriptForge.SF_L10N.Locale
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function AddText(Optional ByVal Context As Variant _
|
||||
, Optional ByVal MsgId As Variant _
|
||||
, Optional ByVal Comment As Variant _
|
||||
, Optional ByVal MsgStr As Variant _
|
||||
) As Boolean
|
||||
''' Add a new entry in the list of localizable text strings
|
||||
''' Args:
|
||||
''' Context: when not empty, the key to retrieve the translated string via GetText. Default = ""
|
||||
''' MsgId: the untranslated string, i.e. the text appearing in the program code. Must not be empty
|
||||
''' The key to retrieve the translated string via GetText when Context is empty
|
||||
''' May contain placeholders (%1 ... %9) for dynamic arguments to be inserted in the text at run-time
|
||||
''' If the string spans multiple lines, insert escape sequences (\n) where relevant
|
||||
''' Comment: the so-called "extracted-comments" intended to inform/help translators
|
||||
''' If the string spans multiple lines, insert escape sequences (\n) where relevant
|
||||
''' MsgStr: (internal use only) the translated string
|
||||
''' If the string spans multiple lines, insert escape sequences (\n) where relevant
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
''' Exceptions:
|
||||
''' DUPLICATEKEYERROR: such a key exists already
|
||||
''' Examples:
|
||||
''' myPO.AddText(, "This is a text to be included in a POT file")
|
||||
|
||||
Dim bAdd As Boolean ' Output buffer
|
||||
Dim sKey As String ' The key part of the new entry in the dictionary
|
||||
Dim vItem As POEntry ' The item part of the new entry in the dictionary
|
||||
Const cstPipe = "|" ' Pipe forbidden in MsgId's
|
||||
Const cstThisSub = "L10N.AddText"
|
||||
Const cstSubArgs = "[Context=""""], MsgId, [Comment=""""]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bAdd = False
|
||||
|
||||
Check:
|
||||
If IsMissing(Context) Or IsMissing(Context) Then Context = ""
|
||||
If IsMissing(Comment) Or IsMissing(Comment) Then Comment = ""
|
||||
If IsMissing(MsgStr) Or IsMissing(MsgStr) Then MsgStr = ""
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Context, "Context", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(MsgId, "MsgId", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Comment, "Comment", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(MsgStr, "MsgStr", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
If Len(MsgId) = 0 Then GoTo Finally
|
||||
|
||||
Try:
|
||||
If Len(Context) > 0 Then sKey = Context Else sKey = MsgId
|
||||
If _Dictionary.Exists(sKey) Then GoTo CatchDuplicate
|
||||
|
||||
With vItem
|
||||
.Comment = Comment
|
||||
If InStr(MsgId, "%") > 0 Then .Flag = "kde-format" Else .Flag = ""
|
||||
.Context = Replace(Context, cstPipe, " ")
|
||||
.MsgId = Replace(MsgId, cstPipe, " ")
|
||||
.MsgStr = MsgStr
|
||||
End With
|
||||
_Dictionary.Add(sKey, vItem)
|
||||
|
||||
Finally:
|
||||
AddText = bAdd
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchDuplicate:
|
||||
SF_Exception.RaiseFatal(DUPLICATEKEYERROR, Iif(Len(Context) > 0, "Context", "MsgId"), sKey)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_L10N.AddText
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ExportToPOTFile(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal Header As Variant _
|
||||
, Optional ByVal Encoding As Variant _
|
||||
) As Boolean
|
||||
''' Export a set of untranslated strings as a POT file
|
||||
''' The set of strings has been built either by a succession of AddText() methods
|
||||
''' or by a successful invocation of the L10N service with the FolderName argument
|
||||
''' The generated file should pass successfully the "msgfmt --check 'the pofile'" GNU command
|
||||
''' Args:
|
||||
''' FileName: the complete file name to export to. If it exists, is overwritten without warning
|
||||
''' Header: Comments that will appear on top of the generated file. Do not include any leading "#"
|
||||
''' If the string spans multiple lines, insert escape sequences (\n) where relevant
|
||||
''' A standard header will be added anyway
|
||||
''' Encoding: The character set that should be used
|
||||
''' Use one of the Names listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml
|
||||
''' Note that LibreOffice probably does not implement all existing sets
|
||||
''' Default = UTF-8
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
''' Examples:
|
||||
''' myPO.ExportToPOTFile("myFile.pot", Header := "Top comment\nSecond line of top comment")
|
||||
|
||||
Dim bExport As Boolean ' Return value
|
||||
Dim oFile As Object ' Generated file handler
|
||||
Dim vLines As Variant ' Wrapped lines
|
||||
Dim sLine As String ' A single line
|
||||
Dim vItems As Variant ' Array of dictionary items
|
||||
Dim vItem As Variant ' POEntry type
|
||||
Const cstSharp = "# ", cstSharpDot = "#. ", cstFlag = "#, kde-format"
|
||||
Const cstTabSize = 4
|
||||
Const cstWrap = 70
|
||||
Const cstThisSub = "L10N.ExportToPOTFile"
|
||||
Const cstSubArgs = "FileName, [Header=""""], [Encoding=""UTF-8"""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bExport = False
|
||||
|
||||
Check:
|
||||
If IsMissing(Header) Or IsMissing(Header) Then Header = ""
|
||||
If IsMissing(Encoding) Or IsMissing(Encoding) Then Encoding = "UTF-8"
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Header, "Header", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Encoding, "Encoding", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
Set oFile = SF_FileSystem.CreateTextFile(FileName, Overwrite := True, Encoding := Encoding)
|
||||
If Not IsNull(oFile) Then
|
||||
With oFile
|
||||
' Standard header
|
||||
.WriteLine(cstSharp)
|
||||
.WriteLine(cstSharp & "This pristine POT file has been generated by LibreOffice/ScriptForge")
|
||||
.WriteLine(cstSharp & "Full documentation is available on https://help.libreoffice.org/")
|
||||
' User header
|
||||
If Len(Header) > 0 Then
|
||||
.WriteLine(cstSharp)
|
||||
vLines = SF_String.Wrap(Header, cstWrap, cstTabSize)
|
||||
For Each sLine In vLines
|
||||
.WriteLine(cstSharp & Replace(sLine, SF_String.sfLF, ""))
|
||||
Next sLine
|
||||
End If
|
||||
' Standard header
|
||||
.WriteLine(cstSharp)
|
||||
.WriteLine("msgid """"")
|
||||
.WriteLine("msgstr """"")
|
||||
.WriteLine(SF_String.Quote("Project-Id-Version: PACKAGE VERSION\n"))
|
||||
.WriteLine(SF_String.Quote("Report-Msgid-Bugs-To: " _
|
||||
& "https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n"))
|
||||
.WriteLine(SF_String.Quote("POT-Creation-Date: " & SF_STring.Represent(Now()) & "\n"))
|
||||
.WriteLine(SF_String.Quote("PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n"))
|
||||
.WriteLine(SF_String.Quote("Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"))
|
||||
.WriteLine(SF_String.Quote("Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"))
|
||||
.WriteLine(SF_String.Quote("Language: en_US\n"))
|
||||
.WriteLine(SF_String.Quote("MIME-Version: 1.0\n"))
|
||||
.WriteLine(SF_String.Quote("Content-Type: text/plain; charset=" & Encoding & "\n"))
|
||||
.WriteLine(SF_String.Quote("Content-Transfer-Encoding: 8bit\n"))
|
||||
.WriteLine(SF_String.Quote("Plural-Forms: nplurals=2; plural=n > 1;\n"))
|
||||
.WriteLine(SF_String.Quote("X-Generator: LibreOffice - ScriptForge\n"))
|
||||
.WriteLine(SF_String.Quote("X-Accelerator-Marker: ~\n"))
|
||||
' Individual translatable strings
|
||||
vItems = _Dictionary.Items()
|
||||
For Each vItem in vItems
|
||||
.WriteBlankLines(1)
|
||||
' Comments
|
||||
vLines = Split(vItem.Comment, "\n")
|
||||
For Each sLine In vLines
|
||||
.WriteLine(cstSharpDot & SF_String.ExpandTabs(SF_String.Unescape(sLine), cstTabSize))
|
||||
Next sLine
|
||||
' Flag
|
||||
If InStr(vItem.MsgId, "%") > 0 Then .WriteLine(cstFlag)
|
||||
' Context
|
||||
If Len(vItem.Context) > 0 Then
|
||||
.WriteLine("msgctxt " & SF_String.Quote(vItem.Context))
|
||||
End If
|
||||
' MsgId
|
||||
vLines = SF_String.Wrap(vItem.MsgId, cstWrap, cstTabSize)
|
||||
If UBound(vLines) = 0 Then
|
||||
.WriteLine("msgid " & SF_String.Quote(SF_String.Escape(vLines(0))))
|
||||
Else
|
||||
.WriteLine("msgid """"")
|
||||
For Each sLine in vLines
|
||||
.WriteLine(SF_String.Quote(SF_String.Escape(sLine)))
|
||||
Next sLine
|
||||
End If
|
||||
' MsgStr
|
||||
.WriteLine("msgstr """"")
|
||||
Next vItem
|
||||
.CloseFile()
|
||||
End With
|
||||
End If
|
||||
bExport = True
|
||||
|
||||
Finally:
|
||||
If Not IsNull(oFile) Then Set oFile = oFile.Dispose()
|
||||
ExportToPOTFile = bExport
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_L10N.ExportToPOTFile
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' If the property does not exist, returns Null
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
''' Examples:
|
||||
''' myL10N.GetProperty("MyProperty")
|
||||
|
||||
Const cstThisSub = "L10N.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_L10N.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetText(Optional ByVal MsgId As Variant _
|
||||
, ParamArray pvArgs As Variant _
|
||||
) As String
|
||||
''' Get the translated string corresponding with the given argument
|
||||
''' Args:
|
||||
''' MsgId: the identifier of the string or the untranslated string
|
||||
''' Either - the untranslated text (MsgId)
|
||||
''' - the reference to the untranslated text (Context)
|
||||
''' - both (Context|MsgId) : the pipe character is essential
|
||||
''' pvArgs(): a list of arguments present as %1, %2, ... in the (un)translated string)
|
||||
''' to be substituted in the returned string
|
||||
''' Any type is admitted but only strings, numbers or dates are relevant
|
||||
''' Returns:
|
||||
''' The translated string
|
||||
''' If not found the MsgId string or the Context string
|
||||
''' Anyway the substitution is done
|
||||
''' Examples:
|
||||
''' myPO.GetText("This is a text to be included in a POT file")
|
||||
''' ' Ceci est un text à inclure dans un fichier POT
|
||||
|
||||
Dim sText As String ' Output buffer
|
||||
Dim sContext As String ' Context part of argument
|
||||
Dim sMsgId As String ' MsgId part of argument
|
||||
Dim vItem As POEntry ' Entry in the dictionary
|
||||
Dim vMsgId As Variant ' MsgId split on pipe
|
||||
Dim sKey As String ' Key of dictionary
|
||||
Dim sPercent As String ' %1, %2, ... placeholders
|
||||
Dim i As Long
|
||||
Const cstPipe = "|"
|
||||
Const cstThisSub = "L10N.GetText"
|
||||
Const cstSubArgs = "MsgId, [Arg0, Arg1, ...]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
sText = ""
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(MsgId, "MsgId", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
If Len(Trim(MsgId)) = 0 Then GoTo Finally
|
||||
sText = MsgId
|
||||
|
||||
Try:
|
||||
' Find and load entry from dictionary
|
||||
If Left(MsgId, 1) = cstPipe then MsgId = Mid(MsgId, 2)
|
||||
vMsgId = Split(MsgId, cstPipe)
|
||||
sKey = vMsgId(0)
|
||||
If Not _Dictionary.Exists(sKey) Then ' Not found
|
||||
If UBound(vMsgId) = 0 Then sText = vMsgId(0) Else sText = Mid(MsgId, InStr(MsgId, cstPipe) + 1)
|
||||
Else
|
||||
vItem = _Dictionary.Item(sKey)
|
||||
If Len(vItem.MsgStr) > 0 Then sText = vItem.MsgStr Else sText = vItem.MsgId
|
||||
End If
|
||||
|
||||
' Substitute %i placeholders
|
||||
For i = UBound(pvArgs) To 0 Step -1 ' Go downwards to not have a limit in number of args
|
||||
sPercent = "%" & (i + 1)
|
||||
sText = Replace(sText, sPercent, SF_String.Represent(pvArgs(i)))
|
||||
Next i
|
||||
|
||||
Finally:
|
||||
GetText = sText
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_L10N.GetText
|
||||
|
||||
REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Public Function _(Optional ByVal MsgId As Variant _
|
||||
, ParamArray pvArgs As Variant _
|
||||
) As String
|
||||
''' Get the translated string corresponding with the given argument
|
||||
''' Alias of GetText() - See above
|
||||
''' Examples:
|
||||
''' myPO._("This is a text to be included in a POT file")
|
||||
''' ' Ceci est un text à inclure dans un fichier POT
|
||||
|
||||
Dim sText As String ' Output buffer
|
||||
Dim sPercent As String ' %1, %2, ... placeholders
|
||||
Dim i As Long
|
||||
Const cstPipe = "|"
|
||||
Const cstThisSub = "L10N._"
|
||||
Const cstSubArgs = "MsgId, [Arg0, Arg1, ...]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
sText = ""
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(MsgId, "MsgId", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
If Len(Trim(MsgId)) = 0 Then GoTo Finally
|
||||
|
||||
Try:
|
||||
' Find and load entry from dictionary
|
||||
sText = GetText(MsgId)
|
||||
|
||||
' Substitute %i placeholders - done here, not in GetText(), because # of arguments is undefined
|
||||
For i = 0 To UBound(pvArgs)
|
||||
sPercent = "%" & (i + 1)
|
||||
sText = Replace(sText, sPercent, SF_String.Represent(pvArgs(i)))
|
||||
Next i
|
||||
|
||||
Finally:
|
||||
_ = sText
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_L10N._
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the L10N service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"AddText" _
|
||||
, "ExportToPOTFile" _
|
||||
, "GetText" _
|
||||
, "_" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_L10N.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Timer class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"Folder" _
|
||||
, "Languages" _
|
||||
, "Locale" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_L10N.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "L10N.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
SetProperty = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_L10N.SetProperty
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _Initialize(ByVal psPOFile As String _
|
||||
, ByVal Encoding As String _
|
||||
)
|
||||
''' Completes initialization of the current instance requested from CreateScriptService()
|
||||
''' Load the POFile in the dictionary, otherwise leave the dictionary empty
|
||||
''' Args:
|
||||
''' psPOFile: the file to load the translated strings from
|
||||
''' Encoding: The character set that should be used. Default = UTF-8
|
||||
|
||||
Dim oFile As Object ' PO file handler
|
||||
Dim sContext As String ' Collected context string
|
||||
Dim sMsgId As String ' Collected untranslated string
|
||||
Dim sComment As String ' Collected comment string
|
||||
Dim sMsgStr As String ' Collected translated string
|
||||
Dim sLine As String ' Last line read
|
||||
Dim iContinue As Integer ' 0 = None, 1 = MsgId, 2 = MsgStr
|
||||
Const cstMsgId = 1, cstMsgStr = 2
|
||||
|
||||
Try:
|
||||
' Initialize dictionary anyway
|
||||
Set _Dictionary = SF_Services.CreateScriptService("Dictionary")
|
||||
Set _Dictionary.[_Parent] = [Me]
|
||||
|
||||
' Load PO file
|
||||
If Len(psPOFile) > 0 Then
|
||||
With SF_FileSystem
|
||||
_POFolder = ._ConvertToUrl(.GetParentFolderName(psPOFile))
|
||||
_Locale = .GetBaseName(psPOFile)
|
||||
_POFile = ._ConvertToUrl(psPOFile)
|
||||
End With
|
||||
' Load PO file
|
||||
Set oFile = SF_FileSystem.OpenTextFile(psPOFile, IOMode := SF_FileSystem.ForReading, Encoding := Encoding)
|
||||
If Not IsNull(oFile) Then
|
||||
With oFile
|
||||
' The PO file is presumed valid => syntax check is not very strict
|
||||
sContext = "" : sMsgId = "" : sComment = "" : sMsgStr = ""
|
||||
Do While Not .AtEndOfStream
|
||||
sLine = Trim(.ReadLine())
|
||||
' Trivial examination of line header
|
||||
Select Case True
|
||||
Case sLine = ""
|
||||
If Len(sMsgId) > 0 Then AddText(sContext, sMsgId, sComment, sMsgStr)
|
||||
sContext = "" : sMsgId = "" : sComment = "" : sMsgStr = ""
|
||||
iContinue = 0
|
||||
Case Left(sLine, 3) = "#. "
|
||||
sComment = sComment & Iif(Len(sComment) > 0, "\n", "") & Trim(Mid(sLine, 4))
|
||||
iContinue = 0
|
||||
Case Left(sLine, 8) = "msgctxt "
|
||||
sContext = SF_String.Unquote(Trim(Mid(sLine, 9)))
|
||||
iContinue = 0
|
||||
Case Left(sLine, 6) = "msgid "
|
||||
sMsgId = SF_String.Unquote(Trim(Mid(sLine, 7)))
|
||||
iContinue = cstMsgId
|
||||
Case Left(sLine, 7) = "msgstr "
|
||||
sMsgStr = sMsgStr & SF_String.Unquote(Trim(Mid(sLine, 8)))
|
||||
iContinue = cstMsgStr
|
||||
Case Left(sLine, 1) = """"
|
||||
If iContinue = cstMsgId Then
|
||||
sMsgId = sMsgId & SF_String.Unquote(sLine)
|
||||
ElseIf iContinue = cstMsgStr Then
|
||||
sMsgStr = sMsgStr & SF_String.Unquote(sLine)
|
||||
Else
|
||||
iContinue = 0
|
||||
End If
|
||||
Case Else ' Skip line
|
||||
iContinue = 0
|
||||
End Select
|
||||
Loop
|
||||
' Be sure to store the last entry
|
||||
If Len(sMsgId) > 0 Then AddText(sContext, sMsgId, sComment, sMsgStr)
|
||||
.CloseFile()
|
||||
Set oFile = .Dispose()
|
||||
End With
|
||||
End If
|
||||
Else
|
||||
_POFolder = ""
|
||||
_Locale = ""
|
||||
_POFile = ""
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Exit Sub
|
||||
End Sub ' ScriptForge.SF_L10N._Initialize
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String)
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim vFiles As Variant ' Array of PO-files
|
||||
Dim i As Long
|
||||
Dim cstThisSub As String
|
||||
Dim cstSubArgs As String
|
||||
|
||||
cstThisSub = "SF_L10N.get" & psProperty
|
||||
cstSubArgs = ""
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
With SF_FileSystem
|
||||
Select Case psProperty
|
||||
Case "Folder"
|
||||
If Len(_POFolder) > 0 Then _PropertyGet = ._ConvertFromUrl(_POFolder) Else _PropertyGet = ""
|
||||
Case "Languages"
|
||||
If Len(_POFolder) > 0 Then
|
||||
vFiles = .Files(._ConvertFromUrl(_POFolder), "??-??.po")
|
||||
For i = 0 To UBound(vFiles)
|
||||
vFiles(i) = SF_FileSystem.GetBaseName(vFiles(i))
|
||||
Next i
|
||||
Else
|
||||
vFiles = Array()
|
||||
End If
|
||||
_PropertyGet = vFiles
|
||||
Case "Locale"
|
||||
_PropertyGet = _Locale
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
End With
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_L10N._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the L10N instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[L10N]: PO file"
|
||||
|
||||
_Repr = "[L10N]: " & _POFile
|
||||
|
||||
End Function ' ScriptForge.SF_L10N._Repr
|
||||
|
||||
REM ============================================ END OF SCRIPTFORGE.SF_L10N
|
||||
</script:module>
|
||||
281
server/windows-office/share/basic/ScriptForge/SF_Platform.xba
Normal file
281
server/windows-office/share/basic/ScriptForge/SF_Platform.xba
Normal file
@@ -0,0 +1,281 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Platform" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Platform
|
||||
''' ===========
|
||||
''' Singleton class implementing the "ScriptForge.Platform" service
|
||||
''' Implemented as a usual Basic module
|
||||
'''
|
||||
''' A collection of properties about the execution environment:
|
||||
''' - HW platform
|
||||
''' - Operating System
|
||||
''' - current user
|
||||
''' - LibreOffice version
|
||||
'''
|
||||
''' Service invocation example:
|
||||
''' Dim platform As Variant
|
||||
''' platform = CreateScriptService("Platform")
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_Array Explicit destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Architecture() As String
|
||||
''' Returns the actual bit architecture
|
||||
''' Example:
|
||||
''' MsgBox platform.Architecture ' 64bit
|
||||
Architecture = _PropertyGet("Architecture")
|
||||
End Property ' ScriptForge.SF_Platform.Architecture (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ComputerName() As String
|
||||
''' Returns the computer's network name
|
||||
''' Example:
|
||||
''' MsgBox platform.ComputerName
|
||||
ComputerName = _PropertyGet("ComputerName")
|
||||
End Property ' ScriptForge.SF_Platform.ComputerName (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get CPUCount() As Integer
|
||||
''' Returns the number of Central Processor Units
|
||||
''' Example:
|
||||
''' MsgBox platform.CPUCount ' 4
|
||||
CPUCount = _PropertyGet("CPUCount")
|
||||
End Property ' ScriptForge.SF_Platform.CPUCount (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get CurrentUser() As String
|
||||
''' Returns the name of logged in user
|
||||
''' Example:
|
||||
''' MsgBox platform.CurrentUser
|
||||
CurrentUser = _PropertyGet("CurrentUser")
|
||||
End Property ' ScriptForge.SF_Platform.CurrentUser (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Machine() As String
|
||||
''' Returns the machine type like 'i386' or 'x86_64'
|
||||
''' Example:
|
||||
''' MsgBox platform.Machine
|
||||
Machine = _PropertyGet("Machine")
|
||||
End Property ' ScriptForge.SF_Platform.Machine (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ObjectType As String
|
||||
''' Only to enable object representation
|
||||
ObjectType = "SF_Platform"
|
||||
End Property ' ScriptForge.SF_Platform.ObjectType
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ServiceName As String
|
||||
''' Internal use
|
||||
ServiceName = "ScriptForge.Platform"
|
||||
End Property ' ScriptForge.SF_Platform.ServiceName
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OfficeVersion() As String
|
||||
''' Returns the office software version in the form 'LibreOffice w.x.y.z (The Document Foundation)'
|
||||
''' Example:
|
||||
''' MsgBox platform.OfficeVersion
|
||||
OfficeVersion = _PropertyGet("OfficeVersion")
|
||||
End Property ' ScriptForge.SF_Platform.OfficeVersion (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OSName() As String
|
||||
''' Returns the name of the operating system like 'Linux' or 'Windows'
|
||||
''' Example:
|
||||
''' MsgBox platform.OSName
|
||||
OSName = _PropertyGet("OSName")
|
||||
End Property ' ScriptForge.SF_Platform.OSName (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OSPlatform() As String
|
||||
''' Returns a single string identifying the underlying platform with as much useful and human-readable information as possible
|
||||
''' Example:
|
||||
''' MsgBox platform.OSPlatform ' Linux-4.15.0-117-generic-x86_64-with-Ubuntu-18.04-bionic
|
||||
OSPlatform = _PropertyGet("OSPlatform")
|
||||
End Property ' ScriptForge.SF_Platform.OSPlatform (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OSRelease() As String
|
||||
''' Returns the operating system's release
|
||||
''' Example:
|
||||
''' MsgBox platform.OSRelease ' 4.15.0-117-generic
|
||||
OSRelease = _PropertyGet("OSRelease")
|
||||
End Property ' ScriptForge.SF_Platform.OSRelease (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get OSVersion() As String
|
||||
''' Returns the name of the operating system build or version
|
||||
''' Example:
|
||||
''' MsgBox platform.OSVersion ' #118-Ubuntu SMP Fri Sep 4 20:02:41 UTC 2020
|
||||
OSVersion = _PropertyGet("OSVersion")
|
||||
End Property ' ScriptForge.SF_Platform.OSVersion (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Processor() As String
|
||||
''' Returns the (real) processor name, e.g. 'amdk6'. Might return the same value as Machine
|
||||
''' Example:
|
||||
''' MsgBox platform.Processor
|
||||
Processor = _PropertyGet("Processor")
|
||||
End Property ' ScriptForge.SF_Platform.Processor (get)
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' If the property does not exist, returns Null
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "Platform.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Platform.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Model service as an array
|
||||
|
||||
Methods = Array( _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Platform.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Platform class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"Architecture" _
|
||||
, "ComputerName" _
|
||||
, "CPUCount" _
|
||||
, "CurrentUser" _
|
||||
, "Machine" _
|
||||
, "OfficeVersion" _
|
||||
, "OSName" _
|
||||
, "OSPlatform" _
|
||||
, "OSRelease" _
|
||||
, "OSVersion" _
|
||||
, "Processor" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Platform.Properties
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _GetProductName() as String
|
||||
''' Returns Office product and version numbers found in configuration registry
|
||||
''' Derived from the Tools library
|
||||
|
||||
Dim oProdNameAccess as Object ' configmgr.RootAccess
|
||||
Dim sProdName as String
|
||||
Dim sVersion as String
|
||||
Dim sVendor As String
|
||||
|
||||
On Local Error GoTo Catch ' Prevent any error
|
||||
_GetProductName = ""
|
||||
|
||||
Try:
|
||||
Set oProdNameAccess = SF_Utils._GetRegistryKeyContent("org.openoffice.Setup/Product")
|
||||
|
||||
sProdName = oProdNameAccess.ooName
|
||||
sVersion = oProdNameAccess.ooSetupVersionAboutBox
|
||||
sVendor = oProdNameAccess.ooVendor
|
||||
|
||||
_GetProductName = sProdName & " " & sVersion & " (" & sVendor & ")"
|
||||
|
||||
Finally:
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Platform._GetProductName
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim sOSName As String ' Operating system
|
||||
|
||||
Const cstPyHelper = "$" & "_SF_Platform"
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
cstThisSub = "Platform.get" & psProperty
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Select Case psProperty
|
||||
Case "Architecture", "ComputerName", "CPUCount", "CurrentUser", "Machine" _
|
||||
, "OSPlatform", "OSRelease", "OSVersion", "Processor"
|
||||
With ScriptForge.SF_Session
|
||||
_PropertyGet = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, psProperty)
|
||||
End With
|
||||
Case "OfficeVersion"
|
||||
_PropertyGet = _GetProductName()
|
||||
Case "OSName"
|
||||
' Calc INFO function preferred to Python script to avoid ScriptForge initialization risks when Python is not installed
|
||||
sOSName = _SF_.OSName
|
||||
If sOSName = "" Then
|
||||
sOSName = SF_Session.ExecuteCalcFunction("INFO", "system")
|
||||
Select Case sOSName
|
||||
Case "WNT" : sOSName = "Windows"
|
||||
Case "MACOSX" : sOSName = "macOS"
|
||||
Case "LINUX" : sOSName = "Linux"
|
||||
Case "SOLARIS" : sOSName = "Solaris"
|
||||
Case Else : sOSName = SF_String.Capitalize(sOSName)
|
||||
End Select
|
||||
EndIf
|
||||
_PropertyGet = sOSName
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Platform._PropertyGet
|
||||
|
||||
REM ============================================ END OF SCRIPTFORGE.SF_PLATFORM
|
||||
</script:module>
|
||||
822
server/windows-office/share/basic/ScriptForge/SF_Root.xba
Normal file
822
server/windows-office/share/basic/ScriptForge/SF_Root.xba
Normal file
@@ -0,0 +1,822 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Root" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
Option Private Module
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Root
|
||||
''' =======
|
||||
''' FOR INTERNAL USE ONLY
|
||||
''' Singleton class holding all persistent variables shared
|
||||
''' by all the modules of the ScriptForge library
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
' Internals
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private ObjectType As String ' Must be "ROOT"
|
||||
Private MainFunction As String ' Name of method or property called by user script
|
||||
Private MainFunctionArgs As String ' Syntax of method called by user script
|
||||
Private StackLevel As Integer ' Depth of calls between internal methods
|
||||
|
||||
' Error management
|
||||
Private ErrorHandler As Boolean ' True = error handling active, False = internal debugging
|
||||
Private ConsoleLines() As Variant ' Array of messages displayable in console
|
||||
Private ConsoleDialog As Object ' SFDialogs.Dialog object
|
||||
Private ConsoleControl As Object ' SFDialogs.DialogControl object
|
||||
Private DisplayEnabled As Boolean ' When True, display of console or error messages is allowed
|
||||
Private StopWhenError As Boolean ' When True, process stops after error > "WARNING"
|
||||
Private DebugMode As Boolean ' When True, log enter/exit each official Sub
|
||||
|
||||
' Services management
|
||||
Private ServicesList As Variant ' Dictionary of provided services
|
||||
|
||||
' Usual UNO services
|
||||
Private FunctionAccess As Object ' com.sun.star.sheet.FunctionAccess
|
||||
Private PathSettings As Object ' com.sun.star.util.PathSettings
|
||||
Private PathSubstitution As Object ' com.sun.star.util.PathSubstitution
|
||||
Private ScriptProvider As Object ' com.sun.star.script.provider.MasterScriptProviderFactory
|
||||
Private SystemShellExecute As Object ' com.sun.star.system.SystemShellExecute
|
||||
Private CoreReflection As Object ' com.sun.star.reflection.CoreReflection
|
||||
Private DispatchHelper As Object ' com.sun.star.frame.DispatchHelper
|
||||
Private TextSearch As Object ' com.sun.star.util.TextSearch
|
||||
Private SearchOptions As Object ' com.sun.star.util.SearchOptions
|
||||
Private Locale As Object ' com.sun.star.lang.Locale
|
||||
Private CharacterClass As Object ' com.sun.star.i18n.CharacterClassification
|
||||
Private FileAccess As Object ' com.sun.star.ucb.SimpleFileAccess
|
||||
Private FilterFactory As Object ' com.sun.star.document.FilterFactory
|
||||
Private FolderPicker As Object ' com.sun.star.ui.dialogs.FolderPicker
|
||||
Private FilePicker As Object ' com.sun.star.ui.dialogs.FilePicker
|
||||
Private URLTransformer As Object ' com.sun.star.util.URLTransformer
|
||||
Private Introspection As Object ' com.sun.star.beans.Introspection
|
||||
Private BrowseNodeFactory As Object ' com.sun.star.script.browse.BrowseNodeFactory
|
||||
Private DatabaseContext As Object ' com.sun.star.sdb.DatabaseContext
|
||||
Private ConfigurationProvider _
|
||||
As Object ' com.sun.star.configuration.ConfigurationProvider
|
||||
Private MailService As Object ' com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
|
||||
|
||||
' Specific persistent services objects or properties
|
||||
Private FileSystemNaming As String ' If "SYS", file and folder naming is based on operating system notation
|
||||
Private PythonHelper As String ' File name of Python helper functions (stored in $(inst)/share/Scripts/python)
|
||||
Private Interface As Object ' ScriptForge own L10N service
|
||||
Private OSName As String ' WIN, LINUX, MACOS
|
||||
Private SFDialogs As Variant ' Persistent storage for the SFDialogs library
|
||||
|
||||
REM ====================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "ROOT"
|
||||
MainFunction = ""
|
||||
MainFunctionArgs = ""
|
||||
StackLevel = 0
|
||||
ErrorHandler = True
|
||||
ConsoleLines = Array()
|
||||
Set ConsoleDialog = Nothing
|
||||
Set ConsoleControl = Nothing
|
||||
DisplayEnabled = True
|
||||
StopWhenError = True
|
||||
DebugMode = False
|
||||
ServicesList = Empty
|
||||
Set FunctionAccess = Nothing
|
||||
Set PathSettings = Nothing
|
||||
Set PathSubstitution = Nothing
|
||||
Set ScriptProvider = Nothing
|
||||
Set SystemShellExecute = Nothing
|
||||
Set CoreReflection = Nothing
|
||||
Set DispatchHelper = Nothing
|
||||
Set TextSearch = Nothing
|
||||
Set SearchOptions = Nothing
|
||||
Set Locale = Nothing
|
||||
Set CharacterClass = Nothing
|
||||
Set FileAccess = Nothing
|
||||
Set FilterFactory = Nothing
|
||||
Set FolderPicker = Nothing
|
||||
Set FilePicker = Nothing
|
||||
Set URLTransformer = Nothing
|
||||
Set Introspection = Nothing
|
||||
FileSystemNaming = "ANY"
|
||||
PythonHelper = "ScriptForgeHelper.py"
|
||||
Set Interface = Nothing
|
||||
Set BrowseNodeFactory = Nothing
|
||||
Set DatabaseContext = Nothing
|
||||
Set ConfigurationProvider = Nothing
|
||||
Set MailService = Nothing
|
||||
OSName = ""
|
||||
SFDialogs = Empty
|
||||
End Sub ' ScriptForge.SF_Root Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' ScriptForge.SF_Root Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_Root Explicit destructor
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _AddToConsole(ByVal psLine As String)
|
||||
''' Add a new line to the console
|
||||
''' TAB characters are expanded before the insertion of the line
|
||||
''' NB: Array redimensioning of a member of an object must be done in the class module
|
||||
''' Args:
|
||||
''' psLine: the line to add
|
||||
|
||||
Dim lConsole As Long ' UBound of ConsoleLines
|
||||
Dim sLine As String ' Alias of psLine
|
||||
|
||||
' Resize ConsoleLines
|
||||
lConsole = UBound(ConsoleLines)
|
||||
If lConsole < 0 Then
|
||||
ReDim ConsoleLines(0)
|
||||
Else
|
||||
ReDim Preserve ConsoleLines(0 To lConsole + 1)
|
||||
End If
|
||||
|
||||
' Add a timestamp to the line and insert it (without date)
|
||||
sLine = Mid(SF_Utils._Repr(Now()), 12) & " -> " & psLine
|
||||
ConsoleLines(lConsole + 1) = Mid(SF_Utils._Repr(Now()), 12) & " -> " & psLine
|
||||
|
||||
' Add the new line to the actual (probably non-modal) console, if active
|
||||
If Not IsNull(ConsoleDialog) Then
|
||||
If ConsoleDialog._IsStillAlive(False) Then ' False to not raise an error
|
||||
If IsNull(ConsoleControl) Then Set ConsoleControl = ConsoleDialog.Controls(SF_Exception.CONSOLENAME) ' Should not happen ...
|
||||
ConsoleControl.WriteLine(sLine)
|
||||
End If
|
||||
End If
|
||||
|
||||
End Sub ' ScriptForge.SF_Root._AddToConsole
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _LoadLocalizedInterface(Optional ByVal psMode As String)
|
||||
''' Build the user interface in a persistent L10N object
|
||||
''' Executed - only once - at first ScriptForge invocation by a user script
|
||||
''' Args:
|
||||
''' psMode: ADDTEXT => the (english) labels are loaded from code below
|
||||
''' POFILE => the localized labels are loaded from a PO file
|
||||
''' the name of the file is "la.po" where la = language part of locale
|
||||
''' (fallback to ADDTEXT mode if file does not exist)
|
||||
|
||||
Dim sInstallFolder As String ' ScriptForge installation directory
|
||||
Dim sPOFolder As String ' Folder containing the PO files
|
||||
Dim sPOFile As String ' PO File to load
|
||||
Dim sLocale As String ' Locale
|
||||
|
||||
If ErrorHandler Then On Local Error GoTo Catch
|
||||
|
||||
Try:
|
||||
'TODO: Modify default value
|
||||
If IsMissing(psMode) Then psMode = "POFILE"
|
||||
|
||||
If psMode = "POFILE" Then ' Use this mode in production
|
||||
' Build the po file name
|
||||
With SF_FileSystem
|
||||
sInstallFolder = ._SFInstallFolder() ' ScriptForge installation folder
|
||||
sLocale = SF_Utils._GetUNOService("Locale").Language
|
||||
sPOFolder = .BuildPath(sInstallFolder, "po")
|
||||
sPOFile = .BuildPath(sPOFolder, sLocale & ".po")
|
||||
If Not .FileExists(sPOFile) Then ' File not found => load texts from code below
|
||||
psMode = "ADDTEXT"
|
||||
Else
|
||||
Set Interface = CreateScriptService("L10N", sPOFolder, sLocale)
|
||||
End If
|
||||
End With
|
||||
End If
|
||||
|
||||
If psMode = "ADDTEXT" Then ' Use this mode in development to prepare a new POT file
|
||||
Set Interface = CreateScriptService("L10N")
|
||||
With Interface
|
||||
' SF_Exception.Raise
|
||||
.AddText( Context := "CLOSEBUTTON" _
|
||||
, MsgId := "Close" _
|
||||
, Comment := "Text in close buttons of progress and console dialog boxes" _
|
||||
)
|
||||
.AddText( Context := "ERRORNUMBER" _
|
||||
, MsgId := "Error %1" _
|
||||
, Comment := "Title in error message box\n" _
|
||||
& "%1: an error number" _
|
||||
)
|
||||
.AddText( Context := "ERRORLOCATION" _
|
||||
, MsgId := "Location : %1" _
|
||||
, Comment := "Error message box\n" _
|
||||
& "%1: a line number" _
|
||||
)
|
||||
.AddText( Context := "LONGERRORDESC" _
|
||||
, MsgId := "Error %1 - Location = %2 - Description = %3" _
|
||||
, Comment := "Logfile record" _
|
||||
)
|
||||
.AddText( Context := "STOPEXECUTION" _
|
||||
, MsgId := "THE EXECUTION IS CANCELLED." _
|
||||
, Comment := "SF_Utils._Validate error message" _
|
||||
)
|
||||
' SF_Exception.RaiseAbort
|
||||
.AddText( Context := "INTERNALERROR" _
|
||||
, MsgId := "The ScriptForge library has crashed. The reason is unknown.\n" _
|
||||
& "Maybe a bug that could be reported on\n" _
|
||||
& "\thttps://bugs.documentfoundation.org/\n\n" _
|
||||
& "More details : \n\n" _
|
||||
, Comment := "SF_Exception.RaiseAbort error message" _
|
||||
)
|
||||
' SF_Utils._Validate
|
||||
.AddText( Context := "VALIDATESOURCE" _
|
||||
, MsgId := "Library : \t%1\nService : \t%2\nMethod : \t%3" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: probably ScriptForge\n" _
|
||||
& "%2: service or module name\n" _
|
||||
& "%3: property or method name where the error occurred" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEARGS" _
|
||||
, MsgId := "Arguments: %1" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: list of arguments of the method" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEERROR" _
|
||||
, MsgId := "A serious error has been detected in your code on argument : « %1 »." _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name" _
|
||||
)
|
||||
.AddText( Context := "VALIDATIONRULES" _
|
||||
, MsgId := "\tValidation rules :", Comment := "SF_Utils.Validate error message" _
|
||||
)
|
||||
.AddText( Context := "VALIDATETYPES" _
|
||||
, MsgId := "\t\t« %1 » must have next type (or one of next types) : %2" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: Comma separated list of allowed types" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEVALUES" _
|
||||
, MsgId := "\t\t« %1 » must contain one of next values : %2" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: Comma separated list of allowed values" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEREGEX" _
|
||||
, MsgId := "\t\t« %1 » must match next regular expression : %2" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: A regular expression" _
|
||||
)
|
||||
.AddText( Context := "VALIDATECLASS" _
|
||||
, MsgId := "\t\t« %1 » must be a Basic object of class : %2" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: The name of a Basic class" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEACTUAL" _
|
||||
, MsgId := "The actual value of « %1 » is : '%2'" _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: The value of the argument as a string" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEMISSING" _
|
||||
, MsgId := "The « %1 » argument is mandatory, yet it is missing." _
|
||||
, Comment := "SF_Utils._Validate error message\n" _
|
||||
& "%1: Wrong argument name" _
|
||||
)
|
||||
' SF_Utils._ValidateArray
|
||||
.AddText( Context := "VALIDATEARRAY" _
|
||||
, MsgId := "\t\t« %1 » must be an array." _
|
||||
, Comment := "SF_Utils._ValidateArray error message\n" _
|
||||
& "%1: Wrong argument name" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEDIMS" _
|
||||
, MsgId := "\t\t« %1 » must have exactly %2 dimension(s)." _
|
||||
, Comment := "SF_Utils._ValidateArray error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: Number of dimensions of the array" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEALLTYPES" _
|
||||
, MsgId := "\t\t« %1 » must have all elements of the same type : %2" _
|
||||
, Comment := "SF_Utils._ValidateArray error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "%2: Either one single type or 'String, Date, Numeric'" _
|
||||
)
|
||||
.AddText( Context := "VALIDATENOTNULL" _
|
||||
, MsgId := "\t\t« %1 » must not contain any NULL or EMPTY elements." _
|
||||
, Comment := "SF_Utils._ValidateArray error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "NULL and EMPTY should not be translated" _
|
||||
)
|
||||
' SF_Utils._ValidateFile
|
||||
.AddText( Context := "VALIDATEFILE" _
|
||||
, MsgId := "\t\t« %1 » must be of type String." _
|
||||
, Comment := "SF_Utils._ValidateFile error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "'String' should not be translated" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEFILESYS" _
|
||||
, MsgId := "\t\t« %1 » must be a valid file or folder name expressed in the operating system native notation." _
|
||||
, Comment := "SF_Utils._ValidateFile error message\n" _
|
||||
& "%1: Wrong argument name" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEFILEURL" _
|
||||
, MsgId := "\t\t« %1 » must be a valid file or folder name expressed in the portable URL notation." _
|
||||
, Comment := "SF_Utils._ValidateFile error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "'URL' should not be translated" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEFILEANY" _
|
||||
, MsgId := "\t\t« %1 » must be a valid file or folder name." _
|
||||
, Comment := "SF_Utils._ValidateFile error message\n" _
|
||||
& "%1: Wrong argument name" _
|
||||
)
|
||||
.AddText( Context := "VALIDATEWILDCARD" _
|
||||
, MsgId := "\t\t« %1 » may contain one or more wildcard characters (?, *) in its last path component only." _
|
||||
, Comment := "SF_Utils._ValidateFile error message\n" _
|
||||
& "%1: Wrong argument name\n" _
|
||||
& "'(?, *)' is to be left as is" _
|
||||
)
|
||||
' SF_Array.RangeInit
|
||||
.AddText( Context := "ARRAYSEQUENCE" _
|
||||
, MsgId := "The respective values of 'From', 'UpTo' and 'ByStep' are incoherent.\n\n" _
|
||||
& "\t« From » = %1\n" _
|
||||
& "\t« UpTo » = %2\n" _
|
||||
& "\t« ByStep » = %3" _
|
||||
, Comment := "SF_Array.RangeInit error message\n" _
|
||||
& "%1, %2, %3: Numeric values\n" _
|
||||
& "'From', 'UpTo', 'ByStep' should not be translated" _
|
||||
)
|
||||
' SF_Array.AppendColumn, AppendRow, PrependColumn, PrependRow
|
||||
.AddText( Context := "ARRAYINSERT" _
|
||||
, MsgId := "The array and the vector to insert have incompatible sizes.\n\n" _
|
||||
& "\t« Array_2D » = %2\n" _
|
||||
& "\t« %1 » = %3" _
|
||||
, Comment := "SF_Array.AppendColumn (...) error message\n" _
|
||||
& "%1: 'Column' or 'Row' of a matrix\n" _
|
||||
& "%2, %3: array contents\n" _
|
||||
& "'Array_2D' should not be translated" _
|
||||
)
|
||||
' SF_Array.ExtractColumn, ExtractRow
|
||||
.AddText( Context := "ARRAYINDEX1" _
|
||||
, MsgId := "The given index does not fit within the bounds of the array.\n\n" _
|
||||
& "\t« Array_2D » = %2\n" _
|
||||
& "\t« %1 » = %3" _
|
||||
, Comment := "SF_Array.ExtractColumn (...) error message\n" _
|
||||
& "%1: 'Column' or 'Row' of a matrix\n" _
|
||||
& "%2, %3: array contents\n" _
|
||||
& "'Array_2D' should not be translated" _
|
||||
)
|
||||
' SF_Array.ExtractColumn, ExtractRow
|
||||
.AddText( Context := "ARRAYINDEX2" _
|
||||
, MsgId := "The given slice limits do not fit within the bounds of the array.\n\n" _
|
||||
& "\t« Array_2D » = %1\n" _
|
||||
& "\t« From » = %2\n" _
|
||||
& "\t« UpTo » = %3" _
|
||||
, Comment := "SF_Array.ExtractColumn (...) error message\n" _
|
||||
& "%1: 'Column' or 'Row' of a matrix\n" _
|
||||
& "%2, %3: array contents\n" _
|
||||
& "'Array_2D', 'From' and 'UpTo' should not be translated" _
|
||||
)
|
||||
' SF_Array.ImportFromCSVFile
|
||||
.AddText( Context := "CSVPARSING" _
|
||||
, MsgId := "The given file could not be parsed as a valid CSV file.\n\n" _
|
||||
& "\t« File name » = %1\n" _
|
||||
& "\tLine number = %2\n" _
|
||||
& "\tContent = %3" _
|
||||
, Comment := "SF_Array.ImportFromCSVFile error message\n" _
|
||||
& "%1: a file name\n" _
|
||||
& "%2: numeric\n" _
|
||||
& "%3: a long string" _
|
||||
)
|
||||
' SF_Dictionary.Add/ReplaceKey
|
||||
.AddText( Context := "DUPLICATEKEY" _
|
||||
, MsgId := "The insertion of a new key " _
|
||||
& "into a dictionary failed because the key already exists.\n" _
|
||||
& "Note that the comparison between keys is NOT case-sensitive.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_Dictionary Add/ReplaceKey error message\n" _
|
||||
& "%1: An identifier" _
|
||||
& "%2: a (potentially long) string" _
|
||||
)
|
||||
' SF_Dictionary.Remove/ReplaceKey/ReplaceItem
|
||||
.AddText( Context := "UNKNOWNKEY" _
|
||||
, MsgId := "The requested key does not exist in the dictionary.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_Dictionary Remove/ReplaceKey/ReplaceItem error message\n" _
|
||||
& "%1: An identifier" _
|
||||
& "%2: a (potentially long) string" _
|
||||
)
|
||||
' SF_Dictionary.Add/ReplaceKey
|
||||
.AddText( Context := "INVALIDKEY" _
|
||||
, MsgId := "The insertion or the update of an entry " _
|
||||
& "into a dictionary failed because the given key contains only spaces." _
|
||||
, Comment := "SF_Dictionary Add/ReplaceKey error message\n" _
|
||||
)
|
||||
' SF_FileSystem.CopyFile/MoveFile/DeleteFile/CreateScriptService("L10N")
|
||||
.AddText( Context := "UNKNOWNFILE" _
|
||||
, MsgId := "The given file could not be found on your system.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/delete error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name" _
|
||||
)
|
||||
' SF_FileSystem.CopyFolder/MoveFolder/DeleteFolder/Files/SubFolders
|
||||
.AddText( Context := "UNKNOWNFOLDER" _
|
||||
, MsgId := "The given folder could not be found on your system.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/delete error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A folder name" _
|
||||
)
|
||||
' SF_FileSystem.CopyFile/MoveFolder/DeleteFile
|
||||
.AddText( Context := "NOTAFILE" _
|
||||
, MsgId := "« %1 » contains the name of an existing folder, not that of a file.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/delete error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name" _
|
||||
)
|
||||
' SF_FileSystem.CopyFolder/MoveFolder/DeleteFolder/Files/SubFolders
|
||||
.AddText( Context := "NOTAFOLDER" _
|
||||
, MsgId := "« %1 » contains the name of an existing file, not that of a folder.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/delete error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A folder name" _
|
||||
)
|
||||
' SF_FileSystem.Copy+Move/File+Folder/CreateTextFile/OpenTextFile
|
||||
.AddText( Context := "OVERWRITE" _
|
||||
, MsgId := "You tried to create a new file which already exists. Overwriting it has been rejected.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/... error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name" _
|
||||
)
|
||||
' SF_FileSystem.Copy+Move+Delete/File+Folder
|
||||
.AddText( Context := "READONLY" _
|
||||
, MsgId := "Copying or moving a file to a destination which has its read-only attribute set, or deleting such a file or folder is forbidden.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/delete error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name" _
|
||||
)
|
||||
' SF_FileSystem.Copy+Move+Delete/File+Folder
|
||||
.AddText( Context := "NOFILEMATCH" _
|
||||
, MsgId := "When « %1 » contains wildcards. at least one file or folder must match the given filter. Otherwise the operation is rejected.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem copy/move/delete error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file or folder name with wildcards" _
|
||||
)
|
||||
' SF_FileSystem.CreateFolder
|
||||
.AddText( Context := "FOLDERCREATION" _
|
||||
, MsgId := "« %1 » contains the name of an existing file or an existing folder. The operation is rejected.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_FileSystem CreateFolder error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file or folder name" _
|
||||
)
|
||||
' SF_Services.CreateScriptService
|
||||
.AddText( Context := "UNKNOWNSERVICE" _
|
||||
, MsgId := "No service named '%4' has been registered for the library '%3'.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_Services.CreateScriptService error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: A Basic library name\n" _
|
||||
& "%4: A service (1 word) name" _
|
||||
)
|
||||
' SF_Services.CreateScriptService
|
||||
.AddText( Context := "SERVICESNOTLOADED" _
|
||||
, MsgId := "The library '%3' and its services could not been loaded.\n" _
|
||||
& "The reason is unknown.\n" _
|
||||
& "However, checking the '%3.SF_Services.RegisterScriptServices()' function and its return value can be a good starting point.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_Services.CreateScriptService error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: A Basic library name" _
|
||||
)
|
||||
' SF_Session.ExecuteCalcFunction
|
||||
.AddText( Context := "CALCFUNC" _
|
||||
, MsgId := "The Calc '%1' function encountered an error. Either the given function does not exist or its arguments are invalid." _
|
||||
, Comment := "SF_Session.ExecuteCalcFunction error message\n" _
|
||||
& "'Calc' should not be translated" _
|
||||
)
|
||||
' SF_Session._GetScript
|
||||
.AddText( Context := "NOSCRIPT" _
|
||||
, MsgId := "The requested %1 script could not be located in the given libraries and modules.\n" _
|
||||
& "« %2 » = %3\n" _
|
||||
& "« %4 » = %5" _
|
||||
, Comment := "SF_Session._GetScript error message\n" _
|
||||
& "%1: 'Basic' or 'Python'\n" _
|
||||
& "%2: An identifier\n" _
|
||||
& "%3: A string\n" _
|
||||
& "%2: An identifier\n" _
|
||||
& "%3: A string" _
|
||||
)
|
||||
' SF_Session.ExecuteBasicScript
|
||||
.AddText( Context := "SCRIPTEXEC" _
|
||||
, MsgId := "An exception occurred during the execution of the Basic script.\n" _
|
||||
& "Cause: %3\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_Session.ExecuteBasicScript error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: A (long) string" _
|
||||
)
|
||||
' SF_Session.SendMail
|
||||
.AddText( Context := "WRONGEMAIL" _
|
||||
, MsgId := "One of the email addresses has been found invalid.\n" _
|
||||
& "Invalid mail = « %1 »" _
|
||||
, Comment := "SF_Session.SendMail error message\n" _
|
||||
& "%1 = a mail address" _
|
||||
)
|
||||
' SF_Session.SendMail
|
||||
.AddText( Context := "SENDMAIL" _
|
||||
, MsgId := "The message could not be sent due to a system error.\n" _
|
||||
& "A possible cause is that LibreOffice could not find any mail client." _
|
||||
, Comment := "SF_Session.SendMail error message" _
|
||||
)
|
||||
' SF_TextStream._IsFileOpen
|
||||
.AddText( Context := "FILENOTOPEN" _
|
||||
, MsgId := "The requested file operation could not be executed because the file was closed previously.\n\n" _
|
||||
& "File name = '%1'" _
|
||||
, Comment := "SF_TextStream._IsFileOpen error message\n" _
|
||||
& "%1: A file name" _
|
||||
)
|
||||
' SF_TextStream._IsFileOpen
|
||||
.AddText( Context := "FILEOPENMODE" _
|
||||
, MsgId := "The requested file operation could not be executed because it is incompatible with the mode in which the file was opened.\n\n" _
|
||||
& "File name = '%1'\n" _
|
||||
& "Open mode = %2" _
|
||||
, Comment := "SF_TextStream._IsFileOpen error message\n" _
|
||||
& "%1: A file name\n" _
|
||||
& "%2: READ, WRITE or APPEND" _
|
||||
)
|
||||
' SF_UI.Document
|
||||
.AddText( Context := "DOCUMENT" _
|
||||
, MsgId := "The requested document could not be found.\n\n" _
|
||||
& "%1 = '%2'" _
|
||||
, Comment := "SF_UI.GetDocument error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string" _
|
||||
)
|
||||
' SF_UI.Create
|
||||
.AddText( Context := "DOCUMENTCREATION" _
|
||||
, MsgId := "The creation of a new document failed.\n" _
|
||||
& "Something must be wrong with some arguments.\n\n" _
|
||||
& "Either the document type is unknown, or no template file was given,\n" _
|
||||
& "or the given template file was not found on your system.\n\n" _
|
||||
& "%1 = '%2'\n" _
|
||||
& "%3 = '%4'" _
|
||||
, Comment := "SF_UI.GetDocument error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A string" _
|
||||
)
|
||||
' SF_UI.OpenDocument
|
||||
.AddText( Context := "DOCUMENTOPEN" _
|
||||
, MsgId := "The opening of the document failed.\n" _
|
||||
& "Something must be wrong with some arguments.\n\n" _
|
||||
& "Either the file does not exist, or the password is wrong, or the given filter is invalid.\n\n" _
|
||||
& "%1 = '%2'\n" _
|
||||
& "%3 = '%4'\n" _
|
||||
& "%5 = '%6'" _
|
||||
, Comment := "SF_UI.OpenDocument error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A string\n" _
|
||||
& "%5: An identifier\n" _
|
||||
& "%6: A string" _
|
||||
)
|
||||
' SF_UI.OpenBaseDocument
|
||||
.AddText( Context := "BASEDOCUMENTOPEN" _
|
||||
, MsgId := "The opening of the Base document failed.\n" _
|
||||
& "Something must be wrong with some arguments.\n\n" _
|
||||
& "Either the file does not exist, or the file is not registered under the given name.\n\n" _
|
||||
& "%1 = '%2'\n" _
|
||||
& "%3 = '%4'" _
|
||||
, Comment := "SF_UI.OpenDocument error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A string" _
|
||||
)
|
||||
' SF_Document._IsStillAlive
|
||||
.AddText( Context := "DOCUMENTDEAD" _
|
||||
, MsgId := "The requested action could not be executed because the document was closed inadvertently.\n\n" _
|
||||
& "The concerned document is '%1'" _
|
||||
, Comment := "SF_Document._IsStillAlive error message\n" _
|
||||
& "%1: A file name" _
|
||||
)
|
||||
' SF_Document.Save
|
||||
.AddText( Context := "DOCUMENTSAVE" _
|
||||
, MsgId := "The document could not be saved.\n" _
|
||||
& "Either the document has been opened read-only, or the destination file has a read-only attribute set, " _
|
||||
& "or the file where to save to is undefined.\n\n" _
|
||||
& "%1 = '%2'" _
|
||||
, Comment := "SF_Document.SaveAs error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name\n" _
|
||||
)
|
||||
' SF_Document.SaveAs
|
||||
.AddText( Context := "DOCUMENTSAVEAS" _
|
||||
, MsgId := "The document could not be saved.\n" _
|
||||
& "Either the document must not be overwritten, or the destination file has a read-only attribute set, " _
|
||||
& "or the given filter is invalid.\n\n" _
|
||||
& "%1 = '%2'\n" _
|
||||
& "%3 = %4\n" _
|
||||
& "%5 = '%6'" _
|
||||
, Comment := "SF_Document.SaveAs error message\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: True or False\n" _
|
||||
& "%5: An identifier\n" _
|
||||
& "%6: A string" _
|
||||
)
|
||||
' SF_Document.any update
|
||||
.AddText( Context := "DOCUMENTREADONLY" _
|
||||
, MsgId := "You tried to edit a document which is not modifiable. The document has not been changed.\n\n" _
|
||||
& "« %1 » = %2" _
|
||||
, Comment := "SF_Document any update\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A file name" _
|
||||
)
|
||||
' SF_Base.GetDatabase
|
||||
.AddText( Context := "DBCONNECT" _
|
||||
, MsgId := "The database related to the actual Base document could not be retrieved.\n" _
|
||||
& "Check the connection/login parameters.\n\n" _
|
||||
& "« %1 » = '%2'\n" _
|
||||
& "« %3 » = '%4'\n" _
|
||||
& "« Document » = %5" _
|
||||
, Comment := "SF_Base GetDatabase\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A user name\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A password\n" _
|
||||
& "%5: A file name" _
|
||||
)
|
||||
' SF_Calc._ParseAddress (sheet)
|
||||
.AddText( Context := "CALCADDRESS1" _
|
||||
, MsgId := "The given address does not correspond with a valid sheet name.\n\n" _
|
||||
& "« %1 » = %2\n" _
|
||||
& "« %3 » = %4" _
|
||||
, Comment := "SF_Calc _ParseAddress (sheet)\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A file name" _
|
||||
)
|
||||
' SF_Calc._ParseAddress (range)
|
||||
.AddText( Context := "CALCADDRESS2" _
|
||||
, MsgId := "The given address does not correspond with a valid range of cells.\n\n" _
|
||||
& "« %1 » = %2\n" _
|
||||
& "« %3 » = %4" _
|
||||
, Comment := "SF_Calc _ParseAddress (range)\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A file name" _
|
||||
)
|
||||
' SF_Calc.InsertSheet
|
||||
.AddText( Context := "DUPLICATESHEET" _
|
||||
, MsgId := "There exists already in the document a sheet with the same name.\n\n" _
|
||||
& "« %1 » = %2\n" _
|
||||
& "« %3 » = %4" _
|
||||
, Comment := "SF_Calc InsertSheet\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A file name" _
|
||||
)
|
||||
' SF_Calc.Offset
|
||||
.AddText( Context := "OFFSETADDRESS" _
|
||||
, MsgId := "The computed range falls beyond the sheet boundaries or is meaningless.\n\n" _
|
||||
& "« %1 » = %2\n" _
|
||||
& "« %3 » = %4\n" _
|
||||
& "« %5 » = %6\n" _
|
||||
& "« %7 » = %8\n" _
|
||||
& "« %9 » = %10\n" _
|
||||
& "« %11 » = %12" _
|
||||
, Comment := "SF_Calc Offset\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A Calc reference\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A number\n" _
|
||||
& "%5: An identifier\n" _
|
||||
& "%6: A number\n" _
|
||||
& "%7: An identifier\n" _
|
||||
& "%8: A number\n" _
|
||||
& "%9: An identifier\n" _
|
||||
& "%10: A number\n" _
|
||||
& "%11: An identifier\n" _
|
||||
& "%12: A file name" _
|
||||
)
|
||||
' SF_Dialog._NewDialog
|
||||
.AddText( Context := "DIALOGNOTFOUND" _
|
||||
, MsgId := "The requested dialog could not be located in the given container or library.\n" _
|
||||
& "« %1 » = %2\n" _
|
||||
& "« %3 » = %4\n" _
|
||||
& "« %5 » = %6\n" _
|
||||
& "« %7 » = %8" _
|
||||
, Comment := "SF_Dialog creation\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: A string\n" _
|
||||
& "%3: An identifier\n" _
|
||||
& "%4: A file name\n" _
|
||||
& "%5: An identifier\n" _
|
||||
& "%6: A string\n" _
|
||||
& "%7: An identifier\n" _
|
||||
& "%8: A string" _
|
||||
)
|
||||
' SF_Dialog._IsStillAlive
|
||||
.AddText( Context := "DIALOGDEAD" _
|
||||
, MsgId := "The requested action could not be executed because the dialog was closed inadvertently.\n\n" _
|
||||
& "The concerned dialog is '%1'." _
|
||||
, Comment := "SF_Dialog._IsStillAlive error message\n" _
|
||||
& "%1: An identifier" _
|
||||
)
|
||||
' SF_DialogControl._SetProperty
|
||||
.AddText( Context := "CONTROLTYPE" _
|
||||
, MsgId := "The control '%1' in dialog '%2' is of type '%3'.\n" _
|
||||
& "The property '%4' is not applicable on that type of dialog controls." _
|
||||
, Comment := "SF_DialogControl property setting\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: An identifier\n" _
|
||||
& "%3: A string\n" _
|
||||
& "%4: An identifier" _
|
||||
)
|
||||
' SF_DialogControl.WriteLine
|
||||
.AddText( Context := "TEXTFIELD" _
|
||||
, MsgId := "The control '%1' in dialog '%2' is not a multiline text field.\n" _
|
||||
& "The requested method could not be executed." _
|
||||
, Comment := "SF_DialogControl add line in textbox\n" _
|
||||
& "%1: An identifier\n" _
|
||||
& "%2: An identifier" _
|
||||
)
|
||||
' SF_Database.RunSql
|
||||
.AddText( Context := "DBREADONLY" _
|
||||
, MsgId := "The database has been opened in read-only mode.\n" _
|
||||
& "The '%1' method must not be executed in this context." _
|
||||
, Comment := "SF_Database when running update SQL statement\n" _
|
||||
& "%1: The concerned method" _
|
||||
)
|
||||
' SF_Database._ExecuteSql
|
||||
.AddText( Context := "SQLSYNTAX" _
|
||||
, MsgId := "An SQL statement could not be interpreted or executed by the database system.\n" _
|
||||
& "Check its syntax, table and/or field names, ...\n\n" _
|
||||
& "SQL Statement : « %1 »" _
|
||||
, Comment := "SF_Database can't interpret SQL statement\n" _
|
||||
& "%1: The statement" _
|
||||
)
|
||||
End With
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Sub ' ScriptForge.SF_Root._LoadLocalizedInterface
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _Repr() As String
|
||||
''' Convert the unique SF_Root instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[Root] (MainFunction: xxx, Console: yyy lines, ServicesList)"
|
||||
|
||||
Dim sRoot As String ' Return value
|
||||
Const cstRoot = "[Root] ("
|
||||
|
||||
sRoot = cstRoot & "MainFunction: " & MainFunction & ", Console: " & UBound(ConsoleLines) + 1 & " lines" _
|
||||
& ", Libraries:" & SF_Utils._Repr(ServicesList.Keys) _
|
||||
& ")"
|
||||
|
||||
_Repr = sRoot
|
||||
|
||||
End Function ' ScriptForge.SF_Root._Repr
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _StackReset()
|
||||
''' Reset private members after a fatal/abort error to leave
|
||||
''' a stable persistent storage after an unwanted interrupt
|
||||
|
||||
MainFunction = ""
|
||||
MainFunctionArgs = ""
|
||||
StackLevel = 0
|
||||
|
||||
End Sub ' ScriptForge.SF_Root._StackReset
|
||||
|
||||
REM ================================================== END OF SCRIPTFORGE.SF_ROOT
|
||||
</script:module>
|
||||
607
server/windows-office/share/basic/ScriptForge/SF_Services.xba
Normal file
607
server/windows-office/share/basic/ScriptForge/SF_Services.xba
Normal file
@@ -0,0 +1,607 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Services" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Services
|
||||
''' ===========
|
||||
''' Singleton class implementing the "ScriptForge.Services" service
|
||||
''' Implemented as a usual Basic module
|
||||
''' The ScriptForge framework includes
|
||||
''' the current ScriptForge library
|
||||
''' a number of "associated" libraries
|
||||
''' any user/contributor extension wanting to fit into the framework
|
||||
''' The methods in this module constitute the kernel of the ScriptForge framework
|
||||
''' - RegisterScriptServices
|
||||
''' Register for a library the list of services it implements
|
||||
''' Each library in the framework must implement its own RegisterScriptServices method
|
||||
''' This method consists in a series of invocations of next 2 methods
|
||||
''' - RegisterService
|
||||
''' Register a single service
|
||||
''' - RegisterEventManager
|
||||
''' Register a single event manager
|
||||
''' - CreateScriptService
|
||||
''' Called by user scripts to get an object giving access to a service or to the event manager
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Const UNKNOWNSERVICEERROR = "UNKNOWNSERVICEERROR" ' Service not found within the registered services of the given library
|
||||
Const SERVICESNOTLOADEDERROR = "SERVICESNOTLOADEDERROR" ' Failure during the registering of the services of the given library
|
||||
Const UNKNOWNFILEERROR = "UNKNOWNFILEERROR" ' Source file does not exist
|
||||
|
||||
REM ============================================================== PUBLIC MEMBERS
|
||||
|
||||
' Defines an entry in in the services dictionary
|
||||
Type _Service
|
||||
ServiceName As String
|
||||
ServiceType As Integer
|
||||
' 0 Undefined
|
||||
' 1 Basic module
|
||||
' 2 Method reference as a string
|
||||
ServiceReference As Object
|
||||
ServiceMethod As String
|
||||
EventManager As Boolean ' True if registered item is an event manager
|
||||
End Type
|
||||
|
||||
Private vServicesArray As Variant ' List of services registered by a library
|
||||
|
||||
REM ============================================================== PUBLIC METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function CreateScriptService(Optional ByRef Service As Variant _
|
||||
, ParamArray pvArgs As Variant _
|
||||
) As Variant
|
||||
''' Create access to the services of a library for the benefit of a user script
|
||||
''' A service is to understand either:
|
||||
''' as a set of methods gathered in a Basic standard module
|
||||
''' or a set of methods and properties gathered in a Basic class module
|
||||
''' Args:
|
||||
''' Service: the name of the service in 2 parts "library.service"
|
||||
''' The library is a Basic library that must exist in the GlobalScope
|
||||
''' (default = "ScriptForge")
|
||||
''' The service is one of the services registered by the library
|
||||
''' thru the RegisterScriptServices() routine
|
||||
''' pvArgs: a set of arguments passed to the constructor of the service
|
||||
''' This is only possible if the service refers to a Basic class module
|
||||
''' Returns
|
||||
''' The object containing either the reference of the Basic module
|
||||
''' or of the Basic class instance
|
||||
''' Both are Basic objects
|
||||
''' Returns Nothing if an error occurred.
|
||||
''' ==>> NOTE: The error can be within the user script creating the new class instance
|
||||
''' Exceptions:
|
||||
''' SERVICESNOTLOADEDERROR RegisterScriptService probable failure
|
||||
''' UNKNOWNSERVICEERROR Service not found
|
||||
''' Examples
|
||||
''' CreateScriptService("Array")
|
||||
''' => Refers to ScriptForge.Array or SF_Array
|
||||
''' CreateScriptService("ScriptForge.Dictionary")
|
||||
''' => Returns a new empty dictionary; "ScriptForge." is optional
|
||||
''' CreateScriptService("SFDocuments.Calc")
|
||||
''' => Refers to the Calc service, implemented in the SFDocuments library
|
||||
''' CreateScriptService("Dialog", dlgName)
|
||||
''' => Returns a Dialog instance referring to the dlgName dialog
|
||||
''' CreateScriptService("SFDocuments.Event", oEvent)
|
||||
''' => Refers to the Document service instance, implemented in the SFDocuments library, having triggered the event
|
||||
|
||||
Dim vScriptService As Variant ' Return value
|
||||
Dim vServiceItem As Variant ' A single service (see _Service type definition)
|
||||
Dim vServicesList As Variant ' Output of RegisterScriptServices
|
||||
Dim vSplit As Variant ' Array to split argument in
|
||||
Dim sLibrary As String ' Library part of the argument
|
||||
Dim sService As String ' Service part of the argument
|
||||
Dim vLibrary As variant ' Dictionary of libraries
|
||||
Dim vService As Variant ' An individual service object
|
||||
Const cstThisSub = "SF_Services.CreateScriptService"
|
||||
Const cstSubArgs = "Service, arg0[, arg1] ..."
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
Set vScriptService = Nothing
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Service, "Service", V_STRING) Then GoTo Catch
|
||||
If Len(Service) = 0 Then GoTo CatchNotFound
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Initialize the list of services when CreateScriptService called for the very 1st time
|
||||
If IsEmpty(_SF_.ServicesList) Then _SF_.ServicesList = SF_Services._NewDictionary()
|
||||
|
||||
' Simple parsing of argument
|
||||
vSplit = Split(Service, ".")
|
||||
If UBound(vSplit) > 1 Then GoTo CatchNotFound
|
||||
If UBound(vSplit) = 0 Then
|
||||
sLibrary = "ScriptForge" ' Yes, the default value !
|
||||
sService = vSplit(0)
|
||||
' Accept other default values for associated libraries
|
||||
Select Case sService
|
||||
Case "Document", "Calc", "Base" : sLibrary = "SFDocuments"
|
||||
Case "Dialog", "DialogEvent" : sLibrary = "SFDialogs"
|
||||
Case "Database" : sLibrary = "SFDatabases"
|
||||
Case Else
|
||||
End Select
|
||||
Else
|
||||
sLibrary = vSplit(0)
|
||||
sService = vSplit(1)
|
||||
End If
|
||||
|
||||
With _SF_.ServicesList
|
||||
|
||||
' Load the set of services from the library, if not yet done
|
||||
If Not .Exists(sLibrary) Then
|
||||
If Not SF_Services._LoadLibraryServices(sLibrary) Then GoTo CatchNotLoaded
|
||||
End If
|
||||
|
||||
' Find and return the requested service
|
||||
vServicesList = .Item(sLibrary)
|
||||
If Not vServicesList.Exists(sService) Then GoTo CatchNotFound
|
||||
vServiceItem = vServicesList.Item(sService)
|
||||
Select Case vServiceItem.ServiceType
|
||||
Case 1 ' Basic module
|
||||
vScriptService = vServiceItem.ServiceReference
|
||||
Case 2 ' Method to call
|
||||
If sLibrary = "ScriptForge" Then ' Direct call
|
||||
Select Case UCase(sService)
|
||||
Case "DICTIONARY" : vScriptService = SF_Services._NewDictionary()
|
||||
Case "L10N" : vScriptService = SF_Services._NewL10N(pvArgs)
|
||||
Case "TIMER" : vScriptService = SF_Services._NewTimer(pvArgs)
|
||||
Case Else
|
||||
End Select
|
||||
Else ' Call via script provider
|
||||
Set vService = SF_Session._GetScript("Basic", SF_Session.SCRIPTISAPPLICATION, vServiceItem.ServiceMethod)
|
||||
vScriptService = vService.Invoke(Array(pvArgs()), Array(), Array())
|
||||
End If
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
End With
|
||||
|
||||
Finally:
|
||||
CreateScriptService = vScriptService
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchNotFound:
|
||||
SF_Exception.RaiseFatal(UNKNOWNSERVICEERROR, "Service", Service, sLibrary, sService)
|
||||
GoTo Finally
|
||||
CatchNotLoaded:
|
||||
SF_Exception.RaiseFatal(SERVICESNOTLOADEDERROR, "Service", Service, sLibrary)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Services.CreateScriptService
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function RegisterEventManager(Optional ByVal ServiceName As Variant _
|
||||
, Optional ByRef ServiceReference As Variant _
|
||||
) As Boolean
|
||||
''' Register into ScriptForge a new event entry for the library
|
||||
''' from which this method is called
|
||||
''' MUST BE CALLED ONLY from a specific RegisterScriptServices() method
|
||||
''' Usually the method should be called only once by library
|
||||
''' Args:
|
||||
''' ServiceName: the name of the service as a string. It the service exists
|
||||
''' already for the library the method overwrites the existing entry
|
||||
''' ServiceReference: the function which will identify the source of the triggered event
|
||||
''' something like: "libraryname.modulename.function"
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
''' Example:
|
||||
''' ' Code snippet stored in a module contained in the SFDocuments library
|
||||
''' Sub RegisterScriptServices()
|
||||
''' ' Register the events manager of the library
|
||||
''' RegisterEventManager("DocumentEvent", "SFDocuments.SF_Register._EventManager")
|
||||
''' End Sub
|
||||
''' ' Code snippet stored in a user script
|
||||
''' Sub Trigger(poEvent As Object) ' Triggered by a DOCUMENTEVENT event
|
||||
''' Dim myDoc As Object
|
||||
''' ' To get the document concerned by the event:
|
||||
''' Set myDoc = CreateScriptService("SFDocuments.DocumentEvent", poEvent)
|
||||
''' End Sub
|
||||
|
||||
Dim bRegister As Boolean ' Return value
|
||||
Const cstThisSub = "SF_Services.RegisterEventManager"
|
||||
Const cstSubArgs = "ServiceName, ServiceReference"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bRegister = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(ServiceName, "ServiceName", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(ServiceReference, "ServiceReference",V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
bRegister = _AddToServicesArray(ServiceName, ServiceReference, True)
|
||||
|
||||
Finally:
|
||||
RegisterEventManager = bRegister
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Services.RegisterEventManager
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function RegisterService(Optional ByVal ServiceName As Variant _
|
||||
, Optional ByRef ServiceReference As Variant _
|
||||
) As Boolean
|
||||
''' Register into ScriptForge a new service entry for the library
|
||||
''' from which this method is called
|
||||
''' MUST BE CALLED ONLY from a specific RegisterScriptServices() method
|
||||
''' Args:
|
||||
''' ServiceName: the name of the service as a string. It the service exists
|
||||
''' already for the library the method overwrites the existing entry
|
||||
''' ServiceReference: either
|
||||
''' - the Basic module that implements the methods of the service
|
||||
''' something like: GlobalScope.Library.Module
|
||||
''' - an instance of the class implementing the methods and properties of the service
|
||||
''' something like: "libraryname.modulename.function"
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
|
||||
Dim bRegister As Boolean ' Return value
|
||||
Const cstThisSub = "SF_Services.RegisterService"
|
||||
Const cstSubArgs = "ServiceName, ServiceReference"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bRegister = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(ServiceName, "ServiceName", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(ServiceReference, "ServiceReference", Array(V_STRING, V_OBJECT)) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
bRegister = _AddToServicesArray(ServiceName, ServiceReference, False)
|
||||
|
||||
Finally:
|
||||
RegisterService = bRegister
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Services.RegisterService
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub RegisterScriptServices() As Variant
|
||||
''' Register into ScriptForge the list of the services implemented by the current library
|
||||
''' Each library pertaining to the framework must implement its own version of this method
|
||||
''' This method may be stored in any standard (i.e. not class-) module
|
||||
'''
|
||||
''' Each individual service is registered by calling the RegisterService() method
|
||||
'''
|
||||
''' The current version is given as an example
|
||||
'''
|
||||
With GlobalScope.ScriptForge.SF_Services
|
||||
.RegisterService("Array", GlobalScope.ScriptForge.SF_Array) ' Reference to the Basic module
|
||||
.RegisterService("Dictionary", "ScriptForge.SF_Services._NewDictionary") ' Reference to the function initializing the service
|
||||
.RegisterService("Exception", GlobalScope.ScriptForge.SF_Exception)
|
||||
.RegisterService("FileSystem", GlobalScope.ScriptForge.SF_FileSystem)
|
||||
.RegisterService("L10N", "ScriptForge.SF_Services._NewL10N")
|
||||
.RegisterService("Platform", GlobalScope.ScriptForge.SF_Platform)
|
||||
.RegisterService("Session", GlobalScope.ScriptForge.SF_Session)
|
||||
.RegisterService("String", GlobalScope.ScriptForge.SF_String)
|
||||
.RegisterService("Timer", "ScriptForge.SF_Services._NewTimer")
|
||||
.RegisterService("UI", GlobalScope.ScriptForge.SF_UI)
|
||||
'TODO
|
||||
End With
|
||||
|
||||
End Sub ' ScriptForge.SF_Services.RegisterScriptServices
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _AddToServicesArray(ByVal psServiceName As String _
|
||||
, ByRef pvServiceReference As Variant _
|
||||
, ByVal pbEvent As Boolean _
|
||||
) As Boolean
|
||||
''' Add the arguments as an additional row in vServicesArray (Public variable)
|
||||
''' Called from RegisterService and RegisterEvent methods
|
||||
|
||||
Dim bRegister As Boolean ' Return value
|
||||
Dim lMax As Long ' Number of rows in vServicesArray
|
||||
|
||||
bRegister = False
|
||||
|
||||
Check:
|
||||
' Ignore when method is not called from RegisterScriptServices()
|
||||
If IsEmpty(vServicesArray) Or IsNull(vServicesArray) Or Not IsArray(vServicesArray) Then GoTo Finally
|
||||
|
||||
Try:
|
||||
lMax = UBound(vServicesArray, 1) + 1
|
||||
If lMax <= 0 Then
|
||||
ReDim vServicesArray(0 To 0, 0 To 2)
|
||||
Else
|
||||
ReDim Preserve vServicesArray(0 To lMax, 0 To 2)
|
||||
End If
|
||||
vServicesArray(lMax, 0) = psServiceName
|
||||
vServicesArray(lMax, 1) = pvServiceReference
|
||||
vServicesArray(lMax, 2) = pbEvent
|
||||
bRegister = True
|
||||
|
||||
Finally:
|
||||
_AddToServicesArray = bRegister
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Services._AddToServicesArray
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _FindModuleFromMethod(ByVal psLibrary As String _
|
||||
, ByVal psMethod As String _
|
||||
) As String
|
||||
''' Find in the given library the name of the module containing
|
||||
''' the method given as 2nd argument (usually RegisterScriptServices)
|
||||
''' Args:
|
||||
''' psLibrary: the name of the Basic library
|
||||
''' psMethod: the method to locate
|
||||
''' Returns:
|
||||
''' The name of the module or a zero-length string if not found
|
||||
|
||||
Dim vCategories As Variant ' "user" or "share" library categories
|
||||
Dim sCategory As String
|
||||
Dim vLanguages As Variant ' "Basic", "Python", ... programming languages
|
||||
Dim sLanguage As String
|
||||
Dim vLibraries As Variant ' Library names
|
||||
Dim sLibrary As String
|
||||
Dim vModules As Variant ' Module names
|
||||
Dim sModule As String ' Return value
|
||||
Dim vMethods As Variant ' Method/properties/subs/functions
|
||||
Dim sMethod As String
|
||||
Dim oRoot As Object ' com.sun.star.script.browse.BrowseNodeFactory
|
||||
Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer
|
||||
|
||||
_FindModuleFromMethod = ""
|
||||
Set oRoot = SF_Utils._GetUNOService("BrowseNodeFactory").createView(com.sun.star.script.browse.BrowseNodeFactoryViewTypes.MACROORGANIZER)
|
||||
|
||||
' Exploration is done via tree nodes
|
||||
If Not IsNull(oRoot) Then
|
||||
If oRoot.hasChildNodes() Then
|
||||
vCategories = oRoot.getChildNodes()
|
||||
For i = 0 To UBound(vCategories)
|
||||
sCategory = vCategories(i).getName()
|
||||
' Consider "My macros & Dialogs" and "LibreOffice Macros & Dialogs" only
|
||||
If sCategory = "user" Or sCategory = "share" Then
|
||||
If vCategories(i).hasChildNodes() Then
|
||||
vLanguages = vCategories(i).getChildNodes()
|
||||
For j = 0 To UBound(vLanguages)
|
||||
sLanguage = vLanguages(j).getName()
|
||||
' Consider Basic libraries only
|
||||
If sLanguage = "Basic" Then
|
||||
If vLanguages(j).hasChildNodes() Then
|
||||
vLibraries = vLanguages(j).getChildNodes()
|
||||
For k = 0 To UBound(vLibraries)
|
||||
sLibrary = vLibraries(k).getName()
|
||||
' Consider the given library only
|
||||
If sLibrary = psLibrary Then
|
||||
If vLibraries(k).hasChildNodes() Then
|
||||
vModules = vLibraries(k).getChildNodes()
|
||||
For l = 0 To UBound(vModules)
|
||||
sModule = vModules(l).getName()
|
||||
' Check if the module contains the targeted method
|
||||
If vModules(l).hasChildNodes() Then
|
||||
vMethods = vModules(l).getChildNodes()
|
||||
For m = 0 To UBound(vMethods)
|
||||
sMethod = vMethods(m).getName()
|
||||
If sMethod = psMethod Then
|
||||
_FindModuleFromMethod = sModule
|
||||
Exit Function
|
||||
End If
|
||||
Next m
|
||||
End If
|
||||
Next l
|
||||
End If
|
||||
End If
|
||||
Next k
|
||||
End If
|
||||
End If
|
||||
Next j
|
||||
End If
|
||||
End If
|
||||
Next i
|
||||
End If
|
||||
End If
|
||||
|
||||
End Function ' ScriptForge.SF_Services._FindModuleFromMethod
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _LoadLibraryServices(ByVal psLibrary As String) As Boolean
|
||||
''' Execute psLibrary.RegisterScriptServices() and load its services into the persistent storage
|
||||
''' Args:
|
||||
''' psLibrary: the name of the Basic library
|
||||
''' Library will be loaded if not yet done
|
||||
''' Returns:
|
||||
''' True if success
|
||||
''' The list of services is loaded directly into the persistent storage
|
||||
|
||||
|
||||
Dim vServicesList As Variant ' Dictionary of services
|
||||
Dim vService As Variant ' Single service entry in dictionary
|
||||
Dim vServiceItem As Variant ' Single service in vServicesArray
|
||||
Dim sModule As String ' Name of module containing the RegisterScriptServices method
|
||||
Dim i As Long
|
||||
Const cstRegister = "RegisterScriptServices"
|
||||
|
||||
Try:
|
||||
_LoadLibraryServices = False
|
||||
|
||||
vServicesArray = Array()
|
||||
|
||||
If psLibrary = "ScriptForge" Then
|
||||
' Direct call
|
||||
ScriptForge.SF_Services.RegisterScriptServices()
|
||||
Else
|
||||
' Register services via script provider
|
||||
If GlobalScope.BasicLibraries.hasByName(psLibrary) Then
|
||||
If Not GlobalScope.BasicLibraries.isLibraryLoaded(psLibrary) Then
|
||||
GlobalScope.BasicLibraries.LoadLibrary(psLibrary)
|
||||
End If
|
||||
Else
|
||||
GoTo Finally
|
||||
End If
|
||||
sModule = SF_Services._FindModuleFromMethod(psLibrary, cstRegister)
|
||||
If Len(sModule) = 0 Then GoTo Finally
|
||||
SF_Session.ExecuteBasicScript(, psLibrary & "." & sModule & "." & cstRegister)
|
||||
End If
|
||||
|
||||
' Store in persistent storage
|
||||
' - Create list of services for the current library
|
||||
Set vServicesList = SF_Services._NewDictionary()
|
||||
For i = 0 To UBound(vServicesArray, 1)
|
||||
Set vService = New _Service
|
||||
With vService
|
||||
.ServiceName = vServicesArray(i, 0)
|
||||
vServiceItem = vServicesArray(i, 1)
|
||||
If VarType(vServiceItem) = V_STRING Then
|
||||
.ServiceType = 2
|
||||
.ServiceMethod = vServiceItem
|
||||
Set .ServiceReference = Nothing
|
||||
Else ' OBJECT
|
||||
.ServiceType = 1
|
||||
.ServiceMethod = ""
|
||||
Set .ServiceReference = vServiceItem
|
||||
End If
|
||||
.EventManager = vServicesArray(i, 2)
|
||||
End With
|
||||
vServicesList.Add(vServicesArray(i, 0), vService)
|
||||
Next i
|
||||
' - Add the new dictionary to the persistent dictionary
|
||||
_SF_.ServicesList.Add(psLibrary, vServicesList)
|
||||
_LoadLibraryServices = True
|
||||
vServicesArray = Empty
|
||||
|
||||
Finally:
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Services._LoadLibraryServices
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _NewDictionary() As Variant
|
||||
''' Create a new instance of the SF_Dictionary class
|
||||
''' Returns: the instance or Nothing
|
||||
|
||||
Dim oDict As Variant
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
|
||||
Try:
|
||||
Set oDict = New SF_Dictionary
|
||||
Set oDict.[Me] = oDict
|
||||
|
||||
Finally:
|
||||
Set _NewDictionary = oDict
|
||||
Exit Function
|
||||
Catch:
|
||||
Set oDict = Nothing
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Services._NewDictionary
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _NewL10N(Optional ByVal pvArgs As Variant) As Variant
|
||||
''' Create a new instance of the SF_L10N class
|
||||
' Args:
|
||||
''' FolderName: the folder containing the PO files in SF_FileSystem.FileNaming notation
|
||||
''' Locale: locale of user session (default) or any other valid la{nguage]-CO[UNTRY] combination
|
||||
''' The country part is optional. Valid are f.i. "fr", "fr-CH", "en-US"
|
||||
''' Encoding: The character set that should be used
|
||||
''' Use one of the Names listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml
|
||||
''' Note that LibreOffice probably does not implement all existing sets
|
||||
''' Default = UTF-8
|
||||
''' Returns: the instance or Nothing
|
||||
''' Exceptions:
|
||||
''' UNKNOWNFILEERROR The PO file does not exist
|
||||
|
||||
Dim oL10N As Variant ' Return value
|
||||
Dim sFolderName As String ' Folder containing the PO files
|
||||
Dim sLocale As String ' Passed argument or that of the user session
|
||||
Dim oLocale As Variant ' com.sun.star.lang.Locale
|
||||
Dim sPOFile As String ' PO file must exist
|
||||
Dim sEncoding As String ' Alias for Encoding
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(pvArgs) Then pvArgs = Array()
|
||||
If UBound(pvArgs) < 0 Then
|
||||
sPOFile = ""
|
||||
sEncoding = ""
|
||||
Else
|
||||
If Not SF_Utils._ValidateFile(pvArgs(0), "Folder (Arg0)") Then GoTo Catch
|
||||
sFolderName = pvArgs(0)
|
||||
If UBound(pvArgs) >= 1 Then
|
||||
If Not SF_Utils._Validate(pvArgs(1), "Locale (Arg1)", V_STRING) Then GoTo Catch
|
||||
sLocale = pvArgs(1)
|
||||
Else
|
||||
Set oLocale = SF_Utils._GetUNOService("Locale")
|
||||
sLocale = oLocale.Language & "-" & oLocale.Country
|
||||
End If
|
||||
If UBound(pvArgs) >= 2 Then
|
||||
If Not SF_Utils._Validate(pvArgs(2), "Encoding (Arg2)", V_STRING) Then GoTo Catch
|
||||
sEncoding = pvArgs(2)
|
||||
Else
|
||||
sEncoding = "UTF-8"
|
||||
End If
|
||||
sPOFile = SF_FileSystem.BuildPath(sFolderName, sLocale & ".po")
|
||||
If Not SF_FileSystem.FileExists(sPOFile) Then GoTo CatchNotExists
|
||||
End If
|
||||
|
||||
Try:
|
||||
Set oL10N = New SF_L10N
|
||||
Set oL10N.[Me] = oL10N
|
||||
oL10N._Initialize(sPOFile, sEncoding)
|
||||
|
||||
Finally:
|
||||
Set _NewL10N = oL10N
|
||||
Exit Function
|
||||
Catch:
|
||||
Set oL10N = Nothing
|
||||
GoTo Finally
|
||||
CatchNotExists:
|
||||
SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "FileName", sPOFile)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Services._NewL10N
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _NewTimer(Optional ByVal pvArgs As Variant) As Variant
|
||||
''' Create a new instance of the SF_Timer class
|
||||
''' Args:
|
||||
''' [0] : If True, start the timer immediately
|
||||
''' Returns: the instance or Nothing
|
||||
|
||||
Dim oTimer As Variant ' Return value
|
||||
Dim bStart As Boolean ' Automatic start ?
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(pvArgs) Then pvArgs = Array()
|
||||
If UBound(pvArgs) < 0 Then
|
||||
bStart = False
|
||||
Else
|
||||
If Not SF_Utils._Validate(pvArgs(0), "Start (Arg0)", V_BOOLEAN) Then GoTo Catch
|
||||
bStart = pvArgs(0)
|
||||
End If
|
||||
Try:
|
||||
Set oTimer = New SF_Timer
|
||||
Set oTimer.[Me] = oTimer
|
||||
If bStart Then oTimer.Start()
|
||||
|
||||
Finally:
|
||||
Set _NewTimer = oTimer
|
||||
Exit Function
|
||||
Catch:
|
||||
Set oTimer = Nothing
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Services._NewTimer
|
||||
|
||||
REM ============================================== END OF SCRIPTFORGE.SF_SERVICES
|
||||
</script:module>
|
||||
918
server/windows-office/share/basic/ScriptForge/SF_Session.xba
Normal file
918
server/windows-office/share/basic/ScriptForge/SF_Session.xba
Normal file
@@ -0,0 +1,918 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Session" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Session
|
||||
''' ==========
|
||||
''' Singleton class implementing the "ScriptForge.Session" service
|
||||
''' Implemented as a usual Basic module
|
||||
'''
|
||||
''' Gathers diverse general-purpose properties and methods about :
|
||||
''' - installation/execution environment
|
||||
''' - UNO introspection utilities
|
||||
''' - clipboard management
|
||||
''' - invocation of external scripts or programs
|
||||
'''
|
||||
''' Service invocation example:
|
||||
''' Dim session As Variant
|
||||
''' session = CreateScriptService("Session")
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Const CALCFUNCERROR = "CALCFUNCERROR" ' Calc function execution failed
|
||||
Const NOSCRIPTERROR = "NOSCRIPTERROR" ' Script could not be located
|
||||
Const SCRIPTEXECERROR = "SCRIPTEXECERROR" ' Exception during script execution
|
||||
Const WRONGEMAILERROR = "WRONGEMAILERROR" ' Wrong email address
|
||||
Const SENDMAILERROR = "SENDMAILERROR" ' Mail could not be sent
|
||||
Const UNKNOWNFILEERROR = "UNKNOWNFILEERROR" ' Source file does not exist
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
''' Script locations
|
||||
''' ================
|
||||
''' Use next constants as Scope argument when invoking next methods:
|
||||
''' ExecuteBasicScript()
|
||||
''' ExecutePythonScript()
|
||||
''' Example:
|
||||
''' session.ExecuteBasicScript(session.SCRIPTISEMBEDDED, "Standard.myLib.myFunc", etc)
|
||||
|
||||
Const cstSCRIPTISEMBEDDED = "document" ' a library of the document (BASIC + PYTHON)
|
||||
Const cstSCRIPTISAPPLICATION = "application" ' a shared library (BASIC)
|
||||
Const cstSCRIPTISPERSONAL = "user" ' a library of My Macros (PYTHON)
|
||||
Const cstSCRIPTISPERSOXT = "user:uno_packages" ' an extension for the current user (PYTHON)
|
||||
Const cstSCRIPTISSHARED = "share" ' a library of LibreOffice Macros (PYTHON)
|
||||
Const cstSCRIPTISSHAROXT = "share:uno_packages" ' an extension for all users (PYTHON)
|
||||
Const cstSCRIPTISOXT = "uno_packages" ' an extension but install params are unknown (PYTHON)
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_Array Explicit destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ObjectType As String
|
||||
''' Only to enable object representation
|
||||
ObjectType = "SF_Session"
|
||||
End Property ' ScriptForge.SF_Session.ObjectType
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ServiceName As String
|
||||
''' Internal use
|
||||
ServiceName = "ScriptForge.Session"
|
||||
End Property ' ScriptForge.SF_Array.ServiceName
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISAPPLICATION As String
|
||||
''' Convenient constants
|
||||
SCRIPTISAPPLICATION = cstSCRIPTISAPPLICATION
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISAPPLICATION
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISEMBEDDED As String
|
||||
''' Convenient constants
|
||||
SCRIPTISEMBEDDED = cstSCRIPTISEMBEDDED
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISEMBEDDED
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISOXT As String
|
||||
''' Convenient constants
|
||||
SCRIPTISOXT = cstSCRIPTISOXT
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISOXT
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISPERSONAL As String
|
||||
''' Convenient constants
|
||||
SCRIPTISPERSONAL = cstSCRIPTISPERSONAL
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISPERSONAL
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISPERSOXT As String
|
||||
''' Convenient constants
|
||||
SCRIPTISPERSOXT = cstSCRIPTISPERSOXT
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISPERSOXT
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISSHARED As String
|
||||
''' Convenient constants
|
||||
SCRIPTISSHARED = cstSCRIPTISSHARED
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISSHARED
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get SCRIPTISSHAROXT As String
|
||||
''' Convenient constants
|
||||
SCRIPTISSHAROXT = cstSCRIPTISSHAROXT
|
||||
End Property ' ScriptForge.SF_Session.SCRIPTISSHAROXT
|
||||
|
||||
REM ============================================================== PUBLIC METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ExecuteBasicScript(Optional ByVal Scope As Variant _
|
||||
, Optional ByVal Script As Variant _
|
||||
, ParamArray pvArgs As Variant _
|
||||
) As Variant
|
||||
''' Execute the Basic script given as a string and return the value returned by the script
|
||||
''' Args:
|
||||
''' Scope: "Application" (default) or "Document" (NOT case-sensitive)
|
||||
''' (or use one of the SCRIPTIS... public constants above)
|
||||
''' Script: library.module.method (Case sensitive)
|
||||
''' library => The library may be not loaded yet
|
||||
''' module => Must not be a class module
|
||||
''' method => Sub or Function
|
||||
''' Read https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification
|
||||
''' pvArgs: the arguments of the called script
|
||||
''' Returns:
|
||||
''' The value returned by the call to the script
|
||||
''' Exceptions:
|
||||
''' NOSCRIPTERROR The script could not be found
|
||||
''' Examples:
|
||||
''' session.ExecuteBasicScript(, "XrayTool._Main.Xray", someuno) ' Sub: no return expected
|
||||
|
||||
Dim oScript As Object ' Script to be invoked
|
||||
Dim vReturn As Variant ' Returned value
|
||||
|
||||
Const cstThisSub = "Session.ExecuteBasicScript"
|
||||
Const cstSubArgs = "[Scope], Script, arg0[, arg1] ..."
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
vReturn = Empty
|
||||
|
||||
Check:
|
||||
If IsMissing(Scope) Or IsEmpty(Scope) Then Scope = SCRIPTISAPPLICATION
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Scope, "Scope", V_STRING _
|
||||
, Array(SCRIPTISAPPLICATION, SCRIPTISEMBEDDED)) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Script, "Script", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Execute script
|
||||
Set oScript = SF_Session._GetScript("Basic", Scope, Script)
|
||||
On Local Error GoTo CatchExec
|
||||
If Not IsNull(oScript) Then vReturn = oScript.Invoke(pvArgs(), Array(), Array())
|
||||
|
||||
Finally:
|
||||
ExecuteBasicScript = vReturn
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchExec:
|
||||
SF_Exception.RaiseFatal(SCRIPTEXECERROR, "Script", Script, Error$)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.ExecuteBasicScript
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ExecuteCalcFunction(Optional ByVal CalcFunction As Variant _
|
||||
, ParamArray pvArgs As Variant _
|
||||
) As Variant
|
||||
''' Execute a Calc function by its (english) name and based on the given arguments
|
||||
''' Args:
|
||||
''' CalcFunction: the english name of the function to execute
|
||||
''' pvArgs: the arguments of the called function
|
||||
''' Each argument must be either a string, a numeric value
|
||||
''' or an array of arrays combining those types
|
||||
''' Returns:
|
||||
''' The (string or numeric) value or the array of arrays returned by the call to the function
|
||||
''' When the arguments contain arrays, the function is executed as an array function
|
||||
''' Wrong arguments generate an error
|
||||
''' Exceptions:
|
||||
''' CALCFUNCERROR ' Execution error in calc function
|
||||
''' Examples:
|
||||
''' session.ExecuteCalcFunction("AVERAGE", 1, 5, 3, 7) returns 4
|
||||
''' session.ExecuteCalcFunction("ABS", Array(Array(-1,2,3),Array(4,-5,6),Array(7,8,-9)))(2)(2) returns 9
|
||||
''' session.ExecuteCalcFunction("LN", -3) generates an error
|
||||
|
||||
Dim oCalc As Object ' Give access to the com.sun.star.sheet.FunctionAccess service
|
||||
Dim vReturn As Variant ' Returned value
|
||||
Const cstThisSub = "Session.ExecuteCalcFunction"
|
||||
Const cstSubArgs = "CalcFunction, arg0[, arg1] ..."
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
vReturn = Empty
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(CalcFunction, "CalcFunction", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Execute function
|
||||
Set oCalc = SF_Utils._GetUNOService("FunctionAccess")
|
||||
On Local Error GoTo CatchCall
|
||||
vReturn = oCalc.callFunction(UCase(CalcFunction), pvArgs())
|
||||
|
||||
Finally:
|
||||
ExecuteCalcFunction = vReturn
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchCall:
|
||||
SF_Exception.RaiseFatal(CALCFUNCERROR, CalcFunction)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.ExecuteCalcFunction
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ExecutePythonScript(Optional ByVal Scope As Variant _
|
||||
, Optional ByVal Script As Variant _
|
||||
, ParamArray pvArgs As Variant _
|
||||
) As Variant
|
||||
''' Execute the Python script given as a string and return the value returned by the script
|
||||
''' Args:
|
||||
''' Scope: one of the SCRIPTIS... public constants above (default = "share")
|
||||
''' Script: (Case sensitive)
|
||||
''' "library/module.py$method"
|
||||
''' or "module.py$method"
|
||||
''' or "myExtension.oxt|myScript|module.py$method"
|
||||
''' library => The library may be not loaded yet
|
||||
''' myScript => The directory containing the python module
|
||||
''' module.py => The python module
|
||||
''' method => The python function
|
||||
''' Read https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification
|
||||
''' pvArgs: the arguments of the called script
|
||||
''' Date arguments are converted to iso format. However dates in arrays are not converted
|
||||
''' Returns:
|
||||
''' The value(s) returned by the call to the script. If >1 values, enclosed in an array
|
||||
''' Exceptions:
|
||||
''' NOSCRIPTERROR The script could not be found
|
||||
''' Examples:
|
||||
''' session.ExecutePythonScript(session.SCRIPTISSHARED, "Capitalise.py$getNewString", "Abc") returns "abc"
|
||||
|
||||
Dim oScript As Object ' Script to be invoked
|
||||
Dim vArg As Variant ' Individual argument
|
||||
Dim vReturn As Variant ' Returned value
|
||||
Dim i As Long
|
||||
|
||||
Const cstThisSub = "Session.ExecutePythonScript"
|
||||
Const cstSubArgs = "[Scope], Script, arg0[, arg1] ..."
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
vReturn = Empty
|
||||
|
||||
Check:
|
||||
If IsError(Scope) Or IsMissing(Scope) Then Scope = SCRIPTISSHARED
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Scope, "Scope", V_STRING _
|
||||
, Array(SCRIPTISSHARED, SCRIPTISEMBEDDED, SCRIPTISPERSONAL, SCRIPTISSHAROXT, SCRIPTISPERSOXT, SCRIPTISOXT) _
|
||||
) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Script, "Script", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Filter date arguments - NB: dates in arrays are not filtered
|
||||
For i = 0 To UBound(pvArgs) ' pvArgs always zero-based
|
||||
vArg = pvArgs(i)
|
||||
If VarType(vArg) = V_DATE Then pvArgs(i) = SF_Utils._CDateToIso(vArg)
|
||||
Next i
|
||||
|
||||
' Find script
|
||||
Set oScript = SF_Session._GetScript("Python", Scope, Script)
|
||||
|
||||
' Execute script
|
||||
If Not IsNull(oScript) Then
|
||||
vReturn = oScript.Invoke(pvArgs(), Array(), Array())
|
||||
' Remove surrounding array when single returned value
|
||||
If IsArray(vReturn) Then
|
||||
If UBound(vReturn) = 0 Then vReturn = vReturn(0)
|
||||
End If
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ExecutePythonScript = vReturn
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.ExecutePythonScript
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "Session.GetProperty"
|
||||
Const cstSubArgs = "PropertyName"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function HasUnoMethod(Optional ByRef UnoObject As Variant _
|
||||
, Optional ByVal MethodName As Variant _
|
||||
) As Boolean
|
||||
''' Returns True if a UNO object contains the given method
|
||||
''' Code-snippet derived from XRAY
|
||||
''' Args:
|
||||
''' UnoObject: the object to identify
|
||||
''' MethodName: the name of the method as a string. The search is case-sensitive
|
||||
''' Returns:
|
||||
''' False when the method is not found or when an argument is invalid
|
||||
|
||||
Dim oIntrospect As Object ' com.sun.star.beans.Introspection
|
||||
Dim oInspect As Object ' com.sun.star.beans.XIntrospectionAccess
|
||||
Dim bMethod As Boolean ' Return value
|
||||
Const cstThisSub = "Session.HasUnoMethod"
|
||||
Const cstSubArgs = "UnoObject, MethodName"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Check:
|
||||
bMethod = False
|
||||
If VarType(UnoObject) <> V_OBJECT Then GoTo Finally
|
||||
If IsNull(UnoObject) Then GoTo Finally
|
||||
If VarType(MethodName) <> V_STRING Then GoTo Finally
|
||||
If MethodName = Space(Len(MethodName)) Then GoTo Finally
|
||||
|
||||
Try:
|
||||
On Local Error GoTo Catch
|
||||
Set oIntrospect = SF_Utils._GetUNOService("Introspection")
|
||||
Set oInspect = oIntrospect.inspect(UnoObject)
|
||||
bMethod = oInspect.hasMethod(MethodName, com.sun.star.beans.MethodConcept.ALL)
|
||||
|
||||
Finally:
|
||||
HasUnoMethod = bMethod
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
On Local Error GoTo 0
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.HasUnoMethod
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function HasUnoProperty(Optional ByRef UnoObject As Variant _
|
||||
, Optional ByVal PropertyName As Variant _
|
||||
) As Boolean
|
||||
''' Returns True if a UNO object contains the given property
|
||||
''' Code-snippet derived from XRAY
|
||||
''' Args:
|
||||
''' UnoObject: the object to identify
|
||||
''' PropertyName: the name of the property as a string. The search is case-sensitive
|
||||
''' Returns:
|
||||
''' False when the property is not found or when an argument is invalid
|
||||
|
||||
Dim oIntrospect As Object ' com.sun.star.beans.Introspection
|
||||
Dim oInspect As Object ' com.sun.star.beans.XIntrospectionAccess
|
||||
Dim bProperty As Boolean ' Return value
|
||||
Const cstThisSub = "Session.HasUnoProperty"
|
||||
Const cstSubArgs = "UnoObject, PropertyName"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Check:
|
||||
bProperty = False
|
||||
If VarType(UnoObject) <> V_OBJECT Then GoTo Finally
|
||||
If IsNull(UnoObject) Then GoTo Finally
|
||||
If VarType(PropertyName) <> V_STRING Then GoTo Finally
|
||||
If PropertyName = Space(Len(PropertyName)) Then GoTo Finally
|
||||
|
||||
Try:
|
||||
On Local Error GoTo Catch
|
||||
Set oIntrospect = SF_Utils._GetUNOService("Introspection")
|
||||
Set oInspect = oIntrospect.inspect(UnoObject)
|
||||
bProperty = oInspect.hasProperty(PropertyName, com.sun.star.beans.PropertyConcept.ALL)
|
||||
|
||||
Finally:
|
||||
HasUnoProperty = bProperty
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
On Local Error GoTo 0
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.HasUnoProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Session service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"ExecuteBasicScript" _
|
||||
, "ExecuteCalcFunction" _
|
||||
, "ExecutePythonScript" _
|
||||
, "HasUnoMethod" _
|
||||
, "HasUnoProperty" _
|
||||
, "OpenURLInBrowser" _
|
||||
, "RunApplication" _
|
||||
, "SendMail" _
|
||||
, "UnoMethods" _
|
||||
, "UnoObjectType" _
|
||||
, "UnoProperties" _
|
||||
, "WebService" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Session.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub OpenURLInBrowser(Optional ByVal URL As Variant)
|
||||
''' Opens a URL in the default browser
|
||||
''' Args:
|
||||
''' URL: The URL to open in the browser
|
||||
''' Examples:
|
||||
''' session.OpenURLInBrowser("https://docs.python.org/3/library/webbrowser.html")
|
||||
|
||||
Const cstPyHelper = "$" & "_SF_Session__OpenURLInBrowser"
|
||||
|
||||
Const cstThisSub = "Session.OpenURLInBrowser"
|
||||
Const cstSubArgs = "URL"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(URL, "URL", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
ExecutePythonScript(SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, URL)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Sub ' ScriptForge.SF_Session.OpenURLInBrowser
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties as an array
|
||||
|
||||
Properties = Array( _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Session.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function RunApplication(Optional ByVal Command As Variant _
|
||||
, Optional ByVal Parameters As Variant _
|
||||
) As Boolean
|
||||
''' Executes an arbitrary system command
|
||||
''' Args:
|
||||
''' Command: The command to execute
|
||||
''' This may be an executable file or a document which is registered with an application
|
||||
''' so that the system knows what application to launch for that document
|
||||
''' Parameters: a list of space separated parameters as a single string
|
||||
''' The method does not validate the given parameters, but only passes them to the specified command
|
||||
''' Returns:
|
||||
''' True if success
|
||||
''' Examples:
|
||||
''' session.RunApplication("Notepad.exe")
|
||||
''' session.RunApplication("C:\myFolder\myDocument.odt")
|
||||
''' session.RunApplication("kate", "/home/me/install.txt") ' (Linux)
|
||||
|
||||
Dim bReturn As Boolean ' Returned value
|
||||
Dim oShell As Object ' com.sun.star.system.SystemShellExecute
|
||||
Dim sCommand As String ' Command as an URL
|
||||
Const cstThisSub = "Session.RunApplication"
|
||||
Const cstSubArgs = "Command, [Parameters]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bReturn = False
|
||||
|
||||
Check:
|
||||
If IsMissing(Parameters) Then Parameters = ""
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._ValidateFile(Command, "Command") Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Parameters, "Parameters", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
Set oShell = SF_Utils._GetUNOService("SystemShellExecute")
|
||||
sCommand = SF_FileSystem._ConvertToUrl(Command)
|
||||
oShell.execute(sCommand, Parameters, com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
|
||||
bReturn = True
|
||||
|
||||
Finally:
|
||||
RunApplication = bReturn
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.RunApplication
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub SendMail(Optional ByVal Recipient As Variant _
|
||||
, Optional ByRef Cc As Variant _
|
||||
, Optional ByRef Bcc As Variant _
|
||||
, Optional ByVal Subject As Variant _
|
||||
, Optional ByRef Body As Variant _
|
||||
, Optional ByVal FileNames As Variant _
|
||||
, Optional ByVal EditMessage As Variant _
|
||||
)
|
||||
''' Send a message (with or without attachments) to recipients from the user's mail client
|
||||
''' The message may be edited by the user before sending or, alternatively, be sent immediately
|
||||
''' Args:
|
||||
''' Recipient: an email addresses (To recipient)
|
||||
''' Cc: a comma-delimited list of email addresses (carbon copy)
|
||||
''' Bcc: a comma-delimited list of email addresses (blind carbon copy)
|
||||
''' Subject: the header of the message
|
||||
''' FileNames: a comma-separated list of filenames to attach to the mail. SF_FileSystem naming conventions apply
|
||||
''' Body: the unformatted text of the message
|
||||
''' EditMessage: when True (default) the message is editable before being sent
|
||||
''' Exceptions:
|
||||
''' UNKNOWNFILEERROR File does not exist
|
||||
''' WRONGEMAILERROR String not recognized as an email address
|
||||
''' SENDMAILERROR System error, probably no mail client
|
||||
|
||||
Dim sEmail As String ' An single email address
|
||||
Dim sFile As String ' A single file name
|
||||
Dim sArg As String ' Argument name
|
||||
Dim vCc As Variant ' Array alias of Cc
|
||||
Dim vBcc As Variant ' Array alias of Bcc
|
||||
Dim vFileNames As Variant ' Array alias of FileNames
|
||||
Dim oMailService As Object ' com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
|
||||
Dim oMail As Object ' com.sun.star.system.XSimpleMailClient
|
||||
Dim oMessage As Object ' com.sun.star.system.XSimpleMailMessage
|
||||
Dim lFlag As Long ' com.sun.star.system.SimpleMailClientFlags.XXX
|
||||
Dim ARR As Object : ARR = ScriptForge.SF_Array
|
||||
Dim i As Long
|
||||
Const cstComma = ",", cstSemiColon = ";"
|
||||
Const cstThisSub = "Session.SendMail"
|
||||
Const cstSubArgs = "Recipient, [Cc=""""], [Bcc=""""], [Subject=""""], [FileNames=""""], [Body=""""], [EditMessage=True]"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(Cc) Or IsEmpty(Cc) Then Cc = ""
|
||||
If IsMissing(Bcc) Or IsEmpty(Bcc) Then Bcc = ""
|
||||
If IsMissing(Subject) Or IsEmpty(Subject) Then Subject = ""
|
||||
If IsMissing(FileNames) Or IsEmpty(FileNames) Then FileNames = ""
|
||||
If IsMissing(Body) Or IsEmpty(Body) Then Body = ""
|
||||
If IsMissing(EditMessage) Or IsEmpty(EditMessage) Then EditMessage = True
|
||||
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(Cc, "Recipient", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Cc, "Cc", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Bcc, "Bcc", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Subject, "Subject", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(FileNames, "FileNames", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Body, "Body", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(EditMessage, "EditMessage", V_BOOLEAN) Then GoTo Finally
|
||||
End If
|
||||
|
||||
' Check email addresses
|
||||
sArg = "Recipient" : sEmail = Recipient
|
||||
If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
|
||||
sArg = "Cc" : vCc = ARR.TrimArray(Split(Cc, cstComma))
|
||||
For Each sEmail In vCc
|
||||
If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
|
||||
Next sEmail
|
||||
sArg = "Bcc" : vBcc = ARR.TrimArray(Split(Bcc, cstComma))
|
||||
For Each sEmail In vBcc
|
||||
If Not SF_String.IsEmail(sEmail) Then GoTo CatchEmail
|
||||
Next sEmail
|
||||
|
||||
' Check file existence
|
||||
If Len(FileNames) > 0 Then
|
||||
vFileNames = ARR.TrimArray(Split(FileNames, cstComma))
|
||||
For i = 0 To UBound(vFileNames)
|
||||
sFile = vFileNames(i)
|
||||
If Not SF_Utils._ValidateFile(sFile, "FileNames") Then GoTo Finally
|
||||
If Not SF_FileSystem.FileExists(sFile) Then GoTo CatchNotExists
|
||||
vFileNames(i) = ConvertToUrl(sFile)
|
||||
Next i
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Initialize the mail service
|
||||
Set oMailService = SF_Utils._GetUNOService("MailService")
|
||||
If IsNull(oMailService) Then GoTo CatchMail
|
||||
Set oMail = oMailService.querySimpleMailClient()
|
||||
If IsNull(oMail) Then GoTo CatchMail
|
||||
Set oMessage = oMail.createSimpleMailMessage()
|
||||
If IsNull(oMessage) Then GoTo CatchMail
|
||||
|
||||
' Feed the new mail message
|
||||
With oMessage
|
||||
.setRecipient(Recipient)
|
||||
If Subject <> "" Then .setSubject(Subject)
|
||||
If UBound(vCc) >= 0 Then .setCcRecipient(vCc)
|
||||
If UBound(vBcc) >= 0 Then .setBccRecipient(vBcc)
|
||||
.Body = Iif(Len(Body) = 0, " ", Body) ' Body must not be the empty string ??
|
||||
.setAttachement(vFileNames)
|
||||
End With
|
||||
lFlag = Iif(EditMessage, com.sun.star.system.SimpleMailClientFlags.DEFAULTS, com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE)
|
||||
|
||||
' Send using the mail service
|
||||
oMail.sendSimpleMailMessage(oMessage, lFlag)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchEmail:
|
||||
SF_Exception.RaiseFatal(WRONGEMAILERROR, sArg, sEmail)
|
||||
GoTo Finally
|
||||
CatchNotExists:
|
||||
SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "FileNames", sFile)
|
||||
GoTo Finally
|
||||
CatchMail:
|
||||
SF_Exception.RaiseFatal(SENDMAILERROR)
|
||||
GoTo Finally
|
||||
End Sub ' ScriptForge.SF_Session.SendMail
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "Session.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
SetProperty = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.SetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function UnoMethods(Optional ByRef UnoObject As Variant) As Variant
|
||||
''' Returns a list of the methods callable from an UNO object
|
||||
''' Code-snippet derived from XRAY
|
||||
''' Args:
|
||||
''' UnoObject: the object to identify
|
||||
''' Returns:
|
||||
''' A zero-based sorted array. May be empty
|
||||
|
||||
Dim oIntrospect As Object ' com.sun.star.beans.Introspection
|
||||
Dim oInspect As Object ' com.sun.star.beans.XIntrospectionAccess
|
||||
Dim vMethods As Variant ' Array of com.sun.star.reflection.XIdlMethod
|
||||
Dim vMethod As Object ' com.sun.star.reflection.XIdlMethod
|
||||
Dim lMax As Long ' UBounf of vMethods
|
||||
Dim vMethodsList As Variant ' Return value
|
||||
Dim i As Long
|
||||
Const cstThisSub = "Session.UnoMethods"
|
||||
Const cstSubArgs = "UnoObject"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Check:
|
||||
vMethodsList = Array()
|
||||
If VarType(UnoObject) <> V_OBJECT Then GoTo Finally
|
||||
If IsNull(UnoObject) Then GoTo Finally
|
||||
|
||||
Try:
|
||||
On Local Error GoTo Catch
|
||||
Set oIntrospect = SF_Utils._GetUNOService("Introspection")
|
||||
Set oInspect = oIntrospect.inspect(UnoObject)
|
||||
vMethods = oInspect.getMethods(com.sun.star.beans.MethodConcept.ALL)
|
||||
|
||||
' The names must be extracted from com.sun.star.reflection.XIdlMethod structures
|
||||
lMax = UBound(vMethods)
|
||||
If lMax >= 0 Then
|
||||
ReDim vMethodsList(0 To lMax)
|
||||
For i = 0 To lMax
|
||||
vMethodsList(i) = vMethods(i).Name
|
||||
Next i
|
||||
vMethodsList = SF_Array.Sort(vMethodsList, CaseSensitive := True)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
UnoMethods = vMethodsList
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
On Local Error GoTo 0
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.UnoMethods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function UnoObjectType(Optional ByRef UnoObject As Variant) As String
|
||||
''' Identify the UNO type of an UNO object
|
||||
''' Code-snippet derived from XRAY
|
||||
''' Args:
|
||||
''' UnoObject: the object to identify
|
||||
''' Returns:
|
||||
''' com.sun.star. ... as a string
|
||||
''' a zero-length string if identification was not successful
|
||||
|
||||
Dim oService As Object ' com.sun.star.reflection.CoreReflection
|
||||
Dim vClass as Variant ' com.sun.star.reflection.XIdlClass
|
||||
Dim sObjectType As String ' Return value
|
||||
Const cstThisSub = "Session.UnoObjectType"
|
||||
Const cstSubArgs = "UnoObject"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Check:
|
||||
sObjectType = ""
|
||||
If VarType(UnoObject) <> V_OBJECT Then GoTo Finally
|
||||
If IsNull(UnoObject) Then GoTo Finally
|
||||
|
||||
Try:
|
||||
On Local Error Resume Next
|
||||
' Try usual ImplementationName method
|
||||
sObjectType = UnoObject.getImplementationName()
|
||||
If sObjectType = "" Then
|
||||
' Now try CoreReflection trick
|
||||
Set oService = SF_Utils._GetUNOService("CoreReflection")
|
||||
vClass = oService.getType(UnoObject)
|
||||
If vClass.TypeClass >= com.sun.star.uno.TypeClass.STRUCT Then sObjectType = vClass.Name
|
||||
End If
|
||||
|
||||
Finally:
|
||||
UnoObjectType = sObjectType
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Session.UnoObjectType
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function UnoProperties(Optional ByRef UnoObject As Variant) As Variant
|
||||
''' Returns a list of the properties of an UNO object
|
||||
''' Code-snippet derived from XRAY
|
||||
''' Args:
|
||||
''' UnoObject: the object to identify
|
||||
''' Returns:
|
||||
''' A zero-based sorted array. May be empty
|
||||
|
||||
Dim oIntrospect As Object ' com.sun.star.beans.Introspection
|
||||
Dim oInspect As Object ' com.sun.star.beans.XIntrospectionAccess
|
||||
Dim vProperties As Variant ' Array of com.sun.star.beans.Property
|
||||
Dim vProperty As Object ' com.sun.star.beans.Property
|
||||
Dim lMax As Long ' UBounf of vProperties
|
||||
Dim vPropertiesList As Variant ' Return value
|
||||
Dim i As Long
|
||||
Const cstThisSub = "Session.UnoProperties"
|
||||
Const cstSubArgs = "UnoObject"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Check:
|
||||
vPropertiesList = Array()
|
||||
If VarType(UnoObject) <> V_OBJECT Then GoTo Finally
|
||||
If IsNull(UnoObject) Then GoTo Finally
|
||||
|
||||
Try:
|
||||
On Local Error GoTo Catch
|
||||
Set oIntrospect = SF_Utils._GetUNOService("Introspection")
|
||||
Set oInspect = oIntrospect.inspect(UnoObject)
|
||||
vProperties = oInspect.getProperties(com.sun.star.beans.PropertyConcept.ALL)
|
||||
|
||||
' The names must be extracted from com.sun.star.beans.Property structures
|
||||
lMax = UBound(vProperties)
|
||||
If lMax >= 0 Then
|
||||
ReDim vPropertiesList(0 To lMax)
|
||||
For i = 0 To lMax
|
||||
vPropertiesList(i) = vProperties(i).Name
|
||||
Next i
|
||||
vPropertiesList = SF_Array.Sort(vPropertiesList, CaseSensitive := True)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
UnoProperties = vPropertiesList
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
On Local Error GoTo 0
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.UnoProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function WebService(Optional ByVal URI As Variant) As String
|
||||
''' Get some web content from a URI
|
||||
''' Args:
|
||||
''' URI: URI text of the web service
|
||||
''' Returns:
|
||||
''' The web page content of the URI
|
||||
''' Exceptions:
|
||||
''' CALCFUNCERROR
|
||||
''' Examples:
|
||||
''' session.WebService("wiki.documentfoundation.org/api.php?" _
|
||||
''' & "hidebots=1&days=7&limit=50&action=feedrecentchanges&feedformat=rss")
|
||||
|
||||
Dim sReturn As String ' Returned value
|
||||
Const cstThisSub = "Session.WebService"
|
||||
Const cstSubArgs = "URI"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
sReturn = ""
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(URI, "URI", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
sReturn = SF_Session.ExecuteCalcFunction("WEBSERVICE", URI)
|
||||
|
||||
Finally:
|
||||
WebService = sReturn
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session.WebService
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _GetScript(ByVal psLanguage As String _
|
||||
, ByVal psScope As String _
|
||||
, ByVal psScript As String _
|
||||
) As Object
|
||||
''' Get the adequate script provider and from there the requested script
|
||||
''' Called by ExecuteBasicScript() and ExecutePythonScript()
|
||||
''' The execution of the script is done by the caller
|
||||
''' Args:
|
||||
''' psLanguage: Basic or Python
|
||||
''' psScope: one of the SCRIPTISxxx constants
|
||||
''' The SCRIPTISOXT constant is an alias for 2 cases, extension either
|
||||
''' installed for one user only, or for all users
|
||||
''' Managed here by trial and error
|
||||
''' psScript: Read https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification
|
||||
''' Returns:
|
||||
''' A com.sun.star.script.provider.XScript object
|
||||
|
||||
Dim sScript As String ' The complete script string
|
||||
Dim oScriptProvider As Object ' Script provider singleton
|
||||
Dim oScript As Object ' Return value
|
||||
Const cstScript1 = "vnd.sun.star.script:"
|
||||
Const cstScript2 = "?language="
|
||||
Const cstScript3 = "&location="
|
||||
|
||||
Try:
|
||||
' Build script string
|
||||
sScript = cstScript1 & psScript & cstScript2 & psLanguage & cstScript3 & LCase(psScope)
|
||||
|
||||
' Find script
|
||||
Set oScript = Nothing
|
||||
' Python only: installation of extension is determined by user => unknown to script author
|
||||
If psScope = SCRIPTISOXT Then ' => Trial and error
|
||||
On Local Error GoTo ForAllUsers
|
||||
sScript = cstScript1 & psScript & cstScript2 & psLanguage & cstScript3 & SCRIPTISPERSOXT
|
||||
Set oScriptProvider = SF_Utils._GetUNOService("ScriptProvider", SCRIPTISPERSOXT)
|
||||
Set oScript = oScriptProvider.getScript(sScript)
|
||||
End If
|
||||
ForAllUsers:
|
||||
On Local Error GoTo CatchNotFound
|
||||
If IsNull(oScript) Then
|
||||
If psScope = SCRIPTISOXT Then psScope = SCRIPTISSHAROXT
|
||||
Set oScriptProvider = SF_Utils._GetUNOService("ScriptProvider", psScope)
|
||||
Set oScript = oScriptProvider.getScript(sScript)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
_GetScript = oScript
|
||||
Exit Function
|
||||
CatchNotFound:
|
||||
SF_Exception.RaiseFatal(NOSCRIPTERROR, psLanguage, "Scope", psScope, "Script", psScript)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Session._GetScript
|
||||
|
||||
REM =============================================== END OF SCRIPTFORGE.SF_SESSION
|
||||
</script:module>
|
||||
2642
server/windows-office/share/basic/ScriptForge/SF_String.xba
Normal file
2642
server/windows-office/share/basic/ScriptForge/SF_String.xba
Normal file
File diff suppressed because it is too large
Load Diff
701
server/windows-office/share/basic/ScriptForge/SF_TextStream.xba
Normal file
701
server/windows-office/share/basic/ScriptForge/SF_TextStream.xba
Normal file
@@ -0,0 +1,701 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_TextStream" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_TextStream
|
||||
''' =============
|
||||
''' Class instantiated by the
|
||||
''' SF_FileSystem.CreateTextFile
|
||||
''' SF_FileSystem.OpenTextFile
|
||||
''' methods to facilitate the sequential processing of text files
|
||||
''' All open/read/write/close operations are presumed to happen during the same macro run
|
||||
''' The encoding to be used may be chosen by the user
|
||||
''' The list is in the Name column of https://www.iana.org/assignments/character-sets/character-sets.xhtml
|
||||
''' Note that probably not all values are available
|
||||
''' Line delimiters may be chosen by the user
|
||||
''' In input, CR, LF or CR+LF are supported
|
||||
''' In output, the default value is the usual newline on the actual operating system (see SF_FileSystem.sfNEWLINE)
|
||||
'''
|
||||
''' The design choices are largely inspired by
|
||||
''' https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/textstream-object
|
||||
''' The implementation is mainly based on the XTextInputStream and XTextOutputStream UNO interfaces
|
||||
''' https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1io_1_1XTextInputStream.html
|
||||
''' https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1io_1_1XTextOutputStream.html
|
||||
'''
|
||||
''' Instantiation example:
|
||||
''' Dim FSO As Object, myFile As Object
|
||||
''' Set FSO = CreateScriptService("FileSystem")
|
||||
''' Set myFile = FSO.OpenTextFile("C:\Temp\ThisFile.txt", FSO.ForReading) ' Once per file
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Const FILENOTOPENERROR = "FILENOTOPENERROR" ' The file is already closed
|
||||
Const FILEOPENMODEERROR = "FILEOPENMODEERROR" ' The file is open in incompatible mode
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private ObjectType As String ' Must be TEXTSTREAM
|
||||
Private ServiceName As String
|
||||
Private _FileName As String ' File where it is about
|
||||
Private _IOMode As Integer ' ForReading, ForWriting or ForAppending
|
||||
Private _Encoding As String ' https://www.iana.org/assignments/character-sets/character-sets.xhtml
|
||||
Private _NewLine As String ' Line break in write mode
|
||||
Private _FileExists As Boolean ' True if file exists before open
|
||||
Private _LineNumber As Long ' Number of lines read or written
|
||||
Private _FileHandler As Object ' com.sun.star.io.XInputStream or
|
||||
' com.sun.star.io.XOutputStream or
|
||||
' com.sun.star.io.XStream
|
||||
Private _InputStream As Object ' com.sun.star.io.TextInputStream
|
||||
Private _OutputStream As Object ' com.sun.star.io.TextOutputStream
|
||||
Private _ForceBlankLine As Boolean ' Workaround: XTextInputStream misses last line if file ends with newline
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "TEXTSTREAM"
|
||||
ServiceName = "ScriptForge.TextStream"
|
||||
_FileName = ""
|
||||
_IOMode = -1
|
||||
_Encoding = ""
|
||||
_NewLine = ""
|
||||
_FileExists = False
|
||||
_LineNumber = 0
|
||||
Set _FileHandler = Nothing
|
||||
Set _InputStream = Nothing
|
||||
Set _OutputStream = Nothing
|
||||
_ForceBlankLine = False
|
||||
End Sub ' ScriptForge.SF_TextStream Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' ScriptForge.SF_TextStream Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_TextStream Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get AtEndOfStream() As Boolean
|
||||
''' In reading mode, True indicates that the end of the file has been reached
|
||||
''' In write and append modes, or if the file is not ready => always True
|
||||
''' The property should be invoked BEFORE each ReadLine() method:
|
||||
''' A ReadLine() executed while AtEndOfStream is True will raise an error
|
||||
''' Example:
|
||||
''' Dim sLine As String
|
||||
''' Do While Not myFile.AtEndOfStream
|
||||
''' sLine = myFile.ReadLine()
|
||||
''' ' ...
|
||||
''' Loop
|
||||
|
||||
AtEndOfStream = _PropertyGet("AtEndOfStream")
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.AtEndOfStream
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Encoding() As String
|
||||
''' Returns the name of the text file either in url or in native operating system format
|
||||
''' Example:
|
||||
''' Dim myFile As Object
|
||||
''' FSO.FileNaming = "SYS"
|
||||
''' Set myFile = FSO.OpenTextFile("C:\Temp\myFile.txt")
|
||||
''' MsgBox myFile.Encoding ' UTF-8
|
||||
|
||||
Encoding = _PropertyGet("Encoding")
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.Encoding
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get FileName() As String
|
||||
''' Returns the name of the text file either in url or in native operating system format
|
||||
''' Example:
|
||||
''' Dim myFile As Object
|
||||
''' FSO.FileNaming = "SYS"
|
||||
''' Set myFile = FSO.OpenTextFile("C:\Temp\myFile.txt")
|
||||
''' MsgBox myFile.FileName ' C:\Temp\myFile.txt
|
||||
|
||||
FileName = _PropertyGet("FileName")
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.FileName
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IOMode() As String
|
||||
''' Returns either "READ", "WRITE" or "APPEND"
|
||||
''' Example:
|
||||
''' Dim myFile As Object
|
||||
''' FSO.FileNaming = "SYS"
|
||||
''' Set myFile = FSO.OpenTextFile("C:\Temp\myFile.txt")
|
||||
''' MsgBox myFile.IOMode ' READ
|
||||
|
||||
IOMode = _PropertyGet("IOMode")
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.IOMode
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Line() As Long
|
||||
''' Returns the number of lines read or written so far
|
||||
''' Example:
|
||||
''' Dim myFile As Object
|
||||
''' FSO.FileNaming = "SYS"
|
||||
''' Set myFile = FSO.OpenTextFile("C:\Temp\myFile.txt", FSO.ForAppending)
|
||||
''' MsgBox myFile.Line ' The number of lines already present in myFile
|
||||
|
||||
Line = _PropertyGet("Line")
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.Line
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get NewLine() As Variant
|
||||
''' Returns the current character string to be inserted between 2 successive written lines
|
||||
''' The default value is the native line separator in the current operating system
|
||||
''' Example:
|
||||
''' MsgBox myFile.NewLine
|
||||
|
||||
NewLine = _PropertyGet("NewLine")
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.NewLine (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let NewLine(ByVal pvLineBreak As Variant)
|
||||
''' Sets the current character string to be inserted between 2 successive written lines
|
||||
''' Example:
|
||||
''' myFile.NewLine = Chr(13) & Chr(10)
|
||||
|
||||
Const cstThisSub = "TextStream.setNewLine"
|
||||
|
||||
SF_Utils._EnterFunction(cstThisSub)
|
||||
If VarType(pvLineBreak) = V_STRING Then _NewLine = pvLineBreak
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
|
||||
End Property ' ScriptForge.SF_TextStream.NewLine (let)
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function CloseFile() As Boolean
|
||||
''' Empties the output buffer if relevant. Closes the actual input or output stream
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' True if the closure was successful
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR Nothing found to close
|
||||
''' Examples:
|
||||
''' myFile.CloseFile()
|
||||
|
||||
Dim bClose As Boolean ' Return value
|
||||
Const cstThisSub = "TextStream.CloseFile"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bClose = False
|
||||
|
||||
Check:
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
If Not _IsFileOpen() Then GoTo Finally
|
||||
|
||||
Try:
|
||||
If Not IsNull(_InputStream) Then _InputStream.closeInput()
|
||||
If Not IsNull(_OutputStream) Then
|
||||
_OutputStream.flush()
|
||||
_OutputStream.closeOutput()
|
||||
End If
|
||||
Set _InputStream = Nothing
|
||||
Set _OutputStream = Nothing
|
||||
Set _FileHandler = Nothing
|
||||
bClose = True
|
||||
|
||||
Finally:
|
||||
CloseFile = bClose
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_TextStream.CloseFile
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' If the property does not exist, returns Null
|
||||
''' Exceptions:
|
||||
''' see the exceptions of the individual properties
|
||||
''' Examples:
|
||||
''' myModel.GetProperty("MyProperty")
|
||||
|
||||
Const cstThisSub = "TextStream.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_TextStream.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Model service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"CloseFile" _
|
||||
, "ReadAll" _
|
||||
, "readLine" _
|
||||
, "SkipLine" _
|
||||
, "WriteBlankLines" _
|
||||
, "WriteLine" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_TextStream.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Timer class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"AtEndOfStream" _
|
||||
, "Encoding" _
|
||||
, "FileName" _
|
||||
, "IOMode" _
|
||||
, "Line" _
|
||||
, "NewLine" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_TextStream.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ReadAll() As String
|
||||
''' Returns all the remaining lines in the text stream as one string. Line breaks are NOT removed
|
||||
''' The resulting string can be split in lines
|
||||
''' either by using the usual Split Basic builtin function if the line delimiter is known
|
||||
''' or with the SF_String.SplitLines method
|
||||
''' For large files, using the ReadAll method wastes memory resources.
|
||||
''' Other techniques should be used to input a file, such as reading a file line-by-line
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' The read lines. The string may be empty.
|
||||
''' Note that the Line property in incremented only by 1
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR File not open or already closed
|
||||
''' FILEOPENMODEERROR File opened in write or append modes
|
||||
''' ENDOFFILEERROR Previous reads already reached the end of the file
|
||||
''' Examples:
|
||||
''' Dim a As String
|
||||
''' a = myFile.ReadAll()
|
||||
|
||||
Dim sRead As String ' Return value
|
||||
Const cstThisSub = "TextStream.ReadAll"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
sRead = ""
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsFileOpen("READ") Then GoTo Finally
|
||||
If _InputStream.isEOF() Then GoTo CatchEOF
|
||||
End If
|
||||
|
||||
Try:
|
||||
sRead = _InputStream.readString(Array(), False)
|
||||
_LineNumber = _LineNumber + 1
|
||||
|
||||
Finally:
|
||||
ReadAll = sRead
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchEOF:
|
||||
'TODO: SF_Exception.RaiseFatal(FILEWRITEMODEERROR, cstThisSub)
|
||||
MsgBox "END OF FILE ERROR !!"
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_TextStream.ReadAll
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ReadLine() As String
|
||||
''' Returns the next line in the text stream as a string. Line breaks are removed.
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' The read line. The string may be empty.
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR File not open or already closed
|
||||
''' FILEOPENMODEERROR File opened in write or append modes
|
||||
''' ENDOFFILEERROR Previous reads already reached the end of the file
|
||||
''' Examples:
|
||||
''' Dim a As String
|
||||
''' a = myFile.ReadLine()
|
||||
|
||||
Dim sRead As String ' Return value
|
||||
Dim iRead As Integer ' Length of line break
|
||||
Const cstThisSub = "TextStream.ReadLine"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
sRead = ""
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsFileOpen("READ") Then GoTo Finally
|
||||
If AtEndOfStream Then GoTo CatchEOF
|
||||
End If
|
||||
|
||||
Try:
|
||||
' When the text file ends with a line break,
|
||||
' XTextInputStream.readLine() returns the line break together with the last line
|
||||
' Hence the workaround to force a blank line at the end
|
||||
If _ForceBlankLine Then
|
||||
sRead = ""
|
||||
_ForceBlankLine = False
|
||||
Else
|
||||
sRead = _InputStream.readLine()
|
||||
' The isEOF() is set immediately after having read the last line
|
||||
If _InputStream.isEOF() And Len(sRead) > 0 Then
|
||||
iRead = 0
|
||||
If SF_String.EndsWith(sRead, SF_String.sfCRLF) Then
|
||||
iRead = 2
|
||||
ElseIf SF_String.EndsWith(sRead, SF_String.sfLF) Or SF_String.EndsWith(sRead, SF_String.sfCR) Then
|
||||
iRead = 1
|
||||
End If
|
||||
If iRead > 0 Then
|
||||
sRead = Left(sRead, Len(sRead) - iRead)
|
||||
_ForceBlankLine = True ' Provision for a last empty line at the next read loop
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
_LineNumber = _LineNumber + 1
|
||||
|
||||
Finally:
|
||||
ReadLine = sRead
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchEOF:
|
||||
'TODO: SF_Exception.RaiseFatal(FILEWRITEMODEERROR, cstThisSub)
|
||||
MsgBox "END OF FILE ERROR !!"
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_TextStream.ReadLine
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Dim bSet As Boolean ' Return value
|
||||
Const cstThisSub = "TextStream.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bSet = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
bSet = True
|
||||
Select Case UCase(PropertyName)
|
||||
Case "NEWLINE"
|
||||
If Not SF_Utils._Validate(Value, "Value", V_STRING) Then GoTo Catch
|
||||
NewLine = Value
|
||||
Case Else
|
||||
bSet = False
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SetProperty = bSet
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_TextStream.SetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub SkipLine()
|
||||
''' Skips the next line when reading a TextStream file.
|
||||
''' Args:
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR File not open or already closed
|
||||
''' FILEOPENMODEERROR File opened in write or append modes
|
||||
''' ENDOFFILEERROR Previous reads already reached the end of the file
|
||||
''' Examples:
|
||||
''' myFile.SkipLine()
|
||||
|
||||
Dim sRead As String ' Read buffer
|
||||
Const cstThisSub = "TextStream.SkipLine"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsFileOpen("READ") Then GoTo Finally
|
||||
If Not _ForceBlankLine Then ' The file ends with a newline => return one empty line more
|
||||
If _InputStream.isEOF() Then GoTo CatchEOF
|
||||
End If
|
||||
End If
|
||||
|
||||
Try:
|
||||
sRead = ReadLine()
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchEOF:
|
||||
'TODO: SF_Exception.RaiseFatal(FILEWRITEMODEERROR, cstThisSub)
|
||||
MsfBox "END OF FILE ERROR !!"
|
||||
GoTo Finally
|
||||
End Sub ' ScriptForge.SF_TextStream.SkipLine
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub WriteBlankLines(Optional ByVal Lines As Variant)
|
||||
''' Writes a number of empty lines in the output stream
|
||||
''' Args:
|
||||
''' Lines: the number of lines to write
|
||||
''' Returns:
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR File not open or already closed
|
||||
''' FILEOPENMODEERROR File opened in in read mode
|
||||
''' Examples:
|
||||
''' myFile.WriteBlankLines(10)
|
||||
Dim i As Long
|
||||
Const cstThisSub = "TextStream.WriteBlankLines"
|
||||
Const cstSubArgs = "Lines"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsFileOpen("WRITE") Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Lines, "Lines", V_NUMERIC) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
For i = 1 To Lines
|
||||
_OutputStream.writeString(_NewLine)
|
||||
Next i
|
||||
_LineNumber = _LineNumber + Lines
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Sub ' ScriptForge.SF_TextStream.WriteBlankLines
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub WriteLine(Optional ByVal Line As Variant)
|
||||
''' Writes the given line to the output stream. A newline is inserted if relevant
|
||||
''' Args:
|
||||
''' Line: the line to write, may be empty
|
||||
''' Returns:
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR File not open or already closed
|
||||
''' FILEOPENMODEERROR File opened in in read mode
|
||||
''' Examples:
|
||||
''' myFile.WriteLine("Next line")
|
||||
Dim i As Long
|
||||
Const cstThisSub = "TextStream.WriteLine"
|
||||
Const cstSubArgs = "Line"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsFileOpen("WRITE") Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Line, "Line", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
_OutputStream.writeString(Iif(_LineNumber > 0, _NewLine, "") & Line)
|
||||
_LineNumber = _LineNumber + 1
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Sub ' ScriptForge.SF_TextStream.WriteLine
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _Initialize()
|
||||
''' Opens file and setup input and/or output streams (ForAppending requires both)
|
||||
|
||||
Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess
|
||||
|
||||
' Default newline related to current operating system
|
||||
_NewLine = SF_String.sfNEWLINE
|
||||
|
||||
Set oSfa = SF_Utils._GetUNOService("FileAccess")
|
||||
|
||||
' Setup input and/or output streams based on READ/WRITE/APPEND IO modes
|
||||
Select Case _IOMode
|
||||
Case SF_FileSystem.ForReading
|
||||
Set _FileHandler = oSfa.openFileRead(_FileName)
|
||||
Set _InputStream = CreateUnoService("com.sun.star.io.TextInputStream")
|
||||
_InputStream.setInputStream(_FileHandler)
|
||||
Case SF_FileSystem.ForWriting
|
||||
' Output file is deleted beforehand
|
||||
If _FileExists Then oSfa.kill(_FileName)
|
||||
Set _FileHandler = oSfa.openFileWrite(_FileName)
|
||||
Set _OutputStream = CreateUnoService("com.sun.star.io.TextOutputStream")
|
||||
_OutputStream.setOutputStream(_FileHandler)
|
||||
Case SF_FileSystem.ForAppending
|
||||
Set _FileHandler = oSfa.openFileReadWrite(_FileName)
|
||||
Set _InputStream = CreateUnoService("com.sun.star.io.TextInputStream")
|
||||
Set _OutputStream = CreateUnoService("com.sun.star.io.TextOutputStream")
|
||||
_InputStream.setInputStream(_FileHandler)
|
||||
' Position at end of file: Skip and count existing lines
|
||||
_LineNumber = 0
|
||||
Do While Not _InputStream.isEOF()
|
||||
_InputStream.readLine()
|
||||
_LineNumber = _LineNumber + 1
|
||||
Loop
|
||||
_OutputStream.setOutputStream(_FileHandler)
|
||||
End Select
|
||||
|
||||
If _Encoding = "" Then _Encoding = "UTF-8"
|
||||
If Not IsNull(_InputStream) Then _InputStream.setEncoding(_Encoding)
|
||||
If Not IsNull(_OutputStream) Then _OutputStream.setEncoding(_Encoding)
|
||||
|
||||
End Sub ' ScriptForge.SF_TextStream._Initialize
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _IsFileOpen(Optional ByVal psMode As String) As Boolean
|
||||
''' Checks if file is open with the right mode (READ or WRITE)
|
||||
''' Raises an exception if the file is not open at all or not in the right mode
|
||||
''' Args:
|
||||
''' psMode: READ or WRITE or zero-length string
|
||||
''' Exceptions:
|
||||
''' FILENOTOPENERROR File not open or already closed
|
||||
''' FILEOPENMODEERROR File opened in incompatible mode
|
||||
|
||||
_IsFileOpen = False
|
||||
If IsMissing(psMode) Then psMode = ""
|
||||
If IsNull(_InputStream) And IsNull(_OutputStream) Then GoTo CatchNotOpen
|
||||
Select Case psMode
|
||||
Case "READ"
|
||||
If IsNull(_InputStream) Then GoTo CatchOpenMode
|
||||
If _IOMode <> SF_FileSystem.ForReading Then GoTo CatchOpenMode
|
||||
Case "WRITE"
|
||||
If IsNull(_OutputStream) Then GoTo CatchOpenMode
|
||||
If _IOMode = SF_FileSystem.ForReading Then GoTo CatchOpenMode
|
||||
Case Else
|
||||
End Select
|
||||
_IsFileOpen = True
|
||||
|
||||
Finally:
|
||||
Exit Function
|
||||
CatchNotOpen:
|
||||
SF_Exception.RaiseFatal(FILENOTOPENERROR, FileName)
|
||||
GoTo Finally
|
||||
CatchOpenMode:
|
||||
SF_Exception.RaiseFatal(FILEOPENMODEERROR, FileName, IOMode)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_TextStream._IsFileOpen
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String)
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim cstThisSub As String
|
||||
Dim cstSubArgs As String
|
||||
|
||||
cstThisSub = "TextStream.get" & psProperty
|
||||
cstSubArgs = ""
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("AtEndOfStream")
|
||||
Select Case _IOMode
|
||||
Case SF_FileSystem.ForReading
|
||||
If IsNull(_InputStream) Then _PropertyGet = True Else _PropertyGet = _InputStream.isEOF() And Not _ForceBlankLine
|
||||
Case Else : _PropertyGet = True
|
||||
End Select
|
||||
Case UCase("Encoding")
|
||||
_PropertyGet = _Encoding
|
||||
Case UCase("FileName")
|
||||
_PropertyGet = SF_FileSystem._ConvertFromUrl(_FileName) ' Depends on FileNaming
|
||||
Case UCase("IOMode")
|
||||
With SF_FileSystem
|
||||
Select Case _IOMode
|
||||
Case .ForReading : _PropertyGet = "READ"
|
||||
Case .ForWriting : _PropertyGet = "WRITE"
|
||||
Case .ForAppending : _PropertyGet = "APPEND"
|
||||
Case Else : _PropertyGet = ""
|
||||
End Select
|
||||
End With
|
||||
Case UCase("Line")
|
||||
_PropertyGet = _LineNumber
|
||||
Case UCase("NewLine")
|
||||
_PropertyGet = _NewLine
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_TextStream._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the TextStream instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[TextStream]: File name, IOMode, LineNumber"
|
||||
|
||||
_Repr = "[TextStream]: " & FileName & "," & IOMode & "," & CStr(Line)
|
||||
|
||||
End Function ' ScriptForge.SF_TextStream._Repr
|
||||
|
||||
REM ============================================ END OF SCRIPTFORGE.SF_TextStream
|
||||
</script:module>
|
||||
463
server/windows-office/share/basic/ScriptForge/SF_Timer.xba
Normal file
463
server/windows-office/share/basic/ScriptForge/SF_Timer.xba
Normal file
@@ -0,0 +1,463 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Timer" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Timer
|
||||
''' ========
|
||||
''' Class for management of scripts execution performance
|
||||
''' A Timer measures durations. It can be suspended, resumed, restarted
|
||||
''' Duration properties are expressed in seconds with a precision of 3 decimal digits
|
||||
'''
|
||||
''' Service invocation example:
|
||||
''' Dim myTimer As Variant
|
||||
''' myTimer = CreateScriptService("Timer")
|
||||
''' myTimer = CreateScriptService("Timer", True) ' => To start timer immediately
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private ObjectType As String ' Must be "TIMER"
|
||||
Private ServiceName As String
|
||||
Private _TimerStatus As Integer ' inactive, started, suspended or stopped
|
||||
Private _StartTime As Double ' Moment when timer started, restarted
|
||||
Private _EndTime As Double ' Moment when timer stopped
|
||||
Private _SuspendTime As Double ' Moment when timer suspended
|
||||
Private _SuspendDuration As Double ' Duration of suspended status as a difference of times
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
Private Const STATUSINACTIVE = 0
|
||||
Private Const STATUSSTARTED = 1
|
||||
Private Const STATUSSUSPENDED = 2
|
||||
Private Const STATUSSTOPPED = 3
|
||||
|
||||
Private Const DSECOND As Double = 1 / (24 * 60 * 60) ' Duration of 1 second as compared to 1.0 = 1 day
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "TIMER"
|
||||
ServiceName = "ScriptForge.Timer"
|
||||
_TimerStatus = STATUSINACTIVE
|
||||
_StartTime = 0
|
||||
_EndTime = 0
|
||||
_SuspendTime = 0
|
||||
_SuspendDuration = 0
|
||||
End Sub ' ScriptForge.SF_Timer Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' ScriptForge.SF_Timer Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_Timer Explicit destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Duration() As Double
|
||||
''' Returns the actual (out of suspensions) time elapsed since start or between start and stop
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' A Double expressing the duration in seconds
|
||||
''' Example:
|
||||
''' myTimer.Duration returns 1.234 (1 sec, 234 ms)
|
||||
|
||||
Duration = _PropertyGet("Duration")
|
||||
|
||||
End Function ' ScriptForge.SF_Timer.Duration
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsStarted() As Boolean
|
||||
''' Returns True if timer is started or suspended
|
||||
''' Example:
|
||||
''' myTimer.IsStarted
|
||||
|
||||
IsStarted = _PropertyGet("IsStarted")
|
||||
|
||||
End Property ' ScriptForge.SF_Timer.IsStarted
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsSuspended() As Boolean
|
||||
''' Returns True if timer is started and suspended
|
||||
''' Example:
|
||||
''' myTimer.IsSuspended
|
||||
|
||||
IsSuspended = _PropertyGet("IsSuspended")
|
||||
|
||||
End Property ' ScriptForge.SF_Timer.IsSuspended
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SuspendDuration() As Double
|
||||
''' Returns the actual time elapsed while suspended since start or between start and stop
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' A Double expressing the duration in seconds
|
||||
''' Example:
|
||||
''' myTimer.SuspendDuration returns 1.234 (1 sec, 234 ms)
|
||||
|
||||
SuspendDuration = _PropertyGet("SuspendDuration")
|
||||
|
||||
End Function ' ScriptForge.SF_Timer.SuspendDuration
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function TotalDuration() As Double
|
||||
''' Returns the actual time elapsed (including suspensions) since start or between start and stop
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' A Double expressing the duration in seconds
|
||||
''' Example:
|
||||
''' myTimer.TotalDuration returns 1.234 (1 sec, 234 ms)
|
||||
|
||||
TotalDuration = _PropertyGet("TotalDuration")
|
||||
|
||||
End Function ' ScriptForge.SF_Timer.TotalDuration
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Continue() As Boolean
|
||||
''' Halt suspension of a running timer
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' True if successful, False if the timer is not suspended
|
||||
''' Examples:
|
||||
''' myTimer.Continue()
|
||||
|
||||
Const cstThisSub = "Timer.Continue"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
Check:
|
||||
Continue = False
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
If _TimerStatus = STATUSSUSPENDED Then
|
||||
_TimerStatus = STATUSSTARTED
|
||||
_SuspendDuration = _SuspendDuration + _Now() - _SuspendTime
|
||||
_SuspendTime = 0
|
||||
Continue = True
|
||||
End If
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Timer.Continue
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
''' Examples:
|
||||
''' myTimer.GetProperty("Duration")
|
||||
|
||||
Const cstThisSub = "Timer.GetProperty"
|
||||
Const cstSubArgs = "PropertyName"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Timer.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list or methods of the Timer class as an array
|
||||
|
||||
Methods = Array( _
|
||||
"Continue" _
|
||||
, "Restart" _
|
||||
, "Start" _
|
||||
, "Suspend" _
|
||||
, "Terminate" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Timer.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Timer class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"Duration" _
|
||||
, "IsStarted" _
|
||||
, "IsSuspended" _
|
||||
, "SuspendDuration" _
|
||||
, "TotalDuration" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Timer.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Restart() As Boolean
|
||||
''' Terminate the timer and restart a new clean timer
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' True if successful, False if the timer is inactive
|
||||
''' Examples:
|
||||
''' myTimer.Restart()
|
||||
|
||||
Const cstThisSub = "Timer.Restart"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
Check:
|
||||
Restart = False
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
If _TimerStatus <> STATUSINACTIVE Then
|
||||
If _TimerStatus <> STATUSSTOPPED Then Terminate()
|
||||
Start()
|
||||
Restart = True
|
||||
End If
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Timer.Restart
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "Timer.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
SetProperty = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Timer.SetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Start() As Boolean
|
||||
''' Start a new clean timer
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' True if successful, False if the timer is already started
|
||||
''' Examples:
|
||||
''' myTimer.Start()
|
||||
|
||||
Const cstThisSub = "Timer.Start"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
Check:
|
||||
Start = False
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
If _TimerStatus = STATUSINACTIVE Or _TimerStatus = STATUSSTOPPED Then
|
||||
_TimerStatus = STATUSSTARTED
|
||||
_StartTime = _Now()
|
||||
_EndTime = 0
|
||||
_SuspendTime = 0
|
||||
_SuspendDuration = 0
|
||||
Start = True
|
||||
End If
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Timer.Start
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Suspend() As Boolean
|
||||
''' Suspend a running timer
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' True if successful, False if the timer is not started or already suspended
|
||||
''' Examples:
|
||||
''' myTimer.Suspend()
|
||||
|
||||
Const cstThisSub = "Timer.Suspend"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
Check:
|
||||
Suspend = False
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
If _TimerStatus = STATUSSTARTED Then
|
||||
_TimerStatus = STATUSSUSPENDED
|
||||
_SuspendTime = _Now()
|
||||
Suspend = True
|
||||
End If
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Timer.Suspend
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Terminate() As Boolean
|
||||
''' Terminate a running timer
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' True if successful, False if the timer is neither started nor suspended
|
||||
''' Examples:
|
||||
''' myTimer.Terminate()
|
||||
|
||||
Const cstThisSub = "Timer.Terminate"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
Check:
|
||||
Terminate = False
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Try:
|
||||
If _TimerStatus = STATUSSTARTED Or _TimerStatus = STATUSSUSPENDED Then
|
||||
If _TimerSTatus = STATUSSUSPENDED Then Continue()
|
||||
_TimerStatus = STATUSSTOPPED
|
||||
_EndTime = _Now()
|
||||
Terminate = True
|
||||
End If
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Timer.Terminate
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Now() As Double
|
||||
''' Returns the current date and time
|
||||
''' Uses the Calc NOW() function to get a higher precision than the usual Basic Now() function
|
||||
''' Args:
|
||||
''' Returns:
|
||||
''' The actual time as a number
|
||||
''' The integer part represents the date, the decimal part represents the time
|
||||
|
||||
_Now = SF_Session.ExecuteCalcFunction("NOW")
|
||||
|
||||
End Function ' ScriptForge.SF_Timer._Now
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String)
|
||||
''' Return the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim dDuration As Double ' Computed duration
|
||||
Dim cstThisSub As String
|
||||
Dim cstSubArgs As String
|
||||
|
||||
cstThisSub = "Timer.get" & psProperty
|
||||
cstSubArgs = ""
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("Duration")
|
||||
Select Case _TimerStatus
|
||||
Case STATUSINACTIVE : dDuration = 0.0
|
||||
Case STATUSSTARTED
|
||||
dDuration = _Now() - _StartTime - _SuspendDuration
|
||||
Case STATUSSUSPENDED
|
||||
dDuration = _SuspendTime - _StartTime - _SuspendDuration
|
||||
Case STATUSSTOPPED
|
||||
dDuration = _EndTime - _StartTime - _SuspendDuration
|
||||
End Select
|
||||
_PropertyGet = Fix(dDuration * 1000 / DSECOND) / 1000
|
||||
Case UCase("IsStarted")
|
||||
_PropertyGet = ( _TimerStatus = STATUSSTARTED Or _TimerStatus = STATUSSUSPENDED )
|
||||
Case UCase("IsSuspended")
|
||||
_PropertyGet = ( _TimerStatus = STATUSSUSPENDED )
|
||||
Case UCase("SuspendDuration")
|
||||
Select Case _TimerStatus
|
||||
Case STATUSINACTIVE : dDuration = 0.0
|
||||
Case STATUSSTARTED, STATUSSTOPPED
|
||||
dDuration = _SuspendDuration
|
||||
Case STATUSSUSPENDED
|
||||
dDuration = _Now() - _SuspendTime + _SuspendDuration
|
||||
End Select
|
||||
_PropertyGet = Fix(dDuration * 1000 / DSECOND) / 1000
|
||||
Case UCase("TotalDuration")
|
||||
Select Case _TimerStatus
|
||||
Case STATUSINACTIVE : dDuration = 0.0
|
||||
Case STATUSSTARTED, STATUSSUSPENDED
|
||||
dDuration = _Now() - _StartTime
|
||||
Case STATUSSTOPPED
|
||||
dDuration = _EndTime - _StartTime
|
||||
End Select
|
||||
_PropertyGet = Fix(dDuration * 1000 / DSECOND) / 1000
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Timer._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the Timer instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[Timer] Duration:xxx.yyy
|
||||
|
||||
Const cstTimer = "[Timer] Duration: "
|
||||
Const cstMaxLength = 50 ' Maximum length for items
|
||||
|
||||
_Repr = cstTimer & Replace(SF_Utils._Repr(Duration), ".", """")
|
||||
|
||||
End Function ' ScriptForge.SF_Timer._Repr
|
||||
|
||||
REM ============================================ END OF SCRIPTFORGE.SF_TIMER
|
||||
</script:module>
|
||||
1175
server/windows-office/share/basic/ScriptForge/SF_UI.xba
Normal file
1175
server/windows-office/share/basic/ScriptForge/SF_UI.xba
Normal file
File diff suppressed because it is too large
Load Diff
967
server/windows-office/share/basic/ScriptForge/SF_Utils.xba
Normal file
967
server/windows-office/share/basic/ScriptForge/SF_Utils.xba
Normal file
@@ -0,0 +1,967 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Utils" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Explicit
|
||||
Option Private Module
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Utils
|
||||
''' ========
|
||||
''' FOR INTERNAL USE ONLY
|
||||
''' Groups all private functions used by the official modules
|
||||
''' Declares the Global variable _SF_
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ===================================================================== GLOBALS
|
||||
|
||||
Global _SF_ As Variant ' SF_Root (Basic) object)
|
||||
|
||||
''' ScriptForge version
|
||||
Const SF_Version = "7.1"
|
||||
|
||||
''' Standard symbolic names for VarTypes
|
||||
' V_EMPTY = 0
|
||||
' V_NULL = 1
|
||||
' V_INTEGER = 2
|
||||
' V_LONG = 3
|
||||
' V_SINGLE = 4
|
||||
' V_DOUBLE = 5
|
||||
' V_CURRENCY = 6
|
||||
' V_DATE = 7
|
||||
' V_STRING = 8
|
||||
''' Additional symbolic names for VarTypes
|
||||
Global Const V_OBJECT = 9
|
||||
Global Const V_BOOLEAN = 11
|
||||
Global Const V_VARIANT = 12
|
||||
Global Const V_BYTE = 17
|
||||
Global Const V_USHORT = 18
|
||||
Global Const V_ULONG = 19
|
||||
Global Const V_BIGINT = 35
|
||||
Global Const V_DECIMAL = 37
|
||||
Global Const V_ARRAY = 8192
|
||||
Global Const V_NUMERIC = 99 ' Fictive VarType synonym of any numeric value
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Const MISSINGARGERROR = "MISSINGARGERROR" ' A mandatory argument is missing
|
||||
Const ARGUMENTERROR = "ARGUMENTERROR" ' An argument does not pass the _Validate() validation
|
||||
Const ARRAYERROR = "ARRAYERROR" ' An argument does not pass the _ValidateArray() validation
|
||||
Const FILEERROR = "FILEERROR" ' An argument does not pass the _ValidateFile() validation
|
||||
|
||||
REM =========================================pvA==================== PRIVATE METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _CDateToIso(pvDate As Variant) As Variant
|
||||
''' Returns a string representation of the given Basic date
|
||||
''' Dates as strings are essential in property values, where Basic dates are evil
|
||||
|
||||
Dim sIsoDate As Variant ' Return value
|
||||
|
||||
If VarType(pvDate) = V_DATE Then
|
||||
If Year(pvDate) < 1900 Then ' Time only
|
||||
sIsoDate = Right("0" & Hour(pvDate), 2) & ":" & Right("0" & Minute(pvDate), 2) & ":" & Right("0" & Second(pvDate), 2)
|
||||
ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then ' Date only
|
||||
sIsoDate = Year(pvDate) & "-" & Right("0" & Month(pvDate), 2) & "-" & Right("0" & Day(pvDate), 2)
|
||||
Else
|
||||
sIsoDate = Year(pvDate) & "-" & Right("0" & Month(pvDate), 2) & "-" & Right("0" & Day(pvDate), 2) _
|
||||
& " " & Right("0" & Hour(pvDate), 2) & ":" & Right("0" & Minute(pvDate), 2) _
|
||||
& ":" & Right("0" & Second(pvDate), 2)
|
||||
End If
|
||||
Else
|
||||
sIsoDate = pvDate
|
||||
End If
|
||||
|
||||
_CDateToIso = sIsoDate
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._CDateToIso
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _CDateToUnoDate(pvDate As Variant) As Variant
|
||||
''' Returns a UNO com.sun.star.util.DateTime/Date/Time object depending on the given date
|
||||
''' by using the appropriate CDateToUnoDateXxx builtin function
|
||||
''' UNO dates are essential in property values, where Basic dates are evil
|
||||
|
||||
Dim vUnoDate As Variant ' Return value
|
||||
|
||||
If VarType(pvDate) = V_DATE Then
|
||||
If Year(pvDate) < 1900 Then
|
||||
vUnoDate = CDateToUnoTime(pvDate)
|
||||
ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then
|
||||
vUnoDate = CDateToUnoDate(pvDate)
|
||||
Else
|
||||
vUnoDate = CDateToUnoDateTime(pvDate)
|
||||
End If
|
||||
Else
|
||||
vUnoDate = pvDate
|
||||
End If
|
||||
|
||||
_CDateToUnoDate = vUnoDate
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._CDateToUnoDate
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _CPropertyValue(ByRef pvValue As Variant) As Variant
|
||||
''' Set a value of a correct type in a com.sun.star.beans.PropertyValue
|
||||
''' Date BASIC variables give error. Change them to UNO types
|
||||
''' Empty arrays should be replaced by Null
|
||||
|
||||
Dim vValue As Variant ' Return value
|
||||
|
||||
If VarType(pvValue) = V_DATE Then
|
||||
vValue = SF_Utils._CDateToUnoDate(pvValue)
|
||||
ElseIf IsArray(pvValue) Then
|
||||
If UBound(pvValue, 1) < LBound(pvValue, 1) Then vValue = Null Else vValue = pvValue
|
||||
Else
|
||||
vValue = pvValue
|
||||
End If
|
||||
_CPropertyValue() = vValue
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._CPropertyValue
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _CStrToDate(ByRef pvStr As String) As Date
|
||||
''' Attempt to convert the input string to a Date variable with the CDate builtin function
|
||||
''' If not successful, returns conventionally -1 (29/12/1899)
|
||||
''' Date patterns: YYYY-MM-DD, HH:MM:DD and YYYY-MM-DD HH:MM:DD
|
||||
|
||||
Dim dDate As Date ' Return value
|
||||
Const cstNoDate = -1
|
||||
|
||||
dDate = cstNoDate
|
||||
Try:
|
||||
On Local Error Resume Next
|
||||
dDate = CDate(pvStr)
|
||||
|
||||
Finally:
|
||||
_CStrToDate = dDate
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Utils._CStrToDate
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _EnterFunction(ByVal psSub As String, Optional ByVal psArgs As String)
|
||||
''' Called on top of each public function
|
||||
''' Used to trace routine in/outs (debug mode)
|
||||
''' and to allow the explicit mention of the user call which caused an error
|
||||
''' Args:
|
||||
''' psSub = the called Sub/Function/Property, usually something like "service.sub"
|
||||
''' Return: True when psSub is called from a user script
|
||||
''' Used to bypass the validation of the arguments when unnecessary
|
||||
|
||||
If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() ' First use of ScriptForge during current LibO session
|
||||
If IsMissing(psArgs) Then psArgs = ""
|
||||
With _SF_
|
||||
If .StackLevel = 0 Then
|
||||
.MainFunction = psSub
|
||||
.MainFunctionArgs = psArgs
|
||||
_EnterFunction = True
|
||||
Else
|
||||
_EnterFunction = False
|
||||
End If
|
||||
.StackLevel = .StackLevel + 1
|
||||
If .DebugMode Then ._AddToConsole("==> " & psSub & "(" & .StackLevel & ")")
|
||||
End With
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._EnterFunction
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _ErrorHandling(Optional ByVal pbErrorHandler As Boolean) As Boolean
|
||||
''' Error handling is normally ON and can be set OFF for debugging purposes
|
||||
''' Each user visible routine starts with a call to this function to enable/disable
|
||||
''' standard handling of internal errors
|
||||
''' Args:
|
||||
''' pbErrorHandler = if present, set its value
|
||||
''' Return: the current value of the error handler
|
||||
|
||||
If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() ' First use of ScriptForge during current LibO session
|
||||
If Not IsMissing(pbErrorHandler) Then _SF_.ErrorHandler = pbErrorHandler
|
||||
_ErrorHandling = _SF_.ErrorHandler
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._ErrorHandling
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _ExitFunction(ByVal psSub As String)
|
||||
''' Called in the Finally block of each public function
|
||||
''' Manage ScriptForge internal aborts
|
||||
''' Resets MainFunction (root) when exiting the method called by a user script
|
||||
''' Used to trace routine in/outs (debug mode)
|
||||
''' Args:
|
||||
''' psSub = the called Sub/Function/Property, usually something like "service.sub"
|
||||
|
||||
If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() ' Useful only when current module has been recompiled
|
||||
With _SF_
|
||||
If Err > 0 Then
|
||||
SF_Exception.RaiseAbort(psSub)
|
||||
End If
|
||||
If .StackLevel = 1 Then
|
||||
.MainFunction = ""
|
||||
.MainFunctionArgs = ""
|
||||
End If
|
||||
If .DebugMode Then ._AddToConsole("<== " & psSub & "(" & .StackLevel & ")")
|
||||
If .StackLevel > 0 Then .StackLevel = .StackLevel - 1
|
||||
End With
|
||||
|
||||
End Sub ' ScriptForge.SF_Utils._ExitFunction
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _ExportScriptForgePOTFile(ByVal FileName As String)
|
||||
''' Export the ScriptForge POT file related to its own user interface
|
||||
''' Should be called only before issuing new ScriptForge releases only
|
||||
''' Args:
|
||||
''' FileName: the resulting file. If it exists, is overwritten without warning
|
||||
|
||||
Dim sHeader As String ' The specific header to insert
|
||||
|
||||
sHeader = "" _
|
||||
& "*********************************************************************\n" _
|
||||
& "*** The ScriptForge library and its associated libraries ***\n" _
|
||||
& "*** are part of the LibreOffice project. ***\n" _
|
||||
& "*********************************************************************\n" _
|
||||
& "\n" _
|
||||
& "ScriptForge Release " & SF_Version & "\n" _
|
||||
& "-----------------------"
|
||||
|
||||
Try:
|
||||
With _SF_
|
||||
.Interface.ExportToPOTFile(FileName, Header := sHeader)
|
||||
End With
|
||||
|
||||
Finally:
|
||||
Exit Sub
|
||||
End Sub ' ScriptForge.SF_Utils._ExportScriptForgePOTFile
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _GetPropertyValue(ByRef pvArgs As Variant, ByVal psName As String) As Variant
|
||||
''' Returns the Value corresponding to the given name
|
||||
''' Args
|
||||
''' pvArgs: a zero_based array of PropertyValues
|
||||
''' psName: the comparison is not case-sensitive
|
||||
''' Returns:
|
||||
''' Zero-length string if not found
|
||||
|
||||
Dim vValue As Variant ' Return value
|
||||
Dim i As Long
|
||||
|
||||
vValue = ""
|
||||
If IsArray(pvArgs) Then
|
||||
For i = LBound(pvArgs) To UBound(pvArgs)
|
||||
If UCase(psName) = UCase(pvArgs(i).Name) Then
|
||||
vValue = pvArgs(i).Value
|
||||
Exit For
|
||||
End If
|
||||
Next i
|
||||
End If
|
||||
_GetPropertyValue = vValue
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._GetPropertyValue
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _GetRegistryKeyContent(ByVal psKeyName as string _
|
||||
, Optional pbForUpdate as Boolean _
|
||||
) As Variant
|
||||
''' Implement a ConfigurationProvider service
|
||||
''' Derived from the Tools library
|
||||
''' Args:
|
||||
''' psKeyName: the name of the node in the configuration tree
|
||||
''' pbForUpdate: default = False
|
||||
|
||||
Dim oConfigProvider as Object ' com.sun.star.configuration.ConfigurationProvider
|
||||
Dim vNodePath(0) as New com.sun.star.beans.PropertyValue
|
||||
Dim sConfig As String ' One of next 2 constants
|
||||
Const cstConfig = "com.sun.star.configuration.ConfigurationAccess"
|
||||
Const cstConfigUpdate = "com.sun.star.configuration.ConfigurationUpdateAccess"
|
||||
|
||||
Set oConfigProvider = _GetUNOService("ConfigurationProvider")
|
||||
vNodePath(0).Name = "nodepath"
|
||||
vNodePath(0).Value = psKeyName
|
||||
|
||||
If IsMissing(pbForUpdate) Then pbForUpdate = False
|
||||
If pbForUpdate Then sConfig = cstConfigUpdate Else sConfig = cstConfig
|
||||
|
||||
Set _GetRegistryKeyContent = oConfigProvider.createInstanceWithArguments(sConfig, vNodePath())
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._GetRegistryKeyContent
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _GetUNOService(ByVal psService As String _
|
||||
, Optional ByVal pvArg As Variant _
|
||||
) As Object
|
||||
''' Create a UNO service
|
||||
''' Each service is called only once
|
||||
''' Args:
|
||||
''' psService: shortcut to service
|
||||
''' pvArg: some services might require an argument
|
||||
|
||||
Dim sLocale As String ' fr-BE f.i.
|
||||
Dim oConfigProvider As Object
|
||||
Dim oDefaultContext As Object
|
||||
Dim vNodePath As Variant
|
||||
|
||||
Set _GetUNOService = Nothing
|
||||
With _SF_
|
||||
Select Case psService
|
||||
Case "BrowseNodeFactory"
|
||||
Set oDefaultContext = GetDefaultContext()
|
||||
If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName("/singletons/com.sun.star.script.browse.theBrowseNodeFactory")
|
||||
Case "CharacterClass"
|
||||
If IsEmpty(.CharacterClass) Or IsNull(.CharacterClass) Then
|
||||
Set .CharacterClass = CreateUnoService("com.sun.star.i18n.CharacterClassification")
|
||||
End If
|
||||
Set _GetUNOService = .CharacterClass
|
||||
Case "ConfigurationProvider"
|
||||
If IsEmpty(.ConfigurationProvider) Or IsNull(.ConfigurationProvider) Then
|
||||
Set .ConfigurationProvider = CreateUnoService("com.sun.star.configuration.ConfigurationProvider")
|
||||
End If
|
||||
Set _GetUNOService = .ConfigurationProvider
|
||||
Case "CoreReflection"
|
||||
If IsEmpty(.CoreReflection) Or IsNull(.CoreReflection) Then
|
||||
Set .CoreReflection = CreateUnoService("com.sun.star.reflection.CoreReflection")
|
||||
End If
|
||||
Set _GetUNOService = .CoreReflection
|
||||
Case "DatabaseContext"
|
||||
If IsEmpty(.DatabaseContext) Or IsNull(.DatabaseContext) Then
|
||||
Set .DatabaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
|
||||
End If
|
||||
Set _GetUNOService = .DatabaseContext
|
||||
Case "DispatchHelper"
|
||||
If IsEmpty(.DispatchHelper) Or IsNull(.DispatchHelper) Then
|
||||
Set .DispatchHelper = CreateUnoService("com.sun.star.frame.DispatchHelper")
|
||||
End If
|
||||
Set _GetUNOService = .DispatchHelper
|
||||
Case "FileAccess"
|
||||
If IsEmpty(.FileAccess) Or IsNull(.FileAccess) Then
|
||||
Set .FileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
|
||||
End If
|
||||
Set _GetUNOService = .FileAccess
|
||||
Case "FilePicker"
|
||||
If IsEmpty(.FilePicker) Or IsNull(.FilePicker) Then
|
||||
Set .FilePicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
|
||||
End If
|
||||
Set _GetUNOService = .FilePicker
|
||||
Case "FilterFactory"
|
||||
If IsEmpty(.FilterFactory) Or IsNull(.FilterFactory) Then
|
||||
Set .FilterFactory = CreateUnoService("com.sun.star.document.FilterFactory")
|
||||
End If
|
||||
Set _GetUNOService = .FilterFactory
|
||||
Case "FolderPicker"
|
||||
If IsEmpty(.FolderPicker) Or IsNull(.FolderPicker) Then
|
||||
Set .FolderPicker = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
|
||||
End If
|
||||
Set _GetUNOService = .FolderPicker
|
||||
Case "FunctionAccess"
|
||||
If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then
|
||||
Set .FunctionAccess = CreateUnoService("com.sun.star.sheet.FunctionAccess")
|
||||
End If
|
||||
Set _GetUNOService = .FunctionAccess
|
||||
Case "Introspection"
|
||||
If IsEmpty(.Introspection) Or IsNull(.Introspection) Then
|
||||
Set .Introspection = CreateUnoService("com.sun.star.beans.Introspection")
|
||||
End If
|
||||
Set _GetUNOService = .Introspection
|
||||
Case "Locale"
|
||||
If IsEmpty(.Locale) Or IsNull(.Locale) Then
|
||||
.Locale = CreateUnoStruct("com.sun.star.lang.Locale")
|
||||
' Derived from the Tools library
|
||||
Set oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
|
||||
vNodePath = Array() : ReDim vNodePath(0)
|
||||
vNodePath(0) = New com.sun.star.beans.PropertyValue
|
||||
vNodePath(0).Name = "nodepath" : vNodePath(0).Value = "org.openoffice.Setup/L10N"
|
||||
sLocale = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", vNodePath()).getByName("ooLocale")
|
||||
.Locale.Language = Left(sLocale, 2)
|
||||
.Locale.Country = Right(sLocale, 2)
|
||||
End If
|
||||
Set _GetUNOService = .Locale
|
||||
Case "MacroExpander"
|
||||
Set oDefaultContext = GetDefaultContext()
|
||||
If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander")
|
||||
Case "MailService"
|
||||
If IsEmpty(.MailService) Or IsNull(.MailService) Then
|
||||
If GetGuiType = 1 Then ' Windows
|
||||
Set .MailService = CreateUnoService("com.sun.star.system.SimpleSystemMail")
|
||||
Else
|
||||
Set .MailService = CreateUnoService("com.sun.star.system.SimpleCommandMail")
|
||||
End If
|
||||
End If
|
||||
Set _GetUNOService = .MailService
|
||||
Case "PathSettings"
|
||||
If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then
|
||||
Set .PathSettings = CreateUnoService("com.sun.star.util.PathSettings")
|
||||
End If
|
||||
Set _GetUNOService = .PathSettings
|
||||
Case "PathSubstitution"
|
||||
If IsEmpty(.PathSubstitution) Or IsNull(.PathSubstitution) Then
|
||||
Set .PathSubstitution = CreateUnoService("com.sun.star.util.PathSubstitution")
|
||||
End If
|
||||
Set _GetUNOService = .PathSubstitution
|
||||
Case "ScriptProvider"
|
||||
If IsMissing(pvArg) Then pvArg = SF_Session.SCRIPTISAPPLICATION
|
||||
Select Case LCase(pvArg)
|
||||
Case SF_Session.SCRIPTISEMBEDDED ' Document
|
||||
If Not IsNull(ThisComponent) Then Set _GetUNOService = ThisComponent.getScriptProvider()
|
||||
Case Else
|
||||
If IsEmpty(.ScriptProvider) Or IsNull(.ScriptProvider) Then
|
||||
Set .ScriptProvider = _
|
||||
CreateUnoService("com.sun.star.script.provider.MasterScriptProviderFactory").createScriptProvider("")
|
||||
End If
|
||||
Set _GetUNOService = .ScriptProvider
|
||||
End Select
|
||||
Case "SearchOptions"
|
||||
If IsEmpty(.SearchOptions) Or IsNull(.SearchOptions) Then
|
||||
Set .SearchOptions = New com.sun.star.util.SearchOptions
|
||||
With .SearchOptions
|
||||
.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
|
||||
.searchFlag = 0
|
||||
End With
|
||||
End If
|
||||
Set _GetUNOService = .SearchOptions
|
||||
Case "SystemShellExecute"
|
||||
If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then
|
||||
Set .SystemShellExecute = CreateUnoService("com.sun.star.system.SystemShellExecute")
|
||||
End If
|
||||
Set _GetUNOService = .SystemShellExecute
|
||||
Case "TextSearch"
|
||||
If IsEmpty(.TextSearch) Or IsNull(.TextSearch) Then
|
||||
Set .TextSearch = CreateUnoService("com.sun.star.util.TextSearch")
|
||||
End If
|
||||
Set _GetUNOService = .TextSearch
|
||||
Case "URLTransformer"
|
||||
If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then
|
||||
Set .URLTransformer = CreateUnoService("com.sun.star.util.URLTransformer")
|
||||
End If
|
||||
Set _GetUNOService = .URLTransformer
|
||||
Case Else
|
||||
End Select
|
||||
End With
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._GetUNOService
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _InitializeRoot(Optional ByVal pbForce As Boolean)
|
||||
''' Initialize _SF_ as SF_Root basic object
|
||||
''' Args:
|
||||
''' pbForce = True forces the reinit (default = False)
|
||||
|
||||
If IsMissing(pbForce) Then pbForce = False
|
||||
If pbForce Then Set _SF_ = Nothing
|
||||
If IsEmpty(_SF_) Or IsNull(_SF_) Then
|
||||
Set _SF_ = New SF_Root
|
||||
Set _SF_.[Me] = _SF_
|
||||
' Localization
|
||||
_SF_._LoadLocalizedInterface()
|
||||
End If
|
||||
|
||||
End Sub ' ScriptForge.SF_Utils._InitializeRoot
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _MakePropertyValue(ByVal psName As String _
|
||||
, ByRef pvValue As Variant _
|
||||
) As com.sun.star.beans.PropertyValue
|
||||
''' Create and return a new com.sun.star.beans.PropertyValue
|
||||
|
||||
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
|
||||
|
||||
With oPropertyValue
|
||||
.Name = psName
|
||||
.Value = SF_Utils._CPropertyValue(pvValue)
|
||||
End With
|
||||
_MakePropertyValue() = oPropertyValue
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._MakePropertyValue
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _Repr(ByVal pvArg As Variant, Optional ByVal plMax As Long) As String
|
||||
''' Convert pvArg into a readable string (truncated if length > plMax)
|
||||
''' Args
|
||||
''' pvArg: may be of any type
|
||||
''' plMax: maximum length of the resulting string (default = 32K)
|
||||
|
||||
Dim sArg As String ' Return value
|
||||
Dim oObject As Object ' Alias of argument to avoid "Object variable not set"
|
||||
Dim sObject As String ' Object representation
|
||||
Dim sObjectType As String ' ObjectType attribute of Basic objects
|
||||
Dim sLength As String ' String length as a string
|
||||
Dim i As Long
|
||||
Const cstBasicObject = "com.sun.star.script.NativeObjectWrapper"
|
||||
|
||||
Const cstMaxLength = 2^15 - 1 ' 32767
|
||||
Const cstByteLength = 25
|
||||
Const cstEtc = " … "
|
||||
|
||||
If IsMissing(plMax) Or plMax = 0 Then plMax = cstMaxLength
|
||||
If IsArray(pvArg) Then
|
||||
sArg = SF_Array._Repr(pvArg)
|
||||
Else
|
||||
Select Case VarType(pvArg)
|
||||
Case V_EMPTY : sArg = "[EMPTY]"
|
||||
Case V_NULL : sArg = "[NULL]"
|
||||
Case V_OBJECT
|
||||
If IsNull(pvArg) Then
|
||||
sArg = "[NULL]"
|
||||
Else
|
||||
sObject = SF_Session.UnoObjectType(pvArg)
|
||||
If sObject = "" Or sObject = cstBasicObject Then ' Not a UNO object
|
||||
' Test if argument is a ScriptForge object
|
||||
sObjectType = ""
|
||||
On Local Error Resume Next
|
||||
Set oObject = pvArg
|
||||
sObjectType = oObject.ObjectType
|
||||
On Error GoTo 0
|
||||
If sObjectType = "" Then
|
||||
sArg = "[OBJECT]"
|
||||
ElseIf Left(sObjectType, 3) = "SF_" Then
|
||||
sArg = "[" & sObjectType & "]"
|
||||
Else
|
||||
sArg = oObject._Repr()
|
||||
End If
|
||||
Else
|
||||
sArg = "[" & sObject & "]"
|
||||
End If
|
||||
End If
|
||||
Case V_VARIANT : sArg = "[VARIANT]"
|
||||
Case V_STRING
|
||||
sArg = SF_String._Repr(pvArg)
|
||||
Case V_BOOLEAN : sArg = Iif(pvArg, "[TRUE]", "[FALSE]")
|
||||
Case V_BYTE : sArg = Right("00" & Hex(pvArg), 2)
|
||||
Case V_SINGLE, V_DOUBLE, V_CURRENCY
|
||||
sArg = Format(pvArg)
|
||||
If InStr(1, sArg, "E", 1) = 0 Then sArg = Format(pvArg, "##0.0##")
|
||||
sArg = Replace(sArg, ",", ".") 'Force decimal point
|
||||
Case V_BIGINT : sArg = CStr(CLng(pvArg))
|
||||
Case V_DATE : sArg = _CDateToIso(pvArg)
|
||||
Case Else : sArg = CStr(pvArg)
|
||||
End Select
|
||||
End If
|
||||
If Len(sArg) > plMax Then
|
||||
sLength = "(" & Len(sArg) & ")"
|
||||
sArg = Left(sArg, plMax - Len(cstEtc) - Len(slength)) & cstEtc & sLength
|
||||
End If
|
||||
_Repr = sArg
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._Repr
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _ReprValues(Optional ByVal pvArgs As Variant _
|
||||
, Optional ByVal plMax As Long _
|
||||
) As String
|
||||
''' Convert an array of values to a comma-separated list of readable strings
|
||||
|
||||
Dim sValues As String ' Return value
|
||||
Dim sValue As String ' A single value
|
||||
Dim vValue As Variant ' A single item in the argument
|
||||
Dim i As Long ' Items counter
|
||||
Const cstMax = 20 ' Maximum length of single string
|
||||
Const cstContinue = "…" ' Unicode continuation char U+2026
|
||||
|
||||
_ReprValues = ""
|
||||
If IsMissing(pvArgs) Then Exit Function
|
||||
If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
|
||||
sValues = ""
|
||||
For i = 0 To UBound(pvArgs)
|
||||
vValue = pvArgs(i)
|
||||
If i < plMax Then
|
||||
If VarType(vValue) = V_STRING Then sValue = """" & vValue & """" Else sValue = SF_Utils._Repr(vValue, cstMax)
|
||||
If Len(sValues) = 0 Then sValues = sValue Else sValues = sValues & ", " & sValue
|
||||
ElseIf i < UBound(pvArgs) Then
|
||||
sValues = sValues & ", " & cstContinue
|
||||
Exit For
|
||||
End If
|
||||
Next i
|
||||
_ReprValues = sValues
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._ReprValues
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub _SetPropertyValue(ByRef pvPropertyValue As Variant _
|
||||
, ByVal psName As String _
|
||||
, ByRef pvValue As Variant _
|
||||
)
|
||||
''' Update the 1st argument (passed by reference), which is an array of property values
|
||||
''' If the property psName exists, update it with pvValue, otherwise create it on top of the array
|
||||
|
||||
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
|
||||
Dim lIndex As Long ' Found entry
|
||||
Dim vValue As Variant ' Alias of pvValue
|
||||
Dim i As Long
|
||||
|
||||
lIndex = -1
|
||||
For i = 0 To UBound(pvPropertyValue)
|
||||
If pvPropertyValue(i).Name = psName Then
|
||||
lIndex = i
|
||||
Exit For
|
||||
End If
|
||||
Next i
|
||||
If lIndex < 0 Then ' Not found
|
||||
lIndex = UBound(pvPropertyValue) + 1
|
||||
ReDim Preserve pvPropertyValue(0 To lIndex)
|
||||
Set oPropertyValue = SF_Utils._MakePropertyValue(psName, pvValue)
|
||||
pvPropertyValue(lIndex) = oPropertyValue
|
||||
Else ' psName exists already in array of property values
|
||||
pvPropertyValue(lIndex).Value = SF_Utils._CPropertyValue(pvValue)
|
||||
End If
|
||||
|
||||
End Sub ' ScriptForge.SF_Utils._SetPropertyValue
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _TypeNames(Optional ByVal pvArgs As Variant) As String
|
||||
''' Converts the array of VarTypes to a comma-separated list of TypeNames
|
||||
|
||||
Dim sTypes As String ' Return value
|
||||
Dim sType As String ' A single type
|
||||
Dim iType As Integer ' A single item of the argument
|
||||
|
||||
_TypeNames = ""
|
||||
If IsMissing(pvArgs) Then Exit Function
|
||||
If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
|
||||
sTypes = ""
|
||||
For Each iType In pvArgs
|
||||
Select Case iType
|
||||
Case V_EMPTY : sType = "Empty"
|
||||
Case V_NULL : sType = "Null"
|
||||
Case V_INTEGER : sType = "Integer"
|
||||
Case V_LONG : sType = "Long"
|
||||
Case V_SINGLE : sType = "Single"
|
||||
Case V_DOUBLE : sType = "Double"
|
||||
Case V_CURRENCY : sType = "Currency"
|
||||
Case V_DATE : sType = "Date"
|
||||
Case V_STRING : sType = "String"
|
||||
Case V_OBJECT : sType = "Object"
|
||||
Case V_BOOLEAN : sType = "Boolean"
|
||||
Case V_VARIANT : sType = "Variant"
|
||||
Case V_DECIMAL : sType = "Decimal"
|
||||
Case >= V_ARRAY : sType = "Array"
|
||||
Case V_NUMERIC : sType = "Numeric"
|
||||
End Select
|
||||
If Len(sTypes) = 0 Then sTypes = sType Else sTypes = sTypes & ", " & sType
|
||||
Next iType
|
||||
_TypeNames = sTypes
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._TypeNames
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _Validate(Optional ByRef pvArgument As Variant _
|
||||
, ByVal psName As String _
|
||||
, Optional ByVal pvTypes As Variant _
|
||||
, Optional ByVal pvValues As Variant _
|
||||
, Optional ByVal pvRegex As Variant _
|
||||
, Optional ByVal pvObjectType As Variant _
|
||||
) As Boolean
|
||||
''' Validate the arguments set by user scripts
|
||||
''' The arguments of the function define the validation rules
|
||||
''' This function ignores arrays. Use _ValidateArray instead
|
||||
''' Args:
|
||||
''' pvArgument: the argument to (in)validate
|
||||
''' psName: the documented name of the argument (can be inserted in an error message)
|
||||
''' pvTypes: array of allowed VarTypes
|
||||
''' pvValues: array of allowed values
|
||||
''' pvRegex: regular expression to comply with
|
||||
''' pvObjectType: mandatory Basic class
|
||||
''' Return: True if validation OK
|
||||
''' Otherwise an error is raised
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR
|
||||
|
||||
Dim iVarType As Integer ' Extended VarType of argument
|
||||
Dim bValid As Boolean ' Returned value
|
||||
Dim oArgument As Variant ' Workaround "Object variable not set" error on 1st executable statement
|
||||
Const cstMaxLength = 256 ' Maximum length of readable value
|
||||
Const cstMaxValues = 10 ' Maximum number of allowed items to list in an error message
|
||||
|
||||
' To avoid useless recursions, keep main function, only increase stack depth
|
||||
_SF_.StackLevel = _SF_.StackLevel + 1
|
||||
On Local Error GoTo Finally ' Do never interrupt
|
||||
|
||||
Try:
|
||||
bValid = True
|
||||
If IsMissing(pvArgument) Then GoTo CatchMissing
|
||||
If IsMissing(pvRegex) Or IsEmpty(pvRegex) Then pvRegex = ""
|
||||
If IsMissing(pvObjectType) Or IsEmpty(pvObjectType) Then pvObjectType = ""
|
||||
iVarType = SF_Utils._VarTypeExt(pvArgument)
|
||||
|
||||
' Arrays NEVER pass validation
|
||||
If iVarType >= V_ARRAY Then
|
||||
bValid = False
|
||||
Else
|
||||
' Check existence of argument
|
||||
bValid = iVarType <> V_NULL And iVarType <> V_EMPTY
|
||||
' Check if argument's VarType is valid
|
||||
If bValid And Not IsMissing(pvTypes) Then
|
||||
If Not IsArray(pvTypes) Then bValid = ( pvTypes = iVarType ) Else bValid = SF_Array.Contains(pvTypes, iVarType)
|
||||
End If
|
||||
' Check if argument's value is valid
|
||||
If bValid And Not IsMissing(pvValues) Then
|
||||
If Not IsArray(pvValues) Then pvValues = Array(pvValues)
|
||||
bValid = SF_Array.Contains(pvValues, pvArgument, CaseSensitive := False)
|
||||
End If
|
||||
' Check regular expression
|
||||
If bValid And Len(pvRegex) > 0 And iVarType = V_STRING Then
|
||||
If Len(pvArgument) > 0 Then bValid = SF_String.IsRegex(pvArgument, pvRegex, CaseSensitive := False)
|
||||
End If
|
||||
' Check instance types
|
||||
If bValid And Len(pvObjectType) > 0 And iVarType = V_OBJECT Then
|
||||
Set oArgument = pvArgument
|
||||
bValid = ( pvObjectType = oArgument.ObjectType )
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not bValid Then
|
||||
''' Library: ScriptForge
|
||||
''' Service: Array
|
||||
''' Method: Contains
|
||||
''' Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=""]
|
||||
''' A serious error has been detected on argument SortOrder
|
||||
''' Rules: SortOrder is of type String
|
||||
''' SortOrder must contain one of next values: "ASC", "DESC", ""
|
||||
''' Actual value: "Ascending"
|
||||
SF_Exception.RaiseFatal(ARGUMENTERROR _
|
||||
, SF_Utils._Repr(pvArgument, cstMaxLength), psName, SF_Utils._TypeNames(pvTypes) _
|
||||
, SF_Utils._ReprValues(pvValues, cstMaxValues), pvRegex, pvObjectType _
|
||||
)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
_Validate = bValid
|
||||
_SF_.StackLevel = _SF_.StackLevel - 1
|
||||
Exit Function
|
||||
CatchMissing:
|
||||
bValid = False
|
||||
SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Utils._Validate
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _ValidateArray(Optional ByRef pvArray As Variant _
|
||||
, ByVal psName As String _
|
||||
, Optional ByVal piDimensions As Integer _
|
||||
, Optional ByVal piType As Integer _
|
||||
, Optional ByVal pbNotNull As Boolean _
|
||||
) As Boolean
|
||||
''' Validate the (array) arguments set by user scripts
|
||||
''' The arguments of the function define the validation rules
|
||||
''' This function ignores non-arrays. Use _Validate instead
|
||||
''' Args:
|
||||
''' pvArray: the argument to (in)validate
|
||||
''' psName: the documented name of the array (can be inserted in an error message)
|
||||
''' piDimensions: the # of dimensions the array must have. 0 = Any (default)
|
||||
''' piType: (default = -1, i.e. not applicable)
|
||||
''' For 2D arrays, the 1st column is checked
|
||||
''' 0 => all items must be any out of next types: string, date or numeric,
|
||||
''' but homogeneously: all strings or all dates or all numeric
|
||||
''' V_STRING or V_DATE or V_NUMERIC => that specific type is required
|
||||
''' pbNotNull: piType must be >=0, otherwise ignored
|
||||
''' If True: Empty, Null items are rejected
|
||||
''' Return: True if validation OK
|
||||
''' Otherwise an error is raised
|
||||
''' Exceptions:
|
||||
''' ARRAYERROR
|
||||
|
||||
Dim iVarType As Integer ' VarType of argument
|
||||
Dim vItem As Variant ' Array item
|
||||
Dim iItemType As Integer ' VarType of individual items of argument
|
||||
Dim iDims As Integer ' Number of dimensions of the argument
|
||||
Dim bValid As Boolean ' Returned value
|
||||
Dim iArrayType As Integer ' Static array type
|
||||
Dim iFirstItemType As Integer ' Type of 1st non-null/empty item
|
||||
Dim sType As String ' Allowed item types as a string
|
||||
Dim i As Long
|
||||
Const cstMaxLength = 256 ' Maximum length of readable value
|
||||
|
||||
' To avoid useless recursions, keep main function, only increase stack depth
|
||||
|
||||
_SF_.StackLevel = _SF_.StackLevel + 1
|
||||
On Local Error GoTo Finally ' Do never interrupt
|
||||
|
||||
Try:
|
||||
bValid = True
|
||||
If IsMissing(pvArray) Then GoTo CatchMissing
|
||||
If IsMissing(piDimensions) Then piDimensions = 0
|
||||
If IsMissing(piType) Then piType = -1
|
||||
If IsMissing(pbNotNull) Then pbNotNull = False
|
||||
iVarType = VarType(pvArray)
|
||||
|
||||
' Scalars NEVER pass validation
|
||||
If iVarType < V_ARRAY Then
|
||||
bValid = False
|
||||
Else
|
||||
' Check dimensions
|
||||
iDims = SF_Array.CountDims(pvArray)
|
||||
If iDims > 2 Then bValid = False ' Only 1D and 2D arrays
|
||||
If bValid And piDimensions > 0 Then
|
||||
bValid = ( iDims = piDimensions Or (iDims = 0 And piDimensions = 1) ) ' Allow empty vectors
|
||||
End If
|
||||
' Check VarType and Empty/Null status of the array items
|
||||
If bValid And iDims = 1 And piType >= 0 Then
|
||||
iArrayType = SF_Array._StaticType(pvArray)
|
||||
If (piType = 0 And iArrayType > 0) Or (piType > 0 And iArrayType = piType) Then
|
||||
' If static array of the right VarType ..., OK
|
||||
Else
|
||||
' Go through array and check individual items
|
||||
iFirstItemType = -1
|
||||
For i = LBound(pvArray, 1) To UBound(pvArray, 1)
|
||||
If iDims = 1 Then vItem = pvArray(i) Else vItem = pvArray(i, LBound(pvArray, 2))
|
||||
iItemType = SF_Utils._VarTypeExt(vItem)
|
||||
If iItemType > V_NULL Then ' Exclude Empty and Null
|
||||
' Initialization at first non-null item
|
||||
If iFirstItemType < 0 Then
|
||||
iFirstItemType = iItemType
|
||||
If piType > 0 Then bValid = ( iFirstItemType = piType ) Else bValid = SF_Array.Contains(Array(V_STRING, V_DATE, V_NUMERIC), iFirstItemType)
|
||||
Else
|
||||
bValid = (iItemType = iFirstItemType)
|
||||
End If
|
||||
Else
|
||||
bValid = Not pbNotNull
|
||||
End If
|
||||
If Not bValid Then Exit For
|
||||
Next i
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not bValid Then
|
||||
''' Library: ScriptForge
|
||||
''' Service: Array
|
||||
''' Method: Contains
|
||||
''' Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=""|"ASC"|"DESC"]
|
||||
''' An error was detected on argument Array_1D
|
||||
''' Rules: Array_1D is of type Array
|
||||
''' Array_1D must have maximum 1 dimension
|
||||
''' Array_1D must have all elements of the same type: either String, Date or Numeric
|
||||
''' Actual value: (0:2, 0:3)
|
||||
sType = ""
|
||||
If piType = 0 Then
|
||||
sType = "String, Date, Numeric"
|
||||
ElseIf piType > 0 Then
|
||||
sType = SF_Utils._TypeNames(piType)
|
||||
End If
|
||||
SF_Exception.RaiseFatal(ARRAYERROR _
|
||||
, SF_Utils._Repr(pvArray, cstMaxLength), psName, piDimensions, sType, pbNotNull)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
_ValidateArray = bValid
|
||||
_SF_.StackLevel = _SF_.StackLevel - 1
|
||||
Exit Function
|
||||
CatchMissing:
|
||||
bValid = False
|
||||
SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Utils._ValidateArray
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _ValidateFile(Optional ByRef pvArgument As Variant _
|
||||
, ByVal psName As String _
|
||||
, Optional ByVal pbWildCards As Boolean _
|
||||
, Optional ByVal pbSpace As Boolean _
|
||||
)
|
||||
''' Validate the argument as a valid FileName
|
||||
''' Args:
|
||||
''' pvArgument: the argument to (in)validate
|
||||
''' pbWildCards: if True, wildcard characters are accepted in the last component of the 1st argument
|
||||
''' pbSpace: if True, the argument may be an empty string. Default = False
|
||||
''' Return: True if validation OK
|
||||
''' Otherwise an error is raised
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR
|
||||
|
||||
Dim iVarType As Integer ' VarType of argument
|
||||
Dim sFile As String ' Alias for argument
|
||||
Dim bValid As Boolean ' Returned value
|
||||
Dim sFileNaming As String ' Alias of SF_FileSystem.FileNaming
|
||||
Dim oArgument As Variant ' Workaround "Object variable not set" error on 1st executable statement
|
||||
Const cstMaxLength = 256 ' Maximum length of readable value
|
||||
|
||||
' To avoid useless recursions, keep main function, only increase stack depth
|
||||
|
||||
_SF_.StackLevel = _SF_.StackLevel + 1
|
||||
On Local Error GoTo Finally ' Do never interrupt
|
||||
|
||||
Try:
|
||||
bValid = True
|
||||
If IsMissing(pvArgument) Then GoTo CatchMissing
|
||||
If IsMissing(pbWildCards) Then pbWildCards = False
|
||||
If IsMissing(pbSpace) Then pbSpace = False
|
||||
iVarType = VarType(pvArgument)
|
||||
|
||||
' Arrays NEVER pass validation
|
||||
If iVarType >= V_ARRAY Then
|
||||
bValid = False
|
||||
Else
|
||||
' Argument must be a string containing a valid file name
|
||||
bValid = ( iVarType = V_STRING )
|
||||
If bValid Then
|
||||
bValid = ( Len(pvArgument) > 0 Or pbSpace )
|
||||
If bValid And Len(pvArgument) > 0 Then
|
||||
' Wildcards are replaced by arbitrary alpha characters
|
||||
If pbWildCards Then
|
||||
sFile = Replace(Replace(pvArgument, "?", "Z"), "*", "A")
|
||||
Else
|
||||
sFile = pvArgument
|
||||
bValid = ( InStr(sFile, "?") + InStr(sFile, "*") = 0 )
|
||||
End If
|
||||
' Check file format without wildcards
|
||||
If bValid Then
|
||||
With SF_FileSystem
|
||||
sFileNaming = .FileNaming
|
||||
Select Case sFileNaming
|
||||
Case "ANY" : bValid = SF_String.IsUrl(ConvertToUrl(sFile))
|
||||
Case "URL" : bValid = SF_String.IsUrl(sFile)
|
||||
Case "SYS" : bValid = SF_String.IsFileName(sFile)
|
||||
End Select
|
||||
End With
|
||||
End If
|
||||
' Check that wildcards are only present in last component
|
||||
If bValid And pbWildCards Then
|
||||
sFile = SF_FileSystem.GetParentFolderName(pvArgument)
|
||||
bValid = ( InStr(sFile, "*") + InStr(sFile, "?") + InStr(sFile,"%3F") = 0 ) ' ConvertToUrl replaces ? by %3F
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not bValid Then
|
||||
''' Library: ScriptForge
|
||||
''' Service: FileSystem
|
||||
''' Method: CopyFile
|
||||
''' Arguments: Source, Destination
|
||||
''' A serious error has been detected on argument Source
|
||||
''' Rules: Source is of type String
|
||||
''' Source must be a valid file name expressed in operating system notation
|
||||
''' Source may contain one or more wildcard characters in its last component
|
||||
''' Actual value: /home/jean-*/SomeFile.odt
|
||||
SF_Exception.RaiseFatal(FILEERROR _
|
||||
, SF_Utils._Repr(pvArgument, cstMaxLength), psName, pbWildCards)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
_ValidateFile = bValid
|
||||
_SF_.StackLevel = _SF_.StackLevel - 1
|
||||
Exit Function
|
||||
CatchMissing:
|
||||
bValid = False
|
||||
SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Utils._ValidateFile
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _VarTypeExt(ByRef pvValue As Variant) As Integer
|
||||
''' Return the VarType of the argument but all numeric types are aggregated into V_NUMERIC
|
||||
''' Args:
|
||||
''' pvValue: value to examine
|
||||
''' Return:
|
||||
''' The extended VarType
|
||||
|
||||
Dim iType As Integer ' VarType of argument
|
||||
|
||||
iType = VarType(pvValue)
|
||||
Select Case iType
|
||||
Case V_INTEGER, V_LONG, V_SINGLE, V_DOUBLE, V_CURRENCY, V_BIGINT, V_DECIMAL
|
||||
_VarTypeExt = V_NUMERIC
|
||||
Case Else : _VarTypeExt = iType
|
||||
End Select
|
||||
|
||||
End Function ' ScriptForge.SF_Utils._VarTypeExt
|
||||
|
||||
REM ================================================= END OF SCRIPTFORGE.SF_UTILS
|
||||
</script:module>
|
||||
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_CodingConventions" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
'''
|
||||
' Conventions used in the coding of the *ScriptForge* library
|
||||
' -----------------------------------------------------------
|
||||
'''
|
||||
' Library and Modules
|
||||
' ===================
|
||||
' * Module names are all prefixed with "SF_".
|
||||
' * The *Option Explicit* statement is mandatory in every module.
|
||||
' * The *Option Private Module* statement is recommended in internal modules.
|
||||
' * A standard header presenting the module/class is mandatory
|
||||
' * An end of file (eof) comment line is mandatory
|
||||
' * Every module lists the constants that are related to it and documented as return values, arguments, etc.
|
||||
' They are defined as *Global Const*.
|
||||
' The scope of global constants being limited to one single library, their invocation from user scripts shall be qualified.
|
||||
' * The Basic reserved words are *Proper-Cased*.
|
||||
'''
|
||||
' Functions and Subroutines
|
||||
' =========================
|
||||
' * LibreOffice ignores the Private/Public attribute in Functions or Subs declarations.
|
||||
' Nevertheless the attribute must be present.
|
||||
' Rules to recognize their scope are:
|
||||
' * Public + name starts with a letter
|
||||
' The Sub/Function belongs to the official ScriptForge API.
|
||||
' As such it may be called from any user script.
|
||||
' * Public + name starts with an underscore "_"
|
||||
' The Sub/Function may be called only from within the ScriptForge library.
|
||||
' As such it MUST NOT be called from another library or from a user script,
|
||||
' as there is no guarantee about the arguments, the semantic or even the existence of that piece of code in a later release.
|
||||
' * Private - The Sub/Function name must start with an underscore "_".
|
||||
' The Sub/Function may be called only from the module in which it is located.
|
||||
' * Functions and Subroutines belonging to the API (= "standard" functions/Subs) are defined in their module in alphabetical order.
|
||||
' For class modules, all the properties precede the methods which precede the events.
|
||||
' * Functions and Subroutines not belonging to the API are defined in their module in alphabetical order below the standard ones.
|
||||
' * The return value of a function is always declared explicitly.
|
||||
' * The parameters are always declared explicitly even if they're variants.
|
||||
' * The Function and Sub declarations start at the 1st column of the line.
|
||||
' * The End Function/Sub statement is followed by a comment reminding the name of the containing library.module and of the function or sub.
|
||||
' If the Function/Sub is declared for the first time or modified in a release > initial public release, the actual release number is mentioned as well.
|
||||
'''
|
||||
' Variable declarations
|
||||
' =====================
|
||||
' * Variable names use only alpha characters, the underscore and digits (no accented characters).
|
||||
' Exceptionally, names of private variables may be embraced with `[` and `]` if `Option Compatible` is present.
|
||||
' * The Global, Dim and Const statements always start in the first column of the line.
|
||||
' * The type (*Dim ... As ...*, *Function ... As ...*) is always declared explicitly, even if the type is Variant.
|
||||
' * Variables are *Proper-Cased*. They are always preceded by a lower-case letter indicating their type.
|
||||
' With next exception: variables i, j, k, l, m and n must be declared as integers or longs.
|
||||
' > b Boolean
|
||||
' > d Date
|
||||
' > v Variant
|
||||
' > o Object
|
||||
' > i Integer
|
||||
' > l Long
|
||||
' > s String
|
||||
' Example:
|
||||
' Dim sValue As String
|
||||
' * Parameters are preceded by the letter *p* which itself precedes the single *typing letter*.
|
||||
' In official methods, to match their published documentation, the *p* and the *typing letter* may be omitted. Like in:
|
||||
' Private Function MyFunction(psValue As String) As Variant
|
||||
' Public Function MyOfficialFunction(Value As String) As Variant
|
||||
' * Global variables in the ScriptForge library are ALL preceded by an underscore "_" as NONE of them should be invoked from outside the library.
|
||||
' * Constant values with a local scope are *Proper-Cased* and preceded by the letters *cst*.
|
||||
' * Constants with a global scope are *UPPER-CASED*.
|
||||
' Example:
|
||||
' Global Const ACONSTANT = "This is a global constant"
|
||||
' Function MyFunction(pocControl As Object, piValue) As Variant
|
||||
' Dim iValue As Integer
|
||||
' Const cstMyConstant = 3
|
||||
'''
|
||||
' Indentation
|
||||
' ===========
|
||||
' Code shall be indented with TAB characters.
|
||||
'''
|
||||
' Goto/Gosub
|
||||
' ==========
|
||||
' The *GoSub* … *Return* statement is forbidden.
|
||||
' The *GoTo* statement is forbidden.
|
||||
' However *GoTo* is highly recommended for *error* and *exception* handling.
|
||||
'''
|
||||
' Comments (english only)
|
||||
' ========
|
||||
' * Every public routine should be documented with a python-like "docstring":
|
||||
' 1. Role of Sub/Function
|
||||
' 2. List of arguments, mandatory/optional, role
|
||||
' 3. Returned value(s) type and meaning
|
||||
' 4. Examples when useful
|
||||
' 5. Eventual specific exception codes
|
||||
' * The "docstring" comments shall be marked by a triple (single) quote character at the beginning of the line
|
||||
' * Meaningful variables shall be declared one per line. Comment on same line.
|
||||
' * Comments about a code block should be left indented.
|
||||
' If it concerns only the next line, no indent required (may also be put at the end of the line).
|
||||
'''
|
||||
</script:module>
|
||||
221
server/windows-office/share/basic/ScriptForge/_ModuleModel.xba
Normal file
221
server/windows-office/share/basic/ScriptForge/_ModuleModel.xba
Normal file
@@ -0,0 +1,221 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_ModuleModel" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
'Option Private Module
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' ModuleModel (aka SF_Model)
|
||||
''' ===========
|
||||
''' Illustration of how the ScriptForge modules are structured
|
||||
''' Copy and paste this code in an empty Basic module to start a new service
|
||||
''' Comment in, comment out, erase what you want, but at the end respect the overall structure
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
''' FAKENEWSERROR
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object ' Should be initialized immediately after the New statement
|
||||
' Dim obj As Object : Set obj = New SF_Model
|
||||
' Set obj.[Me] = obj
|
||||
Private [_Parent] As Object ' To keep trace of the instance having created a sub-instance
|
||||
' Set obj._Parent = [Me]
|
||||
Private ObjectType As String ' Must be UNIQUE
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
Private Const SOMECONSTANT = 1
|
||||
|
||||
REM ====================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "MODEL"
|
||||
End Sub ' ScriptForge.SF_Model Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' ScriptForge.SF_Model Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' ScriptForge.SF_Model Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get MyProperty() As Boolean
|
||||
''' Returns True or False
|
||||
''' Example:
|
||||
''' myModel.MyProperty
|
||||
|
||||
MyProperty = _PropertyGet("MyProperty")
|
||||
|
||||
End Property ' ScriptForge.SF_Model.MyProperty
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' If the property does not exist, returns Null
|
||||
''' Exceptions:
|
||||
''' see the exceptions of the individual properties
|
||||
''' Examples:
|
||||
''' myModel.GetProperty("MyProperty")
|
||||
|
||||
Const cstThisSub = "Model.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Model.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Model service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"MyFunction" _
|
||||
, "etc" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Model.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function MyFunction(Optional ByVal Arg1 As Variant _
|
||||
, Optional ByVal Arg2 As Variant _
|
||||
) As Variant
|
||||
''' Fictive function that concatenates Arg1 Arg2 times
|
||||
''' Args:
|
||||
''' Arg1 String Text
|
||||
''' Arg2 Numeric Number of times (default = 2)
|
||||
''' Returns:
|
||||
''' The new string
|
||||
''' Exceptions:
|
||||
''' FAKENEWSERROR
|
||||
''' Examples:
|
||||
''' MyFunction("value1") returns "value1value1"
|
||||
|
||||
Dim sOutput As String ' Output buffer
|
||||
Dim i As Integer
|
||||
Const cstThisSub = "Model.myFunction"
|
||||
Const cstSubArgs = "Arg1, [Arg2=2]"
|
||||
|
||||
' _ErrorHandling returns False when, for debugging, the standard error handling is preferred
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
myFunction = ""
|
||||
|
||||
Check:
|
||||
If IsMissing(Arg2) Then Arg2 = 2
|
||||
' _EnterFunction returns True when current method is invoked from a user script
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
' Check Arg1 is a string and Arg2 is a number.
|
||||
' Validation rules for scalars and arrays are described in SF_Utils
|
||||
If Not SF_Utils._Validate(Arg1, "Arg1", V_STRING) Then GoTo Finally
|
||||
If Not SF_Utils._Validate(Arg2, "Arg2", V_NUMERIC) Then GoTo Finally
|
||||
' Fatal error ?
|
||||
If Arg2 < 0 Then GoTo CatchFake
|
||||
End If
|
||||
|
||||
Try:
|
||||
sOutput = ""
|
||||
For i = 0 To Arg2
|
||||
sOutput = sOutput & Arg1
|
||||
Next i
|
||||
myFunction = sOutput
|
||||
|
||||
Finally:
|
||||
' _ExitFunction manages internal (On Local) errors
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchFake:
|
||||
SF_Exception.RaiseFatal("FAKENEWSERROR", cstThisSub)
|
||||
GoTo Finally
|
||||
End Function ' ScriptForge.SF_Model.myFunction
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Model class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"MyProperty" _
|
||||
, "etc" _
|
||||
)
|
||||
|
||||
End Function ' ScriptForge.SF_Model.Properties
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
cstThisSub = "SF_Model.get" & psProperty
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
|
||||
Select Case psProperty
|
||||
Case "MyProperty"
|
||||
_PropertyGet = TBD
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' ScriptForge.SF_Model._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[MODEL]: A readable string"
|
||||
|
||||
_Repr = "[MODEL]: A readable string"
|
||||
|
||||
End Function ' ScriptForge.SF_Model._Repr
|
||||
|
||||
REM ============================================ END OF SCRIPTFORGE.SF_MODEL
|
||||
</script:module>
|
||||
25
server/windows-office/share/basic/ScriptForge/__License.xba
Normal file
25
server/windows-office/share/basic/ScriptForge/__License.xba
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="__License" script:language="StarBasic" script:moduleType="normal">
|
||||
''' Copyright 2019-2020 Jean-Pierre LEDURE, Jean-François NIFENECKER, Alain ROMEDENNE
|
||||
|
||||
REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
''' ScriptForge is distributed in the hope that it will be useful,
|
||||
''' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
''' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
''' ScriptForge is free software; you can redistribute it and/or modify it under the terms of either (at your option):
|
||||
|
||||
''' 1) The Mozilla Public License, v. 2.0. If a copy of the MPL was not
|
||||
''' distributed with this file, you can obtain one at http://mozilla.org/MPL/2.0/ .
|
||||
|
||||
''' 2) The GNU Lesser General Public License as published by
|
||||
''' the Free Software Foundation, either version 3 of the License, or
|
||||
''' (at your option) any later version. If a copy of the LGPL was not
|
||||
''' distributed with this file, see http://www.gnu.org/licenses/ .
|
||||
|
||||
</script:module>
|
||||
6
server/windows-office/share/basic/ScriptForge/dialog.xlb
Normal file
6
server/windows-office/share/basic/ScriptForge/dialog.xlb
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
|
||||
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false">
|
||||
<library:element library:name="dlgConsole"/>
|
||||
<library:element library:name="dlgProgress"/>
|
||||
</library:library>
|
||||
14
server/windows-office/share/basic/ScriptForge/dlgConsole.xdl
Normal file
14
server/windows-office/share/basic/ScriptForge/dlgConsole.xdl
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
|
||||
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="dlgConsole" dlg:left="114" dlg:top="32" dlg:width="321" dlg:height="239" dlg:closeable="true" dlg:moveable="true" dlg:title="ScriptForge">
|
||||
<dlg:styles>
|
||||
<dlg:style dlg:style-id="0" dlg:font-name="Courier New" dlg:font-stylename="Regular" dlg:font-family="modern"/>
|
||||
</dlg:styles>
|
||||
<dlg:bulletinboard>
|
||||
<dlg:textfield dlg:style-id="0" dlg:id="ConsoleLines" dlg:tab-index="0" dlg:left="4" dlg:top="2" dlg:width="312" dlg:height="225" dlg:hscroll="true" dlg:vscroll="true" dlg:multiline="true" dlg:readonly="true"/>
|
||||
<dlg:button dlg:id="CloseNonModalButton" dlg:tab-index="2" dlg:left="265" dlg:top="228" dlg:width="50" dlg:height="10" dlg:default="true" dlg:value="Close">
|
||||
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:ScriptForge.SF_Exception._CloseConsole?language=Basic&location=application" script:language="Script"/>
|
||||
</dlg:button>
|
||||
<dlg:button dlg:id="CloseModalButton" dlg:tab-index="1" dlg:left="265" dlg:top="228" dlg:width="50" dlg:height="10" dlg:default="true" dlg:value="Close" dlg:button-type="ok"/>
|
||||
</dlg:bulletinboard>
|
||||
</dlg:window>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
|
||||
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="dlgProgress" dlg:left="180" dlg:top="90" dlg:width="275" dlg:height="37" dlg:closeable="true" dlg:moveable="true">
|
||||
<dlg:bulletinboard>
|
||||
<dlg:text dlg:id="ProgressText" dlg:tab-index="1" dlg:left="16" dlg:top="7" dlg:width="245" dlg:height="8" dlg:value="ProgressText" dlg:tabstop="true"/>
|
||||
<dlg:progressmeter dlg:id="ProgressBar" dlg:tab-index="0" dlg:left="16" dlg:top="18" dlg:width="190" dlg:height="10" dlg:value="50"/>
|
||||
<dlg:button dlg:id="CloseButton" dlg:tab-index="2" dlg:left="210" dlg:top="18" dlg:width="50" dlg:height="10" dlg:value="Close">
|
||||
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:ScriptForge.SF_UI._CloseProgressBar?language=Basic&location=application" script:language="Script"/>
|
||||
</dlg:button>
|
||||
</dlg:bulletinboard>
|
||||
</dlg:window>
|
||||
801
server/windows-office/share/basic/ScriptForge/po/ScriptForge.pot
Normal file
801
server/windows-office/share/basic/ScriptForge/po/ScriptForge.pot
Normal file
@@ -0,0 +1,801 @@
|
||||
#
|
||||
# This pristine POT file has been generated by LibreOffice/ScriptForge
|
||||
# Full documentation is available on https://help.libreoffice.org/
|
||||
#
|
||||
# *********************************************************************
|
||||
# *** The ScriptForge library and its associated libraries ***
|
||||
# *** are part of the LibreOffice project. ***
|
||||
# *********************************************************************
|
||||
#
|
||||
# ScriptForge Release 7.1
|
||||
# -----------------------
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n"
|
||||
"POT-Creation-Date: 2020-10-10 16:05:30\n"
|
||||
"PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
|
||||
"Language: en_US\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=n > 1;\n"
|
||||
"X-Generator: LibreOffice - ScriptForge\n"
|
||||
"X-Accelerator-Marker: ~\n"
|
||||
|
||||
#. Text in close buttons of progress and console dialog boxes
|
||||
msgctxt "CLOSEBUTTON"
|
||||
msgid "Close"
|
||||
msgstr ""
|
||||
|
||||
#. Title in error message box
|
||||
#. %1: an error number
|
||||
#, kde-format
|
||||
msgctxt "ERRORNUMBER"
|
||||
msgid "Error %1"
|
||||
msgstr ""
|
||||
|
||||
#. Error message box
|
||||
#. %1: a line number
|
||||
#, kde-format
|
||||
msgctxt "ERRORLOCATION"
|
||||
msgid "Location : %1"
|
||||
msgstr ""
|
||||
|
||||
#. Logfile record
|
||||
#, kde-format
|
||||
msgctxt "LONGERRORDESC"
|
||||
msgid "Error %1 - Location = %2 - Description = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
msgctxt "STOPEXECUTION"
|
||||
msgid "THE EXECUTION IS CANCELLED."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Exception.RaiseAbort error message
|
||||
msgctxt "INTERNALERROR"
|
||||
msgid ""
|
||||
"The ScriptForge library has crashed. The reason is unknown.\n"
|
||||
"Maybe a bug that could be reported on\n"
|
||||
" https://bugs.documentfoundation.org/\n"
|
||||
"\n"
|
||||
"More details : \n"
|
||||
"\n"
|
||||
""
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: probably ScriptForge
|
||||
#. %2: service or module name
|
||||
#. %3: property or method name where the error occurred
|
||||
#, kde-format
|
||||
msgctxt "VALIDATESOURCE"
|
||||
msgid ""
|
||||
"Library : %1\n"
|
||||
"Service : %2\n"
|
||||
"Method : %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: list of arguments of the method
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEARGS"
|
||||
msgid "Arguments: %1"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEERROR"
|
||||
msgid "A serious error has been detected in your code on argument : « %1 »."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils.Validate error message
|
||||
msgctxt "VALIDATIONRULES"
|
||||
msgid " Validation rules :"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Comma separated list of allowed types
|
||||
#, kde-format
|
||||
msgctxt "VALIDATETYPES"
|
||||
msgid " « %1 » must have next type (or one of next types) : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Comma separated list of allowed values
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEVALUES"
|
||||
msgid " « %1 » must contain one of next values : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: A regular expression
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEREGEX"
|
||||
msgid " « %1 » must match next regular expression : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: The name of a Basic class
|
||||
#, kde-format
|
||||
msgctxt "VALIDATECLASS"
|
||||
msgid " « %1 » must be a Basic object of class : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: The value of the argument as a string
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEACTUAL"
|
||||
msgid "The actual value of « %1 » is : '%2'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEMISSING"
|
||||
msgid "The « %1 » argument is mandatory, yet it is missing."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEARRAY"
|
||||
msgid " « %1 » must be an array."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Number of dimensions of the array
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEDIMS"
|
||||
msgid " « %1 » must have exactly %2 dimension(s)."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Either one single type or 'String, Date, Numeric'
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEALLTYPES"
|
||||
msgid " « %1 » must have all elements of the same type : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#. NULL and EMPTY should not be translated
|
||||
#, kde-format
|
||||
msgctxt "VALIDATENOTNULL"
|
||||
msgid " « %1 » must not contain any NULL or EMPTY elements."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#. 'String' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILE"
|
||||
msgid " « %1 » must be of type String."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILESYS"
|
||||
msgid ""
|
||||
" « %1 » must be a valid file or folder name expressed in the "
|
||||
"operating system native notation."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#. 'URL' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILEURL"
|
||||
msgid ""
|
||||
" « %1 » must be a valid file or folder name expressed in the "
|
||||
"portable URL notation."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILEANY"
|
||||
msgid " « %1 » must be a valid file or folder name."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#. '(?, *)' is to be left as is
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEWILDCARD"
|
||||
msgid ""
|
||||
" « %1 » may contain one or more wildcard characters (?, *) in "
|
||||
"its last path component only."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.RangeInit error message
|
||||
#. %1, %2, %3: Numeric values
|
||||
#. 'From', 'UpTo', 'ByStep' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYSEQUENCE"
|
||||
msgid ""
|
||||
"The respective values of 'From', 'UpTo' and 'ByStep' are incoherent.\n"
|
||||
"\n"
|
||||
" « From » = %1\n"
|
||||
" « UpTo » = %2\n"
|
||||
" « ByStep » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.AppendColumn (...) error message
|
||||
#. %1: 'Column' or 'Row' of a matrix
|
||||
#. %2, %3: array contents
|
||||
#. 'Array_2D' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYINSERT"
|
||||
msgid ""
|
||||
"The array and the vector to insert have incompatible sizes.\n"
|
||||
"\n"
|
||||
" « Array_2D » = %2\n"
|
||||
" « %1 » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.ExtractColumn (...) error message
|
||||
#. %1: 'Column' or 'Row' of a matrix
|
||||
#. %2, %3: array contents
|
||||
#. 'Array_2D' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYINDEX1"
|
||||
msgid ""
|
||||
"The given index does not fit within the bounds of the array.\n"
|
||||
"\n"
|
||||
" « Array_2D » = %2\n"
|
||||
" « %1 » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.ExtractColumn (...) error message
|
||||
#. %1: 'Column' or 'Row' of a matrix
|
||||
#. %2, %3: array contents
|
||||
#. 'Array_2D', 'From' and 'UpTo' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYINDEX2"
|
||||
msgid ""
|
||||
"The given slice limits do not fit within the bounds of the array.\n"
|
||||
"\n"
|
||||
" « Array_2D » = %1\n"
|
||||
" « From » = %2\n"
|
||||
" « UpTo » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.ImportFromCSVFile error message
|
||||
#. %1: a file name
|
||||
#. %2: numeric
|
||||
#. %3: a long string
|
||||
#, kde-format
|
||||
msgctxt "CSVPARSING"
|
||||
msgid ""
|
||||
"The given file could not be parsed as a valid CSV file.\n"
|
||||
"\n"
|
||||
" « File name » = %1\n"
|
||||
" Line number = %2\n"
|
||||
" Content = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dictionary Add/ReplaceKey error message
|
||||
#. %1: An identifier%2: a (potentially long) string
|
||||
#, kde-format
|
||||
msgctxt "DUPLICATEKEY"
|
||||
msgid ""
|
||||
"The insertion of a new key into a dictionary failed because the key "
|
||||
"already exists.\n"
|
||||
"Note that the comparison between keys is NOT case-sensitive.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dictionary Remove/ReplaceKey/ReplaceItem error message
|
||||
#. %1: An identifier%2: a (potentially long) string
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNKEY"
|
||||
msgid ""
|
||||
"The requested key does not exist in the dictionary.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dictionary Add/ReplaceKey error message
|
||||
#.
|
||||
msgctxt "INVALIDKEY"
|
||||
msgid ""
|
||||
"The insertion or the update of an entry into a dictionary failed "
|
||||
"because the given key contains only spaces."
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNFILE"
|
||||
msgid ""
|
||||
"The given file could not be found on your system.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A folder name
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNFOLDER"
|
||||
msgid ""
|
||||
"The given folder could not be found on your system.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "NOTAFILE"
|
||||
msgid ""
|
||||
"« %1 » contains the name of an existing folder, not that of a file.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A folder name
|
||||
#, kde-format
|
||||
msgctxt "NOTAFOLDER"
|
||||
msgid ""
|
||||
"« %1 » contains the name of an existing file, not that of a folder.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/... error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "OVERWRITE"
|
||||
msgid ""
|
||||
"You tried to create a new file which already exists. Overwriting it "
|
||||
"has been rejected.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "READONLY"
|
||||
msgid ""
|
||||
"Copying or moving a file to a destination which has its read-only "
|
||||
"attribute set, or deleting such a file or folder is forbidden.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file or folder name with wildcards
|
||||
#, kde-format
|
||||
msgctxt "NOFILEMATCH"
|
||||
msgid ""
|
||||
"When « %1 » contains wildcards. at least one file or folder must "
|
||||
"match the given filter. Otherwise the operation is rejected.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem CreateFolder error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file or folder name
|
||||
#, kde-format
|
||||
msgctxt "FOLDERCREATION"
|
||||
msgid ""
|
||||
"« %1 » contains the name of an existing file or an existing folder. "
|
||||
"The operation is rejected.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Services.CreateScriptService error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: A Basic library name
|
||||
#. %4: A service (1 word) name
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNSERVICE"
|
||||
msgid ""
|
||||
"No service named '%4' has been registered for the library '%3'.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Services.CreateScriptService error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: A Basic library name
|
||||
#, kde-format
|
||||
msgctxt "SERVICESNOTLOADED"
|
||||
msgid ""
|
||||
"The library '%3' and its services could not been loaded.\n"
|
||||
"The reason is unknown.\n"
|
||||
"However, checking the '%3.SF_Services.RegisterScriptServices()' "
|
||||
"function and its return value can be a good starting point.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.ExecuteCalcFunction error message
|
||||
#. 'Calc' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "CALCFUNC"
|
||||
msgid ""
|
||||
"The Calc '%1' function encountered an error. Either the given "
|
||||
"function does not exist or its arguments are invalid."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session._GetScript error message
|
||||
#. %1: 'Basic' or 'Python'
|
||||
#. %2: An identifier
|
||||
#. %3: A string
|
||||
#. %2: An identifier
|
||||
#. %3: A string
|
||||
#, kde-format
|
||||
msgctxt "NOSCRIPT"
|
||||
msgid ""
|
||||
"The requested %1 script could not be located in the given libraries "
|
||||
"and modules.\n"
|
||||
"« %2 » = %3\n"
|
||||
"« %4 » = %5"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.ExecuteBasicScript error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: A number
|
||||
#, kde-format
|
||||
msgctxt "SCRIPTEXEC"
|
||||
msgid ""
|
||||
"An exception occurred during the execution of the Basic script.\n"
|
||||
"Cause: %3\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.SendMail error message
|
||||
#. %1 = a mail address
|
||||
#, kde-format
|
||||
msgctxt "WRONGEMAIL"
|
||||
msgid ""
|
||||
"One of the email addresses has been found invalid.\n"
|
||||
"Invalid mail = « %1 »"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.SendMail error message
|
||||
msgctxt "SENDMAIL"
|
||||
msgid ""
|
||||
"The message could not be sent due to a system error.\n"
|
||||
"A possible cause is that LibreOffice could not find any mail client."
|
||||
msgstr ""
|
||||
|
||||
#. SF_TextStream._IsFileOpen error message
|
||||
#. %1: A file name
|
||||
#, kde-format
|
||||
msgctxt "FILENOTOPEN"
|
||||
msgid ""
|
||||
"The requested file operation could not be executed because the file "
|
||||
"was closed previously.\n"
|
||||
"\n"
|
||||
"File name = '%1'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_TextStream._IsFileOpen error message
|
||||
#. %1: A file name
|
||||
#. %2: READ, WRITE or APPEND
|
||||
#, kde-format
|
||||
msgctxt "FILEOPENMODE"
|
||||
msgid ""
|
||||
"The requested file operation could not be executed because it is "
|
||||
"incompatible with the mode in which the file was opened.\n"
|
||||
"\n"
|
||||
"File name = '%1'\n"
|
||||
"Open mode = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.GetDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENT"
|
||||
msgid ""
|
||||
"The requested document could not be found.\n"
|
||||
"\n"
|
||||
"%1 = '%2'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.GetDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTCREATION"
|
||||
msgid ""
|
||||
"The creation of a new document failed.\n"
|
||||
"Something must be wrong with some arguments.\n"
|
||||
"\n"
|
||||
"Either the document type is unknown, or no template file was given,\n"
|
||||
"or the given template file was not found on your system.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = '%4'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.OpenDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A string
|
||||
#. %5: An identifier
|
||||
#. %6: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTOPEN"
|
||||
msgid ""
|
||||
"The opening of the document failed.\n"
|
||||
"Something must be wrong with some arguments.\n"
|
||||
"\n"
|
||||
"Either the file does not exist, or the password is wrong, or the "
|
||||
"given filter is invalid.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = '%4'\n"
|
||||
"%5 = '%6'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.OpenDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A string
|
||||
#, kde-format
|
||||
msgctxt "BASEDOCUMENTOPEN"
|
||||
msgid ""
|
||||
"The opening of the Base document failed.\n"
|
||||
"Something must be wrong with some arguments.\n"
|
||||
"\n"
|
||||
"Either the file does not exist, or the file is not registered under "
|
||||
"the given name.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = '%4'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document._IsStillAlive error message
|
||||
#. %1: A file name
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTDEAD"
|
||||
msgid ""
|
||||
"The requested action could not be executed because the document was "
|
||||
"closed inadvertently.\n"
|
||||
"\n"
|
||||
"The concerned document is '%1'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document.SaveAs error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#.
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTSAVE"
|
||||
msgid ""
|
||||
"The document could not be saved.\n"
|
||||
"Either the document has been opened read-only, or the destination "
|
||||
"file has a read-only attribute set, or the file where to save to is "
|
||||
"undefined.\n"
|
||||
"\n"
|
||||
"%1 = '%2'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document.SaveAs error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#. %3: An identifier
|
||||
#. %4: True or False
|
||||
#. %5: An identifier
|
||||
#. %6: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTSAVEAS"
|
||||
msgid ""
|
||||
"The document could not be saved.\n"
|
||||
"Either the document must not be overwritten, or the destination file "
|
||||
"has a read-only attribute set, or the given filter is invalid.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = %4\n"
|
||||
"%5 = '%6'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document any update
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTREADONLY"
|
||||
msgid ""
|
||||
"You tried to edit a document which is not modifiable. The document "
|
||||
"has not been changed.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Base GetDatabase
|
||||
#. %1: An identifier
|
||||
#. %2: A user name
|
||||
#. %3: An identifier
|
||||
#. %4: A password
|
||||
#. %5: A file name
|
||||
#, kde-format
|
||||
msgctxt "DBCONNECT"
|
||||
msgid ""
|
||||
"The database related to the actual Base document could not be "
|
||||
"retrieved.\n"
|
||||
"Check the connection/login parameters.\n"
|
||||
"\n"
|
||||
"« %1 » = '%2'\n"
|
||||
"« %3 » = '%4'\n"
|
||||
"« Document » = %5"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc _ParseAddress (sheet)
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#, kde-format
|
||||
msgctxt "CALCADDRESS1"
|
||||
msgid ""
|
||||
"The given address does not correspond with a valid sheet name.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc _ParseAddress (range)
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#, kde-format
|
||||
msgctxt "CALCADDRESS2"
|
||||
msgid ""
|
||||
"The given address does not correspond with a valid range of cells.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc InsertSheet
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#, kde-format
|
||||
msgctxt "DUPLICATESHEET"
|
||||
msgid ""
|
||||
"There exists already in the document a sheet with the same name.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc Offset
|
||||
#. %1: An identifier
|
||||
#. %2: A Calc reference
|
||||
#. %3: An identifier
|
||||
#. %4: A number
|
||||
#. %5: An identifier
|
||||
#. %6: A number
|
||||
#. %7: An identifier
|
||||
#. %8: A number
|
||||
#. %9: An identifier
|
||||
#. %10: A number
|
||||
#. %11: An identifier
|
||||
#. %12: A file name
|
||||
#, kde-format
|
||||
msgctxt "OFFSETADDRESS"
|
||||
msgid ""
|
||||
"The computed range falls beyond the sheet boundaries or is "
|
||||
"meaningless.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4\n"
|
||||
"« %5 » = %6\n"
|
||||
"« %7 » = %8\n"
|
||||
"« %9 » = %10\n"
|
||||
"« %11 » = %12"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dialog creation
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#. %5: An identifier
|
||||
#. %6: A string
|
||||
#. %7: An identifier
|
||||
#. %8: A string
|
||||
#, kde-format
|
||||
msgctxt "DIALOGNOTFOUND"
|
||||
msgid ""
|
||||
"The requested dialog could not be located in the given container or "
|
||||
"library.\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4\n"
|
||||
"« %5 » = %6\n"
|
||||
"« %7 » = %8"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dialog._IsStillAlive error message
|
||||
#. %1: An identifier
|
||||
#, kde-format
|
||||
msgctxt "DIALOGDEAD"
|
||||
msgid ""
|
||||
"The requested action could not be executed because the dialog was "
|
||||
"closed inadvertently.\n"
|
||||
"\n"
|
||||
"The concerned dialog is '%1'."
|
||||
msgstr ""
|
||||
|
||||
#. SF_DialogControl property setting
|
||||
#. %1: An identifier
|
||||
#. %2: An identifier
|
||||
#. %3: A string
|
||||
#. %4: An identifier
|
||||
#, kde-format
|
||||
msgctxt "CONTROLTYPE"
|
||||
msgid ""
|
||||
"The control '%1' in dialog '%2' is of type '%3'.\n"
|
||||
"The property '%4' is not applicable on that type of dialog controls."
|
||||
msgstr ""
|
||||
|
||||
#. SF_DialogControl add line in textbox
|
||||
#. %1: An identifier
|
||||
#. %2: An identifier
|
||||
#, kde-format
|
||||
msgctxt "TEXTFIELD"
|
||||
msgid ""
|
||||
"The control '%1' in dialog '%2' is not a multiline text field.\n"
|
||||
"The requested method could not be executed."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Database when running update SQL statement
|
||||
#. %1: The concerned method
|
||||
#, kde-format
|
||||
msgctxt "DBREADONLY"
|
||||
msgid ""
|
||||
"The database has been opened in read-only mode.\n"
|
||||
"The '%1' method must not be executed in this context."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Database can't interpret SQL statement
|
||||
#. %1: The statement
|
||||
#, kde-format
|
||||
msgctxt "SQLSYNTAX"
|
||||
msgid ""
|
||||
"An SQL statement could not be interpreted or executed by the "
|
||||
"database system.\n"
|
||||
"Check its syntax, table and/or field names, ...\n"
|
||||
"\n"
|
||||
"SQL Statement : « %1 »"
|
||||
msgstr ""
|
||||
801
server/windows-office/share/basic/ScriptForge/po/en.po
Normal file
801
server/windows-office/share/basic/ScriptForge/po/en.po
Normal file
@@ -0,0 +1,801 @@
|
||||
#
|
||||
# This pristine POT file has been generated by LibreOffice/ScriptForge
|
||||
# Full documentation is available on https://help.libreoffice.org/
|
||||
#
|
||||
# *********************************************************************
|
||||
# *** The ScriptForge library and its associated libraries ***
|
||||
# *** are part of the LibreOffice project. ***
|
||||
# *********************************************************************
|
||||
#
|
||||
# ScriptForge Release 7.1
|
||||
# -----------------------
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n"
|
||||
"POT-Creation-Date: 2020-10-10 16:05:30\n"
|
||||
"PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
|
||||
"Language: en_US\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=n > 1;\n"
|
||||
"X-Generator: LibreOffice - ScriptForge\n"
|
||||
"X-Accelerator-Marker: ~\n"
|
||||
|
||||
#. Text in close buttons of progress and console dialog boxes
|
||||
msgctxt "CLOSEBUTTON"
|
||||
msgid "Close"
|
||||
msgstr ""
|
||||
|
||||
#. Title in error message box
|
||||
#. %1: an error number
|
||||
#, kde-format
|
||||
msgctxt "ERRORNUMBER"
|
||||
msgid "Error %1"
|
||||
msgstr ""
|
||||
|
||||
#. Error message box
|
||||
#. %1: a line number
|
||||
#, kde-format
|
||||
msgctxt "ERRORLOCATION"
|
||||
msgid "Location : %1"
|
||||
msgstr ""
|
||||
|
||||
#. Logfile record
|
||||
#, kde-format
|
||||
msgctxt "LONGERRORDESC"
|
||||
msgid "Error %1 - Location = %2 - Description = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
msgctxt "STOPEXECUTION"
|
||||
msgid "THE EXECUTION IS CANCELLED."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Exception.RaiseAbort error message
|
||||
msgctxt "INTERNALERROR"
|
||||
msgid ""
|
||||
"The ScriptForge library has crashed. The reason is unknown.\n"
|
||||
"Maybe a bug that could be reported on\n"
|
||||
" https://bugs.documentfoundation.org/\n"
|
||||
"\n"
|
||||
"More details : \n"
|
||||
"\n"
|
||||
""
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: probably ScriptForge
|
||||
#. %2: service or module name
|
||||
#. %3: property or method name where the error occurred
|
||||
#, kde-format
|
||||
msgctxt "VALIDATESOURCE"
|
||||
msgid ""
|
||||
"Library : %1\n"
|
||||
"Service : %2\n"
|
||||
"Method : %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: list of arguments of the method
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEARGS"
|
||||
msgid "Arguments: %1"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEERROR"
|
||||
msgid "A serious error has been detected in your code on argument : « %1 »."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils.Validate error message
|
||||
msgctxt "VALIDATIONRULES"
|
||||
msgid " Validation rules :"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Comma separated list of allowed types
|
||||
#, kde-format
|
||||
msgctxt "VALIDATETYPES"
|
||||
msgid " « %1 » must have next type (or one of next types) : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Comma separated list of allowed values
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEVALUES"
|
||||
msgid " « %1 » must contain one of next values : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: A regular expression
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEREGEX"
|
||||
msgid " « %1 » must match next regular expression : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: The name of a Basic class
|
||||
#, kde-format
|
||||
msgctxt "VALIDATECLASS"
|
||||
msgid " « %1 » must be a Basic object of class : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: The value of the argument as a string
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEACTUAL"
|
||||
msgid "The actual value of « %1 » is : '%2'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._Validate error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEMISSING"
|
||||
msgid "The « %1 » argument is mandatory, yet it is missing."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEARRAY"
|
||||
msgid " « %1 » must be an array."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Number of dimensions of the array
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEDIMS"
|
||||
msgid " « %1 » must have exactly %2 dimension(s)."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#. %2: Either one single type or 'String, Date, Numeric'
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEALLTYPES"
|
||||
msgid " « %1 » must have all elements of the same type : %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateArray error message
|
||||
#. %1: Wrong argument name
|
||||
#. NULL and EMPTY should not be translated
|
||||
#, kde-format
|
||||
msgctxt "VALIDATENOTNULL"
|
||||
msgid " « %1 » must not contain any NULL or EMPTY elements."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#. 'String' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILE"
|
||||
msgid " « %1 » must be of type String."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILESYS"
|
||||
msgid ""
|
||||
" « %1 » must be a valid file or folder name expressed in the "
|
||||
"operating system native notation."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#. 'URL' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILEURL"
|
||||
msgid ""
|
||||
" « %1 » must be a valid file or folder name expressed in the "
|
||||
"portable URL notation."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEFILEANY"
|
||||
msgid " « %1 » must be a valid file or folder name."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Utils._ValidateFile error message
|
||||
#. %1: Wrong argument name
|
||||
#. '(?, *)' is to be left as is
|
||||
#, kde-format
|
||||
msgctxt "VALIDATEWILDCARD"
|
||||
msgid ""
|
||||
" « %1 » may contain one or more wildcard characters (?, *) in "
|
||||
"its last path component only."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.RangeInit error message
|
||||
#. %1, %2, %3: Numeric values
|
||||
#. 'From', 'UpTo', 'ByStep' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYSEQUENCE"
|
||||
msgid ""
|
||||
"The respective values of 'From', 'UpTo' and 'ByStep' are incoherent.\n"
|
||||
"\n"
|
||||
" « From » = %1\n"
|
||||
" « UpTo » = %2\n"
|
||||
" « ByStep » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.AppendColumn (...) error message
|
||||
#. %1: 'Column' or 'Row' of a matrix
|
||||
#. %2, %3: array contents
|
||||
#. 'Array_2D' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYINSERT"
|
||||
msgid ""
|
||||
"The array and the vector to insert have incompatible sizes.\n"
|
||||
"\n"
|
||||
" « Array_2D » = %2\n"
|
||||
" « %1 » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.ExtractColumn (...) error message
|
||||
#. %1: 'Column' or 'Row' of a matrix
|
||||
#. %2, %3: array contents
|
||||
#. 'Array_2D' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYINDEX1"
|
||||
msgid ""
|
||||
"The given index does not fit within the bounds of the array.\n"
|
||||
"\n"
|
||||
" « Array_2D » = %2\n"
|
||||
" « %1 » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.ExtractColumn (...) error message
|
||||
#. %1: 'Column' or 'Row' of a matrix
|
||||
#. %2, %3: array contents
|
||||
#. 'Array_2D', 'From' and 'UpTo' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "ARRAYINDEX2"
|
||||
msgid ""
|
||||
"The given slice limits do not fit within the bounds of the array.\n"
|
||||
"\n"
|
||||
" « Array_2D » = %1\n"
|
||||
" « From » = %2\n"
|
||||
" « UpTo » = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Array.ImportFromCSVFile error message
|
||||
#. %1: a file name
|
||||
#. %2: numeric
|
||||
#. %3: a long string
|
||||
#, kde-format
|
||||
msgctxt "CSVPARSING"
|
||||
msgid ""
|
||||
"The given file could not be parsed as a valid CSV file.\n"
|
||||
"\n"
|
||||
" « File name » = %1\n"
|
||||
" Line number = %2\n"
|
||||
" Content = %3"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dictionary Add/ReplaceKey error message
|
||||
#. %1: An identifier%2: a (potentially long) string
|
||||
#, kde-format
|
||||
msgctxt "DUPLICATEKEY"
|
||||
msgid ""
|
||||
"The insertion of a new key into a dictionary failed because the key "
|
||||
"already exists.\n"
|
||||
"Note that the comparison between keys is NOT case-sensitive.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dictionary Remove/ReplaceKey/ReplaceItem error message
|
||||
#. %1: An identifier%2: a (potentially long) string
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNKEY"
|
||||
msgid ""
|
||||
"The requested key does not exist in the dictionary.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dictionary Add/ReplaceKey error message
|
||||
#.
|
||||
msgctxt "INVALIDKEY"
|
||||
msgid ""
|
||||
"The insertion or the update of an entry into a dictionary failed "
|
||||
"because the given key contains only spaces."
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNFILE"
|
||||
msgid ""
|
||||
"The given file could not be found on your system.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A folder name
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNFOLDER"
|
||||
msgid ""
|
||||
"The given folder could not be found on your system.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "NOTAFILE"
|
||||
msgid ""
|
||||
"« %1 » contains the name of an existing folder, not that of a file.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A folder name
|
||||
#, kde-format
|
||||
msgctxt "NOTAFOLDER"
|
||||
msgid ""
|
||||
"« %1 » contains the name of an existing file, not that of a folder.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/... error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "OVERWRITE"
|
||||
msgid ""
|
||||
"You tried to create a new file which already exists. Overwriting it "
|
||||
"has been rejected.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "READONLY"
|
||||
msgid ""
|
||||
"Copying or moving a file to a destination which has its read-only "
|
||||
"attribute set, or deleting such a file or folder is forbidden.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem copy/move/delete error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file or folder name with wildcards
|
||||
#, kde-format
|
||||
msgctxt "NOFILEMATCH"
|
||||
msgid ""
|
||||
"When « %1 » contains wildcards. at least one file or folder must "
|
||||
"match the given filter. Otherwise the operation is rejected.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_FileSystem CreateFolder error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file or folder name
|
||||
#, kde-format
|
||||
msgctxt "FOLDERCREATION"
|
||||
msgid ""
|
||||
"« %1 » contains the name of an existing file or an existing folder. "
|
||||
"The operation is rejected.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Services.CreateScriptService error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: A Basic library name
|
||||
#. %4: A service (1 word) name
|
||||
#, kde-format
|
||||
msgctxt "UNKNOWNSERVICE"
|
||||
msgid ""
|
||||
"No service named '%4' has been registered for the library '%3'.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Services.CreateScriptService error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: A Basic library name
|
||||
#, kde-format
|
||||
msgctxt "SERVICESNOTLOADED"
|
||||
msgid ""
|
||||
"The library '%3' and its services could not been loaded.\n"
|
||||
"The reason is unknown.\n"
|
||||
"However, checking the '%3.SF_Services.RegisterScriptServices()' "
|
||||
"function and its return value can be a good starting point.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.ExecuteCalcFunction error message
|
||||
#. 'Calc' should not be translated
|
||||
#, kde-format
|
||||
msgctxt "CALCFUNC"
|
||||
msgid ""
|
||||
"The Calc '%1' function encountered an error. Either the given "
|
||||
"function does not exist or its arguments are invalid."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session._GetScript error message
|
||||
#. %1: 'Basic' or 'Python'
|
||||
#. %2: An identifier
|
||||
#. %3: A string
|
||||
#. %2: An identifier
|
||||
#. %3: A string
|
||||
#, kde-format
|
||||
msgctxt "NOSCRIPT"
|
||||
msgid ""
|
||||
"The requested %1 script could not be located in the given libraries "
|
||||
"and modules.\n"
|
||||
"« %2 » = %3\n"
|
||||
"« %4 » = %5"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.ExecuteBasicScript error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: A number
|
||||
#, kde-format
|
||||
msgctxt "SCRIPTEXEC"
|
||||
msgid ""
|
||||
"An exception occurred during the execution of the Basic script.\n"
|
||||
"Cause: %3\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.SendMail error message
|
||||
#. %1 = a mail address
|
||||
#, kde-format
|
||||
msgctxt "WRONGEMAIL"
|
||||
msgid ""
|
||||
"One of the email addresses has been found invalid.\n"
|
||||
"Invalid mail = « %1 »"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Session.SendMail error message
|
||||
msgctxt "SENDMAIL"
|
||||
msgid ""
|
||||
"The message could not be sent due to a system error.\n"
|
||||
"A possible cause is that LibreOffice could not find any mail client."
|
||||
msgstr ""
|
||||
|
||||
#. SF_TextStream._IsFileOpen error message
|
||||
#. %1: A file name
|
||||
#, kde-format
|
||||
msgctxt "FILENOTOPEN"
|
||||
msgid ""
|
||||
"The requested file operation could not be executed because the file "
|
||||
"was closed previously.\n"
|
||||
"\n"
|
||||
"File name = '%1'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_TextStream._IsFileOpen error message
|
||||
#. %1: A file name
|
||||
#. %2: READ, WRITE or APPEND
|
||||
#, kde-format
|
||||
msgctxt "FILEOPENMODE"
|
||||
msgid ""
|
||||
"The requested file operation could not be executed because it is "
|
||||
"incompatible with the mode in which the file was opened.\n"
|
||||
"\n"
|
||||
"File name = '%1'\n"
|
||||
"Open mode = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.GetDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENT"
|
||||
msgid ""
|
||||
"The requested document could not be found.\n"
|
||||
"\n"
|
||||
"%1 = '%2'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.GetDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTCREATION"
|
||||
msgid ""
|
||||
"The creation of a new document failed.\n"
|
||||
"Something must be wrong with some arguments.\n"
|
||||
"\n"
|
||||
"Either the document type is unknown, or no template file was given,\n"
|
||||
"or the given template file was not found on your system.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = '%4'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.OpenDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A string
|
||||
#. %5: An identifier
|
||||
#. %6: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTOPEN"
|
||||
msgid ""
|
||||
"The opening of the document failed.\n"
|
||||
"Something must be wrong with some arguments.\n"
|
||||
"\n"
|
||||
"Either the file does not exist, or the password is wrong, or the "
|
||||
"given filter is invalid.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = '%4'\n"
|
||||
"%5 = '%6'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_UI.OpenDocument error message
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A string
|
||||
#, kde-format
|
||||
msgctxt "BASEDOCUMENTOPEN"
|
||||
msgid ""
|
||||
"The opening of the Base document failed.\n"
|
||||
"Something must be wrong with some arguments.\n"
|
||||
"\n"
|
||||
"Either the file does not exist, or the file is not registered under "
|
||||
"the given name.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = '%4'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document._IsStillAlive error message
|
||||
#. %1: A file name
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTDEAD"
|
||||
msgid ""
|
||||
"The requested action could not be executed because the document was "
|
||||
"closed inadvertently.\n"
|
||||
"\n"
|
||||
"The concerned document is '%1'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document.SaveAs error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#.
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTSAVE"
|
||||
msgid ""
|
||||
"The document could not be saved.\n"
|
||||
"Either the document has been opened read-only, or the destination "
|
||||
"file has a read-only attribute set, or the file where to save to is "
|
||||
"undefined.\n"
|
||||
"\n"
|
||||
"%1 = '%2'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document.SaveAs error message
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#. %3: An identifier
|
||||
#. %4: True or False
|
||||
#. %5: An identifier
|
||||
#. %6: A string
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTSAVEAS"
|
||||
msgid ""
|
||||
"The document could not be saved.\n"
|
||||
"Either the document must not be overwritten, or the destination file "
|
||||
"has a read-only attribute set, or the given filter is invalid.\n"
|
||||
"\n"
|
||||
"%1 = '%2'\n"
|
||||
"%3 = %4\n"
|
||||
"%5 = '%6'"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Document any update
|
||||
#. %1: An identifier
|
||||
#. %2: A file name
|
||||
#, kde-format
|
||||
msgctxt "DOCUMENTREADONLY"
|
||||
msgid ""
|
||||
"You tried to edit a document which is not modifiable. The document "
|
||||
"has not been changed.\n"
|
||||
"\n"
|
||||
"« %1 » = %2"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Base GetDatabase
|
||||
#. %1: An identifier
|
||||
#. %2: A user name
|
||||
#. %3: An identifier
|
||||
#. %4: A password
|
||||
#. %5: A file name
|
||||
#, kde-format
|
||||
msgctxt "DBCONNECT"
|
||||
msgid ""
|
||||
"The database related to the actual Base document could not be "
|
||||
"retrieved.\n"
|
||||
"Check the connection/login parameters.\n"
|
||||
"\n"
|
||||
"« %1 » = '%2'\n"
|
||||
"« %3 » = '%4'\n"
|
||||
"« Document » = %5"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc _ParseAddress (sheet)
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#, kde-format
|
||||
msgctxt "CALCADDRESS1"
|
||||
msgid ""
|
||||
"The given address does not correspond with a valid sheet name.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc _ParseAddress (range)
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#, kde-format
|
||||
msgctxt "CALCADDRESS2"
|
||||
msgid ""
|
||||
"The given address does not correspond with a valid range of cells.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc InsertSheet
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#, kde-format
|
||||
msgctxt "DUPLICATESHEET"
|
||||
msgid ""
|
||||
"There exists already in the document a sheet with the same name.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Calc Offset
|
||||
#. %1: An identifier
|
||||
#. %2: A Calc reference
|
||||
#. %3: An identifier
|
||||
#. %4: A number
|
||||
#. %5: An identifier
|
||||
#. %6: A number
|
||||
#. %7: An identifier
|
||||
#. %8: A number
|
||||
#. %9: An identifier
|
||||
#. %10: A number
|
||||
#. %11: An identifier
|
||||
#. %12: A file name
|
||||
#, kde-format
|
||||
msgctxt "OFFSETADDRESS"
|
||||
msgid ""
|
||||
"The computed range falls beyond the sheet boundaries or is "
|
||||
"meaningless.\n"
|
||||
"\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4\n"
|
||||
"« %5 » = %6\n"
|
||||
"« %7 » = %8\n"
|
||||
"« %9 » = %10\n"
|
||||
"« %11 » = %12"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dialog creation
|
||||
#. %1: An identifier
|
||||
#. %2: A string
|
||||
#. %3: An identifier
|
||||
#. %4: A file name
|
||||
#. %5: An identifier
|
||||
#. %6: A string
|
||||
#. %7: An identifier
|
||||
#. %8: A string
|
||||
#, kde-format
|
||||
msgctxt "DIALOGNOTFOUND"
|
||||
msgid ""
|
||||
"The requested dialog could not be located in the given container or "
|
||||
"library.\n"
|
||||
"« %1 » = %2\n"
|
||||
"« %3 » = %4\n"
|
||||
"« %5 » = %6\n"
|
||||
"« %7 » = %8"
|
||||
msgstr ""
|
||||
|
||||
#. SF_Dialog._IsStillAlive error message
|
||||
#. %1: An identifier
|
||||
#, kde-format
|
||||
msgctxt "DIALOGDEAD"
|
||||
msgid ""
|
||||
"The requested action could not be executed because the dialog was "
|
||||
"closed inadvertently.\n"
|
||||
"\n"
|
||||
"The concerned dialog is '%1'."
|
||||
msgstr ""
|
||||
|
||||
#. SF_DialogControl property setting
|
||||
#. %1: An identifier
|
||||
#. %2: An identifier
|
||||
#. %3: A string
|
||||
#. %4: An identifier
|
||||
#, kde-format
|
||||
msgctxt "CONTROLTYPE"
|
||||
msgid ""
|
||||
"The control '%1' in dialog '%2' is of type '%3'.\n"
|
||||
"The property '%4' is not applicable on that type of dialog controls."
|
||||
msgstr ""
|
||||
|
||||
#. SF_DialogControl add line in textbox
|
||||
#. %1: An identifier
|
||||
#. %2: An identifier
|
||||
#, kde-format
|
||||
msgctxt "TEXTFIELD"
|
||||
msgid ""
|
||||
"The control '%1' in dialog '%2' is not a multiline text field.\n"
|
||||
"The requested method could not be executed."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Database when running update SQL statement
|
||||
#. %1: The concerned method
|
||||
#, kde-format
|
||||
msgctxt "DBREADONLY"
|
||||
msgid ""
|
||||
"The database has been opened in read-only mode.\n"
|
||||
"The '%1' method must not be executed in this context."
|
||||
msgstr ""
|
||||
|
||||
#. SF_Database can't interpret SQL statement
|
||||
#. %1: The statement
|
||||
#, kde-format
|
||||
msgctxt "SQLSYNTAX"
|
||||
msgid ""
|
||||
"An SQL statement could not be interpreted or executed by the "
|
||||
"database system.\n"
|
||||
"Check its syntax, table and/or field names, ...\n"
|
||||
"\n"
|
||||
"SQL Statement : « %1 »"
|
||||
msgstr ""
|
||||
21
server/windows-office/share/basic/ScriptForge/script.xlb
Normal file
21
server/windows-office/share/basic/ScriptForge/script.xlb
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
|
||||
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="ScriptForge" library:readonly="false" library:passwordprotected="false">
|
||||
<library:element library:name="__License"/>
|
||||
<library:element library:name="SF_String"/>
|
||||
<library:element library:name="_CodingConventions"/>
|
||||
<library:element library:name="SF_Timer"/>
|
||||
<library:element library:name="_ModuleModel"/>
|
||||
<library:element library:name="SF_Utils"/>
|
||||
<library:element library:name="SF_Root"/>
|
||||
<library:element library:name="SF_Array"/>
|
||||
<library:element library:name="SF_Services"/>
|
||||
<library:element library:name="SF_Dictionary"/>
|
||||
<library:element library:name="SF_Session"/>
|
||||
<library:element library:name="SF_FileSystem"/>
|
||||
<library:element library:name="SF_TextStream"/>
|
||||
<library:element library:name="SF_L10N"/>
|
||||
<library:element library:name="SF_Exception"/>
|
||||
<library:element library:name="SF_UI"/>
|
||||
<library:element library:name="SF_Platform"/>
|
||||
</library:library>
|
||||
Reference in New Issue
Block a user