+class PrivilegeParser : public ElementParser
+{
+ public:
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& name)
+ {
+ return &IgnoringParser::Create;
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ LogDebug("element");
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (m_properNamespace) {
+ if (attribute.name == L"name") {
+ m_feature.name = attribute.value;
+ m_privilege.name = attribute.value;
+ }
+ }
+ m_feature.required = true;
+ }
+
+ virtual void Verify()
+ {
+ LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
+
+ if (m_feature.name != L"") {
+ if (iri.Validate()) {
+ if (m_data.featuresList.find(m_feature) ==
+ m_data.featuresList.end()) {
+ m_data.featuresList.insert(m_feature);
+ } else {
+ LogDebug("Ignoring feature with name" <<
+ DPL::ToUTF8String(m_feature.name));
+ }
+ }
+ }
+
+ LibIri::Wrapper iriPrivilege(
+ DPL::ToUTF8String(m_privilege.name).c_str());
+
+ if (m_privilege.name != L"") {
+ if (iriPrivilege.Validate()) {
+ if (m_data.privilegeList.find(m_privilege) ==
+ m_data.privilegeList.end()) {
+ m_data.privilegeList.insert(m_privilege);
+ } else {
+ LogDebug("Ignoring privilege with name" <<
+ DPL::ToUTF8String(m_privilege.name));
+ }
+ }
+ }
+ }
+
+ PrivilegeParser(ConfigParserData& data) :
+ ElementParser(),
+ m_data(data),
+ m_feature(L""),
+ m_privilege(L""),
+ m_properNamespace(false)
+ {
+ }
+
+ private:
+ ConfigParserData& m_data;
+ ConfigParserData::Feature m_feature;
+ ConfigParserData::Privilege m_privilege;
+ bool m_properNamespace;
+};
+
+class CategoryParser : public ElementParser
+{
+ public:
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& /*name*/)
+ {
+ return &IgnoringParser::Create;
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (attribute.name == L"name") {
+ if (attribute.value.size() > 0) {
+ m_name = attribute.value;
+ }
+ }
+ }
+
+ virtual void Accept(const Element& /*element*/)
+ {
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ }
+
+ virtual void Verify()
+ {
+ if (m_name.IsNull()) {
+ LogWarning("name attribute of category element is mandatory - ignoring");
+ return;
+ }
+
+ if (m_data.categoryList.find(*m_name) ==
+ m_data.categoryList.end()) {
+ m_data.categoryList.insert(*m_name);
+ }
+ }
+
+ explicit CategoryParser(ConfigParserData& data) :
+ m_data(data)
+ {
+ }
+
+ private:
+ DPL::OptionalString m_name;
+ ConfigParserData& m_data;
+};
+
+class LiveboxParser : public ElementParser
+{
+ public:
+
+ struct BoxLabelParser : public ElementParser
+ {
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& /*name*/)
+ {
+ return &IgnoringParser::Create;
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& text)
+ {
+ if(m_properNamespace)
+ m_label = text.value;
+ }
+
+ virtual void Verify()
+ {
+ m_data.m_label = m_label;
+ }
+
+ BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ DPL::String m_label;
+ bool m_properNamespace;
+ ConfigParserData::LiveboxInfo& m_data;
+ };
+
+ struct BoxIconParser : public ElementParser
+ {
+ 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"src") {
+ m_icon = attribute.value;
+ }
+ }
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ }
+
+ virtual void Verify()
+ {
+ m_data.m_icon = m_icon;
+ }
+
+ explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ DPL::String m_icon;
+ bool m_properNamespace;
+ ConfigParserData::LiveboxInfo& m_data;
+ };
+
+ struct BoxContentParser : public ElementParser
+ {
+ struct BoxSizeParser : public ElementParser
+ {
+ 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"preview") {
+ m_preview = attribute.value;
+ }
+ }
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& text)
+ {
+ if(m_properNamespace)
+ m_size = text.value;
+ }
+
+ virtual void Verify()
+ {
+ std::pair<DPL::String, DPL::String> boxSize;
+ boxSize.first = m_size;
+ boxSize.second = m_preview;
+ m_data.m_boxSize.push_back(boxSize);
+ }
+
+ explicit BoxSizeParser(ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
+ ElementParser(),
+ m_data(data)
+ {
+ }
+
+ private:
+ DPL::String m_size;
+ DPL::String m_preview;
+ bool m_properNamespace;
+ ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
+ };
+
+ struct PdParser : public ElementParser
+ {
+ 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"src") {
+ m_src = attribute.value;
+ } else if (attribute.name == L"width") {
+ m_width = attribute.value;
+ } else if (attribute.name == L"height") {
+ m_height = attribute.value;
+ }
+ }
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ }
+
+ virtual void Verify()
+ {
+ m_data.m_pdSrc = m_src;
+ m_data.m_pdWidth = m_width;
+ m_data.m_pdHeight = m_height;
+ }
+
+ explicit PdParser(ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ DPL::String m_src;
+ DPL::String m_width;
+ DPL::String m_height;
+
+ bool m_properNamespace;
+ ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
+ };
+
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& name)
+ {
+ if (name == L"box-size") {
+ return DPL::MakeDelegate(this, &LiveboxParser::BoxContentParser::OnBoxSizeElement);
+ } else if (name == L"pd") {
+ return DPL::MakeDelegate(this, &LiveboxParser::BoxContentParser::OnPdElement);
+ } else{
+ ThrowMsg(Exception::ParseError, "No element parser for name: " << name);
+ }
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (m_properNamespace) {
+ if (attribute.name == L"src")
+ m_box.m_boxSrc = attribute.value;
+ }
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ }
+
+ virtual void Verify()
+ {
+ m_data.m_boxInfo = m_box;
+ }
+
+ explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ ElementParserPtr OnBoxSizeElement()
+ {
+ return ElementParserPtr(new BoxSizeParser(m_box));
+ }
+
+ ElementParserPtr OnPdElement()
+ {
+ return ElementParserPtr(new PdParser(m_box));
+ }
+
+ private:
+ DPL::String m_src;
+ bool m_properNamespace;
+ ConfigParserData::LiveboxInfo& m_data;
+ ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
+ };
+
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& name)
+ {
+ if (name == L"box-label") {
+ return DPL::MakeDelegate(this, &LiveboxParser::OnBoxLabelElement);
+ } else if (name == L"box-icon") {
+ return DPL::MakeDelegate(this, &LiveboxParser::OnBoxIconElement);
+ } else if (name == L"box-content") {
+ return DPL::MakeDelegate(this, &LiveboxParser::OnBoxContentElement);
+ } else {
+ return &IgnoringParser::Create;
+ }
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (m_properNamespace) {
+ if (attribute.name == L"id") {
+ m_liveboxId = attribute.value;
+ } else if (attribute.name == L"primary") {
+ m_primary = attribute.value;
+ } else if (attribute.name == L"auto-launch") {
+ m_autoLaunch = attribute.value;
+ } else if (attribute.name == L"update-period") {
+ m_updatePeriod = attribute.value;
+ }
+ }
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ if (element.ns ==
+ ConfigurationNamespace::TizenWebAppNamespaceName)
+ {
+ m_properNamespace = true;
+ }
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ }
+
+ virtual void Verify()
+ {
+ m_livebox.m_liveboxId = m_liveboxId;
+ m_livebox.m_primary = m_primary;
+ m_livebox.m_autoLaunch = m_autoLaunch;
+ m_livebox.m_updatePeriod = m_updatePeriod;
+
+ m_data.m_livebox.push_back(m_livebox);
+ }
+
+ explicit LiveboxParser(ConfigParserData& data) :
+ ElementParser(),
+ m_data(data),
+ m_properNamespace(false)
+ {
+ m_livebox = ConfigParserData::LiveboxInfo();
+ }
+
+ ElementParserPtr OnBoxLabelElement()
+ {
+ return ElementParserPtr(new BoxLabelParser(m_livebox));
+ }
+
+ ElementParserPtr OnBoxIconElement()
+ {
+ return ElementParserPtr(new BoxIconParser(m_livebox));
+ }
+
+ ElementParserPtr OnBoxContentElement()
+ {
+ return ElementParserPtr(new BoxContentParser(m_livebox));
+ }
+
+ private:
+ ConfigParserData& m_data;
+ ConfigParserData::LiveboxInfo m_livebox;
+ DPL::String m_liveboxId;
+ DPL::String m_primary;
+ DPL::String m_autoLaunch;
+ DPL::String m_updatePeriod;
+ bool m_properNamespace;
+
+};
+