Add background-category parsing from metadata element 56/54456/29 accepted/tizen/mobile/20160115.010736 accepted/tizen/mobile/20160115.010919 accepted/tizen/tv/20160115.010748 accepted/tizen/tv/20160115.010933 accepted/tizen/wearable/20160115.010807 accepted/tizen/wearable/20160115.010954 submit/tizen/20160114.141522 submit/tizen/20160114.224350
authorLukasz Wysocki <l.wysocki@samsung.com>
Tue, 15 Dec 2015 09:49:46 +0000 (10:49 +0100)
committerLukasz Wysocki <l.wysocki@samsung.com>
Thu, 14 Jan 2016 12:14:44 +0000 (13:14 +0100)
Refactoring UI, Service and Widget Application Handlers

This commit is required by following change:
- https://review.tizen.org/gerrit/#/c/54915/

This change requires:
- https://review.tizen.org/gerrit/#/c/55660/
- https://review.tizen.org/gerrit/#/c/55192/

Change-Id: I65d5617f80a2f426ca297b5ca9ad22ce910c2262

62 files changed:
packaging/manifest-parser.spec
src/CMakeLists.txt
src/manifest_handlers/account_handler.cc
src/manifest_handlers/app_control_handler.cc
src/manifest_handlers/application_icons_handler.cc
src/manifest_handlers/category_handler.cc
src/manifest_handlers/content_handler.cc
src/manifest_handlers/ime_handler.cc
src/manifest_handlers/metadata_handler.cc
src/manifest_handlers/permissions_handler.cc
src/manifest_handlers/platform_version.h
src/manifest_handlers/splash_screen_handler.cc
src/manifest_handlers/tizen_application_handler.cc
src/manifest_handlers/widget_config_parser.cc
src/manifest_handlers/widget_handler.cc
src/manifest_parser/CMakeLists.txt
src/manifest_parser/manifest_util.cc
src/manifest_parser/utils/CMakeLists.txt [new file with mode: 0644]
src/manifest_parser/utils/iri_util.cc [new file with mode: 0644]
src/manifest_parser/utils/iri_util.h [new file with mode: 0644]
src/manifest_parser/utils/language_tag_validator.cc [new file with mode: 0644]
src/manifest_parser/utils/language_tag_validator.h [new file with mode: 0644]
src/manifest_parser/utils/logging.h [new file with mode: 0644]
src/manifest_parser/utils/manifest-parser-utils.pc.in [new file with mode: 0644]
src/manifest_parser/utils/string_util.cc [new file with mode: 0644]
src/manifest_parser/utils/string_util.h [new file with mode: 0644]
src/manifest_parser/utils/version_number.cc [new file with mode: 0644]
src/manifest_parser/utils/version_number.h [new file with mode: 0644]
src/manifest_parser/utils/w3c_languages.cc [new file with mode: 0644]
src/manifest_parser/utils/w3c_languages.h [new file with mode: 0644]
src/manifest_parser/values.cc
src/tpk_manifest_handlers/CMakeLists.txt
src/tpk_manifest_handlers/account_handler.cc
src/tpk_manifest_handlers/author_handler.cc
src/tpk_manifest_handlers/common/application_handler.cc [new file with mode: 0644]
src/tpk_manifest_handlers/common/application_handler.h [new file with mode: 0644]
src/tpk_manifest_handlers/description_handler.cc
src/tpk_manifest_handlers/package_handler.cc
src/tpk_manifest_handlers/privileges_handler.cc
src/tpk_manifest_handlers/service_application_handler.cc
src/tpk_manifest_handlers/service_application_handler.h
src/tpk_manifest_handlers/shortcut_handler.cc
src/tpk_manifest_handlers/tpk_config_parser.cc
src/tpk_manifest_handlers/ui_application_handler.cc
src/tpk_manifest_handlers/ui_application_handler.h
src/tpk_manifest_handlers/widget_application_handler.cc
src/tpk_manifest_handlers/widget_application_handler.h
src/unit_tests/string_util_unittest.cc
src/unit_tests/version_number_unittest.cc
src/utils/CMakeLists.txt [deleted file]
src/utils/iri_util.cc [deleted file]
src/utils/iri_util.h [deleted file]
src/utils/language_tag_validator.cc [deleted file]
src/utils/language_tag_validator.h [deleted file]
src/utils/logging.h [deleted file]
src/utils/manifest-parser-utils.pc.in [deleted file]
src/utils/string_util.cc [deleted file]
src/utils/string_util.h [deleted file]
src/utils/version_number.cc [deleted file]
src/utils/version_number.h [deleted file]
src/utils/w3c_languages.cc [deleted file]
src/utils/w3c_languages.h [deleted file]

