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