update dev300-m58
[ooovba.git] / migrationanalysis / src / driver_docs / sources / StringDataManager.cls
blob6bea8530bf95bf70bcf20120fe3a11abedac086f
1 VERSION 1.0 CLASS
2 BEGIN
3 MultiUse = -1 'True
4 END
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 '/*************************************************************************
11 ' *
12 ' * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13 ' *
14 ' * Copyright 2008 by Sun Microsystems, Inc.
15 ' *
16 ' * OpenOffice.org - a multi-platform office productivity suite
17 ' *
18 ' * $RCSfile: StringDataManager.cls,v $
19 ' *
20 ' * This file is part of OpenOffice.org.
21 ' *
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.
25 ' *
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).
31 ' *
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.
36 ' *
37 ' ************************************************************************/
39 Option Explicit
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
49 ' dictionary object.
50 Function InitStringData(fileName As String) As Boolean
51 On Error GoTo HandleErrors
52 Dim stringFile As TextStream
53 Dim aLine As String
54 Dim valueOffset As Long
55 Dim id, Str As String
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
62 Exit Function
63 End If
64 Set stringFile = fso.OpenTextFile(fileName, ForReading, False, TristateTrue)
65 If IsEmpty(stringFile) Then
66 'WriteDebug
67 End If
68 mFileName = fileName
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)
76 langDict.Add id, Str
77 Loop
78 stringFile.Close
80 Dim aProductName As String
81 Dim aProductVersion As String
82 Dim aNextProductVersion As String
83 Dim aKey As Variant
84 Dim aItem 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
99 End If
100 Next
102 InitStringData = True
104 FinalExit:
105 Exit Function
106 HandleErrors:
107 WriteDebug "InitStringData : " & Err.Number & " " & Err.Description & " " & Err.Source
108 InitStringData = False
109 End Function
111 'Set String Data from an existing dictionary
112 Public Property Set StringData(data As Scripting.Dictionary)
113 Set langDict = data
114 End Property
116 'Get String Data dictionary
117 Public Property Get StringData() As Scripting.Dictionary
118 Set StringData = langDict
119 End Property
121 'Initialize a given string variable by id
122 Function InitString(ByRef resRef As String, resName As String)
123 resRef = langDict.item(resName)
124 End Function
126 Private Sub Class_Initialize()
127 Set langDict = New Scripting.Dictionary 'Allocate the string dictonary
128 End Sub
130 Private Sub Class_Terminate()
131 langDict.RemoveAll
132 Set langDict = Nothing 'Empty the dictionary and remove the instance
133 End Sub