Support tizen:metadata
[platform/framework/web/wrt-installer.git] / src / configuration_parser / widget_parser.cpp
index 07d6d7d..56127be 100644 (file)
@@ -2385,6 +2385,69 @@ class AccountParser : public ElementParser
     bool m_multiSupport;
 };
 
+class MetadataParser : public ElementParser
+{
+  public:
+    virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+                                        const DPL::String& /*name*/)
+    {
+        return &IgnoringParser::Create;
+    }
+
+    virtual void Accept(const XmlAttribute& attribute)
+    {
+        if (m_properNamespace) {
+            if (attribute.name == L"key") {
+                m_key = attribute.value;
+            } else if (attribute.name == L"value") {
+                m_value = attribute.value;
+            }
+        }
+    }
+
+    virtual void Accept(const Element& element)
+    {
+        if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
+            m_properNamespace = true;
+        }
+    }
+
+    virtual void Accept(const Text& /*text*/)
+    {
+        ThrowMsg(Exception::ParseError, "param element must be empty");
+    }
+
+    virtual void Verify()
+    {
+        if (m_key.IsNull()) {
+            LogWarning("metadata element must have key attribute");
+            return;
+        }
+        NormalizeString(m_key);
+        NormalizeString(m_value);
+        ConfigParserData::Metadata metaData(*m_key, *m_value);
+        FOREACH(it, m_data.metadataList) {
+            if (!DPL::StringCompare(it->key, *m_key)) {
+                LogError("Key isn't unique");
+                return;
+            }
+        }
+        m_data.metadataList.push_back(metaData);
+    }
+
+    MetadataParser(ConfigParserData& data) :
+        ElementParser(),
+        m_data(data),
+        m_properNamespace(false)
+    {}
+
+  private:
+    DPL::OptionalString m_key;
+    DPL::OptionalString m_value;
+    ConfigParserData& m_data;
+    bool m_properNamespace;
+};
+
 ElementParser::ActionFunc WidgetParser::GetElementParser(
     const DPL::String& /*ns*/,
     const DPL::String&
@@ -2448,6 +2511,7 @@ WidgetParser::WidgetParser(ConfigParserData& data) :
         DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
 #endif
     m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
+    m_map[L"metadata"] = DPL::MakeDelegate(this, &WidgetParser::OnMetadataElement);
 }
 
 ElementParserPtr WidgetParser::OnNameElement()
@@ -2555,6 +2619,11 @@ ElementParserPtr WidgetParser::OnAccountElement()
     return ElementParserPtr(new AccountParser(m_data));
 }
 
+ElementParserPtr WidgetParser::OnMetadataElement()
+{
+    return ElementParserPtr(new MetadataParser(m_data));
+}
+
 void WidgetParser::Accept(const Element& element)
 {
     if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&