xref: /aoo41x/main/l10ntools/inc/cfgmerge.hxx (revision 983d4c8a)
1*983d4c8aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*983d4c8aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*983d4c8aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*983d4c8aSAndrew Rist  * distributed with this work for additional information
6*983d4c8aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*983d4c8aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*983d4c8aSAndrew Rist  * "License"); you may not use this file except in compliance
9*983d4c8aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*983d4c8aSAndrew Rist  *
11*983d4c8aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*983d4c8aSAndrew Rist  *
13*983d4c8aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*983d4c8aSAndrew Rist  * software distributed under the License is distributed on an
15*983d4c8aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*983d4c8aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*983d4c8aSAndrew Rist  * specific language governing permissions and limitations
18*983d4c8aSAndrew Rist  * under the License.
19*983d4c8aSAndrew Rist  *
20*983d4c8aSAndrew Rist  *************************************************************/
21*983d4c8aSAndrew Rist 
22*983d4c8aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CFG_MERGE_HXX
25cdf0e10cSrcweir #define _CFG_MERGE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/string.hxx>
28cdf0e10cSrcweir #include <tools/list.hxx>
29cdf0e10cSrcweir #include <hash_map>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir typedef std::hash_map<ByteString , ByteString , hashByteString,equalByteString>
32cdf0e10cSrcweir                                 ByteStringHashMap;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //
36cdf0e10cSrcweir // class CfgStackData
37cdf0e10cSrcweir //
38cdf0e10cSrcweir 
39cdf0e10cSrcweir class CfgStackData
40cdf0e10cSrcweir {
41cdf0e10cSrcweir friend class CfgParser;
42cdf0e10cSrcweir friend class CfgExport;
43cdf0e10cSrcweir friend class CfgMerge;
44cdf0e10cSrcweir private:
45cdf0e10cSrcweir 	ByteString sTagType;
46cdf0e10cSrcweir 	ByteString sIdentifier;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	ByteString sResTyp;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	ByteString sTextTag;
51cdf0e10cSrcweir 	ByteString sEndTextTag;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     ByteStringHashMap sText;
54cdf0e10cSrcweir public:
CfgStackData(const ByteString & rTag,const ByteString & rId)55cdf0e10cSrcweir 	CfgStackData( const ByteString &rTag, const ByteString &rId )
56cdf0e10cSrcweir 			: sTagType( rTag ), sIdentifier( rId ) {};
57cdf0e10cSrcweir 
GetTagType()58cdf0e10cSrcweir 	ByteString &GetTagType() { return sTagType; }
GetIdentifier()59cdf0e10cSrcweir 	ByteString &GetIdentifier() { return sIdentifier; }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //
64cdf0e10cSrcweir // class CfgStack
65cdf0e10cSrcweir //
66cdf0e10cSrcweir 
67cdf0e10cSrcweir DECLARE_LIST( CfgStackList, CfgStackData * )
68cdf0e10cSrcweir 
69cdf0e10cSrcweir class CfgStack : public CfgStackList
70cdf0e10cSrcweir {
71cdf0e10cSrcweir public:
CfgStack()72cdf0e10cSrcweir 	CfgStack() : CfgStackList( 10, 10 ) {}
73cdf0e10cSrcweir 	~CfgStack();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	sal_uLong Push( CfgStackData *pStackData );
76cdf0e10cSrcweir     CfgStackData *Push( const ByteString &rTag, const ByteString &rId );
Pop()77cdf0e10cSrcweir 	CfgStackData *Pop() { return Remove( Count() - 1 ); }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	CfgStackData *GetStackData( sal_uLong nPos = LIST_APPEND );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	ByteString GetAccessPath( sal_uLong nPos = LIST_APPEND );
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //
85cdf0e10cSrcweir // class CfgParser
86cdf0e10cSrcweir //
87cdf0e10cSrcweir 
88cdf0e10cSrcweir class CfgParser
89cdf0e10cSrcweir {
90cdf0e10cSrcweir protected:
91cdf0e10cSrcweir 	ByteString sCurrentResTyp;
92cdf0e10cSrcweir 	ByteString sCurrentIsoLang;
93cdf0e10cSrcweir 	ByteString sCurrentText;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	ByteString sLastWhitespace;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	CfgStack aStack;
98cdf0e10cSrcweir 	CfgStackData *pStackData;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	sal_Bool bLocalize;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	virtual void WorkOnText(
103cdf0e10cSrcweir 		ByteString &rText,
104cdf0e10cSrcweir         const ByteString &nLangIndex )=0;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	virtual void WorkOnRessourceEnd()=0;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	virtual void Output( const ByteString& rOutput )=0;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	void Error( const ByteString &rError );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir private:
113cdf0e10cSrcweir 	int ExecuteAnalyzedToken( int nToken, char *pToken );
114cdf0e10cSrcweir     std::vector<ByteString> aLanguages;
115cdf0e10cSrcweir 	void AddText(
116cdf0e10cSrcweir 		ByteString &rText,
117cdf0e10cSrcweir 		const ByteString &rIsoLang,
118cdf0e10cSrcweir 		const ByteString &rResTyp );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir sal_Bool IsTokenClosed( const ByteString &rToken );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir public:
123cdf0e10cSrcweir 	CfgParser();
124cdf0e10cSrcweir 	virtual ~CfgParser();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	int Execute( int nToken, char * pToken );
127cdf0e10cSrcweir };
128cdf0e10cSrcweir 
129cdf0e10cSrcweir //
130cdf0e10cSrcweir // class CfgOutputParser
131cdf0e10cSrcweir //
132cdf0e10cSrcweir 
133cdf0e10cSrcweir class CfgOutputParser : public CfgParser
134cdf0e10cSrcweir {
135cdf0e10cSrcweir protected:
136cdf0e10cSrcweir 	SvFileStream *pOutputStream;
137cdf0e10cSrcweir public:
138cdf0e10cSrcweir 	CfgOutputParser ( const ByteString &rOutputFile );
139cdf0e10cSrcweir 	virtual ~CfgOutputParser();
140cdf0e10cSrcweir };
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //
143cdf0e10cSrcweir // class CfgExport
144cdf0e10cSrcweir //
145cdf0e10cSrcweir 
146cdf0e10cSrcweir class CfgExport : public CfgOutputParser
147cdf0e10cSrcweir {
148cdf0e10cSrcweir private:
149cdf0e10cSrcweir 	ByteString sPrj;
150cdf0e10cSrcweir 	ByteString sPath;
151cdf0e10cSrcweir     std::vector<ByteString> aLanguages;
152cdf0e10cSrcweir protected:
153cdf0e10cSrcweir 	void WorkOnText(
154cdf0e10cSrcweir 		ByteString &rText,
155cdf0e10cSrcweir         const ByteString &rIsoLang
156cdf0e10cSrcweir         );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     void WorkOnRessourceEnd();
159cdf0e10cSrcweir     void Output( const ByteString& rOutput );
160cdf0e10cSrcweir public:
161cdf0e10cSrcweir     CfgExport(
162cdf0e10cSrcweir 		const ByteString &rOutputFile,
163cdf0e10cSrcweir 		const ByteString &rProject,
164cdf0e10cSrcweir 		const ByteString &rFilePath
165cdf0e10cSrcweir 	);
166cdf0e10cSrcweir 	~CfgExport();
167cdf0e10cSrcweir };
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //
170cdf0e10cSrcweir // class CfgMerge
171cdf0e10cSrcweir //
172cdf0e10cSrcweir 
173cdf0e10cSrcweir class CfgMerge : public CfgOutputParser
174cdf0e10cSrcweir {
175cdf0e10cSrcweir private:
176cdf0e10cSrcweir 	MergeDataFile *pMergeDataFile;
177cdf0e10cSrcweir     std::vector<ByteString> aLanguages;
178cdf0e10cSrcweir 	ResData *pResData;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	sal_Bool bGerman;
181cdf0e10cSrcweir     ByteString sFilename;
182cdf0e10cSrcweir 	sal_Bool bEnglish;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir protected:
185cdf0e10cSrcweir 	void WorkOnText(
186cdf0e10cSrcweir 		ByteString &rText,
187cdf0e10cSrcweir         const ByteString &nLangIndex );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	void WorkOnRessourceEnd();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	void Output( const ByteString& rOutput );
192cdf0e10cSrcweir public:
193cdf0e10cSrcweir     CfgMerge(
194cdf0e10cSrcweir 		const ByteString &rMergeSource,
195cdf0e10cSrcweir 		const ByteString &rOutputFile,
196cdf0e10cSrcweir 		ByteString &rFilename
197cdf0e10cSrcweir 	);
198cdf0e10cSrcweir 	~CfgMerge();
199cdf0e10cSrcweir };
200cdf0e10cSrcweir 
201cdf0e10cSrcweir #endif
202