1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HGM_XML_PARSER_H 17 #define HGM_XML_PARSER_H 18 19 #include <string> 20 #include <unordered_map> 21 22 #include <libxml/parser.h> 23 #include <libxml/tree.h> 24 25 #include "hgm_command.h" 26 #include "hgm_log.h" 27 28 namespace OHOS::Rosen { 29 class XMLParser { 30 public: 31 int32_t LoadConfiguration(const char* fileDir); 32 int32_t Parse(); 33 void Destroy(); 34 XMLParser()35 explicit XMLParser() : xmlDocument_(nullptr) {} 36 ~XMLParser()37 ~XMLParser() 38 { 39 Destroy(); 40 } 41 GetParsedData()42 std::unique_ptr<PolicyConfigData> GetParsedData() 43 { 44 return std::move(mParsedData_); 45 } 46 47 private: 48 static int32_t GetHgmXmlNodeAsInt(xmlNode &node); 49 bool ParseInternal(xmlNode &node); 50 int32_t ParseParam(xmlNode &node); 51 int32_t ParseParams(xmlNode &node); 52 int32_t ParseStrategyConfig(xmlNode &node); 53 int32_t ParseScreenConfig(xmlNode &node); 54 int32_t ParseSimplex(xmlNode &node, std::unordered_map<std::string, std::string> &config, 55 const std::string valueName = "value", const std::string keyName = "name"); 56 int32_t ParserDynamicSetting(xmlNode &node, PolicyConfigData::DynamicSettingMap &dynamicSettingMap); 57 int32_t ParseSceneList(xmlNode &node, PolicyConfigData::SceneConfigMap &sceneList); 58 std::string ExtractPropertyValue(const std::string &propName, xmlNode &node); 59 static bool IsNumber(const std::string &str); 60 61 xmlDoc *xmlDocument_; 62 std::unique_ptr<PolicyConfigData> mParsedData_ = nullptr; 63 }; 64 } // namespace OHOS::Rosen 65 #endif // HGM_XML_PARSER_H