1cdf0e10cSrcweirVERSION 1.0 CLASS
2cdf0e10cSrcweirBEGIN
3cdf0e10cSrcweir  MultiUse = -1  'True
4cdf0e10cSrcweirEND
5cdf0e10cSrcweirAttribute VB_Name = "StringDataManager"
6cdf0e10cSrcweirAttribute VB_GlobalNameSpace = False
7cdf0e10cSrcweirAttribute VB_Creatable = False
8cdf0e10cSrcweirAttribute VB_PredeclaredId = False
9cdf0e10cSrcweirAttribute VB_Exposed = True
10*d4a3fa4bSAndrew Rist'*************************************************************************
11*d4a3fa4bSAndrew Rist'
12*d4a3fa4bSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
13*d4a3fa4bSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
14*d4a3fa4bSAndrew Rist'  distributed with this work for additional information
15*d4a3fa4bSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
16*d4a3fa4bSAndrew Rist'  to you under the Apache License, Version 2.0 (the
17*d4a3fa4bSAndrew Rist'  "License"); you may not use this file except in compliance
18*d4a3fa4bSAndrew Rist'  with the License.  You may obtain a copy of the License at
19*d4a3fa4bSAndrew Rist'
20*d4a3fa4bSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
21*d4a3fa4bSAndrew Rist'
22*d4a3fa4bSAndrew Rist'  Unless required by applicable law or agreed to in writing,
23*d4a3fa4bSAndrew Rist'  software distributed under the License is distributed on an
24*d4a3fa4bSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
25*d4a3fa4bSAndrew Rist'  KIND, either express or implied.  See the License for the
26*d4a3fa4bSAndrew Rist'  specific language governing permissions and limitations
27*d4a3fa4bSAndrew Rist'  under the License.
28*d4a3fa4bSAndrew Rist'
29*d4a3fa4bSAndrew Rist'*************************************************************************
30cdf0e10cSrcweir
31cdf0e10cSrcweirOption Explicit
32cdf0e10cSrcweirPrivate langDict As Scripting.Dictionary
33cdf0e10cSrcweirPrivate mFileName As String
34cdf0e10cSrcweir
35cdf0e10cSrcweirConst C_PRODUCTNAME = "<PRODUCTNAME>"
36cdf0e10cSrcweirConst C_PRODUCTVERSION = "<PRODUCTVERSION>"
37cdf0e10cSrcweirConst C_NEXTPRODUCTVERSION = "<NEXTPRODUCTVERSION>"
38cdf0e10cSrcweirConst C_NEWLINE = "<CR>"
39cdf0e10cSrcweir
40cdf0e10cSrcweir' Load strings from the data file (in the form "id=string") into
41cdf0e10cSrcweir' dictionary object.
42cdf0e10cSrcweirFunction InitStringData(fileName As String) As Boolean
43cdf0e10cSrcweir    On Error GoTo HandleErrors
44cdf0e10cSrcweir    Dim stringFile As TextStream
45cdf0e10cSrcweir    Dim aLine As String
46cdf0e10cSrcweir    Dim valueOffset As Long
47cdf0e10cSrcweir    Dim id, Str As String
48cdf0e10cSrcweir    Dim fso As FileSystemObject
49cdf0e10cSrcweir
50cdf0e10cSrcweir    'Make sure the string data file exists before opening.
51cdf0e10cSrcweir    Set fso = New Scripting.FileSystemObject
52cdf0e10cSrcweir    If Not fso.FileExists(fileName) Then
53cdf0e10cSrcweir        InitStringData = False
54cdf0e10cSrcweir        Exit Function
55cdf0e10cSrcweir    End If
56cdf0e10cSrcweir    Set stringFile = fso.OpenTextFile(fileName, ForReading, False, TristateTrue)
57cdf0e10cSrcweir    If IsEmpty(stringFile) Then
58cdf0e10cSrcweir        'WriteDebug
59cdf0e10cSrcweir    End If
60cdf0e10cSrcweir    mFileName = fileName
61cdf0e10cSrcweir
62cdf0e10cSrcweir    'Read each line and parse the id and string, then put into dictionary
63cdf0e10cSrcweir    Do While Not stringFile.AtEndOfStream
64cdf0e10cSrcweir        aLine = stringFile.ReadLine
65cdf0e10cSrcweir        valueOffset = InStr(aLine, "=")
66cdf0e10cSrcweir        id = Left(aLine, valueOffset - 1)
67cdf0e10cSrcweir        Str = Right(aLine, Len(aLine) - valueOffset)
68cdf0e10cSrcweir        langDict.Add id, Str
69cdf0e10cSrcweir    Loop
70cdf0e10cSrcweir    stringFile.Close
71cdf0e10cSrcweir
72cdf0e10cSrcweir    Dim aProductName As String
73cdf0e10cSrcweir    Dim aProductVersion As String
74cdf0e10cSrcweir    Dim aNextProductVersion As String
75cdf0e10cSrcweir    Dim aKey As Variant
76cdf0e10cSrcweir    Dim aItem As String
77cdf0e10cSrcweir    Dim aOldItem As String
78cdf0e10cSrcweir
79cdf0e10cSrcweir    aProductName = langDict.item("RID_STR_COMMON_PRODUCTNAME")
80cdf0e10cSrcweir    aProductVersion = langDict.item("RID_STR_COMMON_PRODUCTVERSION")
81cdf0e10cSrcweir    aNextProductVersion = langDict.item("RID_STR_COMMON_NEXTPRODUCTVERSION")
82cdf0e10cSrcweir
83cdf0e10cSrcweir    For Each aKey In langDict
84cdf0e10cSrcweir        aOldItem = langDict.item(aKey)
85cdf0e10cSrcweir        aItem = ReplaceTopicTokens(aOldItem, C_PRODUCTNAME, aProductName)
86cdf0e10cSrcweir        aItem = ReplaceTopicTokens(aItem, C_PRODUCTVERSION, aProductVersion)
87cdf0e10cSrcweir        aItem = ReplaceTopicTokens(aItem, C_NEXTPRODUCTVERSION, aNextProductVersion)
88cdf0e10cSrcweir        aItem = ReplaceTopicTokens(aItem, C_NEWLINE, vbLF)
89cdf0e10cSrcweir        If (Not (aOldItem = aItem)) Then
90cdf0e10cSrcweir            langDict.item(aKey) = aItem
91cdf0e10cSrcweir        End If
92cdf0e10cSrcweir    Next
93cdf0e10cSrcweir
94cdf0e10cSrcweir    InitStringData = True
95cdf0e10cSrcweir
96cdf0e10cSrcweirFinalExit:
97cdf0e10cSrcweir    Exit Function
98cdf0e10cSrcweirHandleErrors:
99cdf0e10cSrcweir    WriteDebug "InitStringData : " & Err.Number & " " & Err.Description & " " & Err.Source
100cdf0e10cSrcweir    InitStringData = False
101cdf0e10cSrcweirEnd Function
102cdf0e10cSrcweir
103cdf0e10cSrcweir'Set String Data from an existing dictionary
104cdf0e10cSrcweirPublic Property Set StringData(data As Scripting.Dictionary)
105cdf0e10cSrcweir    Set langDict = data
106cdf0e10cSrcweirEnd Property
107cdf0e10cSrcweir
108cdf0e10cSrcweir'Get String Data dictionary
109cdf0e10cSrcweirPublic Property Get StringData() As Scripting.Dictionary
110cdf0e10cSrcweir    Set StringData = langDict
111cdf0e10cSrcweirEnd Property
112cdf0e10cSrcweir
113cdf0e10cSrcweir'Initialize a given string variable by id
114cdf0e10cSrcweirFunction InitString(ByRef resRef As String, resName As String)
115cdf0e10cSrcweir    resRef = langDict.item(resName)
116cdf0e10cSrcweirEnd Function
117cdf0e10cSrcweir
118cdf0e10cSrcweirPrivate Sub Class_Initialize()
119cdf0e10cSrcweir    Set langDict = New Scripting.Dictionary 'Allocate the string dictonary
120cdf0e10cSrcweirEnd Sub
121cdf0e10cSrcweir
122cdf0e10cSrcweirPrivate Sub Class_Terminate()
123cdf0e10cSrcweir    langDict.RemoveAll
124cdf0e10cSrcweir    Set langDict = Nothing 'Empty the dictionary and remove the instance
125cdf0e10cSrcweirEnd Sub
126