index 4c4d2a51bb81c2517510ef29a048dbe958045bc0..c12bf7bd6a54ecf016a14a2a3deb71addac20e5f 100644 (file)
@@ -87,6 +87,7 @@ make %{?_smp_mflags}
 %{_includedir}/manifest_parser/utils/*.h
 %{_includedir}/manifest_handlers/*.h
 %{_includedir}/tpk_manifest_handlers/*.h
+%{_includedir}/tpk_manifest_handlers/common/*.h
 %{_includedir}/delta/*.h
 
 %files tests
index 0e25727a7e4894544789533e2e9f116a1c952303..095681ee9fdfd2afcfbd13ec31a2f0d20d8c2b71 100644 (file)
@@ -2,6 +2,5 @@ ADD_SUBDIRECTORY(manifest_parser)
 ADD_SUBDIRECTORY(manifest_handlers)
 ADD_SUBDIRECTORY(tpk_manifest_handlers)
 ADD_SUBDIRECTORY(unit_tests)
-ADD_SUBDIRECTORY(utils)
 ADD_SUBDIRECTORY(examples)
 ADD_SUBDIRECTORY(delta)
index 58979c2ef5e65f34acbcb947ca3db8eb835a9953..7aeda16802be8f756c99cc81ab826d7758490fdb 100644 (file)
@@ -5,8 +5,8 @@
 #include "manifest_handlers/account_handler.h"
 
 #include "manifest_handlers/application_manifest_constants.h"
-#include "utils/language_tag_validator.h"
-#include "utils/logging.h"
+#include "manifest_parser/utils/language_tag_validator.h"
+#include "manifest_parser/utils/logging.h"
 
 namespace {
 
index b254b9a1fac1170fc1ed798396811cead6925bb1..eb65e79c416a06f30b04cbdfc8ba120e53503c50 100644 (file)
@@ -7,9 +7,9 @@
 
 #include "manifest_handlers/application_manifest_constants.h"
 #include "manifest_handlers/tizen_application_handler.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/version_number.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/version_number.h"
 
 namespace {
 const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
index 64ec1f959e688d82b14c29a6d730393935944563..6d007fa7bc85bb982b09615ffa025eebacf88adf 100644 (file)
@@ -7,7 +7,7 @@
 #include <algorithm>
 #include <string>
 
-#include "utils/logging.h"
+#include "manifest_parser/utils/logging.h"
 
 namespace {
 
index 4d639e8dba5c79bd379f1a8fef09bddf59440d80..61ec471161c6b1a6bd7ca2c22f8f983c7b80849a 100644 (file)
@@ -5,8 +5,8 @@
 
 #include "manifest_handlers/category_handler.h"
 
-#include "utils/logging.h"
 #include "manifest_handlers/application_manifest_constants.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
 
 namespace wgt {
index cb30c5a54937419362690292b282114f0cbde475..e0f0a3dc90f867500bbc75574d0fdb48c0ed8213 100644 (file)
@@ -12,9 +12,9 @@
 #include <set>
 
 #include "manifest_handlers/application_manifest_constants.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
-#include "utils/string_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/utils/string_util.h"
 
 namespace ba = boost::algorithm;
 
index 9c036c1b6f0ce3c57fb8e6c9c46c6d23eb0122bf..69ca6ca66a2e17a7d8370a4c6e44e3cf50a28a4b 100644 (file)
@@ -10,8 +10,8 @@
 #include <regex>
 
 #include "manifest_handlers/application_manifest_constants.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/logging.h"
 
 namespace wgt {
 namespace parse {
index 314771236c62aef7fc8be04c618de4ad8816362e..a8e2ca4e03f0f8f64942dc9ef40559a07706b6c7 100755 (executable)
@@ -9,8 +9,8 @@
 #include <map>
 #include <utility>
 
-#include "utils/logging.h"
 #include "manifest_handlers/application_manifest_constants.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
 
 namespace wgt {
index de87272e3701ac9afa907ed9df8981492c9377a0..69f44899a12e592dca12e76628ee327a52e88a22 100644 (file)
@@ -6,8 +6,8 @@
 #include "manifest_handlers/permissions_handler.h"
 
 #include "manifest_handlers/application_manifest_constants.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/logging.h"
 
 namespace {
 const char kTizenPermissionsKey[] = "widget.privilege";
index e6469f9b50fea1aabb25907140f65455cc00acab..4ad36797a2999cd672f394f20959d84bdaab7d9f 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <string>
 
-#include "utils/version_number.h"
+#include "manifest_parser/utils/version_number.h"
 
 namespace parser {
 /**
index 2f750f4dbac1523250bd0b2aed454ab29f181773..e6c1da23c7dcb7002521c867f683e057a74acfe0 100644 (file)
@@ -16,7 +16,7 @@
 #include <utility>
 
 #include "manifest_handlers/application_manifest_constants.h"
-#include "utils/logging.h"
+#include "manifest_parser/utils/logging.h"
 
 namespace bf = boost::filesystem;
 namespace keys = wgt::application_widget_keys;
index 272d7391a3ee0019c5f413bf2367367e681084b4..522d7a7d0499359b618dd540940d2d29d22739fc 100644 (file)
 #include <utility>
 
 #include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/manifest_util.h"
 #include "manifest_handlers/platform_version.h"
+#include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/version_number.h"
 #include "manifest_parser/values.h"
-#include "utils/version_number.h"
 
 namespace wgt {
 namespace parse {
index d02f3b063ed8b5576dffca4dd547bf144f8a95c7..f431f695f69428787c3703756485d682885ab9fc 100644 (file)
@@ -38,8 +38,8 @@
 #include "manifest_handlers/warp_handler.h"
 #include "manifest_handlers/widget_handler.h"
 #include "manifest_parser/manifest_handler.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
 
 namespace ba = boost::algorithm;
 namespace bf = boost::filesystem;
index edad7b632fbfbb28d04c58005282ed42bdfbade1..dca5db33eb4d62acd5bc61b27377622e2de260c0 100644 (file)
 #include <set>
 
 #include "manifest_handlers/application_manifest_constants.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/language_tag_validator.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/language_tag_validator.h"
-#include "utils/logging.h"
 
 namespace wgt {
 namespace parse {
index 8d837bd69c6ec6f03249c844b6ca1b796de1b22f..d6ae7cc90b8cb48137448999fdf5102dbdbb0994 100644 (file)
@@ -47,3 +47,5 @@ INSTALL(FILES ${INCLUDES} DESTINATION ${INCLUDEDIR}/manifest_parser)
 SET(PKG_FILE manifest-parser.pc)
 CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
 INSTALL(FILES ${PKG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+ADD_SUBDIRECTORY(utils)
index 84022095f9ad3fdc0110d8f41463097b8999c00c..16bd5c243ff0d440683831c1f9c243d7ad71c94c 100644 (file)
@@ -13,9 +13,9 @@
 #include <regex>
 #include <vector>
 
-#include "utils/string_util.h"
 #include "manifest_parser/manifest.h"
 #include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/utils/string_util.h"
 #include "manifest_parser/values.h"
 
 namespace bf = boost::filesystem;
diff --git a/src/manifest_parser/utils/CMakeLists.txt b/src/manifest_parser/utils/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0917ce1
--- /dev/null
@@ -0,0 +1,34 @@
+# Target - sources
+SET(SRCS
+  iri_util.cc
+  string_util.cc
+  language_tag_validator.cc
+  version_number.cc
+  w3c_languages.cc
+)
+# Target - definition
+ADD_LIBRARY(${TARGET_LIBNAME_UTILS} SHARED ${SRCS})
+# Target - includes
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_UTILS} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../")
+
+# Target - deps
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_UTILS} PUBLIC
+  LIBIRI_DEPS
+  Boost
+)
+
+# Extra
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_UTILS} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_UTILS} PROPERTIES SOVERSION ${VERSION_MAJOR})
+
+# Install
+INSTALL(TARGETS ${TARGET_LIBNAME_UTILS} DESTINATION ${LIB_INSTALL_DIR})
+
+# Install includes
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDEDIR}/manifest_parser
+        FILES_MATCHING PATTERN "*.h")
+
+# Configure and install pkgconfig file
+SET(PKG_FILE manifest-parser-utils.pc)
+CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
+INSTALL(FILES ${PKG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
diff --git a/src/manifest_parser/utils/iri_util.cc b/src/manifest_parser/utils/iri_util.cc
new file mode 100644 (file)
index 0000000..a6bc1ad
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "manifest_parser/utils/iri_util.h"
+
+#include <iri.h>
+
+#include <memory>
+
+namespace parser {
+namespace utils {
+
+bool IsValidIRI(const std::string& iri_string) {
+  std::unique_ptr<iri_struct, decltype(&iri_destroy)> iri(
+      iri_parse(iri_string.c_str()), iri_destroy);
+  return
+    iri != NULL &&
+    iri->scheme != NULL && (
+      iri->display != NULL ||
+      iri->user != NULL ||
+      iri->auth != NULL ||
+      iri->password != NULL ||
+      iri->host != NULL ||
+      iri->path != NULL ||
+      iri->query != NULL ||
+      iri->anchor != NULL ||
+      iri->qparams != NULL ||
+      iri->schemelist != NULL);
+}
+
+}  // namespace utils
+}  // namespace parser
diff --git a/src/manifest_parser/utils/iri_util.h b/src/manifest_parser/utils/iri_util.h
new file mode 100644 (file)
index 0000000..0ed6f19
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef MANIFEST_PARSER_UTILS_IRI_UTIL_H_
+#define MANIFEST_PARSER_UTILS_IRI_UTIL_H_
+
+#include <string>
+
+namespace parser {
+namespace utils {
+
+/**
+ * @brief IsValidIRI
+ *        Validate IRI with libiri.
+ *
+ * Valid IRI is the one that have at least scheme part and any other component.
+ *
+ * @param iri_string iri string to check
+ * @return bool if iri is valid
+ */
+bool IsValidIRI(const std::string& iri_string);
+
+}  // namespace utils
+}  // namespace parser
+
+#endif  // MANIFEST_PARSER_UTILS_IRI_UTIL_H_
diff --git a/src/manifest_parser/utils/language_tag_validator.cc b/src/manifest_parser/utils/language_tag_validator.cc
new file mode 100644 (file)
index 0000000..5efb567
--- /dev/null
@@ -0,0 +1,116 @@
+// 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 "manifest_parser/utils/language_tag_validator.h"
+
+#include <boost/algorithm/string.hpp>
+#include <vector>
+
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/utils/w3c_languages.h"
+
+namespace ba = boost::algorithm;
+
+namespace {
+const char kTagDelimiter[] = "-";
+const int kSingletonTagSize = 1;
+const int kMaximumExtensionTagSize = 8;
+
+std::string Capitalized(const std::string& input) {
+  std::string output = input;
+  ba::to_lower(output);
+  output[0] = toupper(output[0]);
+  return output;
+}
+
+std::string ToLower(const std::string& input) {
+  std::string output = input;
+  ba::to_lower(output);
+  return output;
+}
+
+std::string ToUpper(const std::string& input) {
+  std::string output = input;
+  ba::to_upper(output);
+  return output;
+}
+
+}  // namespace
+
+namespace utils {
+namespace w3c_languages {
+
+bool ValidateLanguageTag(const std::string& tag) {
+  // algorithm based on http://www.w3.org/International/articles/language-tags/
+  std::vector<std::string> splitted_tag;
+  if (tag.empty()) {
+    LOG(ERROR) << "tag is empty";
+    return false;
+  }
+  boost::split(splitted_tag, tag, boost::is_any_of(kTagDelimiter));
+  auto current_item = splitted_tag.begin();
+  // main language validation
+  if (current_item != splitted_tag.end() &&
+      !lang_set::ValidateOnlyLanguage(*current_item)) {
+    LOG(ERROR) << "Invalid main language tag given";
+    return false;
+  }
+  ++current_item;
+  if (current_item == splitted_tag.end()) {
+    return true;
+  }
+  // extlang validation
+  auto lang_pair = kW3CExtLang.find(ToLower(*current_item));
+  if (lang_pair != kW3CExtLang.end()) {
+    if (splitted_tag.front() == lang_pair->second) {
+      ++current_item;
+      if (current_item == splitted_tag.end())
+        return true;
+    } else {
+      LOG(ERROR) << "Extlang does not match language";
+      return false;
+    }
+  }
+  // script subtag validation
+  if (kW3CScript.find(Capitalized(*current_item)) != kW3CScript.end()) {
+    ++current_item;
+    if (current_item == splitted_tag.end())
+      return true;
+  }
+  // region subtag validation
+  if (kW3CRegion.find(ToUpper(*current_item)) != kW3CRegion.end()) {
+    ++current_item;
+    if (current_item == splitted_tag.end())
+      return true;
+  }
+
+  // TODO(w.kosowicz): variant prefix check
+  if (kW3CVariant.find(ToLower(*current_item)) != kW3CVariant.end()) {
+    ++current_item;
+    if (current_item == splitted_tag.end())
+      return true;
+  }
+  // extension private tag validation
+  if ((*current_item).size() != kSingletonTagSize) {
+    LOG(ERROR) << "Singletion subtag should be of size " << kSingletonTagSize;
+    return false;
+  }
+  ++current_item;
+  if (current_item == splitted_tag.end())
+    return false;
+  for (auto it = current_item; it != splitted_tag.end(); ++current_item) {
+    auto tag_length = (*current_item).size();
+    if (tag_length > kMaximumExtensionTagSize) {
+      LOG(ERROR) << "Any extensions should be maximum "
+                 << kMaximumExtensionTagSize << "characters";
+      return false;
+    }
+  }
+  return true;
+}
+
+}  // namespace w3c_languages
+}  // namespace utils
+
+
diff --git a/src/manifest_parser/utils/language_tag_validator.h b/src/manifest_parser/utils/language_tag_validator.h
new file mode 100644 (file)
index 0000000..0b6eedc
--- /dev/null
@@ -0,0 +1,27 @@
+// 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 MANIFEST_PARSER_UTILS_LANGUAGE_TAG_VALIDATOR_H_
+#define MANIFEST_PARSER_UTILS_LANGUAGE_TAG_VALIDATOR_H_
+
+#include <string>
+#include <unordered_set>
+
+namespace utils {
+namespace w3c_languages {
+
+/**
+ * @brief ValidateLanguageTag
+ *        Checks validity of language tag.
+ *
+ * Languauge tag reference:
+ *  - http://www.w3.org/International/articles/language-tags/
+ *
+ * @param language tag string
+ * @return true if tag is correct
+ */
+bool ValidateLanguageTag(const std::string& tag);
+
+}  // namespace w3c_languages
+}  // namespace utils
+#endif  // MANIFEST_PARSER_UTILS_LANGUAGE_TAG_VALIDATOR_H_
diff --git a/src/manifest_parser/utils/logging.h b/src/manifest_parser/utils/logging.h
new file mode 100644 (file)
index 0000000..1ae3a58
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef MANIFEST_PARSER_UTILS_LOGGING_H_
+#define MANIFEST_PARSER_UTILS_LOGGING_H_
+
+#include <cassert>
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+namespace utils {
+
+enum class LogLevel {
+  LOG_ERROR,
+  LOG_WARNING,
+  LOG_INFO,
+  LOG_DEBUG,
+};
+
+template<LogLevel> struct LogTag;
+template<> struct LogTag<LogLevel::LOG_ERROR> {
+  static constexpr const char* value = "\033[1;31m| ERROR   |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_WARNING> {
+  static constexpr const char* value = "\033[1;33m| WARNING |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_INFO>  {
+  static constexpr const char* value = "\033[1;32m| INFO    |\033[0m";
+};
+template<> struct LogTag<LogLevel::LOG_DEBUG> {
+  static constexpr const char* value = "\033[0m| DEBUG   |\033[0m";
+};
+
+class LogCatcher {
+ public:
+  LogCatcher() { }
+  void operator&(const std::ostream& str) const {
+    // TODO(tiwanek): this cast is error-prone - fix it
+    std::cerr << static_cast<const std::ostringstream*>(&str)->str()
+              << std::endl;
+  }
+};
+
+}  // namespace utils
+
+inline static const constexpr char* __tag_for_logging() {
+  return "";
+}
+
+// To be defined in class namespace if user want different log tag for given
+// scope
+#define SCOPE_LOG_TAG(TAG)                                                     \
+  inline static const constexpr char* __tag_for_logging() {                    \
+    return #TAG;                                                               \
+  }                                                                            \
+
+// Simple logging macro of following usage:
+//   LOG(LEVEL) << object_1 << object_2 << object_n;
+//     where:
+//       LEVEL = ERROR | WARNING | INFO | DEBUG
+#define LOG(LEVEL)                                                             \
+    ::utils::LogCatcher() & std::ostringstream()                               \
+      << std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \
+      << " " << std::setw(20) << std::left << __tag_for_logging()              \
+      << std::setw(0) << " : "                                                 \
+
+#endif  // MANIFEST_PARSER_UTILS_LOGGING_H_
diff --git a/src/manifest_parser/utils/manifest-parser-utils.pc.in b/src/manifest_parser/utils/manifest-parser-utils.pc.in
new file mode 100644 (file)
index 0000000..a63e103
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: manifest-parser-utils
+Description: Universal manifest parser utils
+Version: @VERSION@
+Requires: libiri
+Libs: -L${libdir} -lmanifest-parser-utils
+Cflags: -I${includedir}
\ No newline at end of file
diff --git a/src/manifest_parser/utils/string_util.cc b/src/manifest_parser/utils/string_util.cc
new file mode 100644 (file)
index 0000000..543b4df
--- /dev/null
@@ -0,0 +1,213 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE-xwalk file.
+
+#include "manifest_parser/utils/string_util.h"
+
+#include <cstdlib>
+#include <map>
+#include <vector>
+
+namespace {
+
+const unsigned kBidiControlCharacterLength = 3;
+
+const char kDirLTRKey[] = "ltr";
+const char kDirRTLKey[] = "rtl";
+const char kDirLROKey[] = "lro";
+const char kDirRLOKey[] = "rlo";
+
+const char* kWhitespaceSequences[] = {
+  u8"\x09",          /* CHARACTER TABULATION */
+  u8"\x0A",          /* LINE FEED (LF) */
+  u8"\x0B",          /* LINE TABULATION */
+  u8"\x0C",          /* FORM FEED (FF) */
+  u8"\x0D",          /* CARRIAGE RETURN (CR) */
+  u8"\x20",          /* SPACE */
+  u8"\xc2\x85",      /* NEXT LINE (NEL) */
+  u8"\xc2\xa0",      /* NO-BREAK SPACE */
+  u8"\xe1\x9a\x80",  /* OGHAM SPACE MARK */
+  u8"\xe1\xa0\x8e",  /* MONGOLIAN VOWEL SEPARATOR */
+  u8"\xe2\x80\x80",  /* EN QUAD */
+  u8"\xe2\x80\x81",  /* EM QUAD */
+  u8"\xe2\x80\x82",  /* EN SPACE */
+  u8"\xe2\x80\x83",  /* EM SPACE */
+  u8"\xe2\x80\x84",  /* THREE-PER-EM SPACE */
+  u8"\xe2\x80\x85",  /* FOUR-PER-EM SPACE */
+  u8"\xe2\x80\x86",  /* SIX-PER-EM SPACE */
+  u8"\xe2\x80\x87",  /* FIGURE SPACE */
+  u8"\xe2\x80\x88",  /* PUNCTUATION SPACE */
+  u8"\xe2\x80\x89",  /* THIN SPACE */
+  u8"\xe2\x80\x8A",  /* HAIR SPACE */
+  u8"\xe2\x80\xa8",  /* LINE SEPARATOR */
+  u8"\xe2\x80\xa9",  /* PARAGRAPH SEPARATOR */
+  u8"\xe2\x80\xaf",  /* NARROW NO-BREAK SPACE */
+  u8"\xe2\x81\x9f",  /* MEDIUM MATHEMATICAL SPACE */
+  u8"\xe3\x80\x80"   /* IDEOGRAPHIC SPACE */
+};
+
+// Calculates length of UTF-8 character by checking first byte only
+int UTF8CharLength(const char* character) {
+  if (!(character[0] & 0x80))
+      return 1;
+  int length = 0;
+  unsigned char mask = 0x80;
+  while (character[0] & mask) {
+    mask >>= 1;
+    ++length;
+  }
+  return length;
+}
+
+// Check string offset against occurance of given UTF-8 character
+bool EqualsUTF8Char(const char* str, const char* character) {
+  unsigned i = 0;
+  while (character[i]) {
+    if (!str[i]) {
+      return false;
+    }
+    if (character[i] != str[i]) {
+      return false;
+    }
+    ++i;
+  }
+  return true;
+}
+
+// Returns true if it's a whitespace character.
+inline bool IsWhitespaceUTF8(const char* c) {
+  for (unsigned i = 0;
+       i < sizeof(kWhitespaceSequences) / sizeof(kWhitespaceSequences[0]);
+       ++i) {
+    if (EqualsUTF8Char(c, kWhitespaceSequences[i])) {
+      return true;
+    }
+  }
+  return false;
+}
+
+}  // namespace
+
+namespace parser {
+namespace utils {
+
+// based on http://unicode.org/reports/tr9/
+const char kRightToLeftMark[] = u8"\u200F";
+const char kLeftToRightMark[] = u8"\u200E";
+const char kLeftToRightEmbeddingMark[] = u8"\u202A";
+const char kRightToLeftEmbeddingMark[] = u8"\u202B";
+const char kPopDirectionalFormatting[] = u8"\u202C";
+const char kLeftToRightOverride[] = u8"\u202D";
+const char kRightToLeftOverride[] = u8"\u202E";
+
+const std::map<std::string, std::string> kTextDir = {
+  { std::string(kDirLTRKey), std::string(kLeftToRightEmbeddingMark) },
+  { std::string(kDirRTLKey), std::string(kRightToLeftEmbeddingMark) },
+  { std::string(kDirLROKey), std::string(kLeftToRightOverride) },
+  { std::string(kDirRLOKey), std::string(kRightToLeftOverride) }
+};
+
+
+std::string CollapseWhitespaceUTF8(const std::string& text) {
+  std::string result;
+
+  if (text.empty()) {
+    return result;
+  }
+  result.resize(text.size());
+  // Set flags to pretend we're already in a trimmed whitespace sequence,
+  // so we will trim any leading whitespace.
+  bool in_whitespace = true;
+  int chars_written = 0;
+
+  for (unsigned i = 0; i < text.length();) {
+    int length = UTF8CharLength(&text[i]);
+    if (IsWhitespaceUTF8(&text[i])) {
+      if (!in_whitespace) {
+        // Reduce all whitespace sequences to a single space.
+        in_whitespace = true;
+        result[chars_written++] = ' ';
+      }
+      // roll through UTF8 character
+      i += length;
+    } else {
+      // Non-whitespace chracters are copied straight across.
+      in_whitespace = false;
+      while (length--) {
+        result[chars_written++] = text[i++];
+      }
+    }
+  }
+
+  if (in_whitespace && chars_written > 0) {
+    // Any trailing whitespace is eliminated.
+    --chars_written;
+  }
+
+  result.resize(chars_written);
+  return result;
+}
+
+std::string StripWrappingBidiControlCharactersUTF8(const std::string& text) {
+  if (text.empty())
+    return text;
+  size_t begin_index = 0;
+  const char* begin = &text[begin_index];
+  if (EqualsUTF8Char(begin, kLeftToRightEmbeddingMark) ||
+      EqualsUTF8Char(begin, kRightToLeftEmbeddingMark) ||
+      EqualsUTF8Char(begin, kLeftToRightOverride) ||
+      EqualsUTF8Char(begin, kRightToLeftOverride))
+    begin_index += kBidiControlCharacterLength;
+  size_t end_index = text.length() - kBidiControlCharacterLength;
+  if (EqualsUTF8Char(&text[end_index], kPopDirectionalFormatting))
+    end_index -= 3;
+  return text.substr(begin_index,
+      end_index - begin_index + kBidiControlCharacterLength);
+}
+
+std::string GetDirTextUTF8(const std::string& text, const std::string& dir) {
+  auto dirValue = kTextDir.find(dir);
+  if (dirValue != kTextDir.end())
+    return  dirValue->second + text + kPopDirectionalFormatting;
+  return text;
+}
+
+std::string GetDirUTF8Start(const std::string& dir) {
+  auto dirValue = kTextDir.find(dir);
+  if (dirValue != kTextDir.end())
+    return dirValue->second;
+  return std::string();
+}
+
+std::string GetDirUTF8End() {
+  return std::string(kPopDirectionalFormatting);
+}
+
+std::string DecodePercentEscapedCharacter(const std::string& text) {
+  std::vector<int> input(text.begin(), text.end());
+  std::vector<char> output;
+  unsigned i = 0;
+  while (i < input.size()) {
+    if ('%' == input[i]) {
+      if (i + 2 >= input.size())
+        return std::string();
+      char str[3] = {"\0", };
+      str[0] = input[i + 1];
+      str[1] = input[i + 2];
+      int result = strtol(str, NULL, 16);
+      // RFC 1738 - octets 80 to FF are not allowed
+      if (result >= 128)
+        return std::string();
+      output.push_back(static_cast<char>(result));
+      i += 3;
+    } else {
+      output.push_back(static_cast<char>(input[i]));
+      ++i;
+    }
+  }
+  return std::string(output.begin(), output.end());
+}
+
+}  // namespace utils
+}  // namespace parser
diff --git a/src/manifest_parser/utils/string_util.h b/src/manifest_parser/utils/string_util.h
new file mode 100644 (file)
index 0000000..0f5815c
--- /dev/null
@@ -0,0 +1,92 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE-xwalk file.
+
+#ifndef MANIFEST_PARSER_UTILS_STRING_UTIL_H_
+#define MANIFEST_PARSER_UTILS_STRING_UTIL_H_
+
+#include <string>
+
+namespace parser {
+namespace utils {
+
+// utf8 representation of unicode BIDI characters
+extern const char kRightToLeftMark[];
+extern const char kLeftToRightMark[];
+extern const char kLeftToRightEmbeddingMark[];
+extern const char kRightToLeftEmbeddingMark[];
+extern const char kPopDirectionalFormatting[];
+extern const char kLeftToRightOverride[];
+extern const char kRightToLeftOverride[];
+
+/**
+ * @brief CollapseWhitespaceUTF8
+ *        Replaces all utf-8 whitespace characters sequences with single space
+ *        character. Whitespace at the beginning and at the end are removed
+ *        completely.
+ *
+ * @param text input string
+ * @return collapsed string
+ */
+std::string CollapseWhitespaceUTF8(const std::string& text);
+
+/**
+ * @brief StripWrappingBidiControlCharactersUTF8
+ *        Remove utf-8 bidi characters.
+ *
+ * Function removes single PDF bidi character at the end if exists.
+ * Function removes one single LTR|RTL|LRO|RLO bidi character at the beginning
+ * if exists.
+ *
+ * @param text input string
+ * @return transformed string
+ */
+std::string StripWrappingBidiControlCharactersUTF8(const std::string& text);
+
+/**
+ * @brief GetDirTextUTF8
+ *        Adds given bidi character to beginning of string and adds PDF bifi
+ *        character
+ *
+ * @param text input string
+ * @param dir chosen bidi format defined as "dir" attribute in w3c spec,
+ *        allowed values: "ltr", "rtl", "lro", "rlo"
+ * @return transformed string
+ */
+std::string GetDirTextUTF8(const std::string& text, const std::string& dir);
+
+/**
+ * @brief GetDirUTF8Start
+ *        Returns bidi format character.
+ *
+ * @param dir chosen bidi format defined as "dir" attribute in w3c spec,
+ *        allowed values: "ltr", "rtl", "lro", "rlo"
+ * @return utf-8 character
+ */
+std::string GetDirUTF8Start(const std::string& dir);
+
+/**
+ * @brief GetDirUTF8End
+ *        Return PDF (Pop Directional Format) character encoded in utf-8
+ *
+ * @return UTF-8 PDF bidi character
+ */
+std::string GetDirUTF8End();
+
+/**
+ * @brief DecodePercentEscapedCharacter
+ *        Decodes url-encoded characters in string.
+ *
+ * This should be used to decoded path in configuration files where url spec
+ * is allowed.
+ *
+ * @param path string with url-encoded characters
+ * @return decoded value of text
+ */
+std::string DecodePercentEscapedCharacter(const std::string& text);
+
+}  // namespace utils
+}  // namespace parser
+
+#endif  // MANIFEST_PARSER_UTILS_STRING_UTIL_H_
diff --git a/src/manifest_parser/utils/version_number.cc b/src/manifest_parser/utils/version_number.cc
new file mode 100644 (file)
index 0000000..25142f1
--- /dev/null
@@ -0,0 +1,94 @@
+// 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 "manifest_parser/utils/version_number.h"
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/trim.hpp>
+
+#include <algorithm>
+#include <cstdlib>
+
+namespace ba = boost::algorithm;
+
+namespace utils {
+
+VersionNumber::VersionNumber(const std::string& str) {
+  std::string number = str;
+  ba::trim(number);
+  std::vector<std::string> tokens;
+  ba::split(tokens, number, ba::is_any_of("."));
+  for (auto& token : tokens) {
+    char* end = nullptr;
+    int value = strtol(token.c_str(), &end, 10);
+    if (end != &*token.end() || token.empty()) {
+      parts_.clear();
+      return;
+    }
+    parts_.push_back(value);
+  }
+}
+
+bool VersionNumber::IsValid() const {
+  return !parts_.empty();
+}
+
+int VersionNumber::Compare(const VersionNumber& other) const {
+  size_t i = 0;
+  while (true) {
+    if (i < parts_.size()) {
+      if (i < other.parts_.size()) {
+        if (parts_[i] > other.parts_[i]) {
+          return 1;
+        } else if (parts_[i] < other.parts_[i]) {
+          return -1;
+        }
+      } else {
+        return 1;
+      }
+    } else {
+      if (i < other.parts_.size()) {
+        return -1;
+      } else {
+        return 0;
+      }
+    }
+    ++i;
+  }
+}
+
+bool VersionNumber::operator<(const VersionNumber& other) const {
+  return Compare(other) < 0;
+}
+
+bool VersionNumber::operator>=(const VersionNumber& other) const {
+  return !this->operator<(other);
+}
+
+bool VersionNumber::operator==(const VersionNumber& other) const {
+  return Compare(other) == 0;
+}
+
+bool VersionNumber::operator!=(const VersionNumber& other) const {
+  return !this->operator==(other);
+}
+
+bool VersionNumber::operator>(const VersionNumber& other) const {
+  return Compare(other) > 0;
+}
+
+bool VersionNumber::operator<=(const VersionNumber& other) const {
+  return !this->operator>(other);
+}
+
+std::string VersionNumber::ToString() const {
+  std::vector<std::string> strings;
+  std::transform(parts_.begin(), parts_.end(), std::back_inserter(strings),
+                 static_cast<std::string(*)(int)>(&std::to_string));
+  return ba::join(strings, ".");
+}
+
+}  // namespace utils
diff --git a/src/manifest_parser/utils/version_number.h b/src/manifest_parser/utils/version_number.h
new file mode 100644 (file)
index 0000000..6b798ca
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 MANIFEST_PARSER_UTILS_VERSION_NUMBER_H_
+#define MANIFEST_PARSER_UTILS_VERSION_NUMBER_H_
+
+#include <string>
+#include <vector>
+
+namespace utils {
+
+/**
+ * @brief The VersionNumber class
+ *        Representation of version number
+ *
+ * This class should be used to store version number. Version number is allowed
+ * to be constructed of number segments connected with single dot character.
+ *
+ * Every new version number should be validate be check result of member
+ * function call @ref IsValid()
+ */
+class VersionNumber {
+ public:
+  explicit VersionNumber(const std::string& str);
+
+  bool IsValid() const;
+  int Compare(const VersionNumber& other) const;
+
+  bool operator<(const VersionNumber& other) const;
+  bool operator>=(const VersionNumber& other) const;
+  bool operator==(const VersionNumber& other) const;
+  bool operator!=(const VersionNumber& other) const;
+  bool operator>(const VersionNumber& other) const;
+  bool operator<=(const VersionNumber& other) const;
+
+  std::string ToString() const;
+
+ private:
+  std::vector<int> parts_;
+};
+
+}  // namespace utils
+
+#endif  // MANIFEST_PARSER_UTILS_VERSION_NUMBER_H_
diff --git a/src/manifest_parser/utils/w3c_languages.cc b/src/manifest_parser/utils/w3c_languages.cc
new file mode 100644 (file)
index 0000000..d647c36
--- /dev/null
@@ -0,0 +1,359 @@
+// 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 "manifest_parser/utils/w3c_languages.h"
+
+#include <boost/filesystem.hpp>
+#include <tzplatform_config.h>
+#include <algorithm>
+#include <fstream>
+#include <vector>
+
+#include "manifest_parser/utils/logging.h"
+
+namespace bf = boost::filesystem;
+namespace {
+const bf::path kLanguagesFile =
+    bf::path(tzplatform_getenv(TZ_SYS_SHARE))
+        / "manifest-parser/languages-only.txt";
+const int kLanguagesNumber = 8094;
+}
+
+namespace utils {
+namespace w3c_languages {
+namespace lang_set {
+
+std::vector<std::string> w3c_languages;
+
+bool InitializeLanguageSet() {
+  if (!w3c_languages.empty())
+    return true;
+  if (!bf::exists(kLanguagesFile)) {
+    LOG(ERROR) << "File does not exist";
+    return false;
+  }
+  std::ifstream infile(kLanguagesFile.string());
+  if (!infile.is_open()) {
+    LOG(ERROR) << "Error during file opening";
+    return false;
+  }
+  w3c_languages.reserve(kLanguagesNumber);
+  std::string line;
+  while (std::getline(infile, line)) {
+    w3c_languages.push_back(line);
+  }
+  infile.close();
+  return true;
+}
+
+bool ValidateOnlyLanguage(const std::string& language) {
+  if (!InitializeLanguageSet())
+    return false;
+  if (!std::binary_search(w3c_languages.begin(), w3c_languages.end(), language))
+    return false;
+  return true;
+}
+}  // namespace lang_set
+
+const std::map<std::string, std::string> kW3CExtLang{{"aao", "ar"},
+                                                     {"abh", "ar"},
+                                                     {"abv", "ar"},
+                                                     {"acm", "ar"},
+                                                     {"acq", "ar"},
+                                                     {"acw", "ar"},
+                                                     {"acx", "ar"},
+                                                     {"acy", "ar"},
+                                                     {"adf", "ar"},
+                                                     {"ads", "sgn"},
+                                                     {"aeb", "ar"},
+                                                     {"aec", "ar"},
+                                                     {"aed", "sgn"},
+                                                     {"aen", "sgn"},
+                                                     {"afb", "ar"},
+                                                     {"afg", "sgn"},
+                                                     {"ajp", "ar"},
+                                                     {"apc", "ar"},
+                                                     {"apd", "ar"},
+                                                     {"arb", "ar"},
+                                                     {"arq", "ar"},
+                                                     {"ars", "ar"},
+                                                     {"ary", "ar"},
+                                                     {"arz", "ar"},
+                                                     {"ase", "sgn"},
+                                                     {"asf", "sgn"},
+                                                     {"asp", "sgn"},
+                                                     {"asq", "sgn"},
+                                                     {"asw", "sgn"},
+                                                     {"auz", "ar"},
+                                                     {"avl", "ar"},
+                                                     {"ayh", "ar"},
+                                                     {"ayl", "ar"},
+                                                     {"ayn", "ar"},
+                                                     {"ayp", "ar"},
+                                                     {"bbz", "ar"},
+                                                     {"bfi", "sgn"},
+                                                     {"bfk", "sgn"},
+                                                     {"bjn", "ms"},
+                                                     {"bog", "sgn"},
+                                                     {"bqn", "sgn"},
+                                                     {"bqy", "sgn"},
+                                                     {"btj", "ms"},
+                                                     {"bve", "ms"},
+                                                     {"bvl", "sgn"},
+                                                     {"bvu", "ms"},
+                                                     {"bzs", "sgn"},
+                                                     {"cdo", "zh"},
+                                                     {"cds", "sgn"},
+                                                     {"cjy", "zh"},
+                                                     {"cmn", "zh"},
+                                                     {"coa", "ms"},
+                                                     {"cpx", "zh"},
+                                                     {"csc", "sgn"},
+                                                     {"csd", "sgn"},
+                                                     {"cse", "sgn"},
+                                                     {"csf", "sgn"},
+                                                     {"csg", "sgn"},
+                                                     {"csl", "sgn"},
+                                                     {"csn", "sgn"},
+                                                     {"csq", "sgn"},
+                                                     {"csr", "sgn"},
+                                                     {"czh", "zh"},
+                                                     {"czo", "zh"},
+                                                     {"doq", "sgn"},
+                                                     {"dse", "sgn"},
+                                                     {"dsl", "sgn"},
+                                                     {"dup", "ms"},
+                                                     {"ecs", "sgn"},
+                                                     {"esl", "sgn"},
+                                                     {"esn", "sgn"},
+                                                     {"eso", "sgn"},
+                                                     {"eth", "sgn"},
+                                                     {"fcs", "sgn"},
+                                                     {"fse", "sgn"},
+                                                     {"fsl", "sgn"},
+                                                     {"fss", "sgn"},
+                                                     {"gan", "zh"},
+                                                     {"gds", "sgn"},
+                                                     {"gom", "kok"},
+                                                     {"gse", "sgn"},
+                                                     {"gsg", "sgn"},
+                                                     {"gsm", "sgn"},
+                                                     {"gss", "sgn"},
+                                                     {"gus", "sgn"},
+                                                     {"hab", "sgn"},
+                                                     {"haf", "sgn"},
+                                                     {"hak", "zh"},
+                                                     {"hds", "sgn"},
+                                                     {"hji", "ms"},
+                                                     {"hks", "sgn"},
+                                                     {"hos", "sgn"},
+                                                     {"hps", "sgn"},
+                                                     {"hsh", "sgn"},
+                                                     {"hsl", "sgn"},
+                                                     {"hsn", "zh"},
+                                                     {"icl", "sgn"},
+                                                     {"iks", "sgn"},
+                                                     {"ils", "sgn"},
+                                                     {"inl", "sgn"},
+                                                     {"ins", "sgn"},
+                                                     {"ise", "sgn"},
+                                                     {"isg", "sgn"},
+                                                     {"isr", "sgn"},
+                                                     {"jak", "ms"},
+                                                     {"jax", "ms"},
+                                                     {"jcs", "sgn"},
+                                                     {"jhs", "sgn"},
+                                                     {"jls", "sgn"},
+                                                     {"jos", "sgn"},
+                                                     {"jsl", "sgn"},
+                                                     {"jus", "sgn"},
+                                                     {"kgi", "sgn"},
+                                                     {"knn", "kok"},
+                                                     {"kvb", "ms"},
+                                                     {"kvk", "sgn"},
+                                                     {"kvr", "ms"},
+                                                     {"kxd", "ms"},
+                                                     {"lbs", "sgn"},
+                                                     {"lce", "ms"},
+                                                     {"lcf", "ms"},
+                                                     {"liw", "ms"},
+                                                     {"lls", "sgn"},
+                                                     {"lsg", "sgn"},
+                                                     {"lsl", "sgn"},
+                                                     {"lso", "sgn"},
+                                                     {"lsp", "sgn"},
+                                                     {"lst", "sgn"},
+                                                     {"lsy", "sgn"},
+                                                     {"ltg", "lv"},
+                                                     {"lvs", "lv"},
+                                                     {"lzh", "zh"},
+                                                     {"max", "ms"},
+                                                     {"mdl", "sgn"},
+                                                     {"meo", "ms"},
+                                                     {"mfa", "ms"},
+                                                     {"mfb", "ms"},
+                                                     {"mfs", "sgn"},
+                                                     {"min", "ms"},
+                                                     {"mnp", "zh"},
+                                                     {"mqg", "ms"},
+                                                     {"mre", "sgn"},
+                                                     {"msd", "sgn"},
+                                                     {"msi", "ms"},
+                                                     {"msr", "sgn"},
+                                                     {"mui", "ms"},
+                                                     {"mzc", "sgn"},
+                                                     {"mzg", "sgn"},
+                                                     {"mzy", "sgn"},
+                                                     {"nan", "zh"},
+                                                     {"nbs", "sgn"},
+                                                     {"ncs", "sgn"},
+                                                     {"nsi", "sgn"},
+                                                     {"nsl", "sgn"},
+                                                     {"nsp", "sgn"},
+                                                     {"nsr", "sgn"},
+                                                     {"nzs", "sgn"},
+                                                     {"okl", "sgn"},
+                                                     {"orn", "ms"},
+                                                     {"ors", "ms"},
+                                                     {"pel", "ms"},
+                                                     {"pga", "ar"},
+                                                     {"pks", "sgn"},
+                                                     {"prl", "sgn"},
+                                                     {"prz", "sgn"},
+                                                     {"psc", "sgn"},
+                                                     {"psd", "sgn"},
+                                                     {"pse", "ms"},
+                                                     {"psg", "sgn"},
+                                                     {"psl", "sgn"},
+                                                     {"pso", "sgn"},
+                                                     {"psp", "sgn"},
+                                                     {"psr", "sgn"},
+                                                     {"pys", "sgn"},
+                                                     {"rms", "sgn"},
+                                                     {"rsi", "sgn"},
+                                                     {"rsl", "sgn"},
+                                                     {"sdl", "sgn"},
+                                                     {"sfb", "sgn"},
+                                                     {"sfs", "sgn"},
+                                                     {"sgg", "sgn"},
+                                                     {"sgx", "sgn"},
+                                                     {"shu", "ar"},
+                                                     {"slf", "sgn"},
+                                                     {"sls", "sgn"},
+                                                     {"sqk", "sgn"},
+                                                     {"sqs", "sgn"},
+                                                     {"ssh", "ar"},
+                                                     {"ssp", "sgn"},
+                                                     {"ssr", "sgn"},
+                                                     {"svk", "sgn"},
+                                                     {"swc", "sw"},
+                                                     {"swh", "sw"},
+                                                     {"swl", "sgn"},
+                                                     {"syy", "sgn"},
+                                                     {"tmw", "ms"},
+                                                     {"tse", "sgn"},
+                                                     {"tsm", "sgn"},
+                                                     {"tsq", "sgn"},
+                                                     {"tss", "sgn"},
+                                                     {"tsy", "sgn"},
+                                                     {"tza", "sgn"},
+                                                     {"ugn", "sgn"},
+                                                     {"ugy", "sgn"},
+                                                     {"ukl", "sgn"},
+                                                     {"uks", "sgn"},
+                                                     {"urk", "ms"},
+                                                     {"uzn", "uz"},
+                                                     {"uzs", "uz"},
+                                                     {"vgt", "sgn"},
+                                                     {"vkk", "ms"},
+                                                     {"vkt", "ms"},
+                                                     {"vsi", "sgn"},
+                                                     {"vsl", "sgn"},
+                                                     {"vsv", "sgn"},
+                                                     {"wuu", "zh"},
+                                                     {"xki", "sgn"},
+                                                     {"xml", "sgn"},
+                                                     {"xmm", "ms"},
+                                                     {"xms", "sgn"},
+                                                     {"yds", "sgn"},
+                                                     {"ygs", "sgn"},
+                                                     {"yhs", "sgn"},
+                                                     {"ysl", "sgn"},
+                                                     {"yue", "zh"},
+                                                     {"zib", "sgn"},
+                                                     {"zlm", "ms"},
+                                                     {"zmi", "ms"},
+                                                     {"zsl", "sgn"},
+                                                     {"zsm", "ms"}};
+const std::unordered_set<std::string> kW3CScript{
+    "Adlm", "Afak", "Aghb", "Ahom", "Arab",       "Aran", "Armi", "Armn",
+    "Avst", "Bali", "Bamu", "Bass", "Batk",       "Beng", "Blis", "Bopo",
+    "Brah", "Brai", "Bugi", "Buhd", "Cakm",       "Cans", "Cari", "Cham",
+    "Cher", "Cirt", "Copt", "Cprt", "Cyrl",       "Cyrs", "Deva", "Dsrt",
+    "Dupl", "Egyd", "Egyh", "Egyp", "Elba",       "Ethi", "Geok", "Geor",
+    "Glag", "Goth", "Gran", "Grek", "Gujr",       "Guru", "Hang", "Hani",
+    "Hano", "Hans", "Hant", "Hatr", "Hebr",       "Hira", "Hluw", "Hmng",
+    "Hrkt", "Hung", "Inds", "Ital", "Java",       "Jpan", "Jurc", "Kali",
+    "Kana", "Khar", "Khmr", "Khoj", "Kitl",       "Kits", "Knda", "Kore",
+    "Kpel", "Kthi", "Lana", "Laoo", "Latf",       "Latg", "Latn", "Lepc",
+    "Limb", "Lina", "Linb", "Lisu", "Loma",       "Lyci", "Lydi", "Mahj",
+    "Mand", "Mani", "Marc", "Maya", "Mend",       "Merc", "Mero", "Mlym",
+    "Modi", "Mong", "Moon", "Mroo", "Mtei",       "Mult", "Mymr", "Narb",
+    "Nbat", "Nkgb", "Nkoo", "Nshu", "Ogam",       "Olck", "Orkh", "Orya",
+    "Osge", "Osma", "Palm", "Pauc", "Perm",       "Phag", "Phli", "Phlp",
+    "Phlv", "Phnx", "Plrd", "Prti", "Qaaa..Qabx", "Rjng", "Roro", "Runr",
+    "Samr", "Sara", "Sarb", "Saur", "Sgnw",       "Shaw", "Shrd", "Sidd",
+    "Sind", "Sinh", "Sora", "Sund", "Sylo",       "Syrc", "Syre", "Syrj",
+    "Syrn", "Tagb", "Takr", "Tale", "Talu",       "Taml", "Tang", "Tavt",
+    "Telu", "Teng", "Tfng", "Tglg", "Thaa",       "Thai", "Tibt", "Tirh",
+    "Ugar", "Vaii", "Visp", "Wara", "Wole",       "Xpeo", "Xsux", "Yiii",
+    "Zinh", "Zmth", "Zsym", "Zxxx", "Zyyy",       "Zzzz"};
+const std::unordered_set<std::string> kW3CRegion{
+    "AA",     "AC",  "AD",  "AE",  "AF",  "AG",  "AI",  "AL",  "AM",  "AN",
+    "AO",     "AQ",  "AR",  "AS",  "AT",  "AU",  "AW",  "AX",  "AZ",  "BA",
+    "BB",     "BD",  "BE",  "BF",  "BG",  "BH",  "BI",  "BJ",  "BL",  "BM",
+    "BN",     "BO",  "BQ",  "BR",  "BS",  "BT",  "BU",  "BV",  "BW",  "BY",
+    "BZ",     "CA",  "CC",  "CD",  "CF",  "CG",  "CH",  "CI",  "CK",  "CL",
+    "CM",     "CN",  "CO",  "CP",  "CR",  "CS",  "CU",  "CV",  "CW",  "CX",
+    "CY",     "CZ",  "DD",  "DE",  "DG",  "DJ",  "DK",  "DM",  "DO",  "DZ",
+    "EA",     "EC",  "EE",  "EG",  "EH",  "ER",  "ES",  "ET",  "EU",  "FI",
+    "FJ",     "FK",  "FM",  "FO",  "FR",  "FX",  "GA",  "GB",  "GD",  "GE",
+    "GF",     "GG",  "GH",  "GI",  "GL",  "GM",  "GN",  "GP",  "GQ",  "GR",
+    "GS",     "GT",  "GU",  "GW",  "GY",  "HK",  "HM",  "HN",  "HR",  "HT",
+    "HU",     "IC",  "ID",  "IE",  "IL",  "IM",  "IN",  "IO",  "IQ",  "IR",
+    "IS",     "IT",  "JE",  "JM",  "JO",  "JP",  "KE",  "KG",  "KH",  "KI",
+    "KM",     "KN",  "KP",  "KR",  "KW",  "KY",  "KZ",  "LA",  "LB",  "LC",
+    "LI",     "LK",  "LR",  "LS",  "LT",  "LU",  "LV",  "LY",  "MA",  "MC",
+    "MD",     "ME",  "MF",  "MG",  "MH",  "MK",  "ML",  "MM",  "MN",  "MO",
+    "MP",     "MQ",  "MR",  "MS",  "MT",  "MU",  "MV",  "MW",  "MX",  "MY",
+    "MZ",     "NA",  "NC",  "NE",  "NF",  "NG",  "NI",  "NL",  "NO",  "NP",
+    "NR",     "NT",  "NU",  "NZ",  "OM",  "PA",  "PE",  "PF",  "PG",  "PH",
+    "PK",     "PL",  "PM",  "PN",  "PR",  "PS",  "PT",  "PW",  "PY",  "QA",
+    "QM..QZ", "RE",  "RO",  "RS",  "RU",  "RW",  "SA",  "SB",  "SC",  "SD",
+    "SE",     "SG",  "SH",  "SI",  "SJ",  "SK",  "SL",  "SM",  "SN",  "SO",
+    "SR",     "SS",  "ST",  "SU",  "SV",  "SX",  "SY",  "SZ",  "TA",  "TC",
+    "TD",     "TF",  "TG",  "TH",  "TJ",  "TK",  "TL",  "TM",  "TN",  "TO",
+    "TP",     "TR",  "TT",  "TV",  "TW",  "TZ",  "UA",  "UG",  "UM",  "US",
+    "UY",     "UZ",  "VA",  "VC",  "VE",  "VG",  "VI",  "VN",  "VU",  "WF",
+    "WS",
+    "XA..XZ",  // TODO(w.kosowicz): should it be all the letters from XA to XZ?
+    "YD",     "YE",  "YT",  "YU",  "ZA",  "ZM",  "ZR",  "ZW",  "ZZ",  "001",
+    "002",    "003", "005", "009", "011", "013", "014", "015", "017", "018",
+    "019",    "021", "029", "030", "034", "035", "039", "053", "054", "057",
+    "061",    "142", "143", "145", "150", "151", "154", "155", "419"};
+const std::unordered_set<std::string> kW3CVariant{
+    "1606nict", "1694acad", "1901",     "1959acad", "1994",     "1996",
+    "abl1943",  "alalc97",  "aluku",    "ao1990",   "arevela",  "arevmda",
+    "baku1926", "balanka",  "barla",    "bauddha",  "biscayan", "biske",
+    "bohoric",  "boont",    "colb1945", "dajnko",   "ekavsk",   "emodeng",
+    "fonipa",   "fonupa",   "fonxsamp", "hepburn",  "heploc",   "hognorsk",
+    "ijekavsk", "itihasa",  "jauer",    "jyutping", "kkcor",    "kociewie",
+    "kscor",    "laukika",  "lipaw",    "luna1918", "metelko",  "monoton",
+    "ndyuka",   "nedis",    "njiva",    "nulik",    "osojs",    "oxendict",
+    "pamaka",   "petr1708", "pinyin",   "polyton",  "puter",    "rigik",
+    "rozaj",    "rumgr",    "scotland", "scouse",   "solba",    "sotav",
+    "surmiran", "sursilv",  "sutsilv",  "tarask",   "uccor",    "ucrcor",
+    "ulster",   "unifon",   "vaidika",  "valencia", "vallader", "wadegile"};
+}  // namespace w3c_languages
+}  // namespace utils
diff --git a/src/manifest_parser/utils/w3c_languages.h b/src/manifest_parser/utils/w3c_languages.h
new file mode 100644 (file)
index 0000000..d37759f
--- /dev/null
@@ -0,0 +1,38 @@
+// 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 MANIFEST_PARSER_UTILS_W3C_LANGUAGES_H_
+#define MANIFEST_PARSER_UTILS_W3C_LANGUAGES_H_
+
+#include <map>
+#include <string>
+#include <unordered_set>
+
+namespace utils {
+namespace w3c_languages {
+namespace lang_set {
+
+/**
+ * @brief ValidateOnlyLanguage
+ *        Checks validity of language part of language tag.
+ *
+ * Languauge part is described:
+ *  - http://www.w3.org/International/articles/language-tags/#language
+ *
+ * @param language language
+ * @return true if language is correct
+ */
+bool ValidateOnlyLanguage(const std::string& language);
+
+}  // namespace lang_set
+
+extern const std::map<std::string, std::string> kW3CExtLang;
+extern const std::unordered_set<std::string> kW3CScript;
+extern const std::unordered_set<std::string> kW3CRegion;
+extern const std::unordered_set<std::string> kW3CVariant;
+
+}  // namespace w3c_languages
+}  // namespace utils
+
+#endif  // MANIFEST_PARSER_UTILS_W3C_LANGUAGES_H_
index 6911635c144404e4c2f6f14e8d8efdaa57ff06ac..00d8e175c7d83480c607fd25d1a0df4b733fd9e9 100644 (file)
@@ -12,7 +12,7 @@
 #include <cassert>
 #include <cmath>
 
