| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * This file incorporates work covered by the following license notice: |
| 10 | * |
| 11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 | * contributor license agreements. See the NOTICE file distributed |
| 13 | * with this work for additional information regarding copyright |
| 14 | * ownership. The ASF licenses this file to you under the Apache |
| 15 | * License, Version 2.0 (the "License"); you may not use this file |
| 16 | * except in compliance with the License. You may obtain a copy of |
| 17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 | */ |
| 19 | |
| 20 | #ifndef INCLUDED_L10NTOOLS_INC_XRMMERGE_HXX |
| 21 | #define INCLUDED_L10NTOOLS_INC_XRMMERGE_HXX |
| 22 | |
| 23 | #include <memory> |
| 24 | #include <sal/config.h> |
| 25 | |
| 26 | #include <fstream> |
| 27 | #include <string_view> |
| 28 | |
| 29 | #include <rtl/string.hxx> |
| 30 | |
| 31 | #include "export.hxx" |
| 32 | #include "po.hxx" |
| 33 | |
| 34 | /// Parser for *.xrm and description.xml files |
| 35 | class XRMResParser |
| 36 | { |
| 37 | private: |
| 38 | OString sGID; |
| 39 | |
| 40 | bool bError; |
| 41 | bool bText; |
| 42 | |
| 43 | OString sCurrentOpenTag; |
| 44 | OString sCurrentCloseTag; |
| 45 | OString sCurrentText; |
| 46 | protected: |
| 47 | static OString GetAttribute( const OString &rToken, std::string_view rAttribute ); |
| 48 | static void Error( const OString &rError ); |
| 49 | |
| 50 | virtual void Output( const OString& rOutput )=0; |
| 51 | virtual void WorkOnDesc( |
| 52 | const OString &rOpenTag, |
| 53 | OString &rText |
| 54 | )=0; |
| 55 | virtual void WorkOnText( |
| 56 | const OString &rOpenTag, |
| 57 | OString &rText |
| 58 | )=0; |
| 59 | virtual void EndOfText( |
| 60 | const OString &rOpenTag, |
| 61 | const OString &rCloseTag |
| 62 | )=0; |
| 63 | |
| 64 | const OString& GetGID() const { return sGID; } |
| 65 | |
| 66 | public: |
| 67 | XRMResParser(); |
| 68 | virtual ~XRMResParser(); |
| 69 | |
| 70 | void Execute( int nToken, char * pToken ); |
| 71 | |
| 72 | void SetError() { bError = true; } |
| 73 | bool GetError() const { return bError; } |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | /// Export strings from *.xrm and description.xml files |
| 78 | class XRMResExport final : public XRMResParser |
| 79 | { |
| 80 | private: |
| 81 | std::unique_ptr<ResData> pResData; |
| 82 | OString sPath; |
| 83 | PoOfstream pOutputStream; |
| 84 | |
| 85 | void WorkOnDesc( |
| 86 | const OString &rOpenTag, |
| 87 | OString &rText |
| 88 | ) override; |
| 89 | void WorkOnText( |
| 90 | const OString &rOpenTag, |
| 91 | OString &rText |
| 92 | ) override; |
| 93 | void EndOfText( |
| 94 | const OString &rOpenTag, |
| 95 | const OString &rCloseTag |
| 96 | ) override; |
| 97 | void Output( const OString& rOutput ) override; |
| 98 | |
| 99 | public: |
| 100 | XRMResExport( |
| 101 | const OString &rOutputFile, |
| 102 | OString sFilePath |
| 103 | ); |
| 104 | virtual ~XRMResExport() override; |
| 105 | }; |
| 106 | |
| 107 | |
| 108 | /// Merge strings to *.xrm and description.xml files |
| 109 | class XRMResMerge final : public XRMResParser |
| 110 | { |
| 111 | private: |
| 112 | std::unique_ptr<MergeDataFile> pMergeDataFile; |
| 113 | OString sFilename; |
| 114 | std::unique_ptr<ResData> pResData; |
| 115 | std::ofstream pOutputStream; |
| 116 | std::vector<OString> aLanguages; |
| 117 | |
| 118 | void WorkOnDesc( |
| 119 | const OString &rOpenTag, |
| 120 | OString &rText |
| 121 | ) override; |
| 122 | void WorkOnText( |
| 123 | const OString &rOpenTag, |
| 124 | OString &rText |
| 125 | ) override; |
| 126 | void EndOfText( |
| 127 | const OString &rOpenTag, |
| 128 | const OString &rCloseTag |
| 129 | ) override; |
| 130 | void Output( const OString& rOutput ) override; |
| 131 | public: |
| 132 | XRMResMerge( |
| 133 | const OString &rMergeSource, |
| 134 | const OString &rOutputFile, |
| 135 | OString sFilename |
| 136 | ); |
| 137 | virtual ~XRMResMerge() override; |
| 138 | }; |
| 139 | |
| 140 | #endif // INCLUDED_L10NTOOLS_INC_XRMMERGE_HXX |
| 141 | |
| 142 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |