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 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1137 const DPL::String& name)
1139 if (name == L"src") {
1140 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1141 } else if (name == L"operation") {
1142 return DPL::MakeDelegate(this,
1143 &AppControlParser::OnOperationElement);
1144 } else if (name == L"uri") {
1145 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1146 } else if (name == L"mime") {
1147 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1149 return &IgnoringParser::Create;
1153 virtual void Accept(const XmlAttribute& /*attribute*/)
1156 virtual void Accept(const Element& element)
1158 LogWarning("namespace for app service = " << element.ns);
1159 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1160 ThrowMsg(Exception::ParseError,
1161 "Wrong xml namespace for widget element");
1165 virtual void Accept(const Text& /*text*/)
1167 ThrowMsg(Exception::ParseError, "param element must be empty");
1170 virtual void Verify()
1172 if (m_appControl.m_src == L"") {
1173 LogWarning("service element must have src element");
1177 if (m_appControl.m_operation == L"") {
1178 LogWarning("service element must have operation element");
1182 m_data.appControlList.push_back(m_appControl);
1185 ElementParserPtr OnSourceElement()
1187 return ElementParserPtr(new SourceParser(m_appControl));
1190 ElementParserPtr OnOperationElement()
1192 return ElementParserPtr(new OperationParser(m_appControl));
1195 ElementParserPtr OnUriElement()
1197 return ElementParserPtr(new UriParser(m_appControl));
1200 ElementParserPtr OnMimeElement()
1202 return ElementParserPtr(new MimeParser(m_appControl));
1205 AppControlParser(ConfigParserData& data) :
1212 ConfigParserData& m_data;
1213 ConfigParserData::AppControlInfo m_appControl;
1216 class ApplicationParser : public ElementParser
1219 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1220 const DPL::String& /*name*/)
1222 return &IgnoringParser::Create;
1225 virtual void Accept(const Text& /*text*/)
1227 if (m_properNamespace) {
1229 ThrowMsg(Exception::ParseError, "application element must be empty");
1233 virtual void Accept(const Element& element)
1236 ConfigurationNamespace::TizenWebAppNamespaceName)
1238 m_properNamespace = true;
1240 LogDebug("element");
1243 virtual void Accept(const XmlAttribute& attribute)
1245 if (m_properNamespace) {
1246 LogDebug("attribute");
1247 if (attribute.name == L"id") {
1248 m_id = attribute.value;
1249 NormalizeAndTrimSpaceString(m_id);
1250 } else if (attribute.name == L"package") {
1251 m_package = attribute.value;
1252 } else if (attribute.name == L"required_version") {
1253 m_version = attribute.value;
1254 NormalizeString(m_version);
1256 ThrowMsg(Exception::ParseError,
1257 "unknown attribute '" +
1258 DPL::ToUTF8String(attribute.name) +
1259 "' in application element");
1264 virtual void Verify()
1267 ThrowMsg(Exception::ParseError,
1268 "application element must have id attribute");
1272 m_data.tizenPkgId = m_package;
1276 ThrowMsg(Exception::ParseError,
1277 "application element must have required_version attribute");
1280 //TODO check if id and version format is right
1281 m_data.tizenAppId = m_id;
1282 m_data.tizenMinVersionRequired = m_version;
1285 ApplicationParser(ConfigParserData& data) :
1288 m_id(DPL::OptionalString::Null),
1289 m_version(DPL::OptionalString::Null),
1290 m_properNamespace(false)
1294 ConfigParserData& m_data;
1295 DPL::OptionalString m_id;
1296 DPL::OptionalString m_package;
1297 DPL::OptionalString m_version;
1298 bool m_properNamespace;
1301 class SplashParser : public ElementParser
1304 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1305 const DPL::String& /*name*/)
1307 return &IgnoringParser::Create;
1310 virtual void Accept(const XmlAttribute& attribute)
1312 if (attribute.name == L"src") {
1313 if (attribute.value.size() > 0) {
1314 m_src = attribute.value;
1319 virtual void Accept(const Element& /*element*/)
1322 virtual void Accept(const Text& /*text*/)
1325 virtual void Verify()
1327 if (m_src.IsNull()) {
1329 "src attribute of splash element is mandatory - ignoring");
1333 m_data.splashImgSrc = m_src;
1336 SplashParser(ConfigParserData& data) :
1342 DPL::OptionalString m_src;
1343 ConfigParserData& m_data;
1346 class BackgroundParser : public ElementParser
1349 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1350 const DPL::String& /*name*/)
1352 return &IgnoringParser::Create;
1355 virtual void Accept(const XmlAttribute& attribute)
1357 if (attribute.name == L"src") {
1358 if (attribute.value.size() > 0) {
1359 m_src = attribute.value;
1364 virtual void Accept(const Element& /*element*/)
1367 virtual void Accept(const Text& /*text*/)
1370 virtual void Verify()
1372 if (m_src.IsNull()) {
1374 "src attribute of background element is mandatory - ignoring");
1378 m_data.backgroundPage = m_src;
1381 explicit BackgroundParser(ConfigParserData& data) :
1386 DPL::OptionalString m_src;
1387 ConfigParserData& m_data;
1390 class PrivilegeParser : public ElementParser
1393 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1394 const DPL::String& /*name*/)
1396 return &IgnoringParser::Create;
1399 virtual void Accept(const Text& /*text*/)
1402 virtual void Accept(const Element& element)
1405 ConfigurationNamespace::TizenWebAppNamespaceName)
1407 m_properNamespace = true;
1409 LogDebug("element");
1412 virtual void Accept(const XmlAttribute& attribute)
1414 if (m_properNamespace) {
1415 if (attribute.name == L"name") {
1416 m_feature.name = attribute.value;
1417 m_privilege.name = attribute.value;
1422 virtual void Verify()
1424 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1426 if (m_feature.name != L"") {
1427 if (iri.Validate()) {
1428 if (m_data.featuresList.find(m_feature) ==
1429 m_data.featuresList.end())
1431 m_data.featuresList.insert(m_feature);
1433 LogDebug("Ignoring feature with name" <<
1434 DPL::ToUTF8String(m_feature.name));
1439 LibIri::Wrapper iriPrivilege(
1440 DPL::ToUTF8String(m_privilege.name).c_str());
1442 if (m_privilege.name != L"") {
1443 if (iriPrivilege.Validate()) {
1444 if (m_data.privilegeList.find(m_privilege) ==
1445 m_data.privilegeList.end())
1447 m_data.privilegeList.insert(m_privilege);
1449 LogDebug("Ignoring privilege with name" <<
1450 DPL::ToUTF8String(m_privilege.name));
1456 PrivilegeParser(ConfigParserData& data) :
1461 m_properNamespace(false)
1465 ConfigParserData& m_data;
1466 ConfigParserData::Feature m_feature;
1467 ConfigParserData::Privilege m_privilege;
1468 bool m_properNamespace;
1471 class CategoryParser : public ElementParser
1474 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1475 const DPL::String& /*name*/)
1477 return &IgnoringParser::Create;
1480 virtual void Accept(const XmlAttribute& attribute)
1482 if (attribute.name == L"name") {
1483 if (attribute.value.size() > 0) {
1484 m_name = attribute.value;
1489 virtual void Accept(const Element& /*element*/)
1492 virtual void Accept(const Text& /*text*/)
1495 virtual void Verify()
1497 if (m_name.IsNull()) {
1499 "name attribute of category element is mandatory - ignoring");
1503 if (m_data.categoryList.find(*m_name) ==
1504 m_data.categoryList.end())
1506 m_data.categoryList.insert(*m_name);
1510 explicit CategoryParser(ConfigParserData& data) :
1515 DPL::OptionalString m_name;
1516 ConfigParserData& m_data;
1519 class AppWidgetParser : public ElementParser
1523 struct BoxLabelParser : public ElementParser
1525 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1526 const DPL::String& /*name*/)
1528 return &IgnoringParser::Create;
1531 virtual void Accept(const XmlAttribute& /*attribute*/)
1534 virtual void Accept(const Element& element)
1537 ConfigurationNamespace::TizenWebAppNamespaceName)
1539 m_properNamespace = true;
1543 virtual void Accept(const Text& text)
1545 if (m_properNamespace) {
1546 m_label = text.value;
1550 virtual void Verify()
1552 m_data.m_label = m_label;
1555 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1557 m_properNamespace(false),
1562 DPL::String m_label;
1563 bool m_properNamespace;
1564 ConfigParserData::LiveboxInfo& m_data;
1567 struct BoxIconParser : public ElementParser
1569 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1570 const DPL::String& /*name*/)
1572 return &IgnoringParser::Create;
1575 virtual void Accept(const XmlAttribute& attribute)
1577 if (m_properNamespace) {
1578 if (attribute.name == L"src") {
1579 m_icon = attribute.value;
1584 virtual void Accept(const Element& element)
1587 ConfigurationNamespace::TizenWebAppNamespaceName)
1589 m_properNamespace = true;
1593 virtual void Accept(const Text& /*text*/)
1596 virtual void Verify()
1598 m_data.m_icon = m_icon;
1601 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1603 m_properNamespace(false),
1609 bool m_properNamespace;
1610 ConfigParserData::LiveboxInfo& m_data;
1613 struct BoxContentParser : public ElementParser
1615 struct BoxSizeParser : public ElementParser
1617 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1618 const DPL::String& /*name*/)
1620 return &IgnoringParser::Create;
1623 virtual void Accept(const XmlAttribute& attribute)
1625 if (m_properNamespace) {
1626 if (attribute.name == L"preview") {
1627 m_preview = attribute.value;
1632 virtual void Accept(const Element& element)
1635 ConfigurationNamespace::TizenWebAppNamespaceName)
1637 m_properNamespace = true;
1641 virtual void Accept(const Text& text)
1643 if (m_properNamespace) {
1644 m_size = text.value;
1648 virtual void Verify()
1650 std::pair<DPL::String, DPL::String> boxSize;
1651 boxSize.first = m_size;
1652 boxSize.second = m_preview;
1653 m_data.m_boxSize.push_back(boxSize);
1656 explicit BoxSizeParser(
1657 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1659 m_properNamespace(false),
1665 DPL::String m_preview;
1666 bool m_properNamespace;
1667 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1670 struct PdParser : 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"src") {
1682 m_src = attribute.value;
1683 } else if (attribute.name == L"width") {
1684 m_width = attribute.value;
1685 } else if (attribute.name == L"height") {
1686 m_height = attribute.value;
1691 virtual void Accept(const Element& element)
1694 ConfigurationNamespace::TizenWebAppNamespaceName)
1696 m_properNamespace = true;
1700 virtual void Accept(const Text& /*text*/)
1703 virtual void Verify()
1705 m_data.m_pdSrc = m_src;
1706 m_data.m_pdWidth = m_width;
1707 m_data.m_pdHeight = m_height;
1711 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1713 m_properNamespace(false),
1719 DPL::String m_width;
1720 DPL::String m_height;
1722 bool m_properNamespace;
1723 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1726 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1727 const DPL::String& name)
1729 if (name == L"box-size") {
1730 return DPL::MakeDelegate(
1732 &AppWidgetParser::BoxContentParser::
1734 } else if (name == L"pd") {
1735 return DPL::MakeDelegate(
1737 &AppWidgetParser::BoxContentParser::
1740 ThrowMsg(Exception::ParseError,
1741 "No element parser for name: " << name);
1745 virtual void Accept(const XmlAttribute& attribute)
1747 if (m_properNamespace) {
1748 if (attribute.name == L"src") {
1749 m_box.m_boxSrc = attribute.value;
1751 if (attribute.name == L"mouse-event") {
1752 m_box.m_boxMouseEvent = attribute.value;
1754 if (attribute.name == L"touch-effect") {
1755 m_box.m_boxTouchEffect = attribute.value;
1760 virtual void Accept(const Element& element)
1763 ConfigurationNamespace::TizenWebAppNamespaceName)
1765 m_properNamespace = true;
1769 virtual void Accept(const Text& /*text*/)
1772 virtual void Verify()
1774 m_data.m_boxInfo = m_box;
1777 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1779 m_properNamespace(false),
1783 ElementParserPtr OnBoxSizeElement()
1785 return ElementParserPtr(new BoxSizeParser(m_box));
1788 ElementParserPtr OnPdElement()
1790 return ElementParserPtr(new PdParser(m_box));
1795 bool m_properNamespace;
1796 ConfigParserData::LiveboxInfo& m_data;
1797 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1800 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1801 const DPL::String& name)
1803 if (name == L"box-label") {
1804 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1805 } else if (name == L"box-icon") {
1806 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1807 } else if (name == L"box-content") {
1808 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1810 return &IgnoringParser::Create;
1814 virtual void Accept(const XmlAttribute& attribute)
1816 if (m_properNamespace) {
1817 if (attribute.name == L"id") {
1818 m_liveboxId = attribute.value;
1819 } else if (attribute.name == L"primary") {
1820 m_primary = attribute.value;
1821 } else if (attribute.name == L"auto-launch") {
1822 m_autoLaunch = attribute.value;
1823 } else if (attribute.name == L"update-period") {
1824 m_updatePeriod = attribute.value;
1825 } else if (attribute.name == L"type") {
1826 m_type = attribute.value;
1831 virtual void Accept(const Element& element)
1834 ConfigurationNamespace::TizenWebAppNamespaceName)
1836 m_properNamespace = true;
1840 virtual void Accept(const Text& /*text*/)
1843 virtual void Verify()
1845 m_livebox.m_liveboxId = m_liveboxId;
1846 m_livebox.m_primary = m_primary;
1847 m_livebox.m_autoLaunch = m_autoLaunch;
1848 m_livebox.m_updatePeriod = m_updatePeriod;
1849 m_livebox.m_type = m_type;
1851 m_data.m_livebox.push_back(m_livebox);
1854 explicit AppWidgetParser(ConfigParserData& data) :
1857 m_properNamespace(false)
1859 m_livebox = ConfigParserData::LiveboxInfo();
1862 ElementParserPtr OnBoxLabelElement()
1864 return ElementParserPtr(new BoxLabelParser(m_livebox));
1867 ElementParserPtr OnBoxIconElement()
1869 return ElementParserPtr(new BoxIconParser(m_livebox));
1872 ElementParserPtr OnBoxContentElement()
1874 return ElementParserPtr(new BoxContentParser(m_livebox));
1878 ConfigParserData& m_data;
1879 ConfigParserData::LiveboxInfo m_livebox;
1880 DPL::String m_liveboxId;
1881 DPL::String m_primary;
1882 DPL::String m_autoLaunch;
1883 DPL::String m_updatePeriod;
1885 bool m_properNamespace;
1888 class CspParser : public ElementParser
1891 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1892 const DPL::String& /*name*/)
1894 return &IgnoringParser::Create;
1897 CspParser(ConfigParserData& data) :
1900 m_properNamespace(false)
1903 virtual void Accept(const Element& element)
1905 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
1906 m_properNamespace = true;
1910 virtual void Accept(const XmlAttribute& /*attribute*/)
1913 virtual void Accept(const Text& text)
1915 if (m_properNamespace) {
1916 m_policy = text.value;
1920 virtual void Verify()
1922 if (!m_policy.IsNull()) {
1923 m_data.cspPolicy = *m_policy;
1928 ConfigParserData& m_data;
1929 bool m_properNamespace;
1930 DPL::OptionalString m_policy;
1933 class CspReportOnlyParser : public ElementParser
1936 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1937 const DPL::String& /*name*/)
1939 return &IgnoringParser::Create;
1942 CspReportOnlyParser(ConfigParserData& data) :
1945 m_properNamespace(false)
1948 virtual void Accept(const Element& element)
1950 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
1951 m_properNamespace = true;
1955 virtual void Accept(const XmlAttribute& /*attribute*/)
1958 virtual void Accept(const Text& text)
1960 if (m_properNamespace) {
1961 m_policy = text.value;
1965 virtual void Verify()
1967 if (!m_policy.IsNull()) {
1968 m_data.cspPolicyReportOnly = *m_policy;
1973 ConfigParserData& m_data;
1974 bool m_properNamespace;
1975 DPL::OptionalString m_policy;
1978 class AccountParser : public ElementParser
1981 struct AccountProviderParser : public ElementParser
1985 struct IconParser : public ElementParser
1988 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1989 const DPL::String& /*name*/)
1991 return &IgnoringParser::Create;
1994 virtual void Accept(const Text& text)
1996 if (text.value == L"") {
1999 m_value = text.value;
2002 virtual void Accept(const Element& /*element*/)
2005 virtual void Accept(const XmlAttribute& attribute)
2007 if (attribute.name == L"section") {
2008 if (attribute.value == L"account") {
2009 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2010 } else if (attribute.value == L"account-small") {
2011 m_type = ConfigParserData::IconSectionType::SmallIcon;
2016 virtual void Verify()
2018 if (m_value.IsNull() || *m_value == L"") {
2022 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2023 icon.first = m_type;
2024 icon.second = *m_value;
2026 m_data.m_iconSet.insert(icon);
2029 IconParser(ConfigParserData::AccountProvider& data) :
2031 m_properNamespace(false),
2032 m_type(ConfigParserData::DefaultIcon),
2037 bool m_properNamespace;
2038 ConfigParserData::IconSectionType m_type;
2039 ConfigParserData::AccountProvider& m_data;
2040 DPL::OptionalString m_value;
2043 struct DisplayNameParser : public ElementParser
2046 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2047 const DPL::String& /*name*/)
2049 return &IgnoringParser::Create;
2052 virtual void Accept(const Text& text)
2054 if (text.value == L"") {
2057 m_value = text.value;
2060 virtual void Accept(const Element& element)
2062 m_lang = element.lang;
2066 virtual void Accept(const XmlAttribute& /*attribute*/)
2069 virtual void Verify()
2071 if (m_value.IsNull() || *m_value == L"") {
2075 std::pair<DPL::String, DPL::String> name;
2076 name.first = *m_lang;
2077 name.second = *m_value;
2079 m_data.m_displayNameSet.insert(name);
2082 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2084 m_properNamespace(false),
2089 bool m_properNamespace;
2090 DPL::OptionalString m_lang;
2091 DPL::OptionalString m_value;
2092 ConfigParserData::AccountProvider& m_data;
2095 struct CapabilityParser : public ElementParser
2098 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2099 const DPL::String& /*name*/)
2101 return &IgnoringParser::Create;
2104 virtual void Accept(const Text& text)
2106 if (text.value == L"") {
2109 m_value = text.value;
2112 virtual void Accept(const Element& /*element*/)
2115 virtual void Accept(const XmlAttribute& /*attribute*/)
2118 virtual void Verify()
2120 if (m_value.IsNull() || *m_value == L"") {
2123 m_data.m_capabilityList.push_back(*m_value);
2126 CapabilityParser(ConfigParserData::AccountProvider& data) :
2128 m_properNamespace(false),
2133 bool m_properNamespace;
2134 DPL::OptionalString m_value;
2135 ConfigParserData::AccountProvider& m_data;
2137 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2138 const DPL::String& name)
2140 if (name == L"icon") {
2141 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2142 } else if (name == L"display-name") {
2143 return DPL::MakeDelegate(this,
2144 &AccountProviderParser::OnDisplayNameElement);
2145 } else if (name == L"capability") {
2146 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2148 return &IgnoringParser::Create;
2152 virtual void Accept(const Text& /*text*/)
2155 virtual void Accept(const Element& /*element*/)
2158 virtual void Accept(const XmlAttribute& attribute)
2160 if (attribute.name == L"multiple-accounts-support") {
2161 if (attribute.value == L"") {
2165 if (attribute.value == L"ture") {
2166 m_multiSupport = true;
2171 virtual void Verify()
2173 m_data.m_multiAccountSupport = m_multiSupport;
2176 ElementParserPtr OnIconElement()
2178 return ElementParserPtr(new IconParser(m_data));
2181 ElementParserPtr OnDisplayNameElement()
2183 return ElementParserPtr(new DisplayNameParser(m_data));
2186 ElementParserPtr OnCapabilityElement()
2188 return ElementParserPtr(new CapabilityParser(m_data));
2191 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2193 m_properNamespace(false),
2194 m_multiSupport(false),
2199 bool m_properNamespace;
2200 bool m_multiSupport;
2201 ConfigParserData::AccountProvider& m_data;
2204 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2205 const DPL::String& name)
2207 if (name == L"account-provider") {
2208 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2210 return &IgnoringParser::Create;
2214 virtual void Accept(const Element& element)
2216 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2217 m_properNamespace = true;
2221 virtual void Accept(const XmlAttribute& /*attribute*/)
2224 virtual void Accept(const Text& /*text*/)
2227 virtual void Verify()
2230 ElementParserPtr OnProviderElement()
2232 return ElementParserPtr(new AccountProviderParser(m_account));
2235 AccountParser(ConfigParserData& data) :
2238 m_account(data.accountProvider),
2239 m_properNamespace(false),
2240 m_multiSupport(false)
2244 ConfigParserData& m_data;
2245 ConfigParserData::AccountProvider& m_account;
2246 bool m_properNamespace;
2247 bool m_multiSupport;
2250 ElementParser::ActionFunc WidgetParser::GetElementParser(
2251 const DPL::String& /*ns*/,
2255 FuncMap::const_iterator it = m_map.find(name);
2256 if (it != m_map.end()) {
2259 return &IgnoringParser::Create;
2263 WidgetParser::WidgetParser(ConfigParserData& data) :
2265 m_textDirection(Unicode::EMPTY)
2267 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2268 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2269 m_map[L"description"] =
2270 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2271 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2273 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2274 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2276 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2277 m_map[L"preference"] =
2278 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2279 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2281 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2282 m_map[L"application"] = DPL::MakeDelegate(
2285 OnApplicationElement);
2286 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2287 m_map[L"background"] = DPL::MakeDelegate(this,
2288 &WidgetParser::OnBackgroundElement);
2289 m_map[L"privilege"] = DPL::MakeDelegate(this,
2290 &WidgetParser::OnPrivilegeElement);
2291 m_map[L"app-control"] = DPL::MakeDelegate(
2294 OnAppControlElement);
2295 m_map[L"category"] = DPL::MakeDelegate(this,
2296 &WidgetParser::OnCategoryElement);
2297 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2299 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2303 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2306 OnCspReportOnlyElement);
2308 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2311 ElementParserPtr WidgetParser::OnNameElement()
2313 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2316 ElementParserPtr WidgetParser::OnAccessElement()
2318 return ElementParserPtr(new AccessParser(m_data));
2321 ElementParserPtr WidgetParser::OnDescriptionElement()
2323 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2326 ElementParserPtr WidgetParser::OnAuthorElement()
2328 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2331 ElementParserPtr WidgetParser::OnLicenseElement()
2333 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2336 ElementParserPtr WidgetParser::OnIconElement()
2338 return ElementParserPtr(new IconParser(m_data));
2341 ElementParserPtr WidgetParser::OnContentElement()
2343 return ElementParserPtr(new ContentParser(m_data));
2346 ElementParserPtr WidgetParser::OnPreferenceElement()
2348 return ElementParserPtr(new PreferenceParser(m_data));
2351 ElementParserPtr WidgetParser::OnLinkElement()
2353 return ElementParserPtr(new LinkParser(m_data));
2356 ElementParserPtr WidgetParser::OnSettingElement()
2358 return ElementParserPtr(new SettingParser(m_data));
2361 ElementParserPtr WidgetParser::OnApplicationElement()
2363 return ElementParserPtr(new ApplicationParser(m_data));
2366 ElementParserPtr WidgetParser::OnSplashElement()
2368 return ElementParserPtr(new SplashParser(m_data));
2371 ElementParserPtr WidgetParser::OnBackgroundElement()
2373 return ElementParserPtr(new BackgroundParser(m_data));
2376 ElementParserPtr WidgetParser::OnPrivilegeElement()
2378 return ElementParserPtr(new PrivilegeParser(m_data));
2381 ElementParserPtr WidgetParser::OnAppControlElement()
2383 return ElementParserPtr(new AppControlParser(m_data));
2386 ElementParserPtr WidgetParser::OnCategoryElement()
2388 return ElementParserPtr(new CategoryParser(m_data));
2391 ElementParserPtr WidgetParser::OnAppWidgetElement()
2393 return ElementParserPtr(new AppWidgetParser(m_data));
2396 ElementParserPtr WidgetParser::OnCspElement()
2398 return ElementParserPtr(new CspParser(m_data));
2401 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2403 return ElementParserPtr(new CspReportOnlyParser(m_data));
2406 ElementParserPtr WidgetParser::OnAccountElement()
2408 return ElementParserPtr(new AccountParser(m_data));
2411 void WidgetParser::Accept(const Element& element)
2413 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2414 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2416 ThrowMsg(Exception::ParseError,
2417 "Wrong xml namespace for widget element");
2421 void WidgetParser::Accept(const Text& /*text*/)
2423 ThrowMsg(Exception::ParseError, "widged element must be empty");
2426 void WidgetParser::Accept(const XmlAttribute& attribute)
2428 if (attribute.name == L"id") {
2429 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2430 //If may important tests starts to fail this test we will have
2431 //to consider commenting this test out again.
2432 if (iri.Validate()) {
2433 m_data.widget_id = attribute.value;
2434 NormalizeString(m_data.widget_id);
2436 LogWarning("Widget id validation failed: " << attribute.value);
2438 } else if (attribute.name == L"version") {
2439 m_version = attribute.value;
2440 NormalizeString(m_version);
2441 } else if (attribute.name == L"min-version") {
2442 LogInfo("min-version attribute was found. Value: " << attribute.value);
2443 m_minVersion = attribute.value;
2444 NormalizeString(m_minVersion);
2445 m_data.minVersionRequired = m_minVersion;
2446 } else if (attribute.name == L"height") {
2447 DPL::OptionalString value = attribute.value;
2448 NormalizeString(value);
2449 std::string v = DPL::ToUTF8String(*value);
2452 unsigned char c = v.c_str()[0];
2453 if (c >= '0' && c <= '9') {
2455 for (size_t i = 0; i < v.size(); ++i) {
2457 if (c >= '0' && c <= '9') {
2464 m_data.height = val;
2467 } else if (attribute.name == L"width") {
2468 DPL::OptionalString value = attribute.value;
2469 NormalizeString(value);
2470 std::string v = DPL::ToUTF8String(*value);
2473 unsigned char c = v.c_str()[0];
2474 if (c >= '0' && c <= '9') {
2476 for (size_t i = 0; i < v.size(); ++i) {
2478 if (c >= '0' && c <= '9') {
2488 } else if (attribute.name == L"viewmodes") {
2489 DPL::Tokenize(attribute.value,
2491 std::inserter(m_windowModes,
2492 m_windowModes.end()),
2494 } else if (attribute.name == L"dir") {
2495 m_textDirection = Unicode::ParseDirAttribute(attribute);
2496 } else if (L"defaultlocale" == attribute.name) {
2497 if (!m_defaultlocale) {
2498 m_defaultlocale = attribute.value;
2499 NormalizeString(m_defaultlocale);
2500 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2501 DPL::ToUTF8String(*m_defaultlocale)))
2503 LogWarning("Language tag: " <<
2504 m_defaultlocale << " is not valid");
2505 m_defaultlocale = DPL::OptionalString::Null;
2507 LogDebug("Default Locale Found " << m_defaultlocale);
2510 LogWarning("Ignoring subsequent default locale");
2513 //Any other value consider as a namespace definition
2514 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2515 LogInfo("Namespace domain: " << attribute.name);
2516 LogInfo("Namespace value: " << attribute.value);
2517 m_nameSpaces[attribute.name] = attribute.value;
2519 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2520 ", name=" << attribute.name <<
2521 ", value=" << attribute.value);
2525 void WidgetParser::Verify()
2527 FOREACH(mode, m_windowModes) {
2528 if (L"windowed" == *mode || L"floating" == *mode ||
2529 L"fullscreen" == *mode || L"maximized" == *mode ||
2530 L"minimized" == *mode)
2532 m_data.windowModes.insert(*mode);
2535 if (!m_version.IsNull()) {
2536 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2537 m_data.version = m_version;
2539 m_data.defaultlocale = m_defaultlocale;
2540 FOREACH(ns, m_nameSpaces) {
2541 m_data.nameSpaces.insert(ns->second);