5 Attribute VB_Name = "StringDataManager"
6 Attribute VB_GlobalNameSpace = False
7 Attribute VB_Creatable = False
8 Attribute VB_PredeclaredId = False
9 Attribute VB_Exposed = True
10 '/*************************************************************************
12 ' * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14 ' * Copyright
2008 by Sun Microsystems, Inc.
16 ' * OpenOffice.org - a multi-platform office productivity suite
18 ' * $RCSfile: StringDataManager.cls,v $
20 ' * This file is part of OpenOffice.org.
22 ' * OpenOffice.org is free software: you can redistribute it and/or modify
23 ' * it under the terms of the GNU Lesser General Public License version
3
24 ' * only, as published by the Free Software Foundation.
26 ' * OpenOffice.org is distributed in the hope that it will be useful,
27 ' * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ' * GNU Lesser General Public License version
3 for more details
30 ' * (a copy is included in the LICENSE file that accompanied this code).
32 ' * You should have received a copy of the GNU Lesser General Public License
33 ' * version
3 along with OpenOffice.org. If not, see
34 ' * <http://www.openoffice.org/license.html>
35 ' * for a copy of the LGPLv3 License.
37 ' ************************************************************************/
40 Private langDict As Scripting.Dictionary
41 Private mFileName As String
43 Const C_PRODUCTNAME = "<PRODUCTNAME>"
44 Const C_PRODUCTVERSION = "<PRODUCTVERSION>"
45 Const C_NEXTPRODUCTVERSION = "<NEXTPRODUCTVERSION>"
46 Const C_NEWLINE = "<CR>"
48 ' Load strings from the data file (in the form "id=string") into
50 Function InitStringData(fileName As String) As Boolean
51 On Error GoTo HandleErrors
52 Dim stringFile As TextStream
54 Dim valueOffset As Long
56 Dim fso As FileSystemObject
58 'Make sure the string data file exists before opening.
59 Set fso = New Scripting.FileSystemObject
60 If Not fso.FileExists(fileName) Then
61 InitStringData = False
64 Set stringFile = fso.OpenTextFile(fileName, ForReading, False, TristateTrue)
65 If IsEmpty(stringFile) Then
70 'Read each line and parse the id and string, then put into dictionary
71 Do While Not stringFile.AtEndOfStream
72 aLine = stringFile.ReadLine
73 valueOffset = InStr(aLine, "=")
74 id = Left(aLine, valueOffset -
1)
75 Str = Right(aLine, Len(aLine) - valueOffset)
80 Dim aProductName As String
81 Dim aProductVersion As String
82 Dim aNextProductVersion As String
85 Dim aOldItem As String
87 aProductName = langDict.item("RID_STR_COMMON_PRODUCTNAME")
88 aProductVersion = langDict.item("RID_STR_COMMON_PRODUCTVERSION")
89 aNextProductVersion = langDict.item("RID_STR_COMMON_NEXTPRODUCTVERSION")
91 For Each aKey In langDict
92 aOldItem = langDict.item(aKey)
93 aItem = ReplaceTopicTokens(aOldItem, C_PRODUCTNAME, aProductName)
94 aItem = ReplaceTopicTokens(aItem, C_PRODUCTVERSION, aProductVersion)
95 aItem = ReplaceTopicTokens(aItem, C_NEXTPRODUCTVERSION, aNextProductVersion)
96 aItem = ReplaceTopicTokens(aItem, C_NEWLINE, vbLF)
97 If (Not (aOldItem = aItem)) Then
98 langDict.item(aKey) = aItem
102 InitStringData = True
107 WriteDebug "InitStringData : " & Err.Number & " " & Err.Description & " " & Err.Source
108 InitStringData = False
111 'Set String Data from an existing dictionary
112 Public Property Set StringData(data As Scripting.Dictionary)
116 'Get String Data dictionary
117 Public Property Get StringData() As Scripting.Dictionary
118 Set StringData = langDict
121 'Initialize a given string variable by id
122 Function InitString(ByRef resRef As String, resName As String)
123 resRef = langDict.item(resName)
126 Private Sub Class_Initialize()
127 Set langDict = New Scripting.Dictionary 'Allocate the string dictonary
130 Private Sub Class_Terminate()
132 Set langDict = Nothing 'Empty the dictionary and remove the instance