Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _CFG_MERGE_HXX
30 : : #define _CFG_MERGE_HXX
31 : :
32 : : #include "sal/config.h"
33 : :
34 : : #include <fstream>
35 : : #include <vector>
36 : :
37 : : #include "boost/unordered_map.hpp"
38 : :
39 : : typedef boost::unordered_map<rtl::OString, rtl::OString, rtl::OStringHash> OStringHashMap;
40 : :
41 : :
42 : : //
43 : : // class CfgStackData
44 : : //
45 : :
46 : 0 : class CfgStackData
47 : : {
48 : : friend class CfgParser;
49 : : friend class CfgExport;
50 : : friend class CfgMerge;
51 : : private:
52 : : rtl::OString sTagType;
53 : : rtl::OString sIdentifier;
54 : :
55 : : rtl::OString sResTyp;
56 : :
57 : : rtl::OString sTextTag;
58 : : rtl::OString sEndTextTag;
59 : :
60 : : OStringHashMap sText;
61 : : public:
62 : 0 : CfgStackData(const rtl::OString &rTag, const rtl::OString &rId)
63 : 0 : : sTagType( rTag ), sIdentifier( rId )
64 : 0 : {}
65 : :
66 : 0 : const rtl::OString &GetTagType() { return sTagType; }
67 : 0 : const rtl::OString &GetIdentifier() { return sIdentifier; }
68 : :
69 : : };
70 : :
71 : : //
72 : : // class CfgStack
73 : : //
74 : :
75 : : typedef std::vector< CfgStackData* > CfgStackList;
76 : :
77 : : class CfgStack
78 : : {
79 : : private:
80 : : CfgStackList maList;
81 : :
82 : : public:
83 : 0 : CfgStack() {}
84 : : ~CfgStack();
85 : :
86 : : CfgStackData *Push(const rtl::OString &rTag, const rtl::OString &rId);
87 : 0 : CfgStackData *Pop()
88 : : {
89 : 0 : if (maList.empty())
90 : 0 : return NULL;
91 : 0 : CfgStackData* temp = maList.back();
92 : 0 : maList.pop_back();
93 : 0 : return temp;
94 : : }
95 : :
96 : : CfgStackData *GetStackData();
97 : :
98 : : rtl::OString GetAccessPath( size_t nPos );
99 : :
100 : 0 : size_t size() const { return maList.size(); }
101 : : };
102 : :
103 : : //
104 : : // class CfgParser
105 : : //
106 : :
107 : : class CfgParser
108 : : {
109 : : protected:
110 : : rtl::OString sCurrentResTyp;
111 : : rtl::OString sCurrentIsoLang;
112 : : rtl::OString sCurrentText;
113 : :
114 : : rtl::OString sLastWhitespace;
115 : :
116 : : CfgStack aStack;
117 : : CfgStackData *pStackData;
118 : :
119 : : sal_Bool bLocalize;
120 : :
121 : : virtual void WorkOnText(
122 : : rtl::OString &rText,
123 : : const rtl::OString &rLangIndex )=0;
124 : :
125 : : virtual void WorkOnResourceEnd()=0;
126 : :
127 : : virtual void Output(const rtl::OString & rOutput)=0;
128 : :
129 : : void Error(const rtl::OString &rError);
130 : :
131 : : private:
132 : : int ExecuteAnalyzedToken( int nToken, char *pToken );
133 : : std::vector<rtl::OString> aLanguages;
134 : : void AddText(
135 : : rtl::OString &rText,
136 : : const rtl::OString &rIsoLang,
137 : : const rtl::OString &rResTyp );
138 : :
139 : : sal_Bool IsTokenClosed(const rtl::OString &rToken);
140 : :
141 : : public:
142 : : CfgParser();
143 : : virtual ~CfgParser();
144 : :
145 : : int Execute( int nToken, char * pToken );
146 : : };
147 : :
148 : : //
149 : : // class CfgOutputParser
150 : : //
151 : :
152 : : class CfgOutputParser : public CfgParser
153 : : {
154 : : protected:
155 : : std::ofstream pOutputStream;
156 : : public:
157 : : CfgOutputParser(const rtl::OString &rOutputFile);
158 : : virtual ~CfgOutputParser();
159 : : };
160 : :
161 : : //
162 : : // class CfgExport
163 : : //
164 : :
165 : : class CfgExport : public CfgOutputParser
166 : : {
167 : : private:
168 : : rtl::OString sPrj;
169 : : rtl::OString sPath;
170 : : std::vector<rtl::OString> aLanguages;
171 : : protected:
172 : : virtual void WorkOnText(
173 : : rtl::OString &rText,
174 : : const rtl::OString &rIsoLang
175 : : );
176 : :
177 : : void WorkOnResourceEnd();
178 : : void Output(const rtl::OString& rOutput);
179 : : public:
180 : : CfgExport(
181 : : const rtl::OString &rOutputFile,
182 : : const rtl::OString &rProject,
183 : : const rtl::OString &rFilePath
184 : : );
185 : : ~CfgExport();
186 : : };
187 : :
188 : : //
189 : : // class CfgMerge
190 : : //
191 : :
192 : : class CfgMerge : public CfgOutputParser
193 : : {
194 : : private:
195 : : MergeDataFile *pMergeDataFile;
196 : : std::vector<rtl::OString> aLanguages;
197 : : ResData *pResData;
198 : :
199 : : rtl::OString sFilename;
200 : : sal_Bool bEnglish;
201 : :
202 : : protected:
203 : : virtual void WorkOnText(rtl::OString &rText, const rtl::OString &rLangIndex);
204 : :
205 : : void WorkOnResourceEnd();
206 : :
207 : : void Output(const rtl::OString& rOutput);
208 : : public:
209 : : CfgMerge(const rtl::OString &rMergeSource,
210 : : const rtl::OString &rOutputFile, const rtl::OString &rFilename);
211 : : ~CfgMerge();
212 : : };
213 : :
214 : : #endif
215 : :
216 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|