-#include "utils/logging.h"
+#include "manifest_parser/utils/logging.h"
 
 namespace parser {
 
index 42ba313772f1969112c3162f4d94e57d8397a04b..8fbc51114514a18c530f651dbd5ad6fbb50d5872 100644 (file)
@@ -3,6 +3,7 @@ SET(SRCS
   account_handler.cc
   application_manifest_constants.cc
   author_handler.cc
+  common/application_handler.cc
   description_handler.cc
   package_handler.cc
   privileges_handler.cc
index 51add51438b9dd95b6880bc6157fd4171cb67d1f..c2da04caad9ebf22de6123aa34c48c119efad015 100644 (file)
@@ -4,9 +4,9 @@
 
 #include "tpk_manifest_handlers/account_handler.h"
 
+#include "manifest_parser/utils/language_tag_validator.h"
+#include "manifest_parser/utils/logging.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
-#include "utils/language_tag_validator.h"
-#include "utils/logging.h"
 
 namespace {
 const char kTrueValueString[] = "true";
index 97b01e0e808c2f1c7699450378982934140341b6..f6bd5acd1f465295bd431e924fc285205aac1f86 100644 (file)
@@ -9,9 +9,9 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 
 namespace tpk {
diff --git a/src/tpk_manifest_handlers/common/application_handler.cc b/src/tpk_manifest_handlers/common/application_handler.cc
new file mode 100644 (file)
index 0000000..8c6a825
--- /dev/null
@@ -0,0 +1,45 @@
+// 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/common/application_handler.h"
+
+namespace tpk {
+namespace parse {
+namespace tpk_app_keys {
+// app-control
+const char kAppControlKey[] = "app-control";
+const char kAppControlOperationKey[] = "operation";
+const char kAppControlURIKey[] = "uri";
+const char kAppControlMimeKey[] = "mime";
+const char kAppControlNameChildKey[] = "@name";
+
+// background-category
+const char kBackgroundCategoryKey[] = "background-category";
+const char kBackgroundCategoryValueKey[] = "@value";
+
+// datacontrol
+const char kDataControlKey[] = "datacontrol";
+const char kDataControlAccessKey[] = "@access";
+const char kDataControlProviderIDKey[] = "@providerid";
+const char kDataControlTypeKey[] = "@type";
+
+// icon
+const char kIconKey[] = "icon";
+const char kIconTextKey[] = "#text";
+
+// label
+const char kLabelKey[] = "label";
+const char kLabelTextKey[] = "#text";
+const char kLabelLangKey[] = "@lang";
+
+// metadata
+const char kMetaDataKey[] = "metadata";
+const char kMetaDataKeyKey[] = "@key";
+const char kMetaDataValueKey[] = "@value";
+}  // namespace tpk_app_keys
+
+const utils::VersionNumber kLaunchModeRequiredVersion("2.4");
+
+}  // namespace parse
+}  // namespace tpk
diff --git a/src/tpk_manifest_handlers/common/application_handler.h b/src/tpk_manifest_handlers/common/application_handler.h
new file mode 100644 (file)
index 0000000..cf83d3d
--- /dev/null
@@ -0,0 +1,285 @@
+// 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_COMMON_APPLICATION_HANDLER_H_
+#define TPK_MANIFEST_HANDLERS_COMMON_APPLICATION_HANDLER_H_
+
+#include <algorithm>
+#include <functional>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/version_number.h"
+#include "manifest_parser/values.h"
+#include "tpk_manifest_handlers/ui_and_service_application_infos.h"
+
+namespace tpk {
+namespace parse {
+namespace tpk_app_keys {
+// app-control
+extern const char kAppControlKey[];
+extern const char kAppControlOperationKey[];
+extern const char kAppControlURIKey[];
+extern const char kAppControlMimeKey[];
+extern const char kAppControlNameChildKey[];
+
+// background-category
+extern const char kBackgroundCategoryKey[];
+extern const char kBackgroundCategoryValueKey[];
+
+// datacontrol
+extern const char kDataControlKey[];
+extern const char kDataControlAccessKey[];
+extern const char kDataControlProviderIDKey[];
+extern const char kDataControlTypeKey[];
+
+// icon
+extern const char kIconKey[];
+extern const char kIconTextKey[];
+
+// label
+extern const char kLabelKey[];
+extern const char kLabelTextKey[];
+extern const char kLabelLangKey[];
+
+// metadata
+extern const char kMetaDataKey[];
+extern const char kMetaDataKeyKey[];
+extern const char kMetaDataValueKey[];
+}  // namespace tpk_app_keys
+
+extern const utils::VersionNumber kLaunchModeRequiredVersion;
+
+class ApplicationInfo : public parser::ManifestData {
+ public:
+  void set_appid(const std::string& appid) {
+    appid_ = appid;
+  }
+
+  void set_exec(const std::string& exec) {
+    exec_ = exec;
+  }
+
+  const std::string& appid() const {
+    return appid_;
+  }
+
+  const std::string& exec() const {
+    return exec_;
+  }
+
+ private:
+  std::string appid_;
+  std::string exec_;
+};
+
+template<typename T>
+struct ApplicationSingleEntry : public parser::ManifestData {
+  T app_info;
+  std::vector<MetaDataInfo> meta_data;
+  ApplicationIconsInfo app_icons;
+  std::vector<LabelInfo> label;
+};
+
+template<typename T>
+struct ApplicationInfoList : public parser::ManifestData {
+  std::vector<T> items;
+};
+
+template<typename T>
+bool ParseAppControl(const parser::DictionaryValue& dict,
+                     T* info, std::string*) {
+  for (const auto& item_operation : parser::GetOneOrMany(&dict,
+      tpk_app_keys::kAppControlOperationKey, "")) {
+    std::string operation;
+    std::string uri;
+    std::string mime;
+    item_operation->GetString(
+        tpk_app_keys::kAppControlNameChildKey, &operation);
+
+    auto uri_items = parser::GetOneOrMany(
+        &dict, tpk_app_keys::kAppControlURIKey, "");
+    auto mime_items = parser::GetOneOrMany(
+        &dict, tpk_app_keys::kAppControlMimeKey, "");
+
+    if (uri_items.empty()) uri_items.push_back(new parser::DictionaryValue());
+    if (mime_items.empty()) mime_items.push_back(new parser::DictionaryValue());
+
+    for (const auto& item_uri : uri_items) {
+      item_uri->GetString(tpk_app_keys::kAppControlNameChildKey, &uri);
+
+      for (const auto& item_mime : mime_items) {
+        item_mime->GetString(tpk_app_keys::kAppControlNameChildKey, &mime);
+        info->app_control.emplace_back(operation, uri, mime);
+      }
+    }
+  }
+
+  return true;
+}
+
+template<typename T>
+bool ParseBackgroundCategoryElement(const parser::DictionaryValue& dict,
+                                    T* info, std::string* error) {
+  std::string value;
+
+  if (!dict.GetString(tpk_app_keys::kBackgroundCategoryValueKey, &value)) {
+    *error = "Parsing background-category element failed";
+    return false;
+  }
+
+  info->background_category.emplace_back(std::move(value));
+
+  return true;
+}
+
+template<typename T>
+bool ParseDataControl(const parser::DictionaryValue& dict,
+                      T* info, std::string*) {
+  std::string access;
+  dict.GetString(tpk_app_keys::kDataControlAccessKey, &access);
+  std::string providerid;
+  dict.GetString(tpk_app_keys::kDataControlProviderIDKey, &providerid);
+  std::string type;
+  dict.GetString(tpk_app_keys::kDataControlTypeKey, &type);
+  info->data_control.emplace_back(access, providerid, type);
+  return true;
+}
+
+template<typename T>
+bool ParseAppIcon(const parser::DictionaryValue& dict,
+                  T* info, std::string* error) {
+  std::string icon_path;
+
+  if (!dict.GetString(tpk_app_keys::kIconTextKey, &icon_path)) {
+    *error = "Parsing Icon failed";
+    return false;
+  }
+
+  info->app_icons.AddIcon(ApplicationIcon(icon_path));
+
+  return true;
+}
+
+template<typename T>
+bool ParseLabel(const parser::DictionaryValue& dict,
+                T* info, std::string*) {
+  std::string text;
+  dict.GetString(tpk_app_keys::kLabelTextKey, &text);
+  std::string xml_lang;
+  dict.GetString(tpk_app_keys::kLabelLangKey, &xml_lang);
+  info->label.emplace_back(text, text, xml_lang);
+  return true;
+}
+
+template<typename T>
+bool ParseMetaData(const parser::DictionaryValue& dict,
+                   T* info, std::string*) {
+  std::string key;
+  dict.GetString(tpk_app_keys::kMetaDataKeyKey, &key);
+  std::string val;
+  dict.GetString(tpk_app_keys::kMetaDataValueKey, &val);
+
+  if (key.find(tpk_app_keys::kBackgroundCategoryKey) == std::string::npos) {
+    info->meta_data.emplace_back(key, val);
+  } else {
+    val = key.substr(key.find_last_of("/") + 1);
+    info->background_category.emplace_back(std::move(val));
+  }
+
+  return true;
+}
+
+template<typename T>
+using ParsingFuncPtr =
+    std::function<bool(const parser::DictionaryValue&, T*, std::string*)>;
+
+template<typename T>
+bool InitializeParsingElement(
+    const parser::DictionaryValue& app_dict,
+    const std::string& key,
+    ParsingFuncPtr<T> ParsingFunc,
+    T* applicationinfo, std::string* error) {
+  for (const auto& item : parser::GetOneOrMany(&app_dict, key, "")) {
+    if (!ParsingFunc(*item, applicationinfo, error)) {
+      return false;
+    }
+  }
+  return true;
+}
+
+template<typename T>
+bool AppControlValidation(const T& it, std::string* error) {
+  for (const auto& item : it.app_control) {
+    if (item.operation().empty()) {
+      *error =
+          "The operation child element of app-control element is obligatory";
+      return false;
+    } else if (!parser::utils::IsValidIRI(item.operation())) {
+      *error =
+          "The operation child element of app-control element is not valid url";
+      return false;
+    }
+  }
+  return true;
+}
+
+template<typename T>
+bool DataControlValidation(const T& it, std::string* error) {
+  for (const auto& item : it.data_control) {
+    if (item.access().empty()) {
+      *error =
+          "The access child element of datacontrol element is obligatory";
+      return false;
+    }
+
+    if (item.providerid().empty()) {
+      *error =
+          "The providerid child element of datacontrol element is obligatory";
+      return false;
+    }
+
+    if (item.type().empty()) {
+      *error =
+          "The type child element of datacontrol element is obligatory";
+      return false;
+    }
+  }
+  return true;
+}
+
+template<typename T>
+bool LabelValidation(const T& it, std::string* error) {
+  if (std::any_of(it.label.begin(), it.label.end(),
+      [](const LabelInfo& item) { return item.text().empty(); })) {
+    *error = "The text child element of label element is obligatory";
+    return false;
+  }
+
+  if (std::any_of(it.label.begin(), it.label.end(),
+      [](const LabelInfo& item) { return item.name().empty(); })) {
+    *error = "The name child element of label element is obligatory";
+    return false;
+  }
+
+  return true;
+}
+
+template<typename T>
+bool MetadataValidation(const T& it, std::string* error) {
+  if (std::any_of(it.meta_data.begin(), it.meta_data.end(),
+      [](const MetaDataInfo& item) { return item.key().empty(); })) {
+    *error = "The key child element of metadata element is obligatory";
+    return false;
+  }
+
+  return true;
+}
+
+}  // namespace parse
+}  // namespace tpk
+
+#endif  // TPK_MANIFEST_HANDLERS_COMMON_APPLICATION_HANDLER_H_
index c2d8f078babb160db1dee9799bff2e3302613594..eb48afa8fef9d5100ff6603b3ae8e8493e2ef97f 100644 (file)
@@ -9,9 +9,9 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 
 namespace tpk {
index 2a39f3da1f1d78574cda5980c29119ec4905dcae..919258da6ba500edb58a0a41a95edc5fc7e1e9f5 100644 (file)
@@ -9,9 +9,9 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 
 namespace tpk {
index 09ec5125af46d69e04d80927fff7c86a024be2f7..80fbfecac239850f2a1dab9efa757e936367545e 100644 (file)
@@ -7,9 +7,9 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 
 // TODO(m.socha): Handler is very similar to wgt permissions_handler.
index 3f21c9733cde4a3619ecfb7969dd8b6a6627ca2b..4e7369032cb9c2e08f919ee1352aebf22e0e7e56 100644 (file)
@@ -9,9 +9,8 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/logging.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 
 namespace tpk {
@@ -32,218 +31,21 @@ const char kServiceApplicationTypeKey[] = "@type";
 const char kServiceApplicationProcessPoolKey[] = "@process-pool";
 const char kServiceApplicationKeyText[] = "#text";
 
-// app-control
-const char kAppControlKey[] = "app-control";
-const char kAppControlOperationKey[] = "operation";
-const char kAppControlURIKey[] = "uri";
-const char kAppControlMimeKey[] = "mime";
-const char kAppControlNameChildKey[] = "@name";
-
-// background-category
-const char kBackgroundCategoryKey[] = "background-category";
-const char kBackgroundCategoryValueKey[] = "@value";
-
-// datacontrol
-const char kDataControlKey[] = "datacontrol";
-const char kDataControlAccessKey[] = "@access";
-const char kDataControlProviderIDKey[] = "@providerid";
-const char kDataControlTypeKey[] = "@type";
-
-// icon
-const char kIconKey[] = "icon";
-const char kIconTextKey[] = "#text";
-
-// label
-const char kLabelKey[] = "label";
-const char kLabelTextKey[] = "#text";
-const char kLabelLangKey[] = "@lang";
-
-// metadata
-const char kMetaDataKey[] = "metadata";
-const char kMetaDataKeyKey[] = "@key";
-const char kMetaDataValueKey[] = "@value";
-
-bool ParseAppControl(
-  const parser::DictionaryValue* dict,
-  ServiceApplicationSingleEntry* info) {
-  for (const auto& item_operation : parser::GetOneOrMany(dict,
-      kAppControlOperationKey, "")) {
-    std::string operation;
-    std::string uri;
-    std::string mime;
-    item_operation->GetString(kAppControlNameChildKey, &operation);
-
-    auto uri_items = parser::GetOneOrMany(dict, kAppControlURIKey, "");
-    auto mime_items = parser::GetOneOrMany(dict, kAppControlMimeKey, "");
-
-    if (uri_items.empty()) uri_items.push_back(new parser::DictionaryValue());
-    if (mime_items.empty()) mime_items.push_back(new parser::DictionaryValue());
-
-    for (const auto& item_uri : uri_items) {
-      item_uri->GetString(kAppControlNameChildKey, &uri);
-
-      for (const auto& item_mime : mime_items) {
-        item_mime->GetString(kAppControlNameChildKey, &mime);
-        info->app_control.emplace_back(operation, uri, mime);
-      }
-    }
-  }
-
-  return true;
-}
-
-bool ParseBackgroundCategoryElement(
-    const parser::DictionaryValue* dict,
-    ServiceApplicationSingleEntry* info) {
-  std::string value;
-
-  if (!dict->GetString(kBackgroundCategoryValueKey, &value))
-    return false;
-
-  info->background_category.emplace_back(std::move(value));
-
-  return true;
-}
-
-bool ParseDataControl(
-  const parser::DictionaryValue* dict,
-  ServiceApplicationSingleEntry* info) {
-  std::string access;
-  dict->GetString(kDataControlAccessKey, &access);
-  std::string providerid;
-  dict->GetString(kDataControlProviderIDKey, &providerid);
-  std::string type;
-  dict->GetString(kDataControlTypeKey, &type);
-  info->data_control.emplace_back(access, providerid, type);
-  return true;
-}
-
-bool ParseMetaData(
-  const parser::DictionaryValue* dict,
-  ServiceApplicationSingleEntry* info) {
-  std::string key;
-  dict->GetString(kMetaDataKeyKey, &key);
-  std::string val;
-  dict->GetString(kMetaDataValueKey, &val);
-  info->meta_data.emplace_back(key, val);
-  return true;
-}
-
-bool ParseAppIcon(
-  const parser::DictionaryValue* dict,
-  ServiceApplicationSingleEntry* info) {
-  std::string icon_path;
-  if (!dict->GetString(kIconTextKey, &icon_path))
-    return false;
-  info->app_icons.AddIcon(ApplicationIcon(icon_path));
-  return true;
-}
-
-bool ParseLabel(
-  const parser::DictionaryValue* dict,
-  ServiceApplicationSingleEntry* info) {
-  std::string text;
-  dict->GetString(kLabelTextKey, &text);
-  std::string xml_lang;
-  dict->GetString(kLabelLangKey, &xml_lang);
-  info->label.emplace_back(text, text, xml_lang);
-  return true;
-}
-
-bool InitializeAppControlParsing(
-    const parser::DictionaryValue& app_dict,
-    ServiceApplicationSingleEntry* serviceapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kAppControlKey, "")) {
-    if (!ParseAppControl(item, serviceapplicationinfo)) {
-      *error = "Parsing AppControl failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeBackgroundCategoryParsing(
-    const parser::DictionaryValue& control_dict,
-    ServiceApplicationSingleEntry* serviceapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&control_dict,
-      kBackgroundCategoryKey, "")) {
-    if (!ParseBackgroundCategoryElement(item, serviceapplicationinfo)) {
-      *error = "Parsing background-category element failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeDataControlParsing(
-    const parser::DictionaryValue& app_dict,
-    ServiceApplicationSingleEntry* serviceapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kDataControlKey, "")) {
-    if (!ParseDataControl(item, serviceapplicationinfo)) {
-      *error = "Parsing DataControl failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeMetaDataParsing(
-    const parser::DictionaryValue& app_dict,
-    ServiceApplicationSingleEntry* serviceapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kMetaDataKey, "")) {
-    if (!ParseMetaData(item, serviceapplicationinfo)) {
-      *error = "Parsing Metadata failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeIconParsing(
-    const parser::DictionaryValue& app_dict,
-    ServiceApplicationSingleEntry* serviceapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kIconKey, "")) {
-    if (!ParseAppIcon(item, serviceapplicationinfo)) {
-      *error = "Parsing Icon failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeLabelParsing(
-    const parser::DictionaryValue& app_dict,
-    ServiceApplicationSingleEntry* serviceapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kLabelKey, "")) {
-    if (!ParseLabel(item, serviceapplicationinfo)) {
-      *error = "Parsing Label failed";
-      return false;
-    }
-  }
-  return true;
-}
-
 bool ServiceAppValidation(
     const ServiceApplicationSingleEntry& item,
     std::string* error) {
-  if (item.sa_info.appid().empty()) {
+  if (item.app_info.appid().empty()) {
     *error = "The appid child element of "
              "service application element is obligatory";
     return false;
   }
-  const std::string& exec = item.sa_info.exec();
+  const std::string& exec = item.app_info.exec();
   if (exec.empty()) {
     *error =
         "The exec child element of service application element is obligatory";
     return false;
   }
-  const std::string& type = item.sa_info.type();
+  const std::string& type = item.app_info.type();
   if (type.empty()) {
     *error =
         "The type child element of service application element is obligatory";
@@ -252,82 +54,6 @@ bool ServiceAppValidation(
   return true;
 }
 
-bool AppControlValidation(
-    const ServiceApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.app_control) {
-    if (item.operation().empty()) {
-      *error =
-          "The operation child element of app-control element is obligatory";
-      return false;
-    } else if (!parser::utils::IsValidIRI(item.operation())) {
-      *error =
-          "The operation child element of app-control element is not valid url";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool DataControlValidation(
-    const ServiceApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.data_control) {
-    if (item.access().empty()) {
-      *error =
-          "The access child element of datacontrol element is obligatory";
-      return false;
-    }
-
-    const std::string& providerid = item.providerid();
-    if (providerid.empty()) {
-      *error =
-          "The providerid child element of datacontrol element is obligatory";
-      return false;
-    }
-
-    const std::string& type = item.type();
-    if (type.empty()) {
-      *error =
-          "The type child element of datacontrol element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool MetadataValidation(
-    const ServiceApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.meta_data) {
-    if (item.key().empty()) {
-      *error =
-          "The key child element of metadata element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool LabelValidation(
-    const ServiceApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.label) {
-    if (item.text().empty()) {
-      *error = "The text child element of label element is obligatory";
-      return false;
-    }
-
-    const std::string& name = item.name();
-    if (name.empty()) {
-      *error =
-          "The name child element of label element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
 bool ParseServiceApplicationAndStore(
     const parser::DictionaryValue& app_dict,
     ServiceApplicationSingleEntry* serviceapplicationinfo,
@@ -343,11 +69,11 @@ bool ParseServiceApplicationAndStore(
   std::string type;
   app_dict.GetString(kServiceApplicationTypeKey, &type);
 
-  serviceapplicationinfo->sa_info.set_appid(appid);
-  serviceapplicationinfo->sa_info.set_exec(exec);
-  serviceapplicationinfo->sa_info.set_auto_restart(auto_restart);
-  serviceapplicationinfo->sa_info.set_on_boot(on_boot);
-  serviceapplicationinfo->sa_info.set_type(type);
+  serviceapplicationinfo->app_info.set_appid(appid);
+  serviceapplicationinfo->app_info.set_exec(exec);
+  serviceapplicationinfo->app_info.set_auto_restart(auto_restart);
+  serviceapplicationinfo->app_info.set_on_boot(on_boot);
+  serviceapplicationinfo->app_info.set_type(type);
 
   std::string process_pool;
   if (app_dict.GetString(kServiceApplicationProcessPoolKey, &process_pool)) {
@@ -356,29 +82,35 @@ bool ParseServiceApplicationAndStore(
       *error = "process_pool must be 'true' or 'false'";
       return false;
     }
-    serviceapplicationinfo->sa_info.set_process_pool(process_pool);
+    serviceapplicationinfo->app_info.set_process_pool(process_pool);
   }
 
-  if (!InitializeAppControlParsing(app_dict,
-                                  serviceapplicationinfo,
-                                  error) ||
-     !InitializeDataControlParsing(app_dict,
-                                   serviceapplicationinfo,
-                                   error) ||
-     !InitializeMetaDataParsing(app_dict,
-                                serviceapplicationinfo,
-                                error) ||
-     !InitializeIconParsing(app_dict,
-                            serviceapplicationinfo,
-                            error) ||
-     !InitializeLabelParsing(app_dict,
-                             serviceapplicationinfo,
-                             error) ||
-     !InitializeBackgroundCategoryParsing(app_dict,
-                             serviceapplicationinfo,
-                             error)) {
+  ParsingFuncPtr<ServiceApplicationSingleEntry> parsingFunc =
+      ParseAppControl<ServiceApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kAppControlKey,
+      parsingFunc, serviceapplicationinfo, error))
     return false;
-  }
+  parsingFunc = ParseDataControl<ServiceApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kDataControlKey,
+      parsingFunc, serviceapplicationinfo, error))
+    return false;
+  parsingFunc = ParseMetaData<ServiceApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kMetaDataKey,
+      parsingFunc, serviceapplicationinfo, error))
+    return false;
+  parsingFunc = ParseAppIcon<ServiceApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kIconKey,
+      parsingFunc, serviceapplicationinfo, error))
+    return false;
+  parsingFunc = ParseLabel<ServiceApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kLabelKey,
+      parsingFunc, serviceapplicationinfo, error))
+    return false;
+  parsingFunc = ParseBackgroundCategoryElement<ServiceApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kBackgroundCategoryKey,
+      parsingFunc, serviceapplicationinfo, error))
+    return false;
+
   return true;
 }
 
index 7ce0028d489fac234e2add7222c0d5c4fc8abed5..cc8cd7e389efc200a0d91d6898c70533a56eb3a0 100644 (file)
@@ -7,29 +7,26 @@
 
 #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"
-#include "tpk_manifest_handlers/ui_and_service_application_infos.h"
+#include "tpk_manifest_handlers/common/application_handler.h"
 
 namespace tpk {
 namespace parse {
 
-class ServiceApplicationInfo : public parser::ManifestData {
+class ServiceApplicationInfo : public ApplicationInfo {
  public:
   /**
    * @brief key
    * @param key string
    */
   static std::string key();
-  /**
-   * @brief set_appid sets appid
-   * @param appid
-   */
-  void set_appid(const std::string& appid) {
-    appid_ = appid;
+  void set_type(const std::string& type) {
+    type_ = type;
+  }
+  void set_process_pool(const std::string& process_pool) {
+    process_pool_ = process_pool;
   }
   /**
    * @brief set_auto_restart sets auto restart
@@ -38,13 +35,6 @@ class ServiceApplicationInfo : public parser::ManifestData {
   void set_auto_restart(const std::string& auto_restart) {
     auto_restart_ = auto_restart;
   }
-  /**
-   * @brief set_exec sets exec
-   * @param exec
-   */
-  void set_exec(const std::string& exec) {
-    exec_ = exec;
-  }
   /**
    * @brief set_on_boot sets on boot
    * @param on_boot
@@ -52,23 +42,12 @@ class ServiceApplicationInfo : public parser::ManifestData {
   void set_on_boot(const std::string& on_boot) {
     on_boot_ = on_boot;
   }
-  /**
-   * @brief set_type sets type
-   * @param type
-   */
-  void set_type(const std::string& type) {
-    type_ = type;
-  }
-  void set_process_pool(const std::string& process_pool) {
-    process_pool_ = process_pool;
-  }
 
-  /**
-   * @brief appid
-   * @return appid string
-   */
-  const std::string& appid() const {
-    return appid_;
+  const std::string& type() const {
+    return type_;
+  }
+  const std::string& process_pool() const {
+    return process_pool_;
   }
   /**
    * @brief auto_restart
@@ -77,13 +56,6 @@ class ServiceApplicationInfo : public parser::ManifestData {
   const std::string& auto_restart() const {
     return auto_restart_;
   }
-  /**
-   * @brief exec
-   * @return exec string
-   */
-  const std::string& exec() const {
-    return exec_;
-  }
   /**
    * @brief on_boot
    * @return on_boot string
@@ -91,39 +63,23 @@ class ServiceApplicationInfo : public parser::ManifestData {
   const std::string& on_boot() const {
     return on_boot_;
   }
-  /**
-   * @brief type
-   * @return type string
-   */
-  const std::string& type() const {
-    return type_;
-  }
-  const std::string& process_pool() const {
-    return process_pool_;
-  }
 
  private:
-  std::string appid_;
-  std::string auto_restart_;
-  std::string exec_;
-  std::string on_boot_;
   std::string type_;
   std::string process_pool_;
+  std::string auto_restart_;
+  std::string on_boot_;
 };
 
-struct ServiceApplicationSingleEntry : public parser::ManifestData {
-  ServiceApplicationInfo sa_info;
+struct ServiceApplicationSingleEntry :
+    public ApplicationSingleEntry<ServiceApplicationInfo> {
   std::vector<AppControlInfo> app_control;
   std::vector<BackgroundCategoryInfo> background_category;
   std::vector<DataControlInfo> data_control;
-  std::vector<MetaDataInfo> meta_data;
-  ApplicationIconsInfo app_icons;
-  std::vector<LabelInfo> label;
 };
 
-struct ServiceApplicationInfoList : public parser::ManifestData {
-  std::vector<ServiceApplicationSingleEntry> items;
-};
+using ServiceApplicationInfoList =
+    ApplicationInfoList<ServiceApplicationSingleEntry>;
 
 /**
  * @brief The ServiceApplicationHandler class
@@ -152,7 +108,7 @@ class ServiceApplicationHandler : public parser::ManifestHandler {
   std::string Key() const override;
 };
 
-}   // namespace parse
-}   // namespace tpk
+}  // namespace parse
+}  // namespace tpk
 
 #endif  // TPK_MANIFEST_HANDLERS_SERVICE_APPLICATION_HANDLER_H_
index a02f5ff087de91769436695a52cc9a6cbcd138f4..48fef845e46a3cffbb41960f41783e5c6a7058a9 100644 (file)
@@ -4,9 +4,9 @@
 
 #include "tpk_manifest_handlers/shortcut_handler.h"
 
+#include "manifest_parser/utils/language_tag_validator.h"
 #include "manifest_parser/values.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
-#include "utils/language_tag_validator.h"
 
 namespace keys = tpk::application_keys;
 
index caadf06221a72a495e635f717186ccff07448619..25b6c775bf5584e08a25591b85f72bd3f30fb8b5 100644 (file)
@@ -10,9 +10,8 @@
 #include <vector>
 
 #include "manifest_parser/manifest_handler.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
-
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
 #include "tpk_manifest_handlers/account_handler.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 #include "tpk_manifest_handlers/author_handler.h"
index 833aa6cdeb7b36311664b5fdb44d40ae4e35c125..5ea296b9841dbb6c1846ad11caf00150151c6f54 100644 (file)
@@ -9,20 +9,12 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/utils/version_number.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
-#include "utils/version_number.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 #include "tpk_manifest_handlers/package_handler.h"
 
-namespace {
-
-const utils::VersionNumber kLaunchModeRequiredVersion("2.4");
-const char kUIApplicationKey[] = "manifest.ui-application";
-
-}  // namespace
-
 namespace tpk {
 namespace parse {
 
@@ -30,43 +22,12 @@ namespace ba = boost::algorithm;
 namespace keys = tpk::application_keys;
 
 namespace {
-// app-control
-const char kAppControlKey[] = "app-control";
-const char kAppControlOperationKey[] = "operation";
-const char kAppControlURIKey[] = "uri";
-const char kAppControlMimeKey[] = "mime";
-const char kAppControlNameChildKey[] = "@name";
-
-// background-category
-const char kBackgroundCategoryKey[] = "background-category";
-const char kBackgroundCategoryValueKey[] = "@value";
-
-// datacontrol
-const char kDataControlKey[] = "datacontrol";
-const char kDataControlAccessKey[] = "@access";
-const char kDataControlProviderIDKey[] = "@providerid";
-const char kDataControlTypeKey[] = "@type";
-
-// icon
-const char kIconKey[] = "icon";
-const char kIconTextKey[] = "#text";
-
 // image
 const char kImageKey[] = "image";
 const char kImageNameKey[] = "@name";
 const char kImageSectionKey[] = "@section";
 const char kImageLangKey[] = "@lang";
 
-// label
-const char kLabelKey[] = "label";
-const char kLabelTextKey[] = "#text";
-const char kLabelLangKey[] = "@lang";
-
-// metadata
-const char kMetaDataKey[] = "metadata";
-const char kMetaDataKeyKey[] = "@key";
-const char kMetaDataValueKey[] = "@value";
-
 // ui-application
 const char kUIApplicationAppIDKey[] = "@appid";
 const char kUIApplicationExecKey[] = "@exec";
@@ -95,233 +56,72 @@ bool IsBooleanString(const std::string& value) {
 
 }  // namespace
 
-bool ParseAppControl(
-  const parser::DictionaryValue* dict,
-  UIApplicationSingleEntry* info) {
-  for (const auto& item_operation : parser::GetOneOrMany(dict,
-      kAppControlOperationKey, "")) {
-    std::string operation;
-    std::string uri;
-    std::string mime;
-    item_operation->GetString(kAppControlNameChildKey, &operation);
-
-    auto uri_items = parser::GetOneOrMany(dict, kAppControlURIKey, "");
-    auto mime_items = parser::GetOneOrMany(dict, kAppControlMimeKey, "");
-
-    if (uri_items.empty()) uri_items.push_back(new parser::DictionaryValue());
-    if (mime_items.empty()) mime_items.push_back(new parser::DictionaryValue());
-
-    for (const auto& item_uri : uri_items) {
-      item_uri->GetString(kAppControlNameChildKey, &uri);
-
-      for (const auto& item_mime : mime_items) {
-        item_mime->GetString(kAppControlNameChildKey, &mime);
-        info->app_control.emplace_back(operation, uri, mime);
-      }
-    }
-  }
-
-  return true;
-}
-
-bool ParseBackgroundCategoryElement(
-    const parser::DictionaryValue* dict,
-    UIApplicationSingleEntry* info) {
-  std::string value;
-
-  if (!dict->GetString(kBackgroundCategoryValueKey, &value))
-    return false;
-
-  info->background_category.emplace_back(std::move(value));
-
-  return true;
-}
-
-bool ParseDataControl(
-  const parser::DictionaryValue* dict,
-  UIApplicationSingleEntry* info) {
-  std::string access;
-  dict->GetString(kDataControlAccessKey, &access);
-  std::string providerid;
-  dict->GetString(kDataControlProviderIDKey, &providerid);
-  std::string type;
-  dict->GetString(kDataControlTypeKey, &type);
-  info->data_control.emplace_back(access, providerid, type);
-  return true;
-}
-
-bool ParseMetaData(
-  const parser::DictionaryValue* dict,
-  UIApplicationSingleEntry* info) {
-  std::string key;
-  dict->GetString(kMetaDataKeyKey, &key);
-  std::string val;
-  dict->GetString(kMetaDataValueKey, &val);
-  info->meta_data.emplace_back(key, val);
-  return true;
-}
-
-bool ParseAppIcon(
-  const parser::DictionaryValue* dict,
-  UIApplicationSingleEntry* info) {
-  std::string icon_path;
-  if (!dict->GetString(kIconTextKey, &icon_path))
-    return false;
-  info->app_icons.AddIcon(ApplicationIcon(icon_path));
-  return true;
-}
-
-bool ParseAppImage(
-  const parser::DictionaryValue* dict,
-  UIApplicationSingleEntry* info) {
+bool ParseAppImage(const parser::DictionaryValue& dict,
+                   UIApplicationSingleEntry* info, std::string*) {
   std::string image_name;
   std::string image_section;
   std::string image_lang;
-  if (!dict->GetString(kImageNameKey, &image_name))
-    return false;
-  dict->GetString(kImageSectionKey, &image_section);
-  dict->GetString(kImageLangKey, &image_lang);
-  info->app_images.images.emplace_back(image_name, image_section, image_lang);
-  return true;
-}
-
-bool ParseLabel(
-  const parser::DictionaryValue* dict,
-  UIApplicationSingleEntry* info) {
-  std::string text;
-  dict->GetString(kLabelTextKey, &text);
-  std::string xml_lang;
-  dict->GetString(kLabelLangKey, &xml_lang);
-  info->label.emplace_back(text, text, xml_lang);
-  return true;
-}
-
-bool InitializeAppControlParsing(
-    const parser::DictionaryValue& control_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&control_dict, kAppControlKey, "")) {
-    if (!ParseAppControl(item, uiapplicationinfo)) {
-      *error = "Parsing AppControl failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeBackgroundCategoryParsing(
-    const parser::DictionaryValue& control_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&control_dict,
-      kBackgroundCategoryKey, "")) {
-    if (!ParseBackgroundCategoryElement(item, uiapplicationinfo)) {
-      *error = "Parsing background-category element failed";
-      return false;
-    }
-  }
-  return true;
-}
 
-bool InitializeDataControlParsing(
-    const parser::DictionaryValue& control_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&control_dict, kDataControlKey, "")) {
-    if (!ParseDataControl(item, uiapplicationinfo)) {
-      *error = "Parsing DataControl failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeMetaDataParsing(
-    const parser::DictionaryValue& app_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kMetaDataKey, "")) {
-    if (!ParseMetaData(item, uiapplicationinfo)) {
-      *error = "Parsing Metadata failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeIconParsing(
-    const parser::DictionaryValue& app_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kIconKey, "")) {
-    if (!ParseAppIcon(item, uiapplicationinfo)) {
-      *error = "Parsing Icon failed";
-      return false;
-    }
-  }
-  return true;
-}
+  if (!dict.GetString(kImageNameKey, &image_name))
+    return true;
 
-bool InitializeImageParsing(
-    const parser::DictionaryValue& app_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kImageKey, "")) {
-    if (!ParseAppImage(item, uiapplicationinfo)) {
-      *error = "Parsing Image failed";
-      return false;
-    }
-  }
-  return true;
-}
+  dict.GetString(kImageSectionKey, &image_section);
+  dict.GetString(kImageLangKey, &image_lang);
+  info->app_images.images.emplace_back(image_name, image_section, image_lang);
 
-bool InitializeLabelParsing(
-    const parser::DictionaryValue& control_dict,
-    UIApplicationSingleEntry* uiapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&control_dict, kLabelKey, "")) {
-    if (!ParseLabel(item, uiapplicationinfo)) {
-      *error = "Parsing Label failed";
-      return false;
-    }
-  }
   return true;
 }
 
 bool InitializeParsing(const parser::DictionaryValue& app_dict,
                        UIApplicationSingleEntry* uiapplicationinfo,
                        std::string* error) {
-  if (!InitializeAppControlParsing(app_dict, uiapplicationinfo, error))
+  ParsingFuncPtr<UIApplicationSingleEntry> parsingFunc =
+      ParseAppControl<UIApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kAppControlKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
-  if (!InitializeDataControlParsing(app_dict, uiapplicationinfo, error))
+  parsingFunc = ParseDataControl<UIApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kDataControlKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
-  if (!InitializeMetaDataParsing(app_dict, uiapplicationinfo, error))
+  parsingFunc = ParseMetaData<UIApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kMetaDataKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
-  if (!InitializeIconParsing(app_dict, uiapplicationinfo, error))
+  parsingFunc = ParseAppIcon<UIApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kIconKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
-  if (!InitializeLabelParsing(app_dict, uiapplicationinfo, error))
+  parsingFunc = ParseLabel<UIApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kLabelKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
-  if (!InitializeImageParsing(app_dict, uiapplicationinfo, error))
+  parsingFunc = ParseAppImage;
+  if (!InitializeParsingElement(app_dict, kImageKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
-  if (!InitializeBackgroundCategoryParsing(app_dict, uiapplicationinfo, error))
+  parsingFunc = ParseBackgroundCategoryElement<UIApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kBackgroundCategoryKey,
+      parsingFunc, uiapplicationinfo, error))
     return false;
+
   return true;
 }
 
 bool UIAppValidation(const UIApplicationSingleEntry& item,
                      const std::string& api_version, std::string* error) {
-  if (item.ui_info.appid().empty()) {
+  if (item.app_info.appid().empty()) {
     *error = "The appid child element of ui-application element is obligatory";
     return false;
   }
 
-  const std::string& exec = item.ui_info.exec();
+  const std::string& exec = item.app_info.exec();
   if (exec.empty()) {
     *error = "The exec child element of ui-application element is obligatory";
     return false;
   }
 
-  const std::string& launch_mode = item.ui_info.launch_mode();
+  const std::string& launch_mode = item.app_info.launch_mode();
   if (!launch_mode.empty()) {
     if (utils::VersionNumber(api_version) < kLaunchModeRequiredVersion) {
       *error = "launch_mode attribute cannot be used for api version lower"
@@ -336,25 +136,25 @@ bool UIAppValidation(const UIApplicationSingleEntry& item,
     }
   } else {
     // FIXME currently const_cast used, but it is not the best way.
-    UIApplicationInfo &tmp = const_cast<UIApplicationInfo &>(item.ui_info);
+    UIApplicationInfo &tmp = const_cast<UIApplicationInfo &>(item.app_info);
     tmp.set_launch_mode("single");
   }
 
-  const std::string& multiple = item.ui_info.multiple();
+  const std::string& multiple = item.app_info.multiple();
   if (multiple.empty()) {
     *error =
         "The multiple child element of ui-application element is obligatory";
     return false;
   }
 
-  const std::string& nodisplay = item.ui_info.nodisplay();
+  const std::string& nodisplay = item.app_info.nodisplay();
   if (nodisplay.empty()) {
     *error =
         "The nodisplay child element of ui-application element is obligatory";
     return false;
   }
 
-  const std::string& taskmanage = item.ui_info.taskmanage();
+  const std::string& taskmanage = item.app_info.taskmanage();
   if (taskmanage.empty()) {
     *error =
         "The taskmanage child element of "
@@ -362,7 +162,7 @@ bool UIAppValidation(const UIApplicationSingleEntry& item,
     return false;
   }
 
-  const std::string& type = item.ui_info.type();
+  const std::string& type = item.app_info.type();
   if (type.empty()) {
     *error =
         "The type child element of "
@@ -372,112 +172,38 @@ bool UIAppValidation(const UIApplicationSingleEntry& item,
   return true;
 }
 
-bool AppControlValidation(
-    const UIApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.app_control) {
-    if (item.operation().empty()) {
-      *error =
-          "The operation child element of app-control element is obligatory";
-      return false;
-    } else if (!parser::utils::IsValidIRI(item.operation())) {
-      *error =
-          "The operation child element of app-control element is not valid url";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool DataControlValidation(
-    const UIApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.data_control) {
-    if (item.access().empty()) {
-      *error =
-          "The access child element of datacontrol element is obligatory";
-      return false;
-    }
-
-    const std::string& providerid = item.providerid();
-    if (providerid.empty()) {
-      *error =
-          "The providerid child element of datacontrol element is obligatory";
-      return false;
-    }
-
-    const std::string& type = item.type();
-    if (type.empty()) {
-      *error =
-          "The type child element of datacontrol element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool MetadataValidation(
-    const UIApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.meta_data) {
-    if (item.key().empty()) {
-      *error =
-          "The key child element of metadata element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool LabelValidation(const UIApplicationSingleEntry& it, std::string* error) {
-  for (const auto& item : it.label) {
-    if (item.text().empty()) {
-      *error = "The text child element of label element is obligatory";
-      return false;
-    }
-
-    const std::string& name = item.name();
-    if (name.empty()) {
-      *error =
-          "The name child element of label element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
 bool ParseUIApplicationAndStore(
     const parser::DictionaryValue& app_dict,
     UIApplicationSingleEntry* uiapplicationinfo,
     std::string* error) {
   std::string appid;
   if (app_dict.GetString(kUIApplicationAppIDKey, &appid))
-    uiapplicationinfo->ui_info.set_appid(appid);
+    uiapplicationinfo->app_info.set_appid(appid);
   std::string exec;
   if (app_dict.GetString(kUIApplicationExecKey, &exec))
-    uiapplicationinfo->ui_info.set_exec(exec);
+    uiapplicationinfo->app_info.set_exec(exec);
   std::string multiple;
   if (app_dict.GetString(kUIApplicationMultipleKey, &multiple))
-    uiapplicationinfo->ui_info.set_multiple(multiple);
+    uiapplicationinfo->app_info.set_multiple(multiple);
   std::string nodisplay;
   if (app_dict.GetString(kUIApplicationNoDisplayKey, &nodisplay))
-    uiapplicationinfo->ui_info.set_nodisplay(nodisplay);
+    uiapplicationinfo->app_info.set_nodisplay(nodisplay);
   std::string taskmanage;
   if (app_dict.GetString(kUIApplicationTaskManageKey, &taskmanage))
-    uiapplicationinfo->ui_info.set_taskmanage(taskmanage);
+    uiapplicationinfo->app_info.set_taskmanage(taskmanage);
   std::string type;
   if (app_dict.GetString(kUIApplicationTypeKey, &type))
-    uiapplicationinfo->ui_info.set_type(type);
+    uiapplicationinfo->app_info.set_type(type);
   std::string uigadget;
   if (app_dict.GetString(kUIApplicationUIGadgetKey, &uigadget))
-    uiapplicationinfo->ui_info.set_uigadget(uigadget);
+    uiapplicationinfo->app_info.set_uigadget(uigadget);
   std::string process_pool;
   if (app_dict.GetString(kUIApplicationProcessPoolKey, &process_pool)) {
     if (!IsBooleanString(process_pool)) {
       *error = "process_pool must be 'true' or 'false'";
       return false;
     }
-    uiapplicationinfo->ui_info.set_process_pool(process_pool);
+    uiapplicationinfo->app_info.set_process_pool(process_pool);
   }
   std::string submode;
   if (app_dict.GetString(kUIApplicationSubmodeKey, &submode)) {
@@ -485,11 +211,11 @@ bool ParseUIApplicationAndStore(
       *error = "submode must be 'true' or 'false'";
       return false;
     }
-    uiapplicationinfo->ui_info.set_submode(submode);
+    uiapplicationinfo->app_info.set_submode(submode);
   }
   std::string submode_mainid;
   if (app_dict.GetString(kUIApplicationSubmodeMainIDKey, &submode_mainid))
-    uiapplicationinfo->ui_info.set_submode_mainid(submode_mainid);
+    uiapplicationinfo->app_info.set_submode_mainid(submode_mainid);
   std::string indicator_display;
   if (app_dict.GetString(kUIApplicationIndicatorDisplayKey,
                          &indicator_display)) {
@@ -497,19 +223,19 @@ bool ParseUIApplicationAndStore(
       *error = "indicatordisplay must be 'true' or 'false'";
       return false;
     }
-    uiapplicationinfo->ui_info.set_indicator_display(indicator_display);
+    uiapplicationinfo->app_info.set_indicator_display(indicator_display);
   }
   std::string portrait_effectimage;
   if (app_dict.GetString(kUIApplicationPortraitEffectImageKey,
                      &portrait_effectimage))
-    uiapplicationinfo->ui_info.set_portrait_image(portrait_effectimage);
+    uiapplicationinfo->app_info.set_portrait_image(portrait_effectimage);
   std::string landscape_effectimage;
   if (app_dict.GetString(kUIApplicationLandscapeEffectImageKey,
                      &landscape_effectimage))
-    uiapplicationinfo->ui_info.set_landscape_image(landscape_effectimage);
+    uiapplicationinfo->app_info.set_landscape_image(landscape_effectimage);
   std::string effectimage_type;
   if (app_dict.GetString(kUIApplicationEffectImageTypeKey, &effectimage_type))
-    uiapplicationinfo->ui_info.set_effectimage_type(effectimage_type);
+    uiapplicationinfo->app_info.set_effectimage_type(effectimage_type);
 
   std::string launch_mode;
   if (app_dict.GetString(kUIApplicationLaunchModeKey, &launch_mode)) {
@@ -517,12 +243,12 @@ bool ParseUIApplicationAndStore(
       *error = "launch_mode attribute is empty";
       return false;
     }
-    uiapplicationinfo->ui_info.set_launch_mode(launch_mode);
+    uiapplicationinfo->app_info.set_launch_mode(launch_mode);
   }
 
   std::string hwacceleration;
   if (app_dict.GetString(kUIApplicationHwAccelerationKey, &hwacceleration))
-    uiapplicationinfo->ui_info.set_hwacceleration(hwacceleration);
+    uiapplicationinfo->app_info.set_hwacceleration(hwacceleration);
 
   return InitializeParsing(app_dict, uiapplicationinfo, error);
 }
@@ -564,7 +290,6 @@ bool UIApplicationHandler::Validate(
   const UIApplicationInfoList& elements =
       static_cast<const UIApplicationInfoList&>(data);
 
-
   std::shared_ptr<const PackageInfo> package_info =
       std::static_pointer_cast<const PackageInfo>(
           handlers_output.find(kManifestKey)->second);
index 98cfedd7de3f46347482c8a3d0d63babbe66c62f..e932aacd23f8ff2df0e3ba5d66d2afa567959240 100644 (file)
 #include "manifest_parser/manifest_handler.h"
 #include "manifest_parser/values.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
-#include "tpk_manifest_handlers/ui_and_service_application_infos.h"
+#include "tpk_manifest_handlers/common/application_handler.h"
 
 namespace tpk {
 namespace parse {
 
-class UIApplicationInfo : public parser::ManifestData {
+class UIApplicationInfo : public ApplicationInfo {
  public:
   UIApplicationInfo();
   /**
@@ -25,24 +25,16 @@ class UIApplicationInfo : public parser::ManifestData {
    * @param key string
    */
   static std::string key();
-  /**
-   * @brief set_appid sets app id
-   * @param appid
-   */
-  void set_appid(const std::string& appid) {
-    appid_ = appid;
-  }
-  /**
-   * @brief set_exec sets exec
-   * @param exec
-   */
-  void set_exec(const std::string& exec) {
-    exec_ = exec;
-  }
   /**
    * @brief set_launch_mode sets launch mdoe
    * @param launch_mode
    */
+  void set_type(const std::string& type) {
+    type_ = type;
+  }
+  void set_process_pool(const std::string& process_pool) {
+    process_pool_ = process_pool;
+  }
   void set_launch_mode(const std::string& launch_mode) {
     launch_mode_ = launch_mode;
   }
@@ -67,19 +59,9 @@ class UIApplicationInfo : public parser::ManifestData {
   void set_taskmanage(const std::string& taskmanage) {
     taskmanage_ = taskmanage;
   }
-  /**
-   * @brief set_type set types
-   * @param type
-   */
-  void set_type(const std::string& type) {
-    type_ = type;
-  }
   void set_uigadget(const std::string& uigadget) {
     uigadget_ = uigadget;
   }
-  void set_process_pool(const std::string& process_pool) {
-    process_pool_ = process_pool;
-  }
   void set_submode(const std::string& submode) {
     submode_ = submode;
   }
@@ -102,20 +84,11 @@ class UIApplicationInfo : public parser::ManifestData {
     hwacceleration_ = hwacceleration;
   }
 
-  /**
-   * @brief appid
-   * @return appid string
-   */
-
-  const std::string& appid() const {
-    return appid_;
+  const std::string& type() const {
+    return type_;
   }
-  /**
-   * @brief exec
-   * @return exec string
-   */
-  const std::string& exec() const {
-    return exec_;
+  const std::string& process_pool() const {
+    return process_pool_;
   }
   /**
    * @brief launch_mode
@@ -145,22 +118,11 @@ class UIApplicationInfo : public parser::ManifestData {
   const std::string& taskmanage() const {
     return taskmanage_;
   }
-  /**
-   * @brief type
-   * @return type string
-   */
-  const std::string& type() const {
-    return type_;
-  }
 
   const std::string& uigadget() const {
     return uigadget_;
   }
 
-  const std::string& process_pool() const {
-    return process_pool_;
-  }
-
   const std::string& submode() const {
     return submode_;
   }
@@ -190,15 +152,13 @@ class UIApplicationInfo : public parser::ManifestData {
   }
 
  private:
-  std::string appid_;
-  std::string exec_;
+  std::string type_;
+  std::string process_pool_;
   std::string launch_mode_;
   std::string multiple_;
   std::string nodisplay_;
   std::string taskmanage_;
-  std::string type_;
   std::string uigadget_;
-  std::string process_pool_;
   std::string submode_;
   std::string submode_mainid_;
   std::string indicator_display_;
@@ -208,20 +168,15 @@ class UIApplicationInfo : public parser::ManifestData {
   std::string hwacceleration_;
 };
 
-struct UIApplicationSingleEntry : public parser::ManifestData {
-  UIApplicationInfo ui_info;
+struct UIApplicationSingleEntry :
+    public ApplicationSingleEntry<UIApplicationInfo> {
+  ApplicationImagesInfo app_images;
   std::vector<AppControlInfo> app_control;
   std::vector<BackgroundCategoryInfo> background_category;
   std::vector<DataControlInfo> data_control;
-  std::vector<MetaDataInfo> meta_data;
-  ApplicationIconsInfo app_icons;
-  ApplicationImagesInfo app_images;
-  std::vector<LabelInfo> label;
 };
 
-struct UIApplicationInfoList : public parser::ManifestData {
-  std::vector<UIApplicationSingleEntry> items;
-};
+using UIApplicationInfoList = ApplicationInfoList<UIApplicationSingleEntry>;
 
 /**
  * @brief The UIApplicationHandler class
@@ -252,7 +207,7 @@ class UIApplicationHandler : public parser::ManifestHandler {
   std::vector<std::string> PrerequisiteKeys() const override;
 };
 
-}   // namespace parse
-}   // namespace tpk
+}  // namespace parse
+}  // namespace tpk
 
 #endif  // TPK_MANIFEST_HANDLERS_UI_APPLICATION_HANDLER_H_
index 46cc875b0910fe6ad73ce1a3c6935fe106944b3a..3d5e99a357f04d01640a5e5af080497d02cec6a1 100644 (file)
@@ -9,20 +9,13 @@
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/utils/version_number.h"
 #include "manifest_parser/values.h"
-#include "utils/iri_util.h"
-#include "utils/logging.h"
-#include "utils/version_number.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
 #include "tpk_manifest_handlers/package_handler.h"
 
-namespace {
-
-const utils::VersionNumber kLaunchModeRequiredVersion("2.4");
-const char kWidgetApplicationKey[] = "manifest.widget-application";
-
-}  // namespace
-
 namespace tpk {
 namespace parse {
 
@@ -30,26 +23,12 @@ namespace ba = boost::algorithm;
 namespace keys = tpk::application_keys;
 
 namespace {
-// icon
-const char kIconKey[] = "icon";
-const char kIconTextKey[] = "#text";
-
 // image
 const char kImageKey[] = "image";
 const char kImageNameKey[] = "@name";
 const char kImageSectionKey[] = "@section";
 const char kImageLangKey[] = "@lang";
 
-// label
-const char kLabelKey[] = "label";
-const char kLabelTextKey[] = "#text";
-const char kLabelLangKey[] = "@lang";
-
-// metadata
-const char kMetaDataKey[] = "metadata";
-const char kMetaDataKeyKey[] = "@key";
-const char kMetaDataValueKey[] = "@value";
-
 // widget-application
 const char kWidgetApplicationAppIDKey[] = "@appid";
 const char kWidgetApplicationExecKey[] = "@exec";
@@ -68,24 +47,15 @@ bool IsBooleanString(const std::string& value) {
 
 }  // namespace
 
-bool ParseMetaData(
-  const parser::DictionaryValue* dict,
-  WidgetApplicationSingleEntry* info) {
+template<>
+bool ParseMetaData(const parser::DictionaryValue& dict,
+                   WidgetApplicationSingleEntry* info, std::string*) {
   std::string key;
-  dict->GetString(kMetaDataKeyKey, &key);
+  dict.GetString(tpk_app_keys::kMetaDataKeyKey, &key);
   std::string val;
-  dict->GetString(kMetaDataValueKey, &val);
+  dict.GetString(tpk_app_keys::kMetaDataValueKey, &val);
   info->meta_data.emplace_back(key, val);
-  return true;
-}
 
-bool ParseAppIcon(
-  const parser::DictionaryValue* dict,
-  WidgetApplicationSingleEntry* info) {
-  std::string icon_path;
-  if (!dict->GetString(kIconTextKey, &icon_path))
-    return false;
-  info->app_icons.AddIcon(ApplicationIcon(icon_path));
   return true;
 }
 
@@ -103,43 +73,6 @@ bool ParseAppImage(
   return true;
 }
 
-bool ParseLabel(
-  const parser::DictionaryValue* dict,
-  WidgetApplicationSingleEntry* info) {
-  std::string text;
-  dict->GetString(kLabelTextKey, &text);
-  std::string xml_lang;
-  dict->GetString(kLabelLangKey, &xml_lang);
-  info->label.emplace_back(text, text, xml_lang);
-  return true;
-}
-
-bool InitializeMetaDataParsing(
-    const parser::DictionaryValue& app_dict,
-    WidgetApplicationSingleEntry* widgetapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kMetaDataKey, "")) {
-    if (!ParseMetaData(item, widgetapplicationinfo)) {
-      *error = "Parsing Metadata failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool InitializeIconParsing(
-    const parser::DictionaryValue& app_dict,
-    WidgetApplicationSingleEntry* widgetapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&app_dict, kIconKey, "")) {
-    if (!ParseAppIcon(item, widgetapplicationinfo)) {
-      *error = "Parsing Icon failed";
-      return false;
-    }
-  }
-  return true;
-}
-
 bool InitializeImageParsing(
     const parser::DictionaryValue& app_dict,
     WidgetApplicationSingleEntry* widgetapplicationinfo,
@@ -153,49 +86,46 @@ bool InitializeImageParsing(
   return true;
 }
 
-bool InitializeLabelParsing(
-    const parser::DictionaryValue& control_dict,
-    WidgetApplicationSingleEntry* widgetapplicationinfo,
-    std::string* error) {
-  for (auto& item : parser::GetOneOrMany(&control_dict, kLabelKey, "")) {
-    if (!ParseLabel(item, widgetapplicationinfo)) {
-      *error = "Parsing Label failed";
-      return false;
-    }
-  }
-  return true;
-}
-
 bool InitializeParsing(const parser::DictionaryValue& app_dict,
                        WidgetApplicationSingleEntry* widgetapplicationinfo,
                        std::string* error) {
-  if (!InitializeMetaDataParsing(app_dict, widgetapplicationinfo, error))
+  ParsingFuncPtr<WidgetApplicationSingleEntry> parsingFunc =
+      ParseMetaData<WidgetApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kMetaDataKey,
+      parsingFunc, widgetapplicationinfo, error))
     return false;
-  if (!InitializeIconParsing(app_dict, widgetapplicationinfo, error))
+  parsingFunc = ParseAppIcon<WidgetApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kMetaDataKey,
+      parsingFunc, widgetapplicationinfo, error))
     return false;
-  if (!InitializeLabelParsing(app_dict, widgetapplicationinfo, error))
+  parsingFunc = ParseLabel<WidgetApplicationSingleEntry>;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kMetaDataKey,
+      parsingFunc, widgetapplicationinfo, error))
     return false;
-  if (!InitializeImageParsing(app_dict, widgetapplicationinfo, error))
+  parsingFunc = InitializeImageParsing;
+  if (!InitializeParsingElement(app_dict, tpk_app_keys::kMetaDataKey,
+      parsingFunc, widgetapplicationinfo, error))
     return false;
+
   return true;
 }
 
 bool WidgetAppValidation(const WidgetApplicationSingleEntry& item,
                      const std::string& api_version, std::string* error) {
-  if (item.widget_info.appid().empty()) {
+  if (item.app_info.appid().empty()) {
     *error = "The appid child element of widget-application element "
         "is obligatory";
     return false;
   }
 
-  const std::string& exec = item.widget_info.exec();
+  const std::string& exec = item.app_info.exec();
   if (exec.empty()) {
     *error = "The exec child element of widget-application element "
         "is obligatory";
     return false;
   }
 
-  const std::string& launch_mode = item.widget_info.launch_mode();
+  const std::string& launch_mode = item.app_info.launch_mode();
   if (!launch_mode.empty()) {
     if (utils::VersionNumber(api_version) < kLaunchModeRequiredVersion) {
       *error = "launch_mode attribute cannot be used for api version lower"
@@ -212,18 +142,18 @@ bool WidgetAppValidation(const WidgetApplicationSingleEntry& item,
   } else {
     // FIXME currently const_cast used, but it is not the best way.
     WidgetApplicationInfo &tmp = const_cast<WidgetApplicationInfo &>(
-        item.widget_info);
+        item.app_info);
     tmp.set_launch_mode("single");
   }
 
-  const std::string& multiple = item.widget_info.multiple();
+  const std::string& multiple = item.app_info.multiple();
   if (multiple.empty()) {
     *error = "The multiple child element of widget-application element "
         "is obligatory";
     return false;
   }
 
-  const std::string& nodisplay = item.widget_info.nodisplay();
+  const std::string& nodisplay = item.app_info.nodisplay();
   if (nodisplay.empty()) {
     *error = "The nodisplay child element of widget-application element "
         "is obligatory";
@@ -232,52 +162,22 @@ bool WidgetAppValidation(const WidgetApplicationSingleEntry& item,
   return true;
 }
 
-bool MetadataValidation(
-    const WidgetApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.meta_data) {
-    if (item.key().empty()) {
-      *error = "The key child element of metadata element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
-bool LabelValidation(
-    const WidgetApplicationSingleEntry& it,
-    std::string* error) {
-  for (const auto& item : it.label) {
-    if (item.text().empty()) {
-      *error = "The text child element of label element is obligatory";
-      return false;
-    }
-
-    const std::string& name = item.name();
-    if (name.empty()) {
-      *error = "The name child element of label element is obligatory";
-      return false;
-    }
-  }
-  return true;
-}
-
 bool ParseWidgetApplicationAndStore(
     const parser::DictionaryValue& app_dict,
     WidgetApplicationSingleEntry* widgetapplicationinfo,
     std::string* error) {
   std::string appid;
   if (app_dict.GetString(kWidgetApplicationAppIDKey, &appid))
-    widgetapplicationinfo->widget_info.set_appid(appid);
+    widgetapplicationinfo->app_info.set_appid(appid);
   std::string exec;
   if (app_dict.GetString(kWidgetApplicationExecKey, &exec))
-    widgetapplicationinfo->widget_info.set_exec(exec);
+    widgetapplicationinfo->app_info.set_exec(exec);
   std::string multiple;
   if (app_dict.GetString(kWidgetApplicationMultipleKey, &multiple))
-    widgetapplicationinfo->widget_info.set_multiple(multiple);
+    widgetapplicationinfo->app_info.set_multiple(multiple);
   std::string nodisplay;
   if (app_dict.GetString(kWidgetApplicationNoDisplayKey, &nodisplay))
-    widgetapplicationinfo->widget_info.set_nodisplay(nodisplay);
+    widgetapplicationinfo->app_info.set_nodisplay(nodisplay);
 
   std::string launch_mode;
   if (app_dict.GetString(kWidgetApplicationLaunchModeKey, &launch_mode)) {
@@ -285,12 +185,12 @@ bool ParseWidgetApplicationAndStore(
       *error = "launch_mode attribute is empty";
       return false;
     }
-    widgetapplicationinfo->widget_info.set_launch_mode(launch_mode);
+    widgetapplicationinfo->app_info.set_launch_mode(launch_mode);
   }
 
   std::string hwacceleration;
   if (app_dict.GetString(kWidgetApplicationHwAccelerationKey, &hwacceleration))
-    widgetapplicationinfo->widget_info.set_hwacceleration(hwacceleration);
+    widgetapplicationinfo->app_info.set_hwacceleration(hwacceleration);
 
   return InitializeParsing(app_dict, widgetapplicationinfo, error);
 }
@@ -345,10 +245,6 @@ bool WidgetApplicationHandler::Validate(
   return true;
 }
 
-std::string WidgetApplicationInfo::key() {
-  return kWidgetApplicationKey;
-}
-
 std::string WidgetApplicationHandler::Key() const {
   return kWidgetApplicationKey;
 }
index bb602977db659b19f0ff87cd716941665aa5be19..a6e45dcafd573a832734b0c8a2accd8ce40a0ac2 100644 (file)
 #include "manifest_parser/manifest_handler.h"
 #include "manifest_parser/values.h"
 #include "tpk_manifest_handlers/application_manifest_constants.h"
-#include "tpk_manifest_handlers/ui_and_service_application_infos.h"
+#include "tpk_manifest_handlers/common/application_handler.h"
 
 namespace tpk {
 namespace parse {
 
-class WidgetApplicationInfo : public parser::ManifestData {
+class WidgetApplicationInfo : public ApplicationInfo {
  public:
   WidgetApplicationInfo();
   /**
@@ -25,20 +25,6 @@ class WidgetApplicationInfo : public parser::ManifestData {
    * @param key string
    */
   static std::string key();
-  /**
-   * @brief set_appid sets app id
-   * @param appid
-   */
-  void set_appid(const std::string& appid) {
-    appid_ = appid;
-  }
-  /**
-   * @brief set_exec sets exec
-   * @param exec
-   */
-  void set_exec(const std::string& exec) {
-    exec_ = exec;
-  }
   /**
    * @brief set_launch_mode sets launch mdoe
    * @param launch_mode
@@ -64,21 +50,6 @@ class WidgetApplicationInfo : public parser::ManifestData {
     hwacceleration_ = hwacceleration;
   }
 
-  /**
-   * @brief appid
-   * @return appid string
-   */
-
-  const std::string& appid() const {
-    return appid_;
-  }
-  /**
-   * @brief exec
-   * @return exec string
-   */
-  const std::string& exec() const {
-    return exec_;
-  }
   /**
    * @brief launch_mode
    * @return launch mode string
@@ -106,25 +77,18 @@ class WidgetApplicationInfo : public parser::ManifestData {
   }
 
  private:
-  std::string appid_;
-  std::string exec_;
   std::string launch_mode_;
   std::string multiple_;
   std::string nodisplay_;
   std::string hwacceleration_;
 };
 
-struct WidgetApplicationSingleEntry : public parser::ManifestData {
-  WidgetApplicationInfo widget_info;
-  std::vector<MetaDataInfo> meta_data;
-  ApplicationIconsInfo app_icons;
+struct WidgetApplicationSingleEntry :
+    public ApplicationSingleEntry<WidgetApplicationInfo> {
   ApplicationImagesInfo app_images;
-  std::vector<LabelInfo> label;
 };
 
-struct WidgetApplicationInfoList : public parser::ManifestData {
-  std::vector<WidgetApplicationSingleEntry> items;
-};
+using WidgetApplicationInfoList = ApplicationInfoList<WidgetApplicationSingleEntry>;
 
 /**
  * @brief The WidgetApplicationHandler class
index 806d27605e3c8f9433eac1c88799d43853f0b353..5288288ce3515761e97ca30dc436f20108a1b23b 100644 (file)
@@ -2,11 +2,12 @@
 // Use of this source code is governed by a apache-2.0 license that can be
 // found in the LICENSE file.
 
+#include "manifest_parser/utils/string_util.h"
+
 #include <gtest/gtest.h>
 
 #include <string>
 
-#include "utils/string_util.h"
 
 #define TEST_FOR_COLLAPSE_CHARCTER(Name, Sequence)                             \
   TEST(StringUtilTest, CollapseWhitespaceUTF8_ ## Name) {                      \
index d1ebd8f3058f9655c96f72aabb02c11df1594840..52b04ccb1703c97a55d862199bb869498f2bd460 100644 (file)
@@ -2,9 +2,10 @@
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
+#include "manifest_parser/utils/version_number.h"
+
 #include <gtest/gtest.h>
 
-#include "utils/version_number.h"
 
 namespace utils {
 
diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt
deleted file mode 100644 (file)
index 0786ef0..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-# Target - sources
-SET(SRCS
-  iri_util.cc
-  string_util.cc
-  language_tag_validator.cc
-  version_number.cc
-  w3c_languages.cc
-)
-# Target - definition
-ADD_LIBRARY(${TARGET_LIBNAME_UTILS} SHARED ${SRCS})
-# Target - includes
-TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_UTILS} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
-
-# Target - deps
-APPLY_PKG_CONFIG(${TARGET_LIBNAME_UTILS} PUBLIC
-  LIBIRI_DEPS
-  Boost
-)
-
-# Extra
-SET_TARGET_PROPERTIES(${TARGET_LIBNAME_UTILS} PROPERTIES VERSION ${VERSION})
-SET_TARGET_PROPERTIES(${TARGET_LIBNAME_UTILS} PROPERTIES SOVERSION ${VERSION_MAJOR})
-
-# Install
-INSTALL(TARGETS ${TARGET_LIBNAME_UTILS} DESTINATION ${LIB_INSTALL_DIR})
-
-# Install includes
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDEDIR}/manifest_parser
-        FILES_MATCHING PATTERN "*.h")
-
-# Configure and install pkgconfig file
-SET(PKG_FILE manifest-parser-utils.pc)
-CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
-INSTALL(FILES ${PKG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
diff --git a/src/utils/iri_util.cc b/src/utils/iri_util.cc
deleted file mode 100644 (file)
index 360a836..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "utils/iri_util.h"
-
-#include <iri.h>
-
-#include <memory>
-
-namespace parser {
-namespace utils {
-
-bool IsValidIRI(const std::string& iri_string) {
-  std::unique_ptr<iri_struct, decltype(&iri_destroy)> iri(
-      iri_parse(iri_string.c_str()), iri_destroy);
-  return
-    iri != NULL &&
-    iri->scheme != NULL && (
-      iri->display != NULL ||
-      iri->user != NULL ||
-      iri->auth != NULL ||
-      iri->password != NULL ||
-      iri->host != NULL ||
-      iri->path != NULL ||
-      iri->query != NULL ||
-      iri->anchor != NULL ||
-      iri->qparams != NULL ||
-      iri->schemelist != NULL);
-}
-
-}  // namespace utils
-}  // namespace parser
diff --git a/src/utils/iri_util.h b/src/utils/iri_util.h
deleted file mode 100644 (file)
index cf39381..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef UTILS_IRI_UTIL_H_
-#define UTILS_IRI_UTIL_H_
-
-#include <string>
-
-namespace parser {
-namespace utils {
-
-/**
- * @brief IsValidIRI
- *        Validate IRI with libiri.
- *
- * Valid IRI is the one that have at least scheme part and any other component.
- *
- * @param iri_string iri string to check
- * @return bool if iri is valid
- */
-bool IsValidIRI(const std::string& iri_string);
-
-}  // namespace utils
-}  // namespace parser
-
-#endif  // UTILS_IRI_UTIL_H_
diff --git a/src/utils/language_tag_validator.cc b/src/utils/language_tag_validator.cc
deleted file mode 100644 (file)
index 4f36790..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-// 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 "utils/language_tag_validator.h"
-
-#include <boost/algorithm/string.hpp>
-#include <vector>
-#include "utils/logging.h"
-#include "utils/w3c_languages.h"
-
-namespace ba = boost::algorithm;
-
-namespace {
-const char kTagDelimiter[] = "-";
-const int kSingletonTagSize = 1;
-const int kMaximumExtensionTagSize = 8;
-
-std::string Capitalized(const std::string& input) {
-  std::string output = input;
-  ba::to_lower(output);
-  output[0] = toupper(output[0]);
-  return output;
-}
-
-std::string ToLower(const std::string& input) {
-  std::string output = input;
-  ba::to_lower(output);
-  return output;
-}
-
-std::string ToUpper(const std::string& input) {
-  std::string output = input;
-  ba::to_upper(output);
-  return output;
-}
-
-}  // namespace
-
-namespace utils {
-namespace w3c_languages {
-
-bool ValidateLanguageTag(const std::string& tag) {
-  // algorithm based on http://www.w3.org/International/articles/language-tags/
-  std::vector<std::string> splitted_tag;
-  if (tag.empty()) {
-    LOG(ERROR) << "tag is empty";
-    return false;
-  }
-  boost::split(splitted_tag, tag, boost::is_any_of(kTagDelimiter));
-  auto current_item = splitted_tag.begin();
-  // main language validation
-  if (current_item != splitted_tag.end() &&
-      !lang_set::ValidateOnlyLanguage(*current_item)) {
-    LOG(ERROR) << "Invalid main language tag given";
-    return false;
-  }
-  ++current_item;
-  if (current_item == splitted_tag.end()) {
-    return true;
-  }
-  // extlang validation
-  auto lang_pair = kW3CExtLang.find(ToLower(*current_item));
-  if (lang_pair != kW3CExtLang.end()) {
-    if (splitted_tag.front() == lang_pair->second) {
-      ++current_item;
-      if (current_item == splitted_tag.end())
-        return true;
-    } else {
-      LOG(ERROR) << "Extlang does not match language";
-      return false;
-    }
-  }
-  // script subtag validation
-  if (kW3CScript.find(Capitalized(*current_item)) != kW3CScript.end()) {
-    ++current_item;
-    if (current_item == splitted_tag.end())
-      return true;
-  }
-  // region subtag validation
-  if (kW3CRegion.find(ToUpper(*current_item)) != kW3CRegion.end()) {
-    ++current_item;
-    if (current_item == splitted_tag.end())
-      return true;
-  }
-
-  // TODO(w.kosowicz): variant prefix check
-  if (kW3CVariant.find(ToLower(*current_item)) != kW3CVariant.end()) {
-    ++current_item;
-    if (current_item == splitted_tag.end())
-      return true;
-  }
-  // extension private tag validation
-  if ((*current_item).size() != kSingletonTagSize) {
-    LOG(ERROR) << "Singletion subtag should be of size " << kSingletonTagSize;
-    return false;
-  }
-  ++current_item;
-  if (current_item == splitted_tag.end())
-    return false;
-  for (auto it = current_item; it != splitted_tag.end(); ++current_item) {
-    auto tag_length = (*current_item).size();
-    if (tag_length > kMaximumExtensionTagSize) {
-      LOG(ERROR) << "Any extensions should be maximum "
-                 << kMaximumExtensionTagSize << "characters";
-      return false;
-    }
-  }
-  return true;
-}
-
-}  // namespace w3c_languages
-}  // namespace utils
-
-
diff --git a/src/utils/language_tag_validator.h b/src/utils/language_tag_validator.h
deleted file mode 100644 (file)
index 0ab1129..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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 UTILS_LANGUAGE_TAG_VALIDATOR_H_
-#define UTILS_LANGUAGE_TAG_VALIDATOR_H_
-
-#include <string>
-#include <unordered_set>
-
-namespace utils {
-namespace w3c_languages {
-
-/**
- * @brief ValidateLanguageTag
- *        Checks validity of language tag.
- *
- * Languauge tag reference:
- *  - http://www.w3.org/International/articles/language-tags/
- *
- * @param language tag string
- * @return true if tag is correct
- */
-bool ValidateLanguageTag(const std::string& tag);
-
-}  // namespace w3c_languages
-}  // namespace utils
-#endif  // UTILS_LANGUAGE_TAG_VALIDATOR_H_
diff --git a/src/utils/logging.h b/src/utils/logging.h
deleted file mode 100644 (file)
index 232d078..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef UTILS_LOGGING_H_
-#define UTILS_LOGGING_H_
-
-#include <cassert>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <string>
-
-namespace utils {
-
-enum class LogLevel {
-  LOG_ERROR,
-  LOG_WARNING,
-  LOG_INFO,
-  LOG_DEBUG,
-};
-
-template<LogLevel> struct LogTag;
-template<> struct LogTag<LogLevel::LOG_ERROR> {
-  static constexpr const char* value = "\033[1;31m| ERROR   |\033[0m";
-};
-template<> struct LogTag<LogLevel::LOG_WARNING> {
-  static constexpr const char* value = "\033[1;33m| WARNING |\033[0m";
-};
-template<> struct LogTag<LogLevel::LOG_INFO>  {
-  static constexpr const char* value = "\033[1;32m| INFO    |\033[0m";
-};
-template<> struct LogTag<LogLevel::LOG_DEBUG> {
-  static constexpr const char* value = "\033[0m| DEBUG   |\033[0m";
-};
-
-class LogCatcher {
- public:
-  LogCatcher() { }
-  void operator&(const std::ostream& str) const {
-    // TODO(tiwanek): this cast is error-prone - fix it
-    std::cerr << static_cast<const std::ostringstream*>(&str)->str()
-              << std::endl;
-  }
-};
-
-}  // namespace utils
-
-inline static const constexpr char* __tag_for_logging() {
-  return "";
-}
-
-// To be defined in class namespace if user want different log tag for given
-// scope
-#define SCOPE_LOG_TAG(TAG)                                                     \
-  inline static const constexpr char* __tag_for_logging() {                    \
-    return #TAG;                                                               \
-  }                                                                            \
-
-// Simple logging macro of following usage:
-//   LOG(LEVEL) << object_1 << object_2 << object_n;
-//     where:
-//       LEVEL = ERROR | WARNING | INFO | DEBUG
-#define LOG(LEVEL)                                                             \
-    ::utils::LogCatcher() & std::ostringstream()                               \
-      << std::string(::utils::LogTag<::utils::LogLevel::LOG_ ## LEVEL>::value) \
-      << " " << std::setw(20) << std::left << __tag_for_logging()              \
-      << std::setw(0) << " : "                                                 \
-
-#endif  // UTILS_LOGGING_H_
diff --git a/src/utils/manifest-parser-utils.pc.in b/src/utils/manifest-parser-utils.pc.in
deleted file mode 100644 (file)
index a63e103..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@PREFIX@
-exec_prefix=@PREFIX@
-libdir=@LIBDIR@
-includedir=@INCLUDEDIR@
-
-Name: manifest-parser-utils
-Description: Universal manifest parser utils
-Version: @VERSION@
-Requires: libiri
-Libs: -L${libdir} -lmanifest-parser-utils
-Cflags: -I${includedir}
\ No newline at end of file
diff --git a/src/utils/string_util.cc b/src/utils/string_util.cc
deleted file mode 100644 (file)
index 4f8a307..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE-xwalk file.
-
-#include "utils/string_util.h"
-
-#include <cstdlib>
-#include <map>
-#include <vector>
-
-namespace {
-
-const unsigned kBidiControlCharacterLength = 3;
-
-const char kDirLTRKey[] = "ltr";
-const char kDirRTLKey[] = "rtl";
-const char kDirLROKey[] = "lro";
-const char kDirRLOKey[] = "rlo";
-
-const char* kWhitespaceSequences[] = {
-  u8"\x09",          /* CHARACTER TABULATION */
-  u8"\x0A",          /* LINE FEED (LF) */
-  u8"\x0B",          /* LINE TABULATION */
-  u8"\x0C",          /* FORM FEED (FF) */
-  u8"\x0D",          /* CARRIAGE RETURN (CR) */
-  u8"\x20",          /* SPACE */
-  u8"\xc2\x85",      /* NEXT LINE (NEL) */
-  u8"\xc2\xa0",      /* NO-BREAK SPACE */
-  u8"\xe1\x9a\x80",  /* OGHAM SPACE MARK */
-  u8"\xe1\xa0\x8e",  /* MONGOLIAN VOWEL SEPARATOR */
-  u8"\xe2\x80\x80",  /* EN QUAD */
-  u8"\xe2\x80\x81",  /* EM QUAD */
-  u8"\xe2\x80\x82",  /* EN SPACE */
-  u8"\xe2\x80\x83",  /* EM SPACE */
-  u8"\xe2\x80\x84",  /* THREE-PER-EM SPACE */
-  u8"\xe2\x80\x85",  /* FOUR-PER-EM SPACE */
-  u8"\xe2\x80\x86",  /* SIX-PER-EM SPACE */
-  u8"\xe2\x80\x87",  /* FIGURE SPACE */
-  u8"\xe2\x80\x88",  /* PUNCTUATION SPACE */
-  u8"\xe2\x80\x89",  /* THIN SPACE */
-  u8"\xe2\x80\x8A",  /* HAIR SPACE */
-  u8"\xe2\x80\xa8",  /* LINE SEPARATOR */
-  u8"\xe2\x80\xa9",  /* PARAGRAPH SEPARATOR */
-  u8"\xe2\x80\xaf",  /* NARROW NO-BREAK SPACE */
-  u8"\xe2\x81\x9f",  /* MEDIUM MATHEMATICAL SPACE */
-  u8"\xe3\x80\x80"   /* IDEOGRAPHIC SPACE */
-};
-
-// Calculates length of UTF-8 character by checking first byte only
-int UTF8CharLength(const char* character) {
-  if (!(character[0] & 0x80))
-      return 1;
-  int length = 0;
-  unsigned char mask = 0x80;
-  while (character[0] & mask) {
-    mask >>= 1;
-    ++length;
-  }
-  return length;
-}
-
-// Check string offset against occurance of given UTF-8 character
-bool EqualsUTF8Char(const char* str, const char* character) {
-  unsigned i = 0;
-  while (character[i]) {
-    if (!str[i]) {
-      return false;
-    }
-    if (character[i] != str[i]) {
-      return false;
-    }
-    ++i;
-  }
-  return true;
-}
-
-// Returns true if it's a whitespace character.
-inline bool IsWhitespaceUTF8(const char* c) {
-  for (unsigned i = 0;
-       i < sizeof(kWhitespaceSequences) / sizeof(kWhitespaceSequences[0]);
-       ++i) {
-    if (EqualsUTF8Char(c, kWhitespaceSequences[i])) {
-      return true;
-    }
-  }
-  return false;
-}
-
-}  // namespace
-
-namespace parser {
-namespace utils {
-
-// based on http://unicode.org/reports/tr9/
-const char kRightToLeftMark[] = u8"\u200F";
-const char kLeftToRightMark[] = u8"\u200E";
-const char kLeftToRightEmbeddingMark[] = u8"\u202A";
-const char kRightToLeftEmbeddingMark[] = u8"\u202B";
-const char kPopDirectionalFormatting[] = u8"\u202C";
-const char kLeftToRightOverride[] = u8"\u202D";
-const char kRightToLeftOverride[] = u8"\u202E";
-
-const std::map<std::string, std::string> kTextDir = {
-  { std::string(kDirLTRKey), std::string(kLeftToRightEmbeddingMark) },
-  { std::string(kDirRTLKey), std::string(kRightToLeftEmbeddingMark) },
-  { std::string(kDirLROKey), std::string(kLeftToRightOverride) },
-  { std::string(kDirRLOKey), std::string(kRightToLeftOverride) }
-};
-
-
-std::string CollapseWhitespaceUTF8(const std::string& text) {
-  std::string result;
-
-  if (text.empty()) {
-    return result;
-  }
-  result.resize(text.size());
-  // Set flags to pretend we're already in a trimmed whitespace sequence,
-  // so we will trim any leading whitespace.
-  bool in_whitespace = true;
-  int chars_written = 0;
-
-  for (unsigned i = 0; i < text.length();) {
-    int length = UTF8CharLength(&text[i]);
-    if (IsWhitespaceUTF8(&text[i])) {
-      if (!in_whitespace) {
-        // Reduce all whitespace sequences to a single space.
-        in_whitespace = true;
-        result[chars_written++] = ' ';
-      }
-      // roll through UTF8 character
-      i += length;
-    } else {
-      // Non-whitespace chracters are copied straight across.
-      in_whitespace = false;
-      while (length--) {
-        result[chars_written++] = text[i++];
-      }
-    }
-  }
-
-  if (in_whitespace && chars_written > 0) {
-    // Any trailing whitespace is eliminated.
-    --chars_written;
-  }
-
-  result.resize(chars_written);
-  return result;
-}
-
-std::string StripWrappingBidiControlCharactersUTF8(const std::string& text) {
-  if (text.empty())
-    return text;
-  size_t begin_index = 0;
-  const char* begin = &text[begin_index];
-  if (EqualsUTF8Char(begin, kLeftToRightEmbeddingMark) ||
-      EqualsUTF8Char(begin, kRightToLeftEmbeddingMark) ||
-      EqualsUTF8Char(begin, kLeftToRightOverride) ||
-      EqualsUTF8Char(begin, kRightToLeftOverride))
-    begin_index += kBidiControlCharacterLength;
-  size_t end_index = text.length() - kBidiControlCharacterLength;
-  if (EqualsUTF8Char(&text[end_index], kPopDirectionalFormatting))
-    end_index -= 3;
-  return text.substr(begin_index,
-      end_index - begin_index + kBidiControlCharacterLength);
-}
-
-std::string GetDirTextUTF8(const std::string& text, const std::string& dir) {
-  auto dirValue = kTextDir.find(dir);
-  if (dirValue != kTextDir.end())
-    return  dirValue->second + text + kPopDirectionalFormatting;
-  return text;
-}
-
-std::string GetDirUTF8Start(const std::string& dir) {
-  auto dirValue = kTextDir.find(dir);
-  if (dirValue != kTextDir.end())
-    return dirValue->second;
-  return std::string();
-}
-
-std::string GetDirUTF8End() {
-  return std::string(kPopDirectionalFormatting);
-}
-
-std::string DecodePercentEscapedCharacter(const std::string& text) {
-  std::vector<int> input(text.begin(), text.end());
-  std::vector<char> output;
-  unsigned i = 0;
-  while (i < input.size()) {
-    if ('%' == input[i]) {
-      if (i + 2 >= input.size())
-        return std::string();
-      char str[3] = {"\0", };
-      str[0] = input[i + 1];
-      str[1] = input[i + 2];
-      int result = strtol(str, NULL, 16);
-      // RFC 1738 - octets 80 to FF are not allowed
-      if (result >= 128)
-        return std::string();
-      output.push_back(static_cast<char>(result));
-      i += 3;
-    } else {
-      output.push_back(static_cast<char>(input[i]));
-      ++i;
-    }
-  }
-  return std::string(output.begin(), output.end());
-}
-
-}  // namespace utils
-}  // namespace parser
diff --git a/src/utils/string_util.h b/src/utils/string_util.h
deleted file mode 100644 (file)
index e1d7157..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE-xwalk file.
-
-#ifndef UTILS_STRING_UTIL_H_
-#define UTILS_STRING_UTIL_H_
-
-#include <string>
-
-namespace parser {
-namespace utils {
-
-// utf8 representation of unicode BIDI characters
-extern const char kRightToLeftMark[];
-extern const char kLeftToRightMark[];
-extern const char kLeftToRightEmbeddingMark[];
-extern const char kRightToLeftEmbeddingMark[];
-extern const char kPopDirectionalFormatting[];
-extern const char kLeftToRightOverride[];
-extern const char kRightToLeftOverride[];
-
-/**
- * @brief CollapseWhitespaceUTF8
- *        Replaces all utf-8 whitespace characters sequences with single space
- *        character. Whitespace at the beginning and at the end are removed
- *        completely.
- *
- * @param text input string
- * @return collapsed string
- */
-std::string CollapseWhitespaceUTF8(const std::string& text);
-
-/**
- * @brief StripWrappingBidiControlCharactersUTF8
- *        Remove utf-8 bidi characters.
- *
- * Function removes single PDF bidi character at the end if exists.
- * Function removes one single LTR|RTL|LRO|RLO bidi character at the beginning
- * if exists.
- *
- * @param text input string
- * @return transformed string
- */
-std::string StripWrappingBidiControlCharactersUTF8(const std::string& text);
-
-/**
- * @brief GetDirTextUTF8
- *        Adds given bidi character to beginning of string and adds PDF bifi
- *        character
- *
- * @param text input string
- * @param dir chosen bidi format defined as "dir" attribute in w3c spec,
- *        allowed values: "ltr", "rtl", "lro", "rlo"
- * @return transformed string
- */
-std::string GetDirTextUTF8(const std::string& text, const std::string& dir);
-
-/**
- * @brief GetDirUTF8Start
- *        Returns bidi format character.
- *
- * @param dir chosen bidi format defined as "dir" attribute in w3c spec,
- *        allowed values: "ltr", "rtl", "lro", "rlo"
- * @return utf-8 character
- */
-std::string GetDirUTF8Start(const std::string& dir);
-
-/**
- * @brief GetDirUTF8End
- *        Return PDF (Pop Directional Format) character encoded in utf-8
- *
- * @return UTF-8 PDF bidi character
- */
-std::string GetDirUTF8End();
-
-/**
- * @brief DecodePercentEscapedCharacter
- *        Decodes url-encoded characters in string.
- *
- * This should be used to decoded path in configuration files where url spec
- * is allowed.
- *
- * @param path string with url-encoded characters
- * @return decoded value of text
- */
-std::string DecodePercentEscapedCharacter(const std::string& text);
-
-}  // namespace utils
-}  // namespace parser
-
-#endif  // UTILS_STRING_UTIL_H_
diff --git a/src/utils/version_number.cc b/src/utils/version_number.cc
deleted file mode 100644 (file)
index 5cad524..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-// 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 "utils/version_number.h"
-
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/join.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/algorithm/string/trim.hpp>
-
-#include <algorithm>
-#include <cstdlib>
-
-namespace ba = boost::algorithm;
-
-namespace utils {
-
-VersionNumber::VersionNumber(const std::string& str) {
-  std::string number = str;
-  ba::trim(number);
-  std::vector<std::string> tokens;
-  ba::split(tokens, number, ba::is_any_of("."));
-  for (auto& token : tokens) {
-    char* end = nullptr;
-    int value = strtol(token.c_str(), &end, 10);
-    if (end != &*token.end() || token.empty()) {
-      parts_.clear();
-      return;
-    }
-    parts_.push_back(value);
-  }
-}
-
-bool VersionNumber::IsValid() const {
-  return !parts_.empty();
-}
-
-int VersionNumber::Compare(const VersionNumber& other) const {
-  size_t i = 0;
-  while (true) {
-    if (i < parts_.size()) {
-      if (i < other.parts_.size()) {
-        if (parts_[i] > other.parts_[i]) {
-          return 1;
-        } else if (parts_[i] < other.parts_[i]) {
-          return -1;
-        }
-      } else {
-        return 1;
-      }
-    } else {
-      if (i < other.parts_.size()) {
-        return -1;
-      } else {
-        return 0;
-      }
-    }
-    ++i;
-  }
-}
-
-bool VersionNumber::operator<(const VersionNumber& other) const {
-  return Compare(other) < 0;
-}
-
-bool VersionNumber::operator>=(const VersionNumber& other) const {
-  return !this->operator<(other);
-}
-
-bool VersionNumber::operator==(const VersionNumber& other) const {
-  return Compare(other) == 0;
-}
-
-bool VersionNumber::operator!=(const VersionNumber& other) const {
-  return !this->operator==(other);
-}
-
-bool VersionNumber::operator>(const VersionNumber& other) const {
-  return Compare(other) > 0;
-}
-
-bool VersionNumber::operator<=(const VersionNumber& other) const {
-  return !this->operator>(other);
-}
-
-std::string VersionNumber::ToString() const {
-  std::vector<std::string> strings;
-  std::transform(parts_.begin(), parts_.end(), std::back_inserter(strings),
-                 static_cast<std::string(*)(int)>(&std::to_string));
-  return ba::join(strings, ".");
-}
-
-}  // namespace utils
diff --git a/src/utils/version_number.h b/src/utils/version_number.h
deleted file mode 100644 (file)
index e48dd43..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// 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 UTILS_VERSION_NUMBER_H_
-#define UTILS_VERSION_NUMBER_H_
-
-#include <string>
-#include <vector>
-
-namespace utils {
-
-/**
- * @brief The VersionNumber class
- *        Representation of version number
- *
- * This class should be used to store version number. Version number is allowed
- * to be constructed of number segments connected with single dot character.
- *
- * Every new version number should be validate be check result of member
- * function call @ref IsValid()
- */
-class VersionNumber {
- public:
-  explicit VersionNumber(const std::string& str);
-
-  bool IsValid() const;
-  int Compare(const VersionNumber& other) const;
-
-  bool operator<(const VersionNumber& other) const;
-  bool operator>=(const VersionNumber& other) const;
-  bool operator==(const VersionNumber& other) const;
-  bool operator!=(const VersionNumber& other) const;
-  bool operator>(const VersionNumber& other) const;
-  bool operator<=(const VersionNumber& other) const;
-
-  std::string ToString() const;
-
- private:
-  std::vector<int> parts_;
-};
-
-}  // namespace utils
-
-#endif  // UTILS_VERSION_NUMBER_H_
diff --git a/src/utils/w3c_languages.cc b/src/utils/w3c_languages.cc
deleted file mode 100644 (file)
index 2a0d1cf..0000000
+++ /dev/null
@@ -1,360 +0,0 @@
-// 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 "utils/w3c_languages.h"
-
-
-#include <boost/filesystem.hpp>
-#include <tzplatform_config.h>
-#include <algorithm>
-#include <fstream>
-#include <vector>
-
-#include "utils/logging.h"
-
-namespace bf = boost::filesystem;
-namespace {
-const bf::path kLanguagesFile =
-    bf::path(tzplatform_getenv(TZ_SYS_SHARE))
-        / "manifest-parser/languages-only.txt";
-const int kLanguagesNumber = 8094;
-}
-
-namespace utils {
-namespace w3c_languages {
-namespace lang_set {
-
-std::vector<std::string> w3c_languages;
-
-bool InitializeLanguageSet() {
-  if (!w3c_languages.empty())
-    return true;
-  if (!bf::exists(kLanguagesFile)) {
-    LOG(ERROR) << "File does not exist";
-    return false;
-  }
-  std::ifstream infile(kLanguagesFile.string());
-  if (!infile.is_open()) {
-    LOG(ERROR) << "Error during file opening";
-    return false;
-  }
-  w3c_languages.reserve(kLanguagesNumber);
-  std::string line;
-  while (std::getline(infile, line)) {
-    w3c_languages.push_back(line);
-  }
-  infile.close();
-  return true;
-}
-
-bool ValidateOnlyLanguage(const std::string& language) {
-  if (!InitializeLanguageSet())
-    return false;
-  if (!std::binary_search(w3c_languages.begin(), w3c_languages.end(), language))
-    return false;
-  return true;
-}
-}  // namespace lang_set
-
-const std::map<std::string, std::string> kW3CExtLang{{"aao", "ar"},
-                                                     {"abh", "ar"},
-                                                     {"abv", "ar"},
-                                                     {"acm", "ar"},
-                                                     {"acq", "ar"},
-                                                     {"acw", "ar"},
-                                                     {"acx", "ar"},
-                                                     {"acy", "ar"},
-                                                     {"adf", "ar"},
-                                                     {"ads", "sgn"},
-                                                     {"aeb", "ar"},
-                                                     {"aec", "ar"},
-                                                     {"aed", "sgn"},
-                                                     {"aen", "sgn"},
-                                                     {"afb", "ar"},
-                                                     {"afg", "sgn"},
-                                                     {"ajp", "ar"},
-                                                     {"apc", "ar"},
-                                                     {"apd", "ar"},
-                                                     {"arb", "ar"},
-                                                     {"arq", "ar"},
-                                                     {"ars", "ar"},
-                                                     {"ary", "ar"},
-                                                     {"arz", "ar"},
-                                                     {"ase", "sgn"},
-                                                     {"asf", "sgn"},
-                                                     {"asp", "sgn"},
-                                                     {"asq", "sgn"},
-                                                     {"asw", "sgn"},
-                                                     {"auz", "ar"},
-                                                     {"avl", "ar"},
-                                                     {"ayh", "ar"},
-                                                     {"ayl", "ar"},
-                                                     {"ayn", "ar"},
-                                                     {"ayp", "ar"},
-                                                     {"bbz", "ar"},
-                                                     {"bfi", "sgn"},
-                                                     {"bfk", "sgn"},
-                                                     {"bjn", "ms"},
-                                                     {"bog", "sgn"},
-                                                     {"bqn", "sgn"},
-                                                     {"bqy", "sgn"},
-                                                     {"btj", "ms"},
-                                                     {"bve", "ms"},
-                                                     {"bvl", "sgn"},
-                                                     {"bvu", "ms"},
-                                                     {"bzs", "sgn"},
-                                                     {"cdo", "zh"},
-                                                     {"cds", "sgn"},
-                                                     {"cjy", "zh"},
-                                                     {"cmn", "zh"},
-                                                     {"coa", "ms"},
-                                                     {"cpx", "zh"},
-                                                     {"csc", "sgn"},
-                                                     {"csd", "sgn"},
-                                                     {"cse", "sgn"},
-                                                     {"csf", "sgn"},
-                                                     {"csg", "sgn"},
-                                                     {"csl", "sgn"},
-                                                     {"csn", "sgn"},
-                                                     {"csq", "sgn"},
-                                                     {"csr", "sgn"},
-                                                     {"czh", "zh"},
-                                                     {"czo", "zh"},
-                                                     {"doq", "sgn"},
-                                                     {"dse", "sgn"},
-                                                     {"dsl", "sgn"},
-                                                     {"dup", "ms"},
-                                                     {"ecs", "sgn"},
-                                                     {"esl", "sgn"},
-                                                     {"esn", "sgn"},
-                                                     {"eso", "sgn"},
-                                                     {"eth", "sgn"},
-                                                     {"fcs", "sgn"},
-                                                     {"fse", "sgn"},
-                                                     {"fsl", "sgn"},
-                                                     {"fss", "sgn"},
-                                                     {"gan", "zh"},
-                                                     {"gds", "sgn"},
-                                                     {"gom", "kok"},
-                                                     {"gse", "sgn"},
-                                                     {"gsg", "sgn"},
-                                                     {"gsm", "sgn"},
-                                                     {"gss", "sgn"},
-                                                     {"gus", "sgn"},
-                                                     {"hab", "sgn"},
-                                                     {"haf", "sgn"},
-                                                     {"hak", "zh"},
-                                                     {"hds", "sgn"},
-                                                     {"hji", "ms"},
-                                                     {"hks", "sgn"},
-                                                     {"hos", "sgn"},
-                                                     {"hps", "sgn"},
-                                                     {"hsh", "sgn"},
-                                                     {"hsl", "sgn"},
-                                                     {"hsn", "zh"},
-                                                     {"icl", "sgn"},
-                                                     {"iks", "sgn"},
-                                                     {"ils", "sgn"},
-                                                     {"inl", "sgn"},
-                                                     {"ins", "sgn"},
-                                                     {"ise", "sgn"},
-                                                     {"isg", "sgn"},
-                                                     {"isr", "sgn"},
-                                                     {"jak", "ms"},
-                                                     {"jax", "ms"},
-                                                     {"jcs", "sgn"},
-                                                     {"jhs", "sgn"},
-                                                     {"jls", "sgn"},
-                                                     {"jos", "sgn"},
-                                                     {"jsl", "sgn"},
-                                                     {"jus", "sgn"},
-                                                     {"kgi", "sgn"},
-                                                     {"knn", "kok"},
-                                                     {"kvb", "ms"},
-                                                     {"kvk", "sgn"},
-                                                     {"kvr", "ms"},
-                                                     {"kxd", "ms"},
-                                                     {"lbs", "sgn"},
-                                                     {"lce", "ms"},
-                                                     {"lcf", "ms"},
-                                                     {"liw", "ms"},
-                                                     {"lls", "sgn"},
-                                                     {"lsg", "sgn"},
-                                                     {"lsl", "sgn"},
-                                                     {"lso", "sgn"},
-                                                     {"lsp", "sgn"},
-                                                     {"lst", "sgn"},
-                                                     {"lsy", "sgn"},
-                                                     {"ltg", "lv"},
-                                                     {"lvs", "lv"},
-                                                     {"lzh", "zh"},
-                                                     {"max", "ms"},
-                                                     {"mdl", "sgn"},
-                                                     {"meo", "ms"},
-                                                     {"mfa", "ms"},
-                                                     {"mfb", "ms"},
-                                                     {"mfs", "sgn"},
-                                                     {"min", "ms"},
-                                                     {"mnp", "zh"},
-                                                     {"mqg", "ms"},
-                                                     {"mre", "sgn"},
-                                                     {"msd", "sgn"},
-                                                     {"msi", "ms"},
-                                                     {"msr", "sgn"},
-                                                     {"mui", "ms"},
-                                                     {"mzc", "sgn"},
-                                                     {"mzg", "sgn"},
-                                                     {"mzy", "sgn"},
-                                                     {"nan", "zh"},
-                                                     {"nbs", "sgn"},
-                                                     {"ncs", "sgn"},
-                                                     {"nsi", "sgn"},
-                                                     {"nsl", "sgn"},
-                                                     {"nsp", "sgn"},
-                                                     {"nsr", "sgn"},
-                                                     {"nzs", "sgn"},
-                                                     {"okl", "sgn"},
-                                                     {"orn", "ms"},
-                                                     {"ors", "ms"},
-                                                     {"pel", "ms"},
-                                                     {"pga", "ar"},
-                                                     {"pks", "sgn"},
-                                                     {"prl", "sgn"},
-                                                     {"prz", "sgn"},
-                                                     {"psc", "sgn"},
-                                                     {"psd", "sgn"},
-                                                     {"pse", "ms"},
-                                                     {"psg", "sgn"},
-                                                     {"psl", "sgn"},
-                                                     {"pso", "sgn"},
-                                                     {"psp", "sgn"},
-                                                     {"psr", "sgn"},
-                                                     {"pys", "sgn"},
-                                                     {"rms", "sgn"},
-                                                     {"rsi", "sgn"},
-                                                     {"rsl", "sgn"},
-                                                     {"sdl", "sgn"},
-                                                     {"sfb", "sgn"},
-                                                     {"sfs", "sgn"},
-                                                     {"sgg", "sgn"},
-                                                     {"sgx", "sgn"},
-                                                     {"shu", "ar"},
-                                                     {"slf", "sgn"},
-                                                     {"sls", "sgn"},
-                                                     {"sqk", "sgn"},
-                                                     {"sqs", "sgn"},
-                                                     {"ssh", "ar"},
-                                                     {"ssp", "sgn"},
-                                                     {"ssr", "sgn"},
-                                                     {"svk", "sgn"},
-                                                     {"swc", "sw"},
-                                                     {"swh", "sw"},
-                                                     {"swl", "sgn"},
-                                                     {"syy", "sgn"},
-                                                     {"tmw", "ms"},
-                                                     {"tse", "sgn"},
-                                                     {"tsm", "sgn"},
-                                                     {"tsq", "sgn"},
-                                                     {"tss", "sgn"},
-                                                     {"tsy", "sgn"},
-                                                     {"tza", "sgn"},
-                                                     {"ugn", "sgn"},
-                                                     {"ugy", "sgn"},
-                                                     {"ukl", "sgn"},
-                                                     {"uks", "sgn"},
-                                                     {"urk", "ms"},
-                                                     {"uzn", "uz"},
-                                                     {"uzs", "uz"},
-                                                     {"vgt", "sgn"},
-                                                     {"vkk", "ms"},
-                                                     {"vkt", "ms"},
-                                                     {"vsi", "sgn"},
-                                                     {"vsl", "sgn"},
-                                                     {"vsv", "sgn"},
-                                                     {"wuu", "zh"},
-                                                     {"xki", "sgn"},
-                                                     {"xml", "sgn"},
-                                                     {"xmm", "ms"},
-                                                     {"xms", "sgn"},
-                                                     {"yds", "sgn"},
-                                                     {"ygs", "sgn"},
-                                                     {"yhs", "sgn"},
-                                                     {"ysl", "sgn"},
-                                                     {"yue", "zh"},
-                                                     {"zib", "sgn"},
-                                                     {"zlm", "ms"},
-                                                     {"zmi", "ms"},
-                                                     {"zsl", "sgn"},
-                                                     {"zsm", "ms"}};
-const std::unordered_set<std::string> kW3CScript{
-    "Adlm", "Afak", "Aghb", "Ahom", "Arab",       "Aran", "Armi", "Armn",
-    "Avst", "Bali", "Bamu", "Bass", "Batk",       "Beng", "Blis", "Bopo",
-    "Brah", "Brai", "Bugi", "Buhd", "Cakm",       "Cans", "Cari", "Cham",
-    "Cher", "Cirt", "Copt", "Cprt", "Cyrl",       "Cyrs", "Deva", "Dsrt",
-    "Dupl", "Egyd", "Egyh", "Egyp", "Elba",       "Ethi", "Geok", "Geor",
-    "Glag", "Goth", "Gran", "Grek", "Gujr",       "Guru", "Hang", "Hani",
-    "Hano", "Hans", "Hant", "Hatr", "Hebr",       "Hira", "Hluw", "Hmng",
-    "Hrkt", "Hung", "Inds", "Ital", "Java",       "Jpan", "Jurc", "Kali",
-    "Kana", "Khar", "Khmr", "Khoj", "Kitl",       "Kits", "Knda", "Kore",
-    "Kpel", "Kthi", "Lana", "Laoo", "Latf",       "Latg", "Latn", "Lepc",
-    "Limb", "Lina", "Linb", "Lisu", "Loma",       "Lyci", "Lydi", "Mahj",
-    "Mand", "Mani", "Marc", "Maya", "Mend",       "Merc", "Mero", "Mlym",
-    "Modi", "Mong", "Moon", "Mroo", "Mtei",       "Mult", "Mymr", "Narb",
-    "Nbat", "Nkgb", "Nkoo", "Nshu", "Ogam",       "Olck", "Orkh", "Orya",
-    "Osge", "Osma", "Palm", "Pauc", "Perm",       "Phag", "Phli", "Phlp",
-    "Phlv", "Phnx", "Plrd", "Prti", "Qaaa..Qabx", "Rjng", "Roro", "Runr",
-    "Samr", "Sara", "Sarb", "Saur", "Sgnw",       "Shaw", "Shrd", "Sidd",
-    "Sind", "Sinh", "Sora", "Sund", "Sylo",       "Syrc", "Syre", "Syrj",
-    "Syrn", "Tagb", "Takr", "Tale", "Talu",       "Taml", "Tang", "Tavt",
-    "Telu", "Teng", "Tfng", "Tglg", "Thaa",       "Thai", "Tibt", "Tirh",
-    "Ugar", "Vaii", "Visp", "Wara", "Wole",       "Xpeo", "Xsux", "Yiii",
-    "Zinh", "Zmth", "Zsym", "Zxxx", "Zyyy",       "Zzzz"};
-const std::unordered_set<std::string> kW3CRegion{
-    "AA",     "AC",  "AD",  "AE",  "AF",  "AG",  "AI",  "AL",  "AM",  "AN",
-    "AO",     "AQ",  "AR",  "AS",  "AT",  "AU",  "AW",  "AX",  "AZ",  "BA",
-    "BB",     "BD",  "BE",  "BF",  "BG",  "BH",  "BI",  "BJ",  "BL",  "BM",
-    "BN",     "BO",  "BQ",  "BR",  "BS",  "BT",  "BU",  "BV",  "BW",  "BY",
-    "BZ",     "CA",  "CC",  "CD",  "CF",  "CG",  "CH",  "CI",  "CK",  "CL",
-    "CM",     "CN",  "CO",  "CP",  "CR",  "CS",  "CU",  "CV",  "CW",  "CX",
-    "CY",     "CZ",  "DD",  "DE",  "DG",  "DJ",  "DK",  "DM",  "DO",  "DZ",
-    "EA",     "EC",  "EE",  "EG",  "EH",  "ER",  "ES",  "ET",  "EU",  "FI",
-    "FJ",     "FK",  "FM",  "FO",  "FR",  "FX",  "GA",  "GB",  "GD",  "GE",
-    "GF",     "GG",  "GH",  "GI",  "GL",  "GM",  "GN",  "GP",  "GQ",  "GR",
-    "GS",     "GT",  "GU",  "GW",  "GY",  "HK",  "HM",  "HN",  "HR",  "HT",
-    "HU",     "IC",  "ID",  "IE",  "IL",  "IM",  "IN",  "IO",  "IQ",  "IR",
-    "IS",     "IT",  "JE",  "JM",  "JO",  "JP",  "KE",  "KG",  "KH",  "KI",
-    "KM",     "KN",  "KP",  "KR",  "KW",  "KY",  "KZ",  "LA",  "LB",  "LC",
-    "LI",     "LK",  "LR",  "LS",  "LT",  "LU",  "LV",  "LY",  "MA",  "MC",
-    "MD",     "ME",  "MF",  "MG",  "MH",  "MK",  "ML",  "MM",  "MN",  "MO",
-    "MP",     "MQ",  "MR",  "MS",  "MT",  "MU",  "MV",  "MW",  "MX",  "MY",
-    "MZ",     "NA",  "NC",  "NE",  "NF",  "NG",  "NI",  "NL",  "NO",  "NP",
-    "NR",     "NT",  "NU",  "NZ",  "OM",  "PA",  "PE",  "PF",  "PG",  "PH",
-    "PK",     "PL",  "PM",  "PN",  "PR",  "PS",  "PT",  "PW",  "PY",  "QA",
-    "QM..QZ", "RE",  "RO",  "RS",  "RU",  "RW",  "SA",  "SB",  "SC",  "SD",
-    "SE",     "SG",  "SH",  "SI",  "SJ",  "SK",  "SL",  "SM",  "SN",  "SO",
-    "SR",     "SS",  "ST",  "SU",  "SV",  "SX",  "SY",  "SZ",  "TA",  "TC",
-    "TD",     "TF",  "TG",  "TH",  "TJ",  "TK",  "TL",  "TM",  "TN",  "TO",
-    "TP",     "TR",  "TT",  "TV",  "TW",  "TZ",  "UA",  "UG",  "UM",  "US",
-    "UY",     "UZ",  "VA",  "VC",  "VE",  "VG",  "VI",  "VN",  "VU",  "WF",
-    "WS",
-    "XA..XZ",  // TODO(w.kosowicz): should it be all the letters from XA to XZ?
-    "YD",     "YE",  "YT",  "YU",  "ZA",  "ZM",  "ZR",  "ZW",  "ZZ",  "001",
-    "002",    "003", "005", "009", "011", "013", "014", "015", "017", "018",
-    "019",    "021", "029", "030", "034", "035", "039", "053", "054", "057",
-    "061",    "142", "143", "145", "150", "151", "154", "155", "419"};
-const std::unordered_set<std::string> kW3CVariant{
-    "1606nict", "1694acad", "1901",     "1959acad", "1994",     "1996",
-    "abl1943",  "alalc97",  "aluku",    "ao1990",   "arevela",  "arevmda",
-    "baku1926", "balanka",  "barla",    "bauddha",  "biscayan", "biske",
-    "bohoric",  "boont",    "colb1945", "dajnko",   "ekavsk",   "emodeng",
-    "fonipa",   "fonupa",   "fonxsamp", "hepburn",  "heploc",   "hognorsk",
-    "ijekavsk", "itihasa",  "jauer",    "jyutping", "kkcor",    "kociewie",
-    "kscor",    "laukika",  "lipaw",    "luna1918", "metelko",  "monoton",
-    "ndyuka",   "nedis",    "njiva",    "nulik",    "osojs",    "oxendict",
-    "pamaka",   "petr1708", "pinyin",   "polyton",  "puter",    "rigik",
-    "rozaj",    "rumgr",    "scotland", "scouse",   "solba",    "sotav",
-    "surmiran", "sursilv",  "sutsilv",  "tarask",   "uccor",    "ucrcor",
-    "ulster",   "unifon",   "vaidika",  "valencia", "vallader", "wadegile"};
-}  // namespace w3c_languages
-}  // namespace utils
diff --git a/src/utils/w3c_languages.h b/src/utils/w3c_languages.h
deleted file mode 100644 (file)
index dbaa23c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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 UTILS_W3C_LANGUAGES_H_
-#define UTILS_W3C_LANGUAGES_H_
-
-#include <map>
-#include <string>
-#include <unordered_set>
-
-namespace utils {
-namespace w3c_languages {
-namespace lang_set {
-
-/**
- * @brief ValidateOnlyLanguage
- *        Checks validity of language part of language tag.
- *
- * Languauge part is described:
- *  - http://www.w3.org/International/articles/language-tags/#language
- *
- * @param language language
- * @return true if language is correct
- */
-bool ValidateOnlyLanguage(const std::string& language);
-
-}  // namespace lang_set
-
-extern const std::map<std::string, std::string> kW3CExtLang;
-extern const std::unordered_set<std::string> kW3CScript;
-extern const std::unordered_set<std::string> kW3CRegion;
-extern const std::unordered_set<std::string> kW3CVariant;
-
-}  // namespace w3c_languages
-}  // namespace utils
-
-#endif  // UTILS_W3C_LANGUAGES_H_