+class AppControlParser : public ElementParser
+{
+ public:
+ struct SourceParser : 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*/)
+ {
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (attribute.name == L"name") {
+ if (attribute.value.size() > 0) {
+ m_value = attribute.value;
+ NormalizeString(m_value);
+ }
+ }
+ }
+
+ virtual void Verify()
+ {
+ if (m_value.IsNull() || *m_value== L"") {
+ return;
+ }
+
+ m_data.m_src = *m_value;
+ }
+
+ SourceParser(ConfigParserData::AppControlInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ bool m_properNamespace;
+ DPL::OptionalString m_value;
+ ConfigParserData::AppControlInfo& m_data;
+ };
+
+ struct OperationParser : 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*/)
+ {
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (attribute.name == L"name") {
+ if (attribute.value.size() > 0) {
+ m_value = attribute.value;
+ NormalizeString(m_value);
+ }
+ }
+ }
+
+ virtual void Verify()
+ {
+ if (m_value.IsNull() || *m_value== L"") {
+ return;
+ }
+
+ m_data.m_operation = *m_value;
+ }
+
+ OperationParser(ConfigParserData::AppControlInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ bool m_properNamespace;
+ DPL::OptionalString m_value;
+ ConfigParserData::AppControlInfo& m_data;
+ };
+
+ struct UriParser : 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*/)
+ {
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (attribute.name == L"name") {
+ if (attribute.value.size() > 0) {
+ m_value = attribute.value;
+ NormalizeString(m_value);
+ }
+ }
+ }
+
+ virtual void Verify()
+ {
+ if (m_value.IsNull() || *m_value == L"") {
+ return;
+ }
+
+ DPL::String wildString(L"*/*");
+ if ((m_data.m_uriList.find(wildString) ==
+ m_data.m_uriList.end())
+ && (m_data.m_uriList.find(*m_value) ==
+ m_data.m_uriList.end())) {
+
+ m_data.m_uriList.insert(*m_value);
+ } else {
+ LogDebug("Ignoring uri with name" <<
+ DPL::ToUTF8String(*m_value));
+ }
+ }
+
+ UriParser(ConfigParserData::AppControlInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ bool m_properNamespace;
+ DPL::OptionalString m_value;
+ ConfigParserData::AppControlInfo& m_data;
+ };
+
+ struct MimeParser : 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*/)
+ {
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ if (attribute.name == L"name") {
+ if (attribute.value.size() > 0) {
+ m_value = attribute.value;
+ NormalizeString(m_value);
+ }
+ }
+ }
+
+ virtual void Verify()
+ {
+ if (m_value.IsNull() || *m_value == L"") {
+ return;
+ }
+
+ DPL::String wildString(L"*/*");
+ if ((m_data.m_mimeList.find(wildString) ==
+ m_data.m_mimeList.end())
+ && (m_data.m_mimeList.find(*m_value) ==
+ m_data.m_mimeList.end())) {
+ m_data.m_mimeList.insert(*m_value);
+ } else {
+ LogDebug("Ignoring mime with name" <<
+ DPL::ToUTF8String(*m_value));
+ }
+ }
+
+ MimeParser(ConfigParserData::AppControlInfo& data) :
+ ElementParser(),
+ m_properNamespace(false),
+ m_data(data)
+ {
+ }
+
+ private:
+ bool m_properNamespace;
+ DPL::OptionalString m_value;
+ ConfigParserData::AppControlInfo& m_data;
+ };
+
+ virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
+ const DPL::String& name)
+ {
+ if (name == L"src") {
+ return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
+ } else if (name == L"operation") {
+ return DPL::MakeDelegate(this, &AppControlParser::OnOperationElement);
+ } else if (name == L"uri") {
+ return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
+ } else if (name == L"mime") {
+ return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
+ } else {
+ return &IgnoringParser::Create;
+ }
+ }
+
+ virtual void Accept(const XmlAttribute& attribute)
+ {
+ }
+
+ virtual void Accept(const Element& element)
+ {
+ LogWarning("namespace for app service = " << element.ns);
+ if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
+ ThrowMsg(Exception::ParseError,
+ "Wrong xml namespace for widget element");
+ }
+ }
+
+ virtual void Accept(const Text& /*text*/)
+ {
+ ThrowMsg(Exception::ParseError, "param element must be empty");
+ }
+
+ virtual void Verify()
+ {
+ if (m_appControl.m_src == L""){
+ LogWarning("service element must have src element");
+ return;
+ }
+
+ if (m_appControl.m_operation == L""){
+ LogWarning("service element must have operation element");
+ return;
+ }
+
+ FOREACH(iterator, m_data.appControlList) {
+ if (iterator->m_src == m_appControl.m_src &&
+ iterator->m_operation == m_appControl.m_operation )
+ {
+ ThrowMsg(Exception::ParseError,
+ "app control element is duplicated " +
+ DPL::ToUTF8String(m_appControl.m_src) + ", " +
+ DPL::ToUTF8String(m_appControl.m_operation));
+ }
+ }
+ m_data.appControlList.push_back(m_appControl);
+ }
+
+ ElementParserPtr OnSourceElement()
+ {
+ return ElementParserPtr(new SourceParser(m_appControl));
+ }
+
+ ElementParserPtr OnOperationElement()
+ {
+ return ElementParserPtr(new OperationParser(m_appControl));
+ }
+
+ ElementParserPtr OnUriElement()
+ {
+ return ElementParserPtr(new UriParser(m_appControl));
+ }
+
+ ElementParserPtr OnMimeElement()
+ {
+ return ElementParserPtr(new MimeParser(m_appControl));
+ }
+
+ AppControlParser(ConfigParserData& data) :
+ ElementParser(),
+ m_data(data),
+ m_appControl(L"")
+ {
+ }
+
+ private:
+ ConfigParserData& m_data;
+ ConfigParserData::AppControlInfo m_appControl;
+};
+