From d6b00067042e597e94163d353d5f1b380aabc781 Mon Sep 17 00:00:00 2001 From: Soyoung Kim Date: Thu, 14 Mar 2013 18:04:49 +0900 Subject: [PATCH] Add Account parser and generate manifest. [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Add Account parser. [SCMRequest] N/A Change-Id: Ibc2827e02339a051629a62d66880f07b610a757a --- configuration/config.tizen.xsd | 28 ++- configuration/config.xsd | 1 + src/configuration_parser/widget_parser.cpp | 277 +++++++++++++++++++++++++ src/configuration_parser/widget_parser.h | 1 + src/jobs/widget_install/manifest.cpp | 37 ++++ src/jobs/widget_install/manifest.h | 38 ++++ src/jobs/widget_install/task_manifest_file.cpp | 46 ++++ src/jobs/widget_install/task_manifest_file.h | 1 + 8 files changed, 428 insertions(+), 1 deletion(-) diff --git a/configuration/config.tizen.xsd b/configuration/config.tizen.xsd index 765f2b6..f82cab5 100755 --- a/configuration/config.tizen.xsd +++ b/configuration/config.tizen.xsd @@ -2,6 +2,7 @@ + @@ -202,4 +203,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/configuration/config.xsd b/configuration/config.xsd index ba1c5ab..ff06e1e 100755 --- a/configuration/config.xsd +++ b/configuration/config.xsd @@ -77,6 +77,7 @@ + diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index 71dc7a8..df343dc 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -2220,6 +2220,277 @@ class CspReportOnlyParser : public ElementParser DPL::OptionalString m_policy; }; +class AccountParser : public ElementParser +{ + public: + struct AccountProviderParser : public ElementParser + { + public: + + struct IconParser : public ElementParser + { + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + virtual void Accept(const Text& text) + { + if (text.value == L"") { + return; + } + m_value = text.value; + } + + virtual void Accept(const Element& /*element*/) + {} + + virtual void Accept(const XmlAttribute& attribute) + { + if (attribute.name == L"section") { + if (attribute.value == L"account") { + m_type = ConfigParserData::IconSectionType::DefaultIcon; + } else if (attribute.value == L"account-small") { + m_type = ConfigParserData::IconSectionType::SmallIcon; + } + } + } + + virtual void Verify() + { + if (m_value.IsNull() || *m_value == L"") { + return; + } + + std::pair icon; + icon.first = m_type; + icon.second = *m_value; + + m_data.m_iconSet.insert(icon); + } + + IconParser(ConfigParserData::AccountProvider& data) : + ElementParser(), + m_properNamespace(false), + m_data(data), + m_type(ConfigParserData::DefaultIcon) + {} + + private: + bool m_properNamespace; + ConfigParserData::IconSectionType m_type; + DPL::OptionalString m_value; + ConfigParserData::AccountProvider& m_data; + }; + + struct DisplayNameParser : public ElementParser + { + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + virtual void Accept(const Text& text) + { + if (text.value == L"") { + return; + } + m_value = text.value; + } + + virtual void Accept(const Element& element) + { + m_lang = element.lang; + m_value= L""; + } + + virtual void Accept(const XmlAttribute& /*attribute*/) + {} + + virtual void Verify() + { + if (m_value.IsNull() || *m_value == L"") { + return; + } + + std::pair name; + name.first = *m_lang; + name.second = *m_value; + + m_data.m_displayNameSet.insert(name); + } + + DisplayNameParser(ConfigParserData::AccountProvider& data) : + ElementParser(), + m_properNamespace(false), + m_data(data) + {} + + private: + bool m_properNamespace; + DPL::OptionalString m_lang; + DPL::OptionalString m_value; + ConfigParserData::AccountProvider& m_data; + }; + + struct CapabilityParser : public ElementParser + { + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + virtual void Accept(const Text& text) + { + if (text.value == L"") { + return; + } + m_value = text.value; + } + + virtual void Accept(const Element& /*element*/) + {} + + virtual void Accept(const XmlAttribute& /*attribute*/) + {} + + virtual void Verify() + { + if (m_value.IsNull() || *m_value == L"") { + return; + } + m_data.m_capabilityList.push_back(*m_value); + } + + CapabilityParser(ConfigParserData::AccountProvider& data) : + ElementParser(), + m_properNamespace(false), + m_data(data) + {} + + private: + bool m_properNamespace; + DPL::OptionalString m_value; + ConfigParserData::AccountProvider& m_data; + }; + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& name) + { + if (name == L"icon") { + return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement); + } else if (name == L"display-name") { + return DPL::MakeDelegate(this, + &AccountProviderParser::OnDisplayNameElement); + } else if (name == L"capability") { + return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement); + } else { + return &IgnoringParser::Create; + } + } + + virtual void Accept(const Text& text) + {} + + virtual void Accept(const Element& /*element*/) + {} + + virtual void Accept(const XmlAttribute& attribute) + { + if (attribute.name == L"multiple-accounts-support") { + if (attribute.value == L"") { + return; + } + + if (attribute.value == L"ture") { + m_multiSupport = true; + } + } + } + + virtual void Verify() + { + m_data.m_multiAccountSupport = m_multiSupport; + } + + ElementParserPtr OnIconElement() + { + return ElementParserPtr(new IconParser(m_data)); + } + + ElementParserPtr OnDisplayNameElement() + { + return ElementParserPtr(new DisplayNameParser(m_data)); + } + + ElementParserPtr OnCapabilityElement() + { + return ElementParserPtr(new CapabilityParser(m_data)); + } + + AccountProviderParser(ConfigParserData::AccountProvider& data) : + ElementParser(), + m_properNamespace(false), + m_data(data), + m_multiSupport(false) + {} + + private: + bool m_properNamespace; + bool m_multiSupport; + ConfigParserData::AccountProvider& m_data; + }; + + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& name) + { + if (name == L"account-provider") { + return DPL::MakeDelegate(this, &AccountParser::OnProviderElement); + } else { + return &IgnoringParser::Create; + } + } + + virtual void Accept(const Element& element) + { + if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) { + m_properNamespace = true; + } + } + + virtual void Accept(const XmlAttribute& /*attribute*/) + {} + + virtual void Accept(const Text& /*text*/) + {} + + virtual void Verify() + {} + + ElementParserPtr OnProviderElement() + { + return ElementParserPtr(new AccountProviderParser(m_account)); + } + + AccountParser(ConfigParserData& data) : + ElementParser(), + m_data(data), + m_account(data.accountProvider), + m_properNamespace(false) + {} + + private: + ConfigParserData& m_data; + ConfigParserData::AccountProvider& m_account; + bool m_properNamespace; + bool m_multiSupport; +}; + ElementParser::ActionFunc WidgetParser::GetElementParser( const DPL::String& /*ns*/, const DPL::String& @@ -2283,6 +2554,7 @@ WidgetParser::WidgetParser(ConfigParserData& data) : &WidgetParser:: OnCspReportOnlyElement); #endif + m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement); } ElementParserPtr WidgetParser::OnNameElement() @@ -2390,6 +2662,11 @@ ElementParserPtr WidgetParser::OnCspReportOnlyElement() return ElementParserPtr(new CspReportOnlyParser(m_data)); } +ElementParserPtr WidgetParser::OnAccountElement() +{ + return ElementParserPtr(new AccountParser(m_data)); +} + void WidgetParser::Accept(const Element& element) { if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName && diff --git a/src/configuration_parser/widget_parser.h b/src/configuration_parser/widget_parser.h index af9f7db..c171c9d 100644 --- a/src/configuration_parser/widget_parser.h +++ b/src/configuration_parser/widget_parser.h @@ -85,6 +85,7 @@ class WidgetParser : public ElementParser ElementParserPtr OnAppWidgetElement(); ElementParserPtr OnCspElement(); ElementParserPtr OnCspReportOnlyElement(); + ElementParserPtr OnAccountElement(); virtual ActionFunc GetElementParser(const DPL::String& ns, const DPL::String& name); diff --git a/src/jobs/widget_install/manifest.cpp b/src/jobs/widget_install/manifest.cpp index f143d46..1b1dbd7 100644 --- a/src/jobs/widget_install/manifest.cpp +++ b/src/jobs/widget_install/manifest.cpp @@ -193,6 +193,10 @@ void Manifest::serialize(xmlTextWriterPtr writer) FOREACH(l, this->livebox) { l->serialize(writer); } + FOREACH(acc, this->account) + { + acc->serialize(writer); + } } endElement(writer); } @@ -422,5 +426,38 @@ void LiveBox::serialize(xmlTextWriterPtr writer) endElement(writer); } + +void Account::serialize(xmlTextWriterPtr writer) +{ + startElement(writer, "account"); + { + startElement(writer, "account-provider"); + writeAttribute(writer, "app-id", this->provider.appid); + writeAttribute(writer, "multiple-accounts-support", + this->provider.multiAccount); + + FOREACH(i, this->provider.icon) + { + startElement(writer, "icon"); + writeAttribute(writer, "section", i->first); + writeText(writer, i->second); + endElement(writer); + } + FOREACH(n, this->provider.name) + { + writeElementWithOneAttribute(writer, "label", + n->getString(), "xml:lang", + n->getLang(), n->hasLang()); + } + FOREACH(c, this->provider.capability) + { + startElement(writer, "capability"); + writeText(writer, *c); + endElement(writer); + } + endElement(writer); + } + endElement(writer); +} } //namespace Jobs } //namespace WidgetInstall diff --git a/src/jobs/widget_install/manifest.h b/src/jobs/widget_install/manifest.h index 342c387..28fed98 100644 --- a/src/jobs/widget_install/manifest.h +++ b/src/jobs/widget_install/manifest.h @@ -145,6 +145,38 @@ class AppControl typedef AppControl AppControlType; /** + * @brief account element + */ +typedef std::list> IconListType; +typedef std::list DisplayNameListType; +typedef std::list AccountCapabilityType; + +struct AccountProvider +{ + NcnameType appid; + NcnameType multiAccount; + IconListType icon; + DisplayNameListType name; + AccountCapabilityType capability; +}; + +typedef AccountProvider AccountProviderType; + +class Account +{ + public: + Account() {} + void addAccountProvider(const AccountProvider &x) + { + this->provider = x; + } + void serialize(xmlTextWriterPtr writer); + + private: + AccountProviderType provider; +}; + +/** * @brief ime-application element */ class ImeApplication @@ -441,6 +473,11 @@ class Manifest this->livebox.push_back(x); } + void addAccount(const Account &x) + { + this->account.push_back(x); + } + void setInstallLocation(const InstallLocationType &x) { this->installLocation = x; @@ -474,6 +511,7 @@ class Manifest NcnameType package; PackageType type; NmtokenType version; + std::list account; }; } //namespace Jobs } //namespace WidgetInstall diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp index 6821d26..ce8b844 100644 --- a/src/jobs/widget_install/task_manifest_file.cpp +++ b/src/jobs/widget_install/task_manifest_file.cpp @@ -581,6 +581,7 @@ void TaskManifestFile::writeManifest(const DPL::String & path) setAppControlInfo(uiApp); setAppCategory(uiApp); setLiveBoxInfo(manifest); + setAccount(manifest); manifest.addUiApplication(uiApp); manifest.generate(path); @@ -971,5 +972,50 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest) manifest.addLivebox(liveBox); } } + +void TaskManifestFile::setAccount(Manifest& manifest) +{ + WrtDB::ConfigParserData::AccountProvider account = + m_context.widgetConfig.configInfo.accountProvider; + + AccountProviderType provider; + + if (account.m_iconSet.empty()) { + LogInfo("Widget doesn't contain Account"); + return; + } + if (account.m_multiAccountSupport) { + provider.multiAccount = L"ture"; + } else { + provider.multiAccount = L"false"; + } + provider.appid = m_context.widgetConfig.tzAppid; + + FOREACH(it, account.m_iconSet) { + std::pair icon; + + if (it->first == ConfigParserData::IconSectionType::DefaultIcon) { + icon.first = L"account"; + } else if (it->first == ConfigParserData::IconSectionType::SmallIcon) { + icon.first = L"account-small"; + } + icon.second = it->second; + + provider.icon.push_back(icon); + } + + FOREACH(it, account.m_displayNameSet) { + provider.name.push_back(LabelType(it->second, it->first)); + } + + FOREACH(it, account.m_capabilityList) { + provider.capability.push_back(*it); + } + + Account accountInfo; + accountInfo.addAccountProvider(provider); + manifest.addAccount(accountInfo); +} + } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/task_manifest_file.h b/src/jobs/widget_install/task_manifest_file.h index de18c42..98548cb 100644 --- a/src/jobs/widget_install/task_manifest_file.h +++ b/src/jobs/widget_install/task_manifest_file.h @@ -99,6 +99,7 @@ class TaskManifestFile : void setAppControlInfo(UiApplication & uiApp); void setAppCategory(UiApplication & uiApp); void setLiveBoxInfo(Manifest& manifest); + void setAccount(Manifest& uiApp); void generateWidgetName(Manifest & manifest, UiApplication &uiApp, -- 2.7.4