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