• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "frameworks/bridge/common/manifest/manifest_parser.h"
17 
18 namespace OHOS::Ace::Framework {
19 
ManifestParser()20 ManifestParser::ManifestParser()
21     : manifestAppInfo_(Referenced::MakeRefPtr<ManifestAppInfo>()),
22       manifestRouter_(Referenced::MakeRefPtr<ManifestRouter>()),
23       manifestWidget_(Referenced::MakeRefPtr<ManifestWidgetGroup>()),
24       manifestWindow_(Referenced::MakeRefPtr<ManifestWindow>())
25 {}
26 
GetAppInfo() const27 const RefPtr<ManifestAppInfo>& ManifestParser::GetAppInfo() const
28 {
29     return manifestAppInfo_;
30 }
31 
GetRouter() const32 const RefPtr<ManifestRouter>& ManifestParser::GetRouter() const
33 {
34     return manifestRouter_;
35 }
36 
GetWidget() const37 const RefPtr<ManifestWidgetGroup>& ManifestParser::GetWidget() const
38 {
39     return manifestWidget_;
40 }
41 
GetWindowConfig()42 WindowConfig& ManifestParser::GetWindowConfig()
43 {
44     return manifestWindow_->GetWindowConfig();
45 }
46 
Parse(const std::string & contents)47 void ManifestParser::Parse(const std::string& contents)
48 {
49     auto rootJson = JsonUtil::ParseJsonString(contents);
50     if (!rootJson || !rootJson->IsValid()) {
51         LOGE("the manifest is illegal");
52         return;
53     }
54     manifestAppInfo_->AppInfoParse(rootJson);
55     manifestRouter_->RouterParse(rootJson);
56     manifestWidget_->WidgetParse(rootJson);
57     manifestWindow_->WindowParse(rootJson);
58     webFeature_ = rootJson->GetBool("webFeature", false);
59     auto deviceTypes = rootJson->GetValue("deviceType");
60     if (deviceTypes && deviceTypes->IsArray()) {
61         for (int32_t index = 0; index < deviceTypes->GetArraySize(); ++index) {
62             auto device = deviceTypes->GetArrayItem(index);
63             if (device && device->IsString() && device->GetString() == "liteWearable") {
64                 useLiteStyle_ = true;
65                 break;
66             }
67         }
68     }
69 }
70 
Printer()71 void ManifestParser::Printer()
72 {
73 #ifdef ACE_DEBUG_LOG
74     LOGD("appinfo:{");
75     LOGD("  Icon:%{private}s", manifestAppInfo_->GetIcon().c_str());
76     LOGD("  LogLevel:%{public}s", manifestAppInfo_->GetLogLevel().c_str());
77     LOGD("  Name:%{public}s", manifestAppInfo_->GetAppName().c_str());
78     LOGD("  AppID:%{public}s", manifestAppInfo_->GetAppID().c_str());
79     LOGD("  VersionCode:%{public}d", manifestAppInfo_->GetVersionCode());
80     LOGD("  VersionName:%{public}s", manifestAppInfo_->GetVersionName().c_str());
81     LOGD("  minPlatformVersion:%{public}d", manifestAppInfo_->GetMinPlatformVersion());
82     LOGD("}");
83 
84     LOGD("router:{");
85     LOGD("  entry:%{private}s", manifestRouter_->GetEntry().c_str());
86     LOGD("  pages:{");
87     for (const auto& page : manifestRouter_->GetPageList()) {
88         LOGD("    %{private}s", page.c_str());
89     }
90     LOGD("}");
91 
92     manifestWindow_->PrintInfo();
93 #endif
94 }
95 
96 } // namespace OHOS::Ace::Framework
97