1 /* 2 * Copyright (c) 2021 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 OHOS_RESTOOL_CONFIG_PARSER_H 17 #define OHOS_RESTOOL_CONFIG_PARSER_H 18 19 #include <functional> 20 #include <set> 21 #include "resource_util.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace Restool { 26 class ConfigParser { 27 public: 28 enum class ModuleType { 29 NONE = 0, 30 HAR = 1, 31 ENTRY = 2, 32 FEATURE = 3, 33 SHARED = 4, 34 }; 35 36 ConfigParser(); 37 explicit ConfigParser(const std::string &filePath); 38 virtual ~ConfigParser(); 39 uint32_t Init(); 40 const std::string &GetPackageName() const; 41 const std::string &GetModuleName() const; 42 int32_t GetAbilityIconId() const; 43 int32_t GetAbilityLabelId() const; 44 bool SetAppIcon(std::string &icon, int32_t id); 45 bool SetAppLabel(std::string &label, int32_t id); 46 ModuleType GetModuleType() const; 47 uint32_t ParseRefence(); 48 uint32_t Save(const std::string &filePath) const; GetCheckNode()49 const std::map<std::string, std::set<uint32_t>> GetCheckNode() const 50 { 51 return jsonCheckIds_; 52 } SetDependEntry(const bool isDenpend)53 void SetDependEntry(const bool isDenpend) 54 { 55 dependEntry = isDenpend; 56 } IsDependEntry()57 bool IsDependEntry() 58 { 59 return dependEntry; 60 } SetUseModule()61 static void SetUseModule() 62 { 63 useModule_ = true; 64 }; GetConfigName()65 static std::string GetConfigName() 66 { 67 return useModule_ ? MODULE_JSON : CONFIG_JSON; 68 }; 69 private: 70 bool ParseModule(Json::Value &moduleNode); 71 bool ParseDistro(Json::Value &distroNode); 72 bool ParseAbilities(const Json::Value &abilites); 73 bool ParseAbilitiy(const Json::Value &ability, bool &isMainAbility); 74 bool IsMainAbility(const Json::Value &skills); 75 bool IsHomeAction(const Json::Value &actions); 76 bool dependEntry = false; 77 bool ParseRefImpl(Json::Value &parent, const std::string &key, Json::Value &node); 78 bool ParseJsonArrayRef(Json::Value &parent, const std::string &key, Json::Value &node); 79 bool ParseJsonStringRef(Json::Value &parent, const std::string &key, Json::Value &node); 80 bool GetRefIdFromString(std::string &value, bool &update, const std::string &match) const; 81 bool ParseModuleType(const std::string &type); 82 bool ParseAbilitiesForDepend(Json::Value &moduleNode); 83 void AddCheckNode(const std::string &key, uint32_t id); 84 std::string filePath_; 85 std::string packageName_; 86 std::string moduleName_; 87 ModuleType moduleType_; 88 Json::Value rootNode_; 89 std::string mainAbility_; 90 int32_t abilityIconId_; 91 int32_t abilityLabelId_; 92 std::map<std::string, std::set<uint32_t>> jsonCheckIds_; 93 static const std::map<std::string, ModuleType> MODULE_TYPES; 94 static const std::map<std::string, std::string> JSON_STRING_IDS; 95 static const std::map<std::string, std::string> JSON_ARRAY_IDS; 96 static bool useModule_; 97 }; 98 } 99 } 100 } 101 #endif