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 XML_PARSER_BASE_H 17 #define XML_PARSER_BASE_H 18 19 #include <string> 20 #include <unordered_map> 21 22 #include <libxml/parser.h> 23 #include <libxml/tree.h> 24 25 #include "platform/common/rs_log.h" 26 #include "feature_param.h" 27 28 namespace OHOS::Rosen { 29 using FeatureParamMapType = std::unordered_map<std::string, std::shared_ptr<FeatureParam>>; 30 31 enum ParseXmlNode { 32 PARSE_XML_UNDEFINED = 0, 33 PARSE_XML_FEATURE_SWITCH, 34 PARSE_XML_FEATURE_SINGLEPARAM, 35 PARSE_XML_FEATURE_MULTIPARAM, 36 }; 37 38 class XMLParserBase { 39 public: 40 void Destroy(); 41 ~XMLParserBase()42 virtual ~XMLParserBase() 43 { 44 Destroy(); 45 } 46 ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)47 virtual int32_t ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node) 48 { 49 return 0; 50 }; 51 52 int32_t LoadGraphicConfiguration(const std::string& fileDir); 53 int32_t ParseSysDoc(); 54 int32_t ParseProdDoc(); 55 bool ParseFeatureSwitch(std::string val); 56 std::string ParseFeatureMultiParam(std::string type, std::string val); 57 58 std::string ExtractPropertyValue(const std::string &propName, xmlNode &node); 59 int32_t GetXmlNodeAsInt(xmlNode &node); 60 static bool IsNumber(const std::string& str); 61 62 private: 63 int32_t LoadSysConfiguration(const std::string& fileDir); 64 void LoadProdConfiguration(const std::string& fileDir); 65 bool ParseInternal(xmlNode &node); 66 xmlDoc *xmlSysDocument_ = nullptr; 67 xmlDoc *xmlProdDocument_ = nullptr; 68 std::vector<std::string> sysPaths_ = {"/system/variant/phone/base/", "/system/variant/tablet/base/", 69 "/system/variant/pc/base/", "/system/variant/watch/base/", "/system/variant/tv/base/", 70 "/system/variant/car/base/", "/system/variant/smarthomehost/base/"}; 71 std::string prodPath_ = "/sys_prod/"; 72 }; 73 } // namespace OHOS::Rosen 74 #endif // XML_PARSER_BASE_H 75