1VERSION 1.0 CLASS
2BEGIN
3  MultiUse = -1  'True
4END
5Attribute VB_Name = "StringDataManager"
6Attribute VB_GlobalNameSpace = False
7Attribute VB_Creatable = False
8Attribute VB_PredeclaredId = False
9Attribute VB_Exposed = True
10'/*************************************************************************
11' *
12' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13'
14' Copyright 2000, 2010 Oracle and/or its affiliates.
15'
16' OpenOffice.org - a multi-platform office productivity suite
17'
18' This file is part of OpenOffice.org.
19'
20' OpenOffice.org is free software: you can redistribute it and/or modify
21' it under the terms of the GNU Lesser General Public License version 3
22' only, as published by the Free Software Foundation.
23'
24' OpenOffice.org is distributed in the hope that it will be useful,
25' but WITHOUT ANY WARRANTY; without even the implied warranty of
26' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27' GNU Lesser General Public License version 3 for more details
28' (a copy is included in the LICENSE file that accompanied this code).
29'
30' You should have received a copy of the GNU Lesser General Public License
31' version 3 along with OpenOffice.org.  If not, see
32' <http://www.openoffice.org/license.html>
33' for a copy of the LGPLv3 License.
34'
35' ************************************************************************/
36
37Option Explicit
38Private langDict As Scripting.Dictionary
39Private mFileName As String
40
41Const C_PRODUCTNAME = "<PRODUCTNAME>"
42Const C_PRODUCTVERSION = "<PRODUCTVERSION>"
43Const C_NEXTPRODUCTVERSION = "<NEXTPRODUCTVERSION>"
44Const C_NEWLINE = "<CR>"
45
46' Load strings from the data file (in the form "id=string") into
47' dictionary object.
48Function InitStringData(fileName As String) As Boolean
49    On Error GoTo HandleErrors
50    Dim stringFile As TextStream
51    Dim aLine As String
52    Dim valueOffset As Long
53    Dim id, Str As String
54    Dim fso As FileSystemObject
55
56    'Make sure the string data file exists before opening.
57    Set fso = New Scripting.FileSystemObject
58    If Not fso.FileExists(fileName) Then
59        InitStringData = False
60        Exit Function
61    End If
62    Set stringFile = fso.OpenTextFile(fileName, ForReading, False, TristateTrue)
63    If IsEmpty(stringFile) Then
64        'WriteDebug
65    End If
66    mFileName = fileName
67
68    'Read each line and parse the id and string, then put into dictionary
69    Do While Not stringFile.AtEndOfStream
70        aLine = stringFile.ReadLine
71        valueOffset = InStr(aLine, "=")
72        id = Left(aLine, valueOffset - 1)
73        Str = Right(aLine, Len(aLine) - valueOffset)
74        langDict.Add id, Str
75    Loop
76    stringFile.Close
77
78    Dim aProductName As String
79    Dim aProductVersion As String
80    Dim aNextProductVersion As String
81    Dim aKey As Variant
82    Dim aItem As String
83    Dim aOldItem As String
84
85    aProductName = langDict.item("RID_STR_COMMON_PRODUCTNAME")
86    aProductVersion = langDict.item("RID_STR_COMMON_PRODUCTVERSION")
87    aNextProductVersion = langDict.item("RID_STR_COMMON_NEXTPRODUCTVERSION")
88
89    For Each aKey In langDict
90        aOldItem = langDict.item(aKey)
91        aItem = ReplaceTopicTokens(aOldItem, C_PRODUCTNAME, aProductName)
92        aItem = ReplaceTopicTokens(aItem, C_PRODUCTVERSION, aProductVersion)
93        aItem = ReplaceTopicTokens(aItem, C_NEXTPRODUCTVERSION, aNextProductVersion)
94        aItem = ReplaceTopicTokens(aItem, C_NEWLINE, vbLF)
95        If (Not (aOldItem = aItem)) Then
96            langDict.item(aKey) = aItem
97        End If
98    Next
99
100    InitStringData = True
101
102FinalExit:
103    Exit Function
104HandleErrors:
105    WriteDebug "InitStringData : " & Err.Number & " " & Err.Description & " " & Err.Source
106    InitStringData = False
107End Function
108
109'Set String Data from an existing dictionary
110Public Property Set StringData(data As Scripting.Dictionary)
111    Set langDict = data
112End Property
113
114'Get String Data dictionary
115Public Property Get StringData() As Scripting.Dictionary
116    Set StringData = langDict
117End Property
118
119'Initialize a given string variable by id
120Function InitString(ByRef resRef As String, resName As String)
121    resRef = langDict.item(resName)
122End Function
123
124Private Sub Class_Initialize()
125    Set langDict = New Scripting.Dictionary 'Allocate the string dictonary
126End Sub
127
128Private Sub Class_Terminate()
129    langDict.RemoveAll
130    Set langDict = Nothing 'Empty the dictionary and remove the instance
131End Sub
132