%{_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
ADD_SUBDIRECTORY(manifest_handlers)
ADD_SUBDIRECTORY(tpk_manifest_handlers)
ADD_SUBDIRECTORY(unit_tests)
-ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(delta)
#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 {
#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";
#include <algorithm>
#include <string>
-#include "utils/logging.h"
+#include "manifest_parser/utils/logging.h"
namespace {
#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 {
#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;
#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 {
#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 {
#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";
#include <string>
-#include "utils/version_number.h"
+#include "manifest_parser/utils/version_number.h"
namespace parser {
/**
#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;
#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 {
#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;
#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 {
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)
#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;
--- /dev/null
+# 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)
--- /dev/null
+// 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
--- /dev/null
+// 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_
--- /dev/null
+// 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
+
+
--- /dev/null
+// 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_
--- /dev/null
+// 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_
--- /dev/null
+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
--- /dev/null
+// 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
--- /dev/null
+// 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_
--- /dev/null
+// 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
--- /dev/null
+// 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_
--- /dev/null
+// 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
--- /dev/null
+// 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_
#include <cassert>
#include <cmath>
-#include "utils/logging.h"
+#include "manifest_parser/utils/logging.h"
namespace parser {
account_handler.cc
application_manifest_constants.cc
author_handler.cc
+ common/application_handler.cc
description_handler.cc
package_handler.cc
privileges_handler.cc
#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";
#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 {
--- /dev/null
+// 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
--- /dev/null
+// 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_
#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 {
#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 {
#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.
#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 {
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";
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,
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)) {
*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;
}
#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
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
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
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
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
std::string Key() const override;
};
-} // namespace parse
-} // namespace tpk
+} // namespace parse
+} // namespace tpk
#endif // TPK_MANIFEST_HANDLERS_SERVICE_APPLICATION_HANDLER_H_
#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;
#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"
#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 {
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";
} // 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"
}
} 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 "
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 "
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)) {
*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)) {
*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)) {
*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);
}
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);
#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();
/**
* @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;
}
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;
}
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
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_;
}
}
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_;
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
std::vector<std::string> PrerequisiteKeys() const override;
};
-} // namespace parse
-} // namespace tpk
+} // namespace parse
+} // namespace tpk
#endif // TPK_MANIFEST_HANDLERS_UI_APPLICATION_HANDLER_H_
#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 {
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";
} // 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;
}
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,
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"
} 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";
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)) {
*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);
}
return true;
}
-std::string WidgetApplicationInfo::key() {
- return kWidgetApplicationKey;
-}
-
std::string WidgetApplicationHandler::Key() const {
return kWidgetApplicationKey;
}
#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();
/**
* @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
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
}
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
// 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) { \
// 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 {
+++ /dev/null
-# 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)
+++ /dev/null
-// 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
+++ /dev/null
-// 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_
+++ /dev/null
-// 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
-
-
+++ /dev/null
-// 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_
+++ /dev/null
-// 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_
+++ /dev/null
-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
+++ /dev/null
-// 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
+++ /dev/null
-// 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_
+++ /dev/null
-// 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
+++ /dev/null
-// 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_
+++ /dev/null
-// 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
+++ /dev/null
-// 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_