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 AppServiceParser : public ElementParser
925 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
926 const DPL::String& /*name*/)
928 return &IgnoringParser::Create;
931 virtual void Accept(const XmlAttribute& attribute)
933 if (attribute.name == L"src") {
934 m_src = attribute.value;
935 } else if (attribute.name == L"operation") {
936 m_operation = attribute.value;
937 } else if (attribute.name == L"scheme") {
938 m_scheme = attribute.value;
939 } else if (attribute.name == L"mime") {
940 m_mime = attribute.value;
941 } else if (attribute.name == L"disposition") {
942 if (attribute.value == L"inline")
944 ConfigParserData::ServiceInfo::Disposition::INLINE;
948 virtual void Accept(const Element& element)
950 LogWarning("namespace for app service = " << element.ns);
951 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
952 ThrowMsg(Exception::ParseError,
953 "Wrong xml namespace for widget element");
957 virtual void Accept(const Text& /*text*/)
959 ThrowMsg(Exception::ParseError, "param element must be empty");
962 virtual void Verify()
964 if (m_src.IsNull()) {
965 LogWarning("service element must have target attribute");
967 } else if (m_operation.IsNull()) {
968 LogWarning("service element must have operation attribute");
971 NormalizeString(m_src);
972 NormalizeString(m_operation);
973 NormalizeString(m_scheme);
974 NormalizeString(m_mime);
977 DPL::String ignoreUri(L"file");
979 if (!m_scheme.IsNull() && *m_scheme == ignoreUri)
981 LogInfo("exception : '" << *m_scheme << "' scheme will be ignored.");
982 m_scheme = DPL::OptionalString::Null;
985 // verify duplicate element
986 DPL::String wildString(L"*/*");
987 DPL::String nullString(L"");
988 ConfigParserData::ServiceInfo serviceInfo(
989 m_src.IsNull() ? nullString : *m_src,
990 m_operation.IsNull() ? nullString : *m_operation,
991 m_scheme.IsNull() ? nullString : *m_scheme,
992 m_mime.IsNull() ? nullString : *m_mime,
995 FOREACH(iterator, m_data.appServiceList) {
996 if (iterator->m_operation == serviceInfo.m_operation &&
998 (iterator->m_scheme == serviceInfo.m_scheme ||
999 // check input scheme is "*/*" case
1000 (iterator->m_scheme == wildString &&
1001 serviceInfo.m_scheme != nullString) ||
1002 // check iterator scheme is "*/*" case
1003 (serviceInfo.m_scheme == wildString &&
1004 iterator->m_scheme != nullString)) &&
1006 (iterator->m_mime == serviceInfo.m_mime ||
1007 // check input mime is "*/*" case
1008 (iterator->m_mime == wildString &&
1009 serviceInfo.m_mime != nullString) ||
1010 // check iterator mime is "*/*" case
1011 (serviceInfo.m_mime == wildString &&
1012 iterator->m_mime != nullString)))
1014 ThrowMsg(Exception::ParseError,
1015 "service operation is duplicated " +
1016 DPL::ToUTF8String(*m_operation));
1019 m_data.appServiceList.push_back(serviceInfo);
1022 AppServiceParser(ConfigParserData& data) :
1024 m_src(DPL::OptionalString::Null),
1025 m_operation(DPL::OptionalString::Null),
1026 m_scheme(DPL::OptionalString::Null),
1027 m_mime(DPL::OptionalString::Null),
1028 m_disposition(ConfigParserData::ServiceInfo::Disposition::WINDOW),
1033 DPL::OptionalString m_src;
1034 DPL::OptionalString m_operation;
1035 DPL::OptionalString m_scheme;
1036 DPL::OptionalString m_mime;
1037 ConfigParserData::ServiceInfo::Disposition m_disposition;
1038 ConfigParserData& m_data;
1041 class AppControlParser : public ElementParser
1044 struct SourceParser : public ElementParser
1047 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1048 const DPL::String& /*name*/)
1050 return &IgnoringParser::Create;
1053 virtual void Accept(const Text& /*text*/)
1056 virtual void Accept(const Element& /*element*/)
1059 virtual void Accept(const XmlAttribute& attribute)
1061 if (attribute.name == L"name") {
1062 if (attribute.value.size() > 0) {
1063 m_value = attribute.value;
1064 NormalizeString(m_value);
1069 virtual void Verify()
1071 if (m_value.IsNull() || *m_value == L"") {
1075 m_data.m_src = *m_value;
1078 SourceParser(ConfigParserData::AppControlInfo& data) :
1080 m_properNamespace(false),
1085 bool m_properNamespace;
1086 DPL::OptionalString m_value;
1087 ConfigParserData::AppControlInfo& m_data;
1090 struct OperationParser : public ElementParser
1093 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1094 const DPL::String& /*name*/)
1096 return &IgnoringParser::Create;
1099 virtual void Accept(const Text& /*text*/)
1102 virtual void Accept(const Element& /*element*/)
1105 virtual void Accept(const XmlAttribute& attribute)
1107 if (attribute.name == L"name") {
1108 if (attribute.value.size() > 0) {
1109 m_value = attribute.value;
1110 NormalizeString(m_value);
1115 virtual void Verify()
1117 if (m_value.IsNull() || *m_value == L"") {
1121 m_data.m_operation = *m_value;
1124 OperationParser(ConfigParserData::AppControlInfo& data) :
1126 m_properNamespace(false),
1131 bool m_properNamespace;
1132 DPL::OptionalString m_value;
1133 ConfigParserData::AppControlInfo& m_data;
1136 struct UriParser : 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"name") {
1154 if (attribute.value.size() > 0) {
1155 m_value = attribute.value;
1156 NormalizeString(m_value);
1161 virtual void Verify()
1164 DPL::String ignoreUri(L"file");
1166 if (!m_value.IsNull() && *m_value == ignoreUri)
1168 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
1169 m_value = DPL::OptionalString::Null;
1172 if (m_value.IsNull() || *m_value == L"") {
1176 DPL::String wildString(L"*/*");
1177 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1178 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1180 m_data.m_uriList.insert(*m_value);
1182 LogDebug("Ignoring uri with name" <<
1183 DPL::ToUTF8String(*m_value));
1187 UriParser(ConfigParserData::AppControlInfo& data) :
1189 m_properNamespace(false),
1194 bool m_properNamespace;
1195 DPL::OptionalString m_value;
1196 ConfigParserData::AppControlInfo& m_data;
1199 struct MimeParser : public ElementParser
1202 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1203 const DPL::String& /*name*/)
1205 return &IgnoringParser::Create;
1208 virtual void Accept(const Text& /*text*/)
1211 virtual void Accept(const Element& /*element*/)
1214 virtual void Accept(const XmlAttribute& attribute)
1216 if (attribute.name == L"name") {
1217 if (attribute.value.size() > 0) {
1218 m_value = attribute.value;
1219 NormalizeString(m_value);
1224 virtual void Verify()
1226 if (m_value.IsNull() || *m_value == L"") {
1230 DPL::String wildString(L"*/*");
1231 if ((m_data.m_mimeList.find(wildString) ==
1232 m_data.m_mimeList.end())
1233 && (m_data.m_mimeList.find(*m_value) ==
1234 m_data.m_mimeList.end()))
1236 m_data.m_mimeList.insert(*m_value);
1238 LogDebug("Ignoring mime with name" <<
1239 DPL::ToUTF8String(*m_value));
1243 MimeParser(ConfigParserData::AppControlInfo& data) :
1245 m_properNamespace(false),
1250 bool m_properNamespace;
1251 DPL::OptionalString m_value;
1252 ConfigParserData::AppControlInfo& m_data;
1255 struct DispositionParser : public ElementParser
1258 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1259 const DPL::String& /*name*/)
1261 return &IgnoringParser::Create;
1264 virtual void Accept(const Text& /*text*/)
1267 virtual void Accept(const Element& /*element*/)
1270 virtual void Accept(const XmlAttribute& attribute)
1272 if (attribute.name == L"disposition") {
1273 if (attribute.value.size() > 0) {
1274 m_value = attribute.value;
1275 NormalizeString(m_value);
1280 virtual void Verify()
1282 if (m_value.IsNull() || *m_value != L"inline") {
1283 m_data.m_disposition = ConfigParserData::AppControlInfo::Disposition::WINDOW;
1286 m_data.m_disposition = ConfigParserData::AppControlInfo::Disposition::INLINE;
1290 DispositionParser(ConfigParserData::AppControlInfo& data) :
1292 m_properNamespace(false),
1297 bool m_properNamespace;
1298 DPL::OptionalString m_value;
1299 ConfigParserData::AppControlInfo& m_data;
1302 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1303 const DPL::String& name)
1305 if (name == L"src") {
1306 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1307 } else if (name == L"operation") {
1308 return DPL::MakeDelegate(this,
1309 &AppControlParser::OnOperationElement);
1310 } else if (name == L"uri") {
1311 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1312 } else if (name == L"mime") {
1313 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1314 } else if (name == L"disposition") {
1315 return DPL::MakeDelegate(this,
1316 &AppControlParser::OnDispositionElement);
1318 return &IgnoringParser::Create;
1322 virtual void Accept(const XmlAttribute& /*attribute*/)
1325 virtual void Accept(const Element& element)
1327 LogWarning("namespace for app service = " << element.ns);
1328 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1329 ThrowMsg(Exception::ParseError,
1330 "Wrong xml namespace for widget element");
1334 virtual void Accept(const Text& /*text*/)
1336 ThrowMsg(Exception::ParseError, "param element must be empty");
1339 virtual void Verify()
1341 if (m_appControl.m_src == L"") {
1342 LogWarning("service element must have src element");
1346 if (m_appControl.m_operation == L"") {
1347 LogWarning("service element must have operation element");
1351 m_data.appControlList.push_back(m_appControl);
1354 ElementParserPtr OnSourceElement()
1356 return ElementParserPtr(new SourceParser(m_appControl));
1359 ElementParserPtr OnOperationElement()
1361 return ElementParserPtr(new OperationParser(m_appControl));
1364 ElementParserPtr OnUriElement()
1366 return ElementParserPtr(new UriParser(m_appControl));
1369 ElementParserPtr OnMimeElement()
1371 return ElementParserPtr(new MimeParser(m_appControl));
1374 ElementParserPtr OnDispositionElement()
1376 return ElementParserPtr(new DispositionParser(m_appControl));
1379 AppControlParser(ConfigParserData& data) :
1386 ConfigParserData& m_data;
1387 ConfigParserData::AppControlInfo m_appControl;
1390 class ApplicationParser : 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*/)
1401 if (m_properNamespace) {
1403 ThrowMsg(Exception::ParseError, "application element must be empty");
1407 virtual void Accept(const Element& element)
1410 ConfigurationNamespace::TizenWebAppNamespaceName)
1412 m_properNamespace = true;
1414 LogDebug("element");
1417 virtual void Accept(const XmlAttribute& attribute)
1419 if (m_properNamespace) {
1420 LogDebug("attribute");
1421 if (attribute.name == L"id") {
1422 m_id = attribute.value;
1423 NormalizeAndTrimSpaceString(m_id);
1424 } else if (attribute.name == L"package") {
1425 m_package = attribute.value;
1426 } else if (attribute.name == L"required_version") {
1427 m_version = attribute.value;
1428 NormalizeString(m_version);
1430 ThrowMsg(Exception::ParseError,
1431 "unknown attribute '" +
1432 DPL::ToUTF8String(attribute.name) +
1433 "' in application element");
1438 virtual void Verify()
1441 ThrowMsg(Exception::ParseError,
1442 "application element must have id attribute");
1446 m_data.tizenPkgId = m_package;
1450 ThrowMsg(Exception::ParseError,
1451 "application element must have required_version attribute");
1454 //TODO check if id and version format is right
1455 m_data.tizenAppId = m_id;
1456 m_data.tizenMinVersionRequired = m_version;
1459 ApplicationParser(ConfigParserData& data) :
1462 m_id(DPL::OptionalString::Null),
1463 m_version(DPL::OptionalString::Null),
1464 m_properNamespace(false)
1468 ConfigParserData& m_data;
1469 DPL::OptionalString m_id;
1470 DPL::OptionalString m_package;
1471 DPL::OptionalString m_version;
1472 bool m_properNamespace;
1475 class SplashParser : public ElementParser
1478 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1479 const DPL::String& /*name*/)
1481 return &IgnoringParser::Create;
1484 virtual void Accept(const XmlAttribute& attribute)
1486 if (attribute.name == L"src") {
1487 if (attribute.value.size() > 0) {
1488 m_src = attribute.value;
1493 virtual void Accept(const Element& /*element*/)
1496 virtual void Accept(const Text& /*text*/)
1499 virtual void Verify()
1501 if (m_src.IsNull()) {
1503 "src attribute of splash element is mandatory - ignoring");
1507 m_data.splashImgSrc = m_src;
1510 SplashParser(ConfigParserData& data) :
1516 DPL::OptionalString m_src;
1517 ConfigParserData& m_data;
1520 class BackgroundParser : public ElementParser
1523 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1524 const DPL::String& /*name*/)
1526 return &IgnoringParser::Create;
1529 virtual void Accept(const XmlAttribute& attribute)
1531 if (attribute.name == L"src") {
1532 if (attribute.value.size() > 0) {
1533 m_src = attribute.value;
1538 virtual void Accept(const Element& /*element*/)
1541 virtual void Accept(const Text& /*text*/)
1544 virtual void Verify()
1546 if (m_src.IsNull()) {
1548 "src attribute of background element is mandatory - ignoring");
1552 m_data.backgroundPage = m_src;
1555 explicit BackgroundParser(ConfigParserData& data) :
1560 DPL::OptionalString m_src;
1561 ConfigParserData& m_data;
1564 class PrivilegeParser : public ElementParser
1567 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1568 const DPL::String& /*name*/)
1570 return &IgnoringParser::Create;
1573 virtual void Accept(const Text& /*text*/)
1576 virtual void Accept(const Element& element)
1579 ConfigurationNamespace::TizenWebAppNamespaceName)
1581 m_properNamespace = true;
1583 LogDebug("element");
1586 virtual void Accept(const XmlAttribute& attribute)
1588 if (m_properNamespace) {
1589 if (attribute.name == L"name") {
1590 m_feature.name = attribute.value;
1591 m_privilege.name = attribute.value;
1596 virtual void Verify()
1598 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1600 if (m_feature.name != L"") {
1601 if (iri.Validate()) {
1602 if (m_data.featuresList.find(m_feature) ==
1603 m_data.featuresList.end())
1605 m_data.featuresList.insert(m_feature);
1607 LogDebug("Ignoring feature with name" <<
1608 DPL::ToUTF8String(m_feature.name));
1613 LibIri::Wrapper iriPrivilege(
1614 DPL::ToUTF8String(m_privilege.name).c_str());
1616 if (m_privilege.name != L"") {
1617 if (iriPrivilege.Validate()) {
1618 if (m_data.privilegeList.find(m_privilege) ==
1619 m_data.privilegeList.end())
1621 m_data.privilegeList.insert(m_privilege);
1623 LogDebug("Ignoring privilege with name" <<
1624 DPL::ToUTF8String(m_privilege.name));
1630 PrivilegeParser(ConfigParserData& data) :
1635 m_properNamespace(false)
1639 ConfigParserData& m_data;
1640 ConfigParserData::Feature m_feature;
1641 ConfigParserData::Privilege m_privilege;
1642 bool m_properNamespace;
1645 class CategoryParser : public ElementParser
1648 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1649 const DPL::String& /*name*/)
1651 return &IgnoringParser::Create;
1654 virtual void Accept(const XmlAttribute& attribute)
1656 if (attribute.name == L"name") {
1657 if (attribute.value.size() > 0) {
1658 m_name = attribute.value;
1663 virtual void Accept(const Element& /*element*/)
1666 virtual void Accept(const Text& /*text*/)
1669 virtual void Verify()
1671 if (m_name.IsNull()) {
1673 "name attribute of category element is mandatory - ignoring");
1677 if (m_data.categoryList.find(*m_name) ==
1678 m_data.categoryList.end())
1680 m_data.categoryList.insert(*m_name);
1684 explicit CategoryParser(ConfigParserData& data) :
1689 DPL::OptionalString m_name;
1690 ConfigParserData& m_data;
1693 class AppWidgetParser : public ElementParser
1697 struct BoxLabelParser : public ElementParser
1699 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1700 const DPL::String& /*name*/)
1702 return &IgnoringParser::Create;
1705 virtual void Accept(const XmlAttribute& /*attribute*/)
1708 virtual void Accept(const Element& element)
1711 ConfigurationNamespace::TizenWebAppNamespaceName)
1713 m_properNamespace = true;
1717 virtual void Accept(const Text& text)
1719 if (m_properNamespace) {
1720 m_label = text.value;
1724 virtual void Verify()
1726 m_data.m_label = m_label;
1729 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1731 m_properNamespace(false),
1736 DPL::String m_label;
1737 bool m_properNamespace;
1738 ConfigParserData::LiveboxInfo& m_data;
1741 struct BoxIconParser : public ElementParser
1743 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1744 const DPL::String& /*name*/)
1746 return &IgnoringParser::Create;
1749 virtual void Accept(const XmlAttribute& attribute)
1751 if (m_properNamespace) {
1752 if (attribute.name == L"src") {
1753 m_icon = attribute.value;
1758 virtual void Accept(const Element& element)
1761 ConfigurationNamespace::TizenWebAppNamespaceName)
1763 m_properNamespace = true;
1767 virtual void Accept(const Text& /*text*/)
1770 virtual void Verify()
1772 m_data.m_icon = m_icon;
1775 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1777 m_properNamespace(false),
1783 bool m_properNamespace;
1784 ConfigParserData::LiveboxInfo& m_data;
1787 struct BoxContentParser : public ElementParser
1789 struct BoxSizeParser : public ElementParser
1791 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1792 const DPL::String& /*name*/)
1794 return &IgnoringParser::Create;
1797 virtual void Accept(const XmlAttribute& attribute)
1799 if (m_properNamespace) {
1800 if (attribute.name == L"preview") {
1801 m_preview = attribute.value;
1806 virtual void Accept(const Element& element)
1809 ConfigurationNamespace::TizenWebAppNamespaceName)
1811 m_properNamespace = true;
1815 virtual void Accept(const Text& text)
1817 if (m_properNamespace) {
1818 m_size = text.value;
1822 virtual void Verify()
1824 std::pair<DPL::String, DPL::String> boxSize;
1825 boxSize.first = m_size;
1826 boxSize.second = m_preview;
1827 m_data.m_boxSize.push_back(boxSize);
1830 explicit BoxSizeParser(
1831 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1833 m_properNamespace(false),
1839 DPL::String m_preview;
1840 bool m_properNamespace;
1841 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1844 struct PdParser : public ElementParser
1846 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1847 const DPL::String& /*name*/)
1849 return &IgnoringParser::Create;
1852 virtual void Accept(const XmlAttribute& attribute)
1854 if (m_properNamespace) {
1855 if (attribute.name == L"src") {
1856 m_src = attribute.value;
1857 } else if (attribute.name == L"width") {
1858 m_width = attribute.value;
1859 } else if (attribute.name == L"height") {
1860 m_height = attribute.value;
1865 virtual void Accept(const Element& element)
1868 ConfigurationNamespace::TizenWebAppNamespaceName)
1870 m_properNamespace = true;
1874 virtual void Accept(const Text& /*text*/)
1877 virtual void Verify()
1879 m_data.m_pdSrc = m_src;
1880 m_data.m_pdWidth = m_width;
1881 m_data.m_pdHeight = m_height;
1885 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1887 m_properNamespace(false),
1893 DPL::String m_width;
1894 DPL::String m_height;
1896 bool m_properNamespace;
1897 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1900 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1901 const DPL::String& name)
1903 if (name == L"box-size") {
1904 return DPL::MakeDelegate(
1906 &AppWidgetParser::BoxContentParser::
1908 } else if (name == L"pd") {
1909 return DPL::MakeDelegate(
1911 &AppWidgetParser::BoxContentParser::
1914 ThrowMsg(Exception::ParseError,
1915 "No element parser for name: " << name);
1919 virtual void Accept(const XmlAttribute& attribute)
1921 if (m_properNamespace) {
1922 if (attribute.name == L"src") {
1923 m_box.m_boxSrc = attribute.value;
1925 if (attribute.name == L"mouse-event") {
1926 m_box.m_boxMouseEvent = attribute.value;
1928 if (attribute.name == L"touch-effect") {
1929 m_box.m_boxTouchEffect = attribute.value;
1934 virtual void Accept(const Element& element)
1937 ConfigurationNamespace::TizenWebAppNamespaceName)
1939 m_properNamespace = true;
1943 virtual void Accept(const Text& /*text*/)
1946 virtual void Verify()
1948 m_data.m_boxInfo = m_box;
1951 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1953 m_properNamespace(false),
1957 ElementParserPtr OnBoxSizeElement()
1959 return ElementParserPtr(new BoxSizeParser(m_box));
1962 ElementParserPtr OnPdElement()
1964 return ElementParserPtr(new PdParser(m_box));
1969 bool m_properNamespace;
1970 ConfigParserData::LiveboxInfo& m_data;
1971 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1974 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1975 const DPL::String& name)
1977 if (name == L"box-label") {
1978 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1979 } else if (name == L"box-icon") {
1980 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1981 } else if (name == L"box-content") {
1982 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1984 return &IgnoringParser::Create;
1988 virtual void Accept(const XmlAttribute& attribute)
1990 if (m_properNamespace) {
1991 if (attribute.name == L"id") {
1992 m_liveboxId = attribute.value;
1993 } else if (attribute.name == L"primary") {
1994 m_primary = attribute.value;
1995 } else if (attribute.name == L"auto-launch") {
1996 m_autoLaunch = attribute.value;
1997 } else if (attribute.name == L"update-period") {
1998 m_updatePeriod = attribute.value;
1999 } else if (attribute.name == L"type") {
2000 m_type = attribute.value;
2005 virtual void Accept(const Element& element)
2008 ConfigurationNamespace::TizenWebAppNamespaceName)
2010 m_properNamespace = true;
2014 virtual void Accept(const Text& /*text*/)
2017 virtual void Verify()
2019 m_livebox.m_liveboxId = m_liveboxId;
2020 m_livebox.m_primary = m_primary;
2021 m_livebox.m_autoLaunch = m_autoLaunch;
2022 m_livebox.m_updatePeriod = m_updatePeriod;
2023 m_livebox.m_type = m_type;
2025 m_data.m_livebox.push_back(m_livebox);
2028 explicit AppWidgetParser(ConfigParserData& data) :
2031 m_properNamespace(false)
2033 m_livebox = ConfigParserData::LiveboxInfo();
2036 ElementParserPtr OnBoxLabelElement()
2038 return ElementParserPtr(new BoxLabelParser(m_livebox));
2041 ElementParserPtr OnBoxIconElement()
2043 return ElementParserPtr(new BoxIconParser(m_livebox));
2046 ElementParserPtr OnBoxContentElement()
2048 return ElementParserPtr(new BoxContentParser(m_livebox));
2052 ConfigParserData& m_data;
2053 ConfigParserData::LiveboxInfo m_livebox;
2054 DPL::String m_liveboxId;
2055 DPL::String m_primary;
2056 DPL::String m_autoLaunch;
2057 DPL::String m_updatePeriod;
2059 bool m_properNamespace;
2062 class CspParser : public ElementParser
2065 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2066 const DPL::String& /*name*/)
2068 return &IgnoringParser::Create;
2071 CspParser(ConfigParserData& data) :
2074 m_properNamespace(false)
2077 virtual void Accept(const Element& element)
2079 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2080 m_properNamespace = true;
2084 virtual void Accept(const XmlAttribute& /*attribute*/)
2087 virtual void Accept(const Text& text)
2089 if (m_properNamespace) {
2090 m_policy = text.value;
2094 virtual void Verify()
2096 if (!m_policy.IsNull()) {
2097 m_data.cspPolicy = *m_policy;
2102 ConfigParserData& m_data;
2103 bool m_properNamespace;
2104 DPL::OptionalString m_policy;
2107 class CspReportOnlyParser : public ElementParser
2110 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2111 const DPL::String& /*name*/)
2113 return &IgnoringParser::Create;
2116 CspReportOnlyParser(ConfigParserData& data) :
2119 m_properNamespace(false)
2122 virtual void Accept(const Element& element)
2124 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2125 m_properNamespace = true;
2129 virtual void Accept(const XmlAttribute& /*attribute*/)
2132 virtual void Accept(const Text& text)
2134 if (m_properNamespace) {
2135 m_policy = text.value;
2139 virtual void Verify()
2141 if (!m_policy.IsNull()) {
2142 m_data.cspPolicyReportOnly = *m_policy;
2147 ConfigParserData& m_data;
2148 bool m_properNamespace;
2149 DPL::OptionalString m_policy;
2152 class AccountParser : public ElementParser
2155 struct AccountProviderParser : public ElementParser
2159 struct IconParser : public ElementParser
2162 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2163 const DPL::String& /*name*/)
2165 return &IgnoringParser::Create;
2168 virtual void Accept(const Text& text)
2170 if (text.value == L"") {
2173 m_value = text.value;
2176 virtual void Accept(const Element& /*element*/)
2179 virtual void Accept(const XmlAttribute& attribute)
2181 if (attribute.name == L"section") {
2182 if (attribute.value == L"account") {
2183 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2184 } else if (attribute.value == L"account-small") {
2185 m_type = ConfigParserData::IconSectionType::SmallIcon;
2190 virtual void Verify()
2192 if (m_value.IsNull() || *m_value == L"") {
2196 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2197 icon.first = m_type;
2198 icon.second = *m_value;
2200 m_data.m_iconSet.insert(icon);
2203 IconParser(ConfigParserData::AccountProvider& data) :
2205 m_properNamespace(false),
2206 m_type(ConfigParserData::DefaultIcon),
2211 bool m_properNamespace;
2212 ConfigParserData::IconSectionType m_type;
2213 ConfigParserData::AccountProvider& m_data;
2214 DPL::OptionalString m_value;
2217 struct DisplayNameParser : public ElementParser
2220 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2221 const DPL::String& /*name*/)
2223 return &IgnoringParser::Create;
2226 virtual void Accept(const Text& text)
2228 if (text.value == L"") {
2231 m_value = text.value;
2234 virtual void Accept(const Element& element)
2236 m_lang = element.lang;
2240 virtual void Accept(const XmlAttribute& /*attribute*/)
2243 virtual void Verify()
2245 if (m_value.IsNull() || *m_value == L"") {
2249 std::pair<DPL::String, DPL::String> name;
2250 name.first = *m_lang;
2251 name.second = *m_value;
2253 m_data.m_displayNameSet.insert(name);
2256 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2258 m_properNamespace(false),
2263 bool m_properNamespace;
2264 DPL::OptionalString m_lang;
2265 DPL::OptionalString m_value;
2266 ConfigParserData::AccountProvider& m_data;
2269 struct CapabilityParser : public ElementParser
2272 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2273 const DPL::String& /*name*/)
2275 return &IgnoringParser::Create;
2278 virtual void Accept(const Text& text)
2280 if (text.value == L"") {
2283 m_value = text.value;
2286 virtual void Accept(const Element& /*element*/)
2289 virtual void Accept(const XmlAttribute& /*attribute*/)
2292 virtual void Verify()
2294 if (m_value.IsNull() || *m_value == L"") {
2297 m_data.m_capabilityList.push_back(*m_value);
2300 CapabilityParser(ConfigParserData::AccountProvider& data) :
2302 m_properNamespace(false),
2307 bool m_properNamespace;
2308 DPL::OptionalString m_value;
2309 ConfigParserData::AccountProvider& m_data;
2311 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2312 const DPL::String& name)
2314 if (name == L"icon") {
2315 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2316 } else if (name == L"display-name") {
2317 return DPL::MakeDelegate(this,
2318 &AccountProviderParser::OnDisplayNameElement);
2319 } else if (name == L"capability") {
2320 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2322 return &IgnoringParser::Create;
2326 virtual void Accept(const Text& /*text*/)
2329 virtual void Accept(const Element& /*element*/)
2332 virtual void Accept(const XmlAttribute& attribute)
2334 if (attribute.name == L"multiple-accounts-support") {
2335 if (attribute.value == L"") {
2339 if (attribute.value == L"ture") {
2340 m_multiSupport = true;
2345 virtual void Verify()
2347 m_data.m_multiAccountSupport = m_multiSupport;
2350 ElementParserPtr OnIconElement()
2352 return ElementParserPtr(new IconParser(m_data));
2355 ElementParserPtr OnDisplayNameElement()
2357 return ElementParserPtr(new DisplayNameParser(m_data));
2360 ElementParserPtr OnCapabilityElement()
2362 return ElementParserPtr(new CapabilityParser(m_data));
2365 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2367 m_properNamespace(false),
2368 m_multiSupport(false),
2373 bool m_properNamespace;
2374 bool m_multiSupport;
2375 ConfigParserData::AccountProvider& m_data;
2378 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2379 const DPL::String& name)
2381 if (name == L"account-provider") {
2382 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2384 return &IgnoringParser::Create;
2388 virtual void Accept(const Element& element)
2390 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2391 m_properNamespace = true;
2395 virtual void Accept(const XmlAttribute& /*attribute*/)
2398 virtual void Accept(const Text& /*text*/)
2401 virtual void Verify()
2404 ElementParserPtr OnProviderElement()
2406 return ElementParserPtr(new AccountProviderParser(m_account));
2409 AccountParser(ConfigParserData& data) :
2412 m_account(data.accountProvider),
2413 m_properNamespace(false),
2414 m_multiSupport(false)
2418 ConfigParserData& m_data;
2419 ConfigParserData::AccountProvider& m_account;
2420 bool m_properNamespace;
2421 bool m_multiSupport;
2424 ElementParser::ActionFunc WidgetParser::GetElementParser(
2425 const DPL::String& /*ns*/,
2429 FuncMap::const_iterator it = m_map.find(name);
2430 if (it != m_map.end()) {
2433 return &IgnoringParser::Create;
2437 WidgetParser::WidgetParser(ConfigParserData& data) :
2439 m_textDirection(Unicode::EMPTY)
2441 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2442 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2443 m_map[L"description"] =
2444 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2445 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2447 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2448 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2450 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2451 m_map[L"preference"] =
2452 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2453 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2455 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2456 // TODO: appservice will be removed
2457 m_map[L"appservice"] = DPL::MakeDelegate(this,
2458 &WidgetParser::OnAppServiceElement);
2459 m_map[L"application"] = DPL::MakeDelegate(
2462 OnApplicationElement);
2463 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2464 m_map[L"background"] = DPL::MakeDelegate(this,
2465 &WidgetParser::OnBackgroundElement);
2466 m_map[L"privilege"] = DPL::MakeDelegate(this,
2467 &WidgetParser::OnPrivilegeElement);
2468 m_map[L"app-control"] = DPL::MakeDelegate(
2471 OnAppControlElement);
2472 m_map[L"category"] = DPL::MakeDelegate(this,
2473 &WidgetParser::OnCategoryElement);
2474 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2476 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2480 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2483 OnCspReportOnlyElement);
2485 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2488 ElementParserPtr WidgetParser::OnNameElement()
2490 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2493 ElementParserPtr WidgetParser::OnAccessElement()
2495 return ElementParserPtr(new AccessParser(m_data));
2498 ElementParserPtr WidgetParser::OnDescriptionElement()
2500 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2503 ElementParserPtr WidgetParser::OnAuthorElement()
2505 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2508 ElementParserPtr WidgetParser::OnLicenseElement()
2510 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2513 ElementParserPtr WidgetParser::OnIconElement()
2515 return ElementParserPtr(new IconParser(m_data));
2518 ElementParserPtr WidgetParser::OnContentElement()
2520 return ElementParserPtr(new ContentParser(m_data));
2523 ElementParserPtr WidgetParser::OnPreferenceElement()
2525 return ElementParserPtr(new PreferenceParser(m_data));
2528 ElementParserPtr WidgetParser::OnLinkElement()
2530 return ElementParserPtr(new LinkParser(m_data));
2533 ElementParserPtr WidgetParser::OnSettingElement()
2535 return ElementParserPtr(new SettingParser(m_data));
2538 ElementParserPtr WidgetParser::OnApplicationElement()
2540 return ElementParserPtr(new ApplicationParser(m_data));
2543 ElementParserPtr WidgetParser::OnSplashElement()
2545 return ElementParserPtr(new SplashParser(m_data));
2548 ElementParserPtr WidgetParser::OnBackgroundElement()
2550 return ElementParserPtr(new BackgroundParser(m_data));
2553 ElementParserPtr WidgetParser::OnPrivilegeElement()
2555 return ElementParserPtr(new PrivilegeParser(m_data));
2558 ElementParserPtr WidgetParser::OnAppServiceElement()
2560 return ElementParserPtr(new AppServiceParser(m_data));
2563 ElementParserPtr WidgetParser::OnAppControlElement()
2565 return ElementParserPtr(new AppControlParser(m_data));
2568 ElementParserPtr WidgetParser::OnCategoryElement()
2570 return ElementParserPtr(new CategoryParser(m_data));
2573 ElementParserPtr WidgetParser::OnAppWidgetElement()
2575 return ElementParserPtr(new AppWidgetParser(m_data));
2578 ElementParserPtr WidgetParser::OnCspElement()
2580 return ElementParserPtr(new CspParser(m_data));
2583 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2585 return ElementParserPtr(new CspReportOnlyParser(m_data));
2588 ElementParserPtr WidgetParser::OnAccountElement()
2590 return ElementParserPtr(new AccountParser(m_data));
2593 void WidgetParser::Accept(const Element& element)
2595 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2596 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2598 ThrowMsg(Exception::ParseError,
2599 "Wrong xml namespace for widget element");
2603 void WidgetParser::Accept(const Text& /*text*/)
2605 ThrowMsg(Exception::ParseError, "widged element must be empty");
2608 void WidgetParser::Accept(const XmlAttribute& attribute)
2610 if (attribute.name == L"id") {
2611 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2612 //If may important tests starts to fail this test we will have
2613 //to consider commenting this test out again.
2614 if (iri.Validate()) {
2615 m_data.widget_id = attribute.value;
2616 NormalizeString(m_data.widget_id);
2618 LogWarning("Widget id validation failed: " << attribute.value);
2620 } else if (attribute.name == L"version") {
2621 m_version = attribute.value;
2622 NormalizeString(m_version);
2623 } else if (attribute.name == L"min-version") {
2624 LogInfo("min-version attribute was found. Value: " << attribute.value);
2625 m_minVersion = attribute.value;
2626 NormalizeString(m_minVersion);
2627 m_data.minVersionRequired = m_minVersion;
2628 } else if (attribute.name == L"height") {
2629 DPL::OptionalString value = attribute.value;
2630 NormalizeString(value);
2631 std::string v = DPL::ToUTF8String(*value);
2634 unsigned char c = v.c_str()[0];
2635 if (c >= '0' && c <= '9') {
2637 for (size_t i = 0; i < v.size(); ++i) {
2639 if (c >= '0' && c <= '9') {
2646 m_data.height = val;
2649 } else if (attribute.name == L"width") {
2650 DPL::OptionalString value = attribute.value;
2651 NormalizeString(value);
2652 std::string v = DPL::ToUTF8String(*value);
2655 unsigned char c = v.c_str()[0];
2656 if (c >= '0' && c <= '9') {
2658 for (size_t i = 0; i < v.size(); ++i) {
2660 if (c >= '0' && c <= '9') {
2670 } else if (attribute.name == L"viewmodes") {
2671 DPL::Tokenize(attribute.value,
2673 std::inserter(m_windowModes,
2674 m_windowModes.end()),
2676 } else if (attribute.name == L"dir") {
2677 m_textDirection = Unicode::ParseDirAttribute(attribute);
2678 } else if (L"defaultlocale" == attribute.name) {
2679 if (!m_defaultlocale) {
2680 m_defaultlocale = attribute.value;
2681 NormalizeString(m_defaultlocale);
2682 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2683 DPL::ToUTF8String(*m_defaultlocale)))
2685 LogWarning("Language tag: " <<
2686 m_defaultlocale << " is not valid");
2687 m_defaultlocale = DPL::OptionalString::Null;
2689 LogDebug("Default Locale Found " << m_defaultlocale);
2692 LogWarning("Ignoring subsequent default locale");
2695 //Any other value consider as a namespace definition
2696 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2697 LogInfo("Namespace domain: " << attribute.name);
2698 LogInfo("Namespace value: " << attribute.value);
2699 m_nameSpaces[attribute.name] = attribute.value;
2701 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2702 ", name=" << attribute.name <<
2703 ", value=" << attribute.value);
2707 void WidgetParser::Verify()
2709 FOREACH(mode, m_windowModes) {
2710 if (L"windowed" == *mode || L"floating" == *mode ||
2711 L"fullscreen" == *mode || L"maximized" == *mode ||
2712 L"minimized" == *mode)
2714 m_data.windowModes.insert(*mode);
2717 if (!m_version.IsNull()) {
2718 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2719 m_data.version = m_version;
2721 m_data.defaultlocale = m_defaultlocale;
2722 FOREACH(ns, m_nameSpaces) {
2723 m_data.nameSpaces.insert(ns->second);