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