2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * This file have been implemented in compliance with W3C WARP SPEC.
18 * but there are some patent issue between W3C WARP SPEC and APPLE.
19 * so if you want to use this file, refer to the README file in root directory
22 * @file widget_parser.cpp
23 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
27 #include "widget_parser.h"
28 #include "ignoring_parser.h"
29 #include "deny_all_parser.h"
30 #include <dpl/wrt-dao-ro/config_parser_data.h>
31 #include "libiriwrapper.h"
32 #include <dpl/utils/warp_iri.h>
33 #include <dpl/utils/mime_type_utils.h>
34 #include <language_subtag_rst_tree.h>
37 #include <dpl/log/log.h>
38 #include <dpl/fast_delegate.h>
39 #include <dpl/foreach.h>
44 using namespace WrtDB;
47 static const DPL::String UTF_LRE = L"\x0202a";
48 static const DPL::String UTF_LRO = L"\x0202d";
49 static const DPL::String UTF_RLE = L"\x0202b";
50 static const DPL::String UTF_RLO = L"\x0202e";
51 static const DPL::String UTF_PDF = L"\x0202c";
53 Direction ParseDirAttribute(const XmlAttribute& attribute)
55 Assert(L"dir" == attribute.name);
56 if (L"ltr" == attribute.value) {
58 } else if (L"rtl" == attribute.value) {
60 } else if (L"lro" == attribute.value) {
62 } else if (L"rlo" == attribute.value) {
65 LogWarning("dir attribute has wrong value:" << attribute.value);
70 void UpdateTextWithDirectionMark(Direction direction,
76 *text = UTF_RLO + *text + UTF_PDF;
79 *text = UTF_RLE + *text + UTF_PDF;
82 *text = UTF_LRE + *text + UTF_PDF;
85 *text = UTF_LRO + *text + UTF_PDF;
94 } // namespace Unicode
96 class InnerElementsParser : public ElementParser
99 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
100 const DPL::String& /*name*/)
102 return DPL::MakeDelegate(this, &InnerElementsParser::Other);
105 virtual void Accept(const Element& /*element*/)
108 virtual void Accept(const Text& text)
110 if (m_text.IsNull()) {
113 m_text->value += text.value;
117 virtual void Accept(const XmlAttribute& attribute)
119 if (attribute.name == L"dir") {
120 m_textDirection = Unicode::ParseDirAttribute(attribute);
124 virtual void Verify()
126 if (!m_text.IsNull()) {
127 Unicode::UpdateTextWithDirectionMark(m_textDirection,
129 m_parentParser->Accept(*m_text);
133 InnerElementsParser(ElementParserPtr parent) :
134 m_parentParser(parent),
135 m_textDirection(Unicode::EMPTY)
138 ElementParserPtr Other()
140 return ElementParserPtr(new InnerElementsParser(
141 std::static_pointer_cast<ElementParser>(
142 shared_from_this())));
146 DPL::Optional<Text> m_text;
147 ElementParserPtr m_parentParser;
148 Unicode::Direction m_textDirection;
151 class NameParser : public ElementParser
154 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
155 const DPL::String& /*name*/)
157 return DPL::MakeDelegate(this, &NameParser::Other);
160 virtual void Accept(const Element& element)
162 m_lang = element.lang;
166 virtual void Accept(const Text& text)
168 if (m_name.IsNull()) {
171 *m_name += text.value;
175 virtual void Accept(const XmlAttribute& attribute)
177 if (attribute.name == L"short") {
178 if (m_shortName.IsNull()) {
179 m_shortName = attribute.value;
181 } else if (attribute.name == L"dir") {
182 m_textDirection = Unicode::ParseDirAttribute(attribute);
186 virtual void Verify()
188 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
189 if (data.name.IsNull()) {
190 NormalizeString(m_name);
191 NormalizeString(m_shortName);
192 if (!m_name.IsNull()) {
193 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
196 if (!m_shortName.IsNull()) {
197 Unicode::UpdateTextWithDirectionMark(m_textDirection,
200 data.shortName = m_shortName;
204 NameParser(Unicode::Direction direction,
205 ConfigParserData& data) :
207 m_textDirection(direction)
210 ElementParserPtr Other()
212 return ElementParserPtr(new InnerElementsParser(
213 std::static_pointer_cast<ElementParser>(
214 shared_from_this())));
218 ConfigParserData& m_data;
219 DPL::OptionalString m_name;
220 DPL::OptionalString m_shortName;
221 DPL::OptionalString m_dir;
223 Unicode::Direction m_textDirection;
226 class AccessParser : public ElementParser
235 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
236 const DPL::String& /*name*/)
238 return DPL::MakeDelegate(this, &AccessParser::Other);
241 virtual void Accept(const Element& element)
243 // for tizen web apps WARP should be used
244 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
245 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
247 m_standardType = STANDARD_TYPE_WARP;
251 virtual void Accept(const Text& /*text*/)
254 void AcceptWac(const XmlAttribute& attribute)
256 if (attribute.name == L"origin") {
257 m_strIRIOrigin = attribute.value;
258 NormalizeString(m_strIRIOrigin);
259 } else if (attribute.name == L"subdomains") {
260 DPL::String normalizedValue = attribute.value;
261 NormalizeString(normalizedValue);
263 if (normalizedValue == L"true") {
264 m_bSubDomainAccess = true;
265 } else if (normalizedValue == L"false") {
266 m_bSubDomainAccess = false;
271 virtual void Accept(const XmlAttribute& attribute)
273 switch (m_standardType) {
274 case STANDARD_TYPE_WARP:
275 AcceptWac(attribute);
278 LogError("Error in Access tag - unknown standard.");
286 iri.set(m_strIRIOrigin, false);
288 if (!iri.isAccessDefinition()) {
289 LogWarning("Access list element: " <<
291 " is not acceptable by WARP" <<
292 "standard and will be ignored!");
296 if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains
298 m_bSubDomainAccess = true;
301 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
303 //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
304 m_data.accessInfoSet.insert(accessInfo);
307 virtual void Verify()
309 switch (m_standardType) {
310 case STANDARD_TYPE_WARP:
314 LogError("Error in Access tag - unknown standard.");
319 AccessParser(ConfigParserData& data) :
321 m_bSubDomainAccess(false),
322 m_standardType(STANDARD_TYPE_NONE),
327 ElementParserPtr Other()
329 return ElementParserPtr(new InnerElementsParser(
330 ElementParserPtr(shared_from_this())));
334 DPL::String m_strIRIOrigin;
335 bool m_bSubDomainAccess;
336 StandardType m_standardType;
338 ConfigParserData& m_data;
341 class DescriptionParser : public ElementParser
344 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
345 const DPL::String& /*name*/)
347 return DPL::MakeDelegate(this, &DescriptionParser::Other);
350 virtual void Accept(const Element& element)
352 m_lang = element.lang;
356 ElementParserPtr Other()
358 return ElementParserPtr(new InnerElementsParser(
359 std::static_pointer_cast<ElementParser>(
360 shared_from_this())));
363 virtual void Accept(const Text& text)
365 if (m_description.IsNull()) {
366 m_description = text.value;
368 *m_description += text.value;
372 virtual void Accept(const XmlAttribute& attribute)
374 if (attribute.name == L"dir") {
375 m_textDirection = Unicode::ParseDirAttribute(attribute);
379 virtual void Verify()
381 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
382 if (data.description.IsNull()) {
383 if (!m_description.IsNull()) {
384 Unicode::UpdateTextWithDirectionMark(m_textDirection,
387 data.description = m_description;
391 DescriptionParser(Unicode::Direction direction,
392 ConfigParserData& data) :
396 m_textDirection(direction)
400 ConfigParserData& m_data;
402 DPL::OptionalString m_description;
403 Unicode::Direction m_textDirection;
406 class AuthorParser : public ElementParser
409 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
410 const DPL::String& /*name*/)
412 return DPL::MakeDelegate(this, &AuthorParser::Other);
415 AuthorParser(Unicode::Direction direction,
416 ConfigParserData& data) :
418 m_textDirection(direction)
421 virtual void Accept(const Element& /*element*/)
426 virtual void Accept(const Text& text)
428 *(m_authorName) += text.value;
431 virtual void Accept(const XmlAttribute& attribute)
433 if (attribute.name == L"href") {
434 //Validate href IRI and ignore it if invalid
435 //See also test: ta-argMozRiC-an
436 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
437 if (iri.Validate()) {
438 m_authorHref = attribute.value;
440 } else if (attribute.name == L"email") {
441 m_authorEmail = attribute.value;
442 } else if (attribute.name == L"dir") {
443 m_textDirection = Unicode::ParseDirAttribute(attribute);
447 virtual void Verify()
449 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
450 NormalizeString(m_authorName);
451 NormalizeString(m_authorHref);
452 NormalizeString(m_authorEmail);
453 if (!!m_authorName) {
454 Unicode::UpdateTextWithDirectionMark(m_textDirection,
456 m_data.authorName = m_authorName;
458 if (!!m_authorHref) {
459 m_data.authorHref = m_authorHref;
461 if (!!m_authorEmail) {
462 m_data.authorEmail = m_authorEmail;
467 ElementParserPtr Other()
469 return ElementParserPtr(new InnerElementsParser(
470 std::static_pointer_cast<ElementParser>(
471 shared_from_this())));
475 ConfigParserData& m_data;
476 DPL::OptionalString m_authorEmail;
477 DPL::OptionalString m_authorHref;
478 DPL::OptionalString m_authorName;
479 Unicode::Direction m_textDirection;
482 class LicenseParser : public ElementParser
485 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
486 const DPL::String& /*name*/)
488 return DPL::MakeDelegate(this, &LicenseParser::Other);
491 LicenseParser(Unicode::Direction direction,
492 ConfigParserData& data) :
495 m_textDirection(direction)
498 virtual void Accept(const Element& element)
500 if (m_license.IsNull()) {
501 m_lang = element.lang;
507 virtual void Accept(const Text& text)
510 *m_license += text.value;
514 virtual void Accept(const XmlAttribute& attribute)
517 if (attribute.name == L"href" && m_licenseHref.IsNull()) {
518 m_licenseHref = attribute.value;
519 } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
520 m_licenseFile = attribute.value;
521 } else if (attribute.name == L"dir") {
522 m_textDirection = Unicode::ParseDirAttribute(attribute);
527 virtual void Verify()
529 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
530 if (data.license.IsNull()) {
531 if (!m_license.IsNull()) {
532 Unicode::UpdateTextWithDirectionMark(m_textDirection,
535 data.license = m_license;
536 data.licenseHref = m_licenseHref;
537 data.licenseFile = m_licenseFile;
541 ElementParserPtr Other()
543 return ElementParserPtr(new InnerElementsParser(
544 ElementParserPtr(shared_from_this())));
548 ConfigParserData& m_data;
552 DPL::OptionalString m_license;
553 DPL::OptionalString m_licenseFile;
554 DPL::OptionalString m_licenseHref;
555 Unicode::Direction m_textDirection;
558 class IconParser : public ElementParser
560 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
563 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
564 const DPL::String& /*name*/)
566 return &IgnoringParser::Create;
569 IconParser(ConfigParserData& data) : ElementParser(),
573 virtual void Accept(const Element& /*element*/)
576 virtual void Accept(const XmlAttribute& attribute)
578 if (attribute.name == L"src") {
579 if (attribute.value.size() > 0) {
580 m_src = attribute.value;
582 } else if (attribute.name == L"width") {
583 m_width = ParseSizeAttributeValue(attribute.value);
584 } else if (attribute.name == L"height") {
585 m_height = ParseSizeAttributeValue(attribute.value);
589 virtual void Accept(const Text& /*text*/)
591 ThrowMsg(Exception::ParseError, "Icon element must be empty");
594 virtual void Verify()
596 if (m_src.IsNull()) {
597 LogWarning("src attribute of icon element is mandatory - ignoring");
603 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
604 icon.width = m_width;
605 icon.height = m_height;
607 ConfigParserData::IconsList::iterator it = std::find(
608 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
609 if (it == m_data.iconsList.end()) {
610 m_data.iconsList.push_front(icon);
615 LogWarning("src attribute is invalid: " << m_src);
620 ConfigParserData& m_data;
621 DPL::OptionalString m_src;
622 DPL::OptionalInt m_width;
623 DPL::OptionalInt m_height;
625 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
627 DPL::OptionalString normalizedValue = value;
628 NormalizeString(normalizedValue);
629 if (!(*normalizedValue).empty()) {
633 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
635 std::string(reterr) == DPL::ToUTF8String(value) ||
638 return DPL::OptionalInt::Null;
643 return DPL::OptionalInt::Null;
647 * @brief delocalizePath removes locales folder from relative path if
649 * @param source source string
651 * @throw BadSrcError if string is bad value of src attribute
653 * @return corrected string
655 static DPL::String delocalizeSrcPath(const DPL::String & source)
657 static const DPL::String localeFolder(L"locales/");
658 static const int index = localeFolder.size();
660 DPL::String result = source;
662 if (source.substr(0, index) == localeFolder) {
663 size_t pos = result.find_first_of('/', index);
664 if (pos != std::string::npos && pos + 1 < source.size()) {
665 result = result.substr(pos + 1, source.size());
674 class ContentParser : public ElementParser
677 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
678 const DPL::String& /*name*/)
680 return &IgnoringParser::Create;
683 ContentParser(ConfigParserData& data) :
688 virtual void Accept(const Element& /*element*/)
691 virtual void Accept(const Text& /*text*/)
694 virtual void Accept(const XmlAttribute& attribute)
696 DPL::String value = attribute.value;
697 NormalizeString(value);
699 if (attribute.name == L"src") {
701 } else if (attribute.name == L"type") {
703 MimeTypeUtils::MimeAttributes mimeAttributes =
704 MimeTypeUtils::getMimeAttributes(value);
705 if ((mimeAttributes.count(L"charset") > 0) && m_encoding.IsNull())
707 m_encoding = mimeAttributes[L"charset"];
709 } else if (attribute.name == L"encoding") {
710 if (!value.empty()) {
716 virtual void Verify()
718 if (m_data.startFileEncountered) {
719 LogWarning("This is not the first encountered "
720 "'content' element - ignoring.");
724 m_data.startFileEncountered = true;
726 //we're consciously setting startFile even if m_src is null or invalid.
727 //WidgetConfigurationManager will deal with this.
728 m_data.startFile = m_src;
731 m_data.startFileContentType = m_type;
733 m_data.startFileEncoding = m_encoding;
735 m_data.startFileEncoding = L"UTF-8";
741 DPL::OptionalString m_src;
742 DPL::OptionalString m_type;
743 DPL::OptionalString m_encoding;
744 ConfigParserData& m_data;
747 class PreferenceParser : public ElementParser
750 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
751 const DPL::String& /*name*/)
753 return &IgnoringParser::Create;
756 virtual void Accept(const XmlAttribute& attribute)
758 if (attribute.name == L"name") {
759 m_name = attribute.value;
760 } else if (attribute.name == L"value") {
761 m_value = attribute.value;
762 } else if (attribute.name == L"readonly") {
763 if (attribute.value == L"true") {
771 virtual void Accept(const Element& /*element*/)
774 virtual void Accept(const Text& /*text*/)
776 ThrowMsg(Exception::ParseError, "param element must be empty");
779 virtual void Verify()
781 if (m_name.IsNull()) {
782 LogWarning("preference element must have name attribute");
785 NormalizeString(m_name);
786 NormalizeString(m_value);
787 ConfigParserData::Preference preference(*m_name, m_required);
788 preference.value = m_value;
789 if (m_data.preferencesList.find(preference) ==
790 m_data.preferencesList.end())
792 m_data.preferencesList.insert(preference);
796 PreferenceParser(ConfigParserData& data) :
803 DPL::OptionalString m_name;
804 DPL::OptionalString m_value;
806 ConfigParserData& m_data;
809 class LinkParser : public ElementParser
812 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
813 const DPL::String& /*name*/)
815 return &DenyAllParser::Create;
818 virtual void Accept(const XmlAttribute& attribute)
820 if (m_properNamespace) {
821 LogDebug("attribute");
822 if (attribute.name == L"rel") {
823 if (attribute.value != L"describedby") {
824 ThrowMsg(Exception::ParseError,
825 "rel attribute must have describedby value");
827 } else if (attribute.name == L"type") {} else if (attribute.name ==
830 LogDebug("here is href");
831 m_href = attribute.value;
833 ThrowMsg(Exception::ParseError,
834 "unknown attribute '" +
835 DPL::ToUTF8String(attribute.name) +
836 "' in link element");
841 virtual void Accept(const Element& element)
844 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
846 m_properNamespace = true;
851 virtual void Accept(const Text&)
853 if (m_properNamespace) {
855 ThrowMsg(Exception::ParseError, "link element must be empty");
859 virtual void Verify()
862 ThrowMsg(Exception::ParseError,
863 "link element must have href attribute");
866 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
867 if (!iri.Validate()) { // TODO: Better uri validator ?
868 ThrowMsg(Exception::ParseError,
869 "href attribute must be a valid iri/uri/url");
873 LinkParser(ConfigParserData& data) :
875 m_properNamespace(false),
877 m_href(DPL::OptionalString::Null)
881 bool m_properNamespace;
882 ConfigParserData& m_data;
883 DPL::OptionalString m_href;
886 class SettingParser : public ElementParser
889 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
890 const DPL::String& /*name*/)
892 return &IgnoringParser::Create;
895 virtual void Accept(const Text& /*text*/)
898 virtual void Accept(const Element& /*element*/)
901 virtual void Accept(const XmlAttribute& attribute)
903 m_setting.m_name = attribute.name;
904 m_setting.m_value = attribute.value;
905 m_data.settingsList.insert(m_setting);
908 virtual void Verify()
911 SettingParser(ConfigParserData& data) :
918 ConfigParserData& m_data;
919 ConfigParserData::Setting m_setting;
922 class AppControlParser : public ElementParser
925 struct SourceParser : public ElementParser
928 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
929 const DPL::String& /*name*/)
931 return &IgnoringParser::Create;
934 virtual void Accept(const Text& /*text*/)
937 virtual void Accept(const Element& /*element*/)
940 virtual void Accept(const XmlAttribute& attribute)
942 if (attribute.name == L"name") {
943 if (attribute.value.size() > 0) {
944 m_value = attribute.value;
945 NormalizeString(m_value);
950 virtual void Verify()
952 if (m_value.IsNull() || *m_value == L"") {
956 m_data.m_src = *m_value;
959 SourceParser(ConfigParserData::AppControlInfo& data) :
961 m_properNamespace(false),
966 bool m_properNamespace;
967 DPL::OptionalString m_value;
968 ConfigParserData::AppControlInfo& m_data;
971 struct OperationParser : public ElementParser
974 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
975 const DPL::String& /*name*/)
977 return &IgnoringParser::Create;
980 virtual void Accept(const Text& /*text*/)
983 virtual void Accept(const Element& /*element*/)
986 virtual void Accept(const XmlAttribute& attribute)
988 if (attribute.name == L"name") {
989 if (attribute.value.size() > 0) {
990 m_value = attribute.value;
991 NormalizeString(m_value);
996 virtual void Verify()
998 if (m_value.IsNull() || *m_value == L"") {
1002 m_data.m_operation = *m_value;
1005 OperationParser(ConfigParserData::AppControlInfo& data) :
1007 m_properNamespace(false),
1012 bool m_properNamespace;
1013 DPL::OptionalString m_value;
1014 ConfigParserData::AppControlInfo& m_data;
1017 struct UriParser : public ElementParser
1020 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1021 const DPL::String& /*name*/)
1023 return &IgnoringParser::Create;
1026 virtual void Accept(const Text& /*text*/)
1029 virtual void Accept(const Element& /*element*/)
1032 virtual void Accept(const XmlAttribute& attribute)
1034 if (attribute.name == L"name") {
1035 if (attribute.value.size() > 0) {
1036 m_value = attribute.value;
1037 NormalizeString(m_value);
1042 virtual void Verify()
1045 DPL::String ignoreUri(L"file");
1047 if (!m_value.IsNull() && *m_value == ignoreUri)
1049 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
1050 m_value = DPL::OptionalString::Null;
1053 if (m_value.IsNull() || *m_value == L"") {
1057 DPL::String wildString(L"*/*");
1058 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1059 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1061 m_data.m_uriList.insert(*m_value);
1063 LogDebug("Ignoring uri with name" <<
1064 DPL::ToUTF8String(*m_value));
1068 UriParser(ConfigParserData::AppControlInfo& data) :
1070 m_properNamespace(false),
1075 bool m_properNamespace;
1076 DPL::OptionalString m_value;
1077 ConfigParserData::AppControlInfo& m_data;
1080 struct MimeParser : public ElementParser
1083 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1084 const DPL::String& /*name*/)
1086 return &IgnoringParser::Create;
1089 virtual void Accept(const Text& /*text*/)
1092 virtual void Accept(const Element& /*element*/)
1095 virtual void Accept(const XmlAttribute& attribute)
1097 if (attribute.name == L"name") {
1098 if (attribute.value.size() > 0) {
1099 m_value = attribute.value;
1100 NormalizeString(m_value);
1105 virtual void Verify()
1107 if (m_value.IsNull() || *m_value == L"") {
1111 DPL::String wildString(L"*/*");
1112 if ((m_data.m_mimeList.find(wildString) ==
1113 m_data.m_mimeList.end())
1114 && (m_data.m_mimeList.find(*m_value) ==
1115 m_data.m_mimeList.end()))
1117 m_data.m_mimeList.insert(*m_value);
1119 LogDebug("Ignoring mime with name" <<
1120 DPL::ToUTF8String(*m_value));
1124 MimeParser(ConfigParserData::AppControlInfo& data) :
1126 m_properNamespace(false),
1131 bool m_properNamespace;
1132 DPL::OptionalString m_value;
1133 ConfigParserData::AppControlInfo& m_data;
1136 struct DispositionParser : public ElementParser
1139 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1140 const DPL::String& /*name*/)
1142 return &IgnoringParser::Create;
1145 virtual void Accept(const Text& /*text*/)
1148 virtual void Accept(const Element& /*element*/)
1151 virtual void Accept(const XmlAttribute& attribute)
1153 if (attribute.name == L"disposition") {
1154 if (attribute.value.size() > 0) {
1155 m_value = attribute.value;
1156 NormalizeString(m_value);
1161 virtual void Verify()
1163 if (m_value.IsNull() || *m_value != L"inline") {
1164 m_data.m_disposition = ConfigParserData::AppControlInfo::Disposition::WINDOW;
1167 m_data.m_disposition = ConfigParserData::AppControlInfo::Disposition::INLINE;
1171 DispositionParser(ConfigParserData::AppControlInfo& data) :
1173 m_properNamespace(false),
1178 bool m_properNamespace;
1179 DPL::OptionalString m_value;
1180 ConfigParserData::AppControlInfo& m_data;
1183 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1184 const DPL::String& name)
1186 if (name == L"src") {
1187 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1188 } else if (name == L"operation") {
1189 return DPL::MakeDelegate(this,
1190 &AppControlParser::OnOperationElement);
1191 } else if (name == L"uri") {
1192 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1193 } else if (name == L"mime") {
1194 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1195 } else if (name == L"disposition") {
1196 return DPL::MakeDelegate(this,
1197 &AppControlParser::OnDispositionElement);
1199 return &IgnoringParser::Create;
1203 virtual void Accept(const XmlAttribute& /*attribute*/)
1206 virtual void Accept(const Element& element)
1208 LogWarning("namespace for app service = " << element.ns);
1209 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1210 ThrowMsg(Exception::ParseError,
1211 "Wrong xml namespace for widget element");
1215 virtual void Accept(const Text& /*text*/)
1217 ThrowMsg(Exception::ParseError, "param element must be empty");
1220 virtual void Verify()
1222 if (m_appControl.m_src == L"") {
1223 LogWarning("service element must have src element");
1227 if (m_appControl.m_operation == L"") {
1228 LogWarning("service element must have operation element");
1232 m_data.appControlList.push_back(m_appControl);
1235 ElementParserPtr OnSourceElement()
1237 return ElementParserPtr(new SourceParser(m_appControl));
1240 ElementParserPtr OnOperationElement()
1242 return ElementParserPtr(new OperationParser(m_appControl));
1245 ElementParserPtr OnUriElement()
1247 return ElementParserPtr(new UriParser(m_appControl));
1250 ElementParserPtr OnMimeElement()
1252 return ElementParserPtr(new MimeParser(m_appControl));
1255 ElementParserPtr OnDispositionElement()
1257 return ElementParserPtr(new DispositionParser(m_appControl));
1260 AppControlParser(ConfigParserData& data) :
1267 ConfigParserData& m_data;
1268 ConfigParserData::AppControlInfo m_appControl;
1271 class ApplicationParser : public ElementParser
1274 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1275 const DPL::String& /*name*/)
1277 return &IgnoringParser::Create;
1280 virtual void Accept(const Text& /*text*/)
1282 if (m_properNamespace) {
1284 ThrowMsg(Exception::ParseError, "application element must be empty");
1288 virtual void Accept(const Element& element)
1291 ConfigurationNamespace::TizenWebAppNamespaceName)
1293 m_properNamespace = true;
1295 LogDebug("element");
1298 virtual void Accept(const XmlAttribute& attribute)
1300 if (m_properNamespace) {
1301 LogDebug("attribute");
1302 if (attribute.name == L"id") {
1303 m_id = attribute.value;
1304 NormalizeAndTrimSpaceString(m_id);
1305 } else if (attribute.name == L"package") {
1306 m_package = attribute.value;
1307 } else if (attribute.name == L"required_version") {
1308 m_version = attribute.value;
1309 NormalizeString(m_version);
1311 ThrowMsg(Exception::ParseError,
1312 "unknown attribute '" +
1313 DPL::ToUTF8String(attribute.name) +
1314 "' in application element");
1319 virtual void Verify()
1322 ThrowMsg(Exception::ParseError,
1323 "application element must have id attribute");
1327 m_data.tizenPkgId = m_package;
1331 ThrowMsg(Exception::ParseError,
1332 "application element must have required_version attribute");
1335 //TODO check if id and version format is right
1336 m_data.tizenAppId = m_id;
1337 m_data.tizenMinVersionRequired = m_version;
1340 ApplicationParser(ConfigParserData& data) :
1343 m_id(DPL::OptionalString::Null),
1344 m_version(DPL::OptionalString::Null),
1345 m_properNamespace(false)
1349 ConfigParserData& m_data;
1350 DPL::OptionalString m_id;
1351 DPL::OptionalString m_package;
1352 DPL::OptionalString m_version;
1353 bool m_properNamespace;
1356 class SplashParser : public ElementParser
1359 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1360 const DPL::String& /*name*/)
1362 return &IgnoringParser::Create;
1365 virtual void Accept(const XmlAttribute& attribute)
1367 if (attribute.name == L"src") {
1368 if (attribute.value.size() > 0) {
1369 m_src = attribute.value;
1374 virtual void Accept(const Element& /*element*/)
1377 virtual void Accept(const Text& /*text*/)
1380 virtual void Verify()
1382 if (m_src.IsNull()) {
1384 "src attribute of splash element is mandatory - ignoring");
1388 m_data.splashImgSrc = m_src;
1391 SplashParser(ConfigParserData& data) :
1397 DPL::OptionalString m_src;
1398 ConfigParserData& m_data;
1401 class BackgroundParser : public ElementParser
1404 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1405 const DPL::String& /*name*/)
1407 return &IgnoringParser::Create;
1410 virtual void Accept(const XmlAttribute& attribute)
1412 if (attribute.name == L"src") {
1413 if (attribute.value.size() > 0) {
1414 m_src = attribute.value;
1419 virtual void Accept(const Element& /*element*/)
1422 virtual void Accept(const Text& /*text*/)
1425 virtual void Verify()
1427 if (m_src.IsNull()) {
1429 "src attribute of background element is mandatory - ignoring");
1433 m_data.backgroundPage = m_src;
1436 explicit BackgroundParser(ConfigParserData& data) :
1441 DPL::OptionalString m_src;
1442 ConfigParserData& m_data;
1445 class PrivilegeParser : public ElementParser
1448 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1449 const DPL::String& /*name*/)
1451 return &IgnoringParser::Create;
1454 virtual void Accept(const Text& /*text*/)
1457 virtual void Accept(const Element& element)
1460 ConfigurationNamespace::TizenWebAppNamespaceName)
1462 m_properNamespace = true;
1464 LogDebug("element");
1467 virtual void Accept(const XmlAttribute& attribute)
1469 if (m_properNamespace) {
1470 if (attribute.name == L"name") {
1471 m_feature.name = attribute.value;
1472 m_privilege.name = attribute.value;
1477 virtual void Verify()
1479 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1481 if (m_feature.name != L"") {
1482 if (iri.Validate()) {
1483 if (m_data.featuresList.find(m_feature) ==
1484 m_data.featuresList.end())
1486 m_data.featuresList.insert(m_feature);
1488 LogDebug("Ignoring feature with name" <<
1489 DPL::ToUTF8String(m_feature.name));
1494 LibIri::Wrapper iriPrivilege(
1495 DPL::ToUTF8String(m_privilege.name).c_str());
1497 if (m_privilege.name != L"") {
1498 if (iriPrivilege.Validate()) {
1499 if (m_data.privilegeList.find(m_privilege) ==
1500 m_data.privilegeList.end())
1502 m_data.privilegeList.insert(m_privilege);
1504 LogDebug("Ignoring privilege with name" <<
1505 DPL::ToUTF8String(m_privilege.name));
1511 PrivilegeParser(ConfigParserData& data) :
1516 m_properNamespace(false)
1520 ConfigParserData& m_data;
1521 ConfigParserData::Feature m_feature;
1522 ConfigParserData::Privilege m_privilege;
1523 bool m_properNamespace;
1526 class CategoryParser : public ElementParser
1529 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1530 const DPL::String& /*name*/)
1532 return &IgnoringParser::Create;
1535 virtual void Accept(const XmlAttribute& attribute)
1537 if (attribute.name == L"name") {
1538 if (attribute.value.size() > 0) {
1539 m_name = attribute.value;
1544 virtual void Accept(const Element& /*element*/)
1547 virtual void Accept(const Text& /*text*/)
1550 virtual void Verify()
1552 if (m_name.IsNull()) {
1554 "name attribute of category element is mandatory - ignoring");
1558 if (m_data.categoryList.find(*m_name) ==
1559 m_data.categoryList.end())
1561 m_data.categoryList.insert(*m_name);
1565 explicit CategoryParser(ConfigParserData& data) :
1570 DPL::OptionalString m_name;
1571 ConfigParserData& m_data;
1574 class AppWidgetParser : public ElementParser
1578 struct BoxLabelParser : public ElementParser
1580 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1581 const DPL::String& /*name*/)
1583 return &IgnoringParser::Create;
1586 virtual void Accept(const XmlAttribute& /*attribute*/)
1589 virtual void Accept(const Element& element)
1592 ConfigurationNamespace::TizenWebAppNamespaceName)
1594 m_properNamespace = true;
1598 virtual void Accept(const Text& text)
1600 if (m_properNamespace) {
1601 m_label = text.value;
1605 virtual void Verify()
1607 m_data.m_label = m_label;
1610 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1612 m_properNamespace(false),
1617 DPL::String m_label;
1618 bool m_properNamespace;
1619 ConfigParserData::LiveboxInfo& m_data;
1622 struct BoxIconParser : public ElementParser
1624 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1625 const DPL::String& /*name*/)
1627 return &IgnoringParser::Create;
1630 virtual void Accept(const XmlAttribute& attribute)
1632 if (m_properNamespace) {
1633 if (attribute.name == L"src") {
1634 m_icon = attribute.value;
1639 virtual void Accept(const Element& element)
1642 ConfigurationNamespace::TizenWebAppNamespaceName)
1644 m_properNamespace = true;
1648 virtual void Accept(const Text& /*text*/)
1651 virtual void Verify()
1653 m_data.m_icon = m_icon;
1656 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1658 m_properNamespace(false),
1664 bool m_properNamespace;
1665 ConfigParserData::LiveboxInfo& m_data;
1668 struct BoxContentParser : public ElementParser
1670 struct BoxSizeParser : public ElementParser
1672 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1673 const DPL::String& /*name*/)
1675 return &IgnoringParser::Create;
1678 virtual void Accept(const XmlAttribute& attribute)
1680 if (m_properNamespace) {
1681 if (attribute.name == L"preview") {
1682 m_preview = attribute.value;
1687 virtual void Accept(const Element& element)
1690 ConfigurationNamespace::TizenWebAppNamespaceName)
1692 m_properNamespace = true;
1696 virtual void Accept(const Text& text)
1698 if (m_properNamespace) {
1699 m_size = text.value;
1703 virtual void Verify()
1705 std::pair<DPL::String, DPL::String> boxSize;
1706 boxSize.first = m_size;
1707 boxSize.second = m_preview;
1708 m_data.m_boxSize.push_back(boxSize);
1711 explicit BoxSizeParser(
1712 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1714 m_properNamespace(false),
1720 DPL::String m_preview;
1721 bool m_properNamespace;
1722 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1725 struct PdParser : public ElementParser
1727 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1728 const DPL::String& /*name*/)
1730 return &IgnoringParser::Create;
1733 virtual void Accept(const XmlAttribute& attribute)
1735 if (m_properNamespace) {
1736 if (attribute.name == L"src") {
1737 m_src = attribute.value;
1738 } else if (attribute.name == L"width") {
1739 m_width = attribute.value;
1740 } else if (attribute.name == L"height") {
1741 m_height = attribute.value;
1746 virtual void Accept(const Element& element)
1749 ConfigurationNamespace::TizenWebAppNamespaceName)
1751 m_properNamespace = true;
1755 virtual void Accept(const Text& /*text*/)
1758 virtual void Verify()
1760 m_data.m_pdSrc = m_src;
1761 m_data.m_pdWidth = m_width;
1762 m_data.m_pdHeight = m_height;
1766 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1768 m_properNamespace(false),
1774 DPL::String m_width;
1775 DPL::String m_height;
1777 bool m_properNamespace;
1778 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1781 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1782 const DPL::String& name)
1784 if (name == L"box-size") {
1785 return DPL::MakeDelegate(
1787 &AppWidgetParser::BoxContentParser::
1789 } else if (name == L"pd") {
1790 return DPL::MakeDelegate(
1792 &AppWidgetParser::BoxContentParser::
1795 ThrowMsg(Exception::ParseError,
1796 "No element parser for name: " << name);
1800 virtual void Accept(const XmlAttribute& attribute)
1802 if (m_properNamespace) {
1803 if (attribute.name == L"src") {
1804 m_box.m_boxSrc = attribute.value;
1806 if (attribute.name == L"mouse-event") {
1807 m_box.m_boxMouseEvent = attribute.value;
1809 if (attribute.name == L"touch-effect") {
1810 m_box.m_boxTouchEffect = attribute.value;
1815 virtual void Accept(const Element& element)
1818 ConfigurationNamespace::TizenWebAppNamespaceName)
1820 m_properNamespace = true;
1824 virtual void Accept(const Text& /*text*/)
1827 virtual void Verify()
1829 m_data.m_boxInfo = m_box;
1832 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1834 m_properNamespace(false),
1838 ElementParserPtr OnBoxSizeElement()
1840 return ElementParserPtr(new BoxSizeParser(m_box));
1843 ElementParserPtr OnPdElement()
1845 return ElementParserPtr(new PdParser(m_box));
1850 bool m_properNamespace;
1851 ConfigParserData::LiveboxInfo& m_data;
1852 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1855 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1856 const DPL::String& name)
1858 if (name == L"box-label") {
1859 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1860 } else if (name == L"box-icon") {
1861 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1862 } else if (name == L"box-content") {
1863 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1865 return &IgnoringParser::Create;
1869 virtual void Accept(const XmlAttribute& attribute)
1871 if (m_properNamespace) {
1872 if (attribute.name == L"id") {
1873 m_liveboxId = attribute.value;
1874 } else if (attribute.name == L"primary") {
1875 m_primary = attribute.value;
1876 } else if (attribute.name == L"auto-launch") {
1877 m_autoLaunch = attribute.value;
1878 } else if (attribute.name == L"update-period") {
1879 m_updatePeriod = attribute.value;
1880 } else if (attribute.name == L"type") {
1881 m_type = attribute.value;
1886 virtual void Accept(const Element& element)
1889 ConfigurationNamespace::TizenWebAppNamespaceName)
1891 m_properNamespace = true;
1895 virtual void Accept(const Text& /*text*/)
1898 virtual void Verify()
1900 m_livebox.m_liveboxId = m_liveboxId;
1901 m_livebox.m_primary = m_primary;
1902 m_livebox.m_autoLaunch = m_autoLaunch;
1903 m_livebox.m_updatePeriod = m_updatePeriod;
1904 m_livebox.m_type = m_type;
1906 m_data.m_livebox.push_back(m_livebox);
1909 explicit AppWidgetParser(ConfigParserData& data) :
1912 m_properNamespace(false)
1914 m_livebox = ConfigParserData::LiveboxInfo();
1917 ElementParserPtr OnBoxLabelElement()
1919 return ElementParserPtr(new BoxLabelParser(m_livebox));
1922 ElementParserPtr OnBoxIconElement()
1924 return ElementParserPtr(new BoxIconParser(m_livebox));
1927 ElementParserPtr OnBoxContentElement()
1929 return ElementParserPtr(new BoxContentParser(m_livebox));
1933 ConfigParserData& m_data;
1934 ConfigParserData::LiveboxInfo m_livebox;
1935 DPL::String m_liveboxId;
1936 DPL::String m_primary;
1937 DPL::String m_autoLaunch;
1938 DPL::String m_updatePeriod;
1940 bool m_properNamespace;
1943 class CspParser : public ElementParser
1946 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1947 const DPL::String& /*name*/)
1949 return &IgnoringParser::Create;
1952 CspParser(ConfigParserData& data) :
1955 m_properNamespace(false)
1958 virtual void Accept(const Element& element)
1960 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
1961 m_properNamespace = true;
1965 virtual void Accept(const XmlAttribute& /*attribute*/)
1968 virtual void Accept(const Text& text)
1970 if (m_properNamespace) {
1971 m_policy = text.value;
1975 virtual void Verify()
1977 if (!m_policy.IsNull()) {
1978 m_data.cspPolicy = *m_policy;
1983 ConfigParserData& m_data;
1984 bool m_properNamespace;
1985 DPL::OptionalString m_policy;
1988 class CspReportOnlyParser : public ElementParser
1991 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1992 const DPL::String& /*name*/)
1994 return &IgnoringParser::Create;
1997 CspReportOnlyParser(ConfigParserData& data) :
2000 m_properNamespace(false)
2003 virtual void Accept(const Element& element)
2005 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2006 m_properNamespace = true;
2010 virtual void Accept(const XmlAttribute& /*attribute*/)
2013 virtual void Accept(const Text& text)
2015 if (m_properNamespace) {
2016 m_policy = text.value;
2020 virtual void Verify()
2022 if (!m_policy.IsNull()) {
2023 m_data.cspPolicyReportOnly = *m_policy;
2028 ConfigParserData& m_data;
2029 bool m_properNamespace;
2030 DPL::OptionalString m_policy;
2033 class AccountParser : public ElementParser
2036 struct AccountProviderParser : public ElementParser
2040 struct IconParser : public ElementParser
2043 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2044 const DPL::String& /*name*/)
2046 return &IgnoringParser::Create;
2049 virtual void Accept(const Text& text)
2051 if (text.value == L"") {
2054 m_value = text.value;
2057 virtual void Accept(const Element& /*element*/)
2060 virtual void Accept(const XmlAttribute& attribute)
2062 if (attribute.name == L"section") {
2063 if (attribute.value == L"account") {
2064 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2065 } else if (attribute.value == L"account-small") {
2066 m_type = ConfigParserData::IconSectionType::SmallIcon;
2071 virtual void Verify()
2073 if (m_value.IsNull() || *m_value == L"") {
2077 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2078 icon.first = m_type;
2079 icon.second = *m_value;
2081 m_data.m_iconSet.insert(icon);
2084 IconParser(ConfigParserData::AccountProvider& data) :
2086 m_properNamespace(false),
2087 m_type(ConfigParserData::DefaultIcon),
2092 bool m_properNamespace;
2093 ConfigParserData::IconSectionType m_type;
2094 ConfigParserData::AccountProvider& m_data;
2095 DPL::OptionalString m_value;
2098 struct DisplayNameParser : public ElementParser
2101 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2102 const DPL::String& /*name*/)
2104 return &IgnoringParser::Create;
2107 virtual void Accept(const Text& text)
2109 if (text.value == L"") {
2112 m_value = text.value;
2115 virtual void Accept(const Element& element)
2117 m_lang = element.lang;
2121 virtual void Accept(const XmlAttribute& /*attribute*/)
2124 virtual void Verify()
2126 if (m_value.IsNull() || *m_value == L"") {
2130 std::pair<DPL::String, DPL::String> name;
2131 name.first = *m_lang;
2132 name.second = *m_value;
2134 m_data.m_displayNameSet.insert(name);
2137 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2139 m_properNamespace(false),
2144 bool m_properNamespace;
2145 DPL::OptionalString m_lang;
2146 DPL::OptionalString m_value;
2147 ConfigParserData::AccountProvider& m_data;
2150 struct CapabilityParser : public ElementParser
2153 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2154 const DPL::String& /*name*/)
2156 return &IgnoringParser::Create;
2159 virtual void Accept(const Text& text)
2161 if (text.value == L"") {
2164 m_value = text.value;
2167 virtual void Accept(const Element& /*element*/)
2170 virtual void Accept(const XmlAttribute& /*attribute*/)
2173 virtual void Verify()
2175 if (m_value.IsNull() || *m_value == L"") {
2178 m_data.m_capabilityList.push_back(*m_value);
2181 CapabilityParser(ConfigParserData::AccountProvider& data) :
2183 m_properNamespace(false),
2188 bool m_properNamespace;
2189 DPL::OptionalString m_value;
2190 ConfigParserData::AccountProvider& m_data;
2192 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2193 const DPL::String& name)
2195 if (name == L"icon") {
2196 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2197 } else if (name == L"display-name") {
2198 return DPL::MakeDelegate(this,
2199 &AccountProviderParser::OnDisplayNameElement);
2200 } else if (name == L"capability") {
2201 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2203 return &IgnoringParser::Create;
2207 virtual void Accept(const Text& /*text*/)
2210 virtual void Accept(const Element& /*element*/)
2213 virtual void Accept(const XmlAttribute& attribute)
2215 if (attribute.name == L"multiple-accounts-support") {
2216 if (attribute.value == L"") {
2220 if (attribute.value == L"ture") {
2221 m_multiSupport = true;
2226 virtual void Verify()
2228 m_data.m_multiAccountSupport = m_multiSupport;
2231 ElementParserPtr OnIconElement()
2233 return ElementParserPtr(new IconParser(m_data));
2236 ElementParserPtr OnDisplayNameElement()
2238 return ElementParserPtr(new DisplayNameParser(m_data));
2241 ElementParserPtr OnCapabilityElement()
2243 return ElementParserPtr(new CapabilityParser(m_data));
2246 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2248 m_properNamespace(false),
2249 m_multiSupport(false),
2254 bool m_properNamespace;
2255 bool m_multiSupport;
2256 ConfigParserData::AccountProvider& m_data;
2259 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2260 const DPL::String& name)
2262 if (name == L"account-provider") {
2263 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2265 return &IgnoringParser::Create;
2269 virtual void Accept(const Element& element)
2271 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2272 m_properNamespace = true;
2276 virtual void Accept(const XmlAttribute& /*attribute*/)
2279 virtual void Accept(const Text& /*text*/)
2282 virtual void Verify()
2285 ElementParserPtr OnProviderElement()
2287 return ElementParserPtr(new AccountProviderParser(m_account));
2290 AccountParser(ConfigParserData& data) :
2293 m_account(data.accountProvider),
2294 m_properNamespace(false),
2295 m_multiSupport(false)
2299 ConfigParserData& m_data;
2300 ConfigParserData::AccountProvider& m_account;
2301 bool m_properNamespace;
2302 bool m_multiSupport;
2305 ElementParser::ActionFunc WidgetParser::GetElementParser(
2306 const DPL::String& /*ns*/,
2310 FuncMap::const_iterator it = m_map.find(name);
2311 if (it != m_map.end()) {
2314 return &IgnoringParser::Create;
2318 WidgetParser::WidgetParser(ConfigParserData& data) :
2320 m_textDirection(Unicode::EMPTY)
2322 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2323 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2324 m_map[L"description"] =
2325 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2326 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2328 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2329 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2331 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2332 m_map[L"preference"] =
2333 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2334 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2336 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2337 m_map[L"application"] = DPL::MakeDelegate(
2340 OnApplicationElement);
2341 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2342 m_map[L"background"] = DPL::MakeDelegate(this,
2343 &WidgetParser::OnBackgroundElement);
2344 m_map[L"privilege"] = DPL::MakeDelegate(this,
2345 &WidgetParser::OnPrivilegeElement);
2346 m_map[L"app-control"] = DPL::MakeDelegate(
2349 OnAppControlElement);
2350 m_map[L"category"] = DPL::MakeDelegate(this,
2351 &WidgetParser::OnCategoryElement);
2352 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2354 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2358 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2361 OnCspReportOnlyElement);
2363 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2366 ElementParserPtr WidgetParser::OnNameElement()
2368 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2371 ElementParserPtr WidgetParser::OnAccessElement()
2373 return ElementParserPtr(new AccessParser(m_data));
2376 ElementParserPtr WidgetParser::OnDescriptionElement()
2378 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2381 ElementParserPtr WidgetParser::OnAuthorElement()
2383 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2386 ElementParserPtr WidgetParser::OnLicenseElement()
2388 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2391 ElementParserPtr WidgetParser::OnIconElement()
2393 return ElementParserPtr(new IconParser(m_data));
2396 ElementParserPtr WidgetParser::OnContentElement()
2398 return ElementParserPtr(new ContentParser(m_data));
2401 ElementParserPtr WidgetParser::OnPreferenceElement()
2403 return ElementParserPtr(new PreferenceParser(m_data));
2406 ElementParserPtr WidgetParser::OnLinkElement()
2408 return ElementParserPtr(new LinkParser(m_data));
2411 ElementParserPtr WidgetParser::OnSettingElement()
2413 return ElementParserPtr(new SettingParser(m_data));
2416 ElementParserPtr WidgetParser::OnApplicationElement()
2418 return ElementParserPtr(new ApplicationParser(m_data));
2421 ElementParserPtr WidgetParser::OnSplashElement()
2423 return ElementParserPtr(new SplashParser(m_data));
2426 ElementParserPtr WidgetParser::OnBackgroundElement()
2428 return ElementParserPtr(new BackgroundParser(m_data));
2431 ElementParserPtr WidgetParser::OnPrivilegeElement()
2433 return ElementParserPtr(new PrivilegeParser(m_data));
2436 ElementParserPtr WidgetParser::OnAppControlElement()
2438 return ElementParserPtr(new AppControlParser(m_data));
2441 ElementParserPtr WidgetParser::OnCategoryElement()
2443 return ElementParserPtr(new CategoryParser(m_data));
2446 ElementParserPtr WidgetParser::OnAppWidgetElement()
2448 return ElementParserPtr(new AppWidgetParser(m_data));
2451 ElementParserPtr WidgetParser::OnCspElement()
2453 return ElementParserPtr(new CspParser(m_data));
2456 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2458 return ElementParserPtr(new CspReportOnlyParser(m_data));
2461 ElementParserPtr WidgetParser::OnAccountElement()
2463 return ElementParserPtr(new AccountParser(m_data));
2466 void WidgetParser::Accept(const Element& element)
2468 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2469 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2471 ThrowMsg(Exception::ParseError,
2472 "Wrong xml namespace for widget element");
2476 void WidgetParser::Accept(const Text& /*text*/)
2478 ThrowMsg(Exception::ParseError, "widged element must be empty");
2481 void WidgetParser::Accept(const XmlAttribute& attribute)
2483 if (attribute.name == L"id") {
2484 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2485 //If may important tests starts to fail this test we will have
2486 //to consider commenting this test out again.
2487 if (iri.Validate()) {
2488 m_data.widget_id = attribute.value;
2489 NormalizeString(m_data.widget_id);
2491 LogWarning("Widget id validation failed: " << attribute.value);
2493 } else if (attribute.name == L"version") {
2494 m_version = attribute.value;
2495 NormalizeString(m_version);
2496 } else if (attribute.name == L"min-version") {
2497 LogInfo("min-version attribute was found. Value: " << attribute.value);
2498 m_minVersion = attribute.value;
2499 NormalizeString(m_minVersion);
2500 m_data.minVersionRequired = m_minVersion;
2501 } else if (attribute.name == L"height") {
2502 DPL::OptionalString value = attribute.value;
2503 NormalizeString(value);
2504 std::string v = DPL::ToUTF8String(*value);
2507 unsigned char c = v.c_str()[0];
2508 if (c >= '0' && c <= '9') {
2510 for (size_t i = 0; i < v.size(); ++i) {
2512 if (c >= '0' && c <= '9') {
2519 m_data.height = val;
2522 } else if (attribute.name == L"width") {
2523 DPL::OptionalString value = attribute.value;
2524 NormalizeString(value);
2525 std::string v = DPL::ToUTF8String(*value);
2528 unsigned char c = v.c_str()[0];
2529 if (c >= '0' && c <= '9') {
2531 for (size_t i = 0; i < v.size(); ++i) {
2533 if (c >= '0' && c <= '9') {
2543 } else if (attribute.name == L"viewmodes") {
2544 DPL::Tokenize(attribute.value,
2546 std::inserter(m_windowModes,
2547 m_windowModes.end()),
2549 } else if (attribute.name == L"dir") {
2550 m_textDirection = Unicode::ParseDirAttribute(attribute);
2551 } else if (L"defaultlocale" == attribute.name) {
2552 if (!m_defaultlocale) {
2553 m_defaultlocale = attribute.value;
2554 NormalizeString(m_defaultlocale);
2555 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2556 DPL::ToUTF8String(*m_defaultlocale)))
2558 LogWarning("Language tag: " <<
2559 m_defaultlocale << " is not valid");
2560 m_defaultlocale = DPL::OptionalString::Null;
2562 LogDebug("Default Locale Found " << m_defaultlocale);
2565 LogWarning("Ignoring subsequent default locale");
2568 //Any other value consider as a namespace definition
2569 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2570 LogInfo("Namespace domain: " << attribute.name);
2571 LogInfo("Namespace value: " << attribute.value);
2572 m_nameSpaces[attribute.name] = attribute.value;
2574 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2575 ", name=" << attribute.name <<
2576 ", value=" << attribute.value);
2580 void WidgetParser::Verify()
2582 FOREACH(mode, m_windowModes) {
2583 if (L"windowed" == *mode || L"floating" == *mode ||
2584 L"fullscreen" == *mode || L"maximized" == *mode ||
2585 L"minimized" == *mode)
2587 m_data.windowModes.insert(*mode);
2590 if (!m_version.IsNull()) {
2591 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2592 m_data.version = m_version;
2594 m_data.defaultlocale = m_defaultlocale;
2595 FOREACH(ns, m_nameSpaces) {
2596 m_data.nameSpaces.insert(ns->second);