Tpk profile handler 31/50831/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 2 Nov 2015 13:58:24 +0000 (14:58 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 4 Nov 2015 11:59:42 +0000 (03:59 -0800)
https://developer.tizen.org/ko/development/tools/native-tools/manifest-text-editor?langredirect=1#profile_element

Change-Id: I21e95986109a48a1e5e49d53b6b4b7ecc8c59e25

src/tpk_manifest_handlers/CMakeLists.txt
src/tpk_manifest_handlers/application_manifest_constants.cc
src/tpk_manifest_handlers/application_manifest_constants.h
src/tpk_manifest_handlers/profile_handler.cc [new file with mode: 0644]
src/tpk_manifest_handlers/profile_handler.h [new file with mode: 0644]
src/tpk_manifest_handlers/tpk_config_parser.cc

index 98053b75696e844b07556c1dcca25f30b565fa9c..e7985d14d766c045a214d9dd8c6dff6a96027ae0 100644 (file)
@@ -6,6 +6,7 @@ SET(SRCS
   description_handler.cc
   package_handler.cc
   privileges_handler.cc
+  profile_handler.cc
   service_application_handler.cc
   shortcut_handler.cc
   tpk_config_parser.cc
index 7032759d1a3117f6aed9bdc6378efc5b135dde71..23454cbb90498be22da27a5e50a95ac8c56f0834 100644 (file)
@@ -40,5 +40,8 @@ const char kShortcutLabelKey[] = "label";
 const char kShortcutLabelTextKey[] = "#text";
 const char kShortcutLabelLangKey[] = "@lang";
 
+//profile
+const char kProfileKey[] = "manifest.profile";
+
 }  // namespace application_keys
 }  // namespace tpk
index 8868735901133483bc45aaa93d085483ecebe799..e89f26a63899f6a2bd43486a9e7483b3b89db46a 100644 (file)
@@ -42,6 +42,9 @@ extern const char kShortcutLabelKey[];
 extern const char kShortcutLabelTextKey[];
 extern const char kShortcutLabelLangKey[];
 
+// profile
+extern const char kProfileKey[];
+
 }  // namespace application_keys
 }  // namespace tpk
 
diff --git a/src/tpk_manifest_handlers/profile_handler.cc b/src/tpk_manifest_handlers/profile_handler.cc
new file mode 100644 (file)
index 0000000..c98f8ac
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk_manifest_handlers/profile_handler.h"
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "manifest_parser/manifest_util.h"
+#include "tpk_manifest_handlers/application_manifest_constants.h"
+
+namespace tpk {
+namespace parse {
+
+namespace keys = tpk::application_keys;
+
+namespace {
+
+const char kProfileNameKey[] = "@name";
+
+}  // namespace
+
+bool ProfileHandler::Parse(
+    const parser::Manifest& manifest,
+    std::shared_ptr<parser::ManifestData>* output,
+    std::string* error) {
+  if (!manifest.HasPath(keys::kProfileKey))
+    return true;
+
+  std::shared_ptr<ProfileInfo> profile_info(new ProfileInfo());
+  for (auto& item : parser::GetOneOrMany(manifest.value(), keys::kProfileKey,
+                                         "")) {
+    std::string name;
+    if (!item->GetString(kProfileNameKey, &name)) {
+      *error = "Missing 'name' attribute in profile tag";
+      return false;
+    }
+    profile_info->AddProfile(name);
+  }
+
+  *output = std::static_pointer_cast<parser::ManifestData>(profile_info);
+  return true;
+}
+
+std::string ProfileHandler::Key() const {
+  return keys::kProfileKey;
+}
+
+}  // namespace parse
+}  // namespace tpk
diff --git a/src/tpk_manifest_handlers/profile_handler.h b/src/tpk_manifest_handlers/profile_handler.h
new file mode 100644 (file)
index 0000000..a1b9156
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_MANIFEST_HANDLERS_PROFILE_HANDLER_H_
+#define TPK_MANIFEST_HANDLERS_PROFILE_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+#include "tpk_manifest_handlers/application_manifest_constants.h"
+
+namespace tpk {
+namespace parse {
+
+class ProfileInfo : public parser::ManifestData {
+ public:
+  void AddProfile(const std::string& profile) {
+    profiles_.push_back(profile);
+  }
+
+  const std::vector<std::string>& profiles() const {
+    return profiles_;
+  }
+
+ private:
+  std::vector<std::string> profiles_;
+};
+
+/**
+ * @brief The ProfileHandler class
+ *
+ * Handler of tizen-manifest.xml for xml elements:
+ *  <profile>
+ */
+class ProfileHandler : public parser::ManifestHandler {
+ public:
+  bool Parse(
+      const parser::Manifest& manifest,
+      std::shared_ptr<parser::ManifestData>* output,
+      std::string* error) override;
+  std::string Key() const override;
+};
+
+}   // namespace parse
+}   // namespace tpk
+
+#endif  // TPK_MANIFEST_HANDLERS_PROFILE_HANDLER_H_
index 3021cc9fbe69294cc75c3acdddf9eed75a394e19..4a1536345b646844915af41e5314d0fbaf0924e9 100644 (file)
@@ -20,6 +20,7 @@
 #include "tpk_manifest_handlers/description_handler.h"
 #include "tpk_manifest_handlers/package_handler.h"
 #include "tpk_manifest_handlers/privileges_handler.h"
+#include "tpk_manifest_handlers/profile_handler.h"
 #include "tpk_manifest_handlers/service_application_handler.h"
 #include "tpk_manifest_handlers/shortcut_handler.h"
 #include "tpk_manifest_handlers/ui_application_handler.h"
@@ -42,6 +43,7 @@ TPKConfigParser::TPKConfigParser() {
   new DescriptionHandler,
   new PackageHandler,
   new PrivilegesHandler,
+  new ProfileHandler,
   new ServiceApplicationHandler,
   new UIApplicationHandler,
   new ShortcutHandler