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