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)
28 #include <widget_parser.h>
29 #include "ignoring_parser.h"
30 #include "deny_all_parser.h"
31 #include <dpl/wrt-dao-ro/config_parser_data.h>
32 #include "libiriwrapper.h"
33 #include "wrt-commons/i18n-dao-ro/i18n_dao_read_only.h"
34 #include <dpl/utils/warp_iri.h>
35 #include <dpl/utils/mime_type_utils.h>
36 #include <language_subtag_rst_tree.h>
47 #include <boost/optional.hpp>
49 #include <dpl/foreach.h>
50 #include <dpl/platform.h>
51 #include <dpl/utils/warp_iri.h>
52 #include <dpl/utils/mime_type_utils.h>
53 #include <dpl/wrt-dao-ro/config_parser_data.h>
57 #include <deny_all_parser.h>
58 #include <ignoring_parser.h>
59 #include <installer_log.h>
60 #include <language_subtag_rst_tree.h>
61 #include <libiriwrapper.h>
63 using namespace WrtDB;
66 static const DPL::String UTF_LRE = L"\x0202a";
67 static const DPL::String UTF_LRO = L"\x0202d";
68 static const DPL::String UTF_RLE = L"\x0202b";
69 static const DPL::String UTF_RLO = L"\x0202e";
70 static const DPL::String UTF_PDF = L"\x0202c";
72 Direction ParseDirAttribute(const XmlAttribute& attribute)
74 Assert(L"dir" == attribute.name);
75 if (L"ltr" == attribute.value) {
77 } else if (L"rtl" == attribute.value) {
79 } else if (L"lro" == attribute.value) {
81 } else if (L"rlo" == attribute.value) {
84 _W("dir attribute has wrong value: %ls ", attribute.value.c_str());
89 void UpdateTextWithDirectionMark(Direction direction,
95 *text = UTF_RLO + *text + UTF_PDF;
98 *text = UTF_RLE + *text + UTF_PDF;
101 *text = UTF_LRE + *text + UTF_PDF;
104 *text = UTF_LRO + *text + UTF_PDF;
113 } // namespace Unicode
115 class InnerElementsParser : public ElementParser
118 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
119 const DPL::String& /*name*/)
121 return std::bind(&InnerElementsParser::Other, this);
124 virtual void Accept(const Element& /*element*/)
127 virtual void Accept(const Text& text)
132 m_text->value += text.value;
136 virtual void Accept(const XmlAttribute& attribute)
138 if (attribute.name == L"dir") {
139 m_textDirection = Unicode::ParseDirAttribute(attribute);
143 virtual void Verify()
146 Unicode::UpdateTextWithDirectionMark(m_textDirection,
148 m_parentParser->Accept(*m_text);
152 InnerElementsParser(ElementParserPtr parent) :
153 m_parentParser(parent),
154 m_textDirection(Unicode::EMPTY)
157 ElementParserPtr Other()
159 return ElementParserPtr(new InnerElementsParser(
160 std::static_pointer_cast<ElementParser>(
161 shared_from_this())));
165 boost::optional<Text> m_text;
166 ElementParserPtr m_parentParser;
167 Unicode::Direction m_textDirection;
170 class NameParser : public ElementParser
173 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
174 const DPL::String& /*name*/)
176 return std::bind(&NameParser::Other, this);
179 virtual void Accept(const Element& element)
181 m_lang = element.lang;
185 virtual void Accept(const Text& text)
190 *m_name += text.value;
194 virtual void Accept(const XmlAttribute& attribute)
196 if (attribute.name == L"short") {
198 m_shortName = attribute.value;
200 } else if (attribute.name == L"dir") {
201 m_textDirection = Unicode::ParseDirAttribute(attribute);
205 virtual void Verify()
207 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
209 NormalizeString(m_name);
210 NormalizeString(m_shortName);
212 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
216 Unicode::UpdateTextWithDirectionMark(m_textDirection,
219 data.shortName = m_shortName;
223 NameParser(Unicode::Direction direction,
224 ConfigParserData& data) :
226 m_textDirection(direction)
229 ElementParserPtr Other()
231 return ElementParserPtr(new InnerElementsParser(
232 std::static_pointer_cast<ElementParser>(
233 shared_from_this())));
237 ConfigParserData& m_data;
238 DPL::OptionalString m_name;
239 DPL::OptionalString m_shortName;
240 DPL::OptionalString m_dir;
242 Unicode::Direction m_textDirection;
245 class AccessParser : public ElementParser
254 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
255 const DPL::String& /*name*/)
257 return std::bind(&AccessParser::Other, this);
260 virtual void Accept(const Element& element)
262 // for tizen web apps WARP should be used
263 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
264 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
266 m_standardType = STANDARD_TYPE_WARP;
270 virtual void Accept(const Text& /*text*/)
273 void AcceptWac(const XmlAttribute& attribute)
275 if (attribute.name == L"origin") {
276 m_strIRIOrigin = attribute.value;
277 NormalizeString(m_strIRIOrigin);
278 } else if (attribute.name == L"subdomains") {
279 DPL::String normalizedValue = attribute.value;
280 NormalizeString(normalizedValue);
282 if (normalizedValue == L"true") {
283 m_bSubDomainAccess = true;
284 } else if (normalizedValue == L"false") {
285 m_bSubDomainAccess = false;
290 virtual void Accept(const XmlAttribute& attribute)
292 switch (m_standardType) {
293 case STANDARD_TYPE_WARP:
294 AcceptWac(attribute);
297 _E("Error in Access tag - unknown standard.");
305 iri.set(m_strIRIOrigin, false);
307 if (!iri.isAccessDefinition()) {
308 _W("Access list element: %ls is not acceptable by WARP standard and will be ignored!",
309 m_strIRIOrigin.c_str());
313 if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains
315 m_bSubDomainAccess = true;
318 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
320 //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
321 m_data.accessInfoSet.insert(accessInfo);
324 virtual void Verify()
326 switch (m_standardType) {
327 case STANDARD_TYPE_WARP:
331 _E("Error in Access tag - unknown standard.");
336 AccessParser(ConfigParserData& data) :
338 m_bSubDomainAccess(false),
339 m_standardType(STANDARD_TYPE_NONE),
344 ElementParserPtr Other()
346 return ElementParserPtr(new InnerElementsParser(
347 ElementParserPtr(shared_from_this())));
351 DPL::String m_strIRIOrigin;
352 bool m_bSubDomainAccess;
353 StandardType m_standardType;
355 ConfigParserData& m_data;
358 class DescriptionParser : public ElementParser
361 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
362 const DPL::String& /*name*/)
364 return std::bind(&DescriptionParser::Other, this);
367 virtual void Accept(const Element& element)
369 m_lang = element.lang;
373 ElementParserPtr Other()
375 return ElementParserPtr(new InnerElementsParser(
376 std::static_pointer_cast<ElementParser>(
377 shared_from_this())));
380 virtual void Accept(const Text& text)
382 if (!m_description) {
383 m_description = text.value;
385 *m_description += text.value;
389 virtual void Accept(const XmlAttribute& attribute)
391 if (attribute.name == L"dir") {
392 m_textDirection = Unicode::ParseDirAttribute(attribute);
396 virtual void Verify()
398 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
399 if (!data.description) {
400 if (!!m_description) {
401 Unicode::UpdateTextWithDirectionMark(m_textDirection,
404 data.description = m_description;
408 DescriptionParser(Unicode::Direction direction,
409 ConfigParserData& data) :
413 m_textDirection(direction)
417 ConfigParserData& m_data;
419 DPL::OptionalString m_description;
420 Unicode::Direction m_textDirection;
423 class AuthorParser : public ElementParser
426 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
427 const DPL::String& /*name*/)
429 return std::bind(&AuthorParser::Other, this);
432 AuthorParser(Unicode::Direction direction,
433 ConfigParserData& data) :
435 m_textDirection(direction)
438 virtual void Accept(const Element& /*element*/)
443 virtual void Accept(const Text& text)
445 *(m_authorName) += text.value;
448 virtual void Accept(const XmlAttribute& attribute)
450 if (attribute.name == L"href") {
451 //Validate href IRI and ignore it if invalid
452 //See also test: ta-argMozRiC-an
453 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
454 if (iri.Validate()) {
455 m_authorHref = attribute.value;
457 } else if (attribute.name == L"email") {
458 m_authorEmail = attribute.value;
459 } else if (attribute.name == L"dir") {
460 m_textDirection = Unicode::ParseDirAttribute(attribute);
464 virtual void Verify()
466 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
467 NormalizeString(m_authorName);
468 NormalizeString(m_authorHref);
469 NormalizeString(m_authorEmail);
470 if (!!m_authorName) {
471 Unicode::UpdateTextWithDirectionMark(m_textDirection,
473 m_data.authorName = m_authorName;
475 if (!!m_authorHref) {
476 m_data.authorHref = m_authorHref;
478 if (!!m_authorEmail) {
479 m_data.authorEmail = m_authorEmail;
484 ElementParserPtr Other()
486 return ElementParserPtr(new InnerElementsParser(
487 std::static_pointer_cast<ElementParser>(
488 shared_from_this())));
492 ConfigParserData& m_data;
493 DPL::OptionalString m_authorEmail;
494 DPL::OptionalString m_authorHref;
495 DPL::OptionalString m_authorName;
496 Unicode::Direction m_textDirection;
499 class LicenseParser : public ElementParser
502 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
503 const DPL::String& /*name*/)
505 return std::bind(&LicenseParser::Other, this);
508 LicenseParser(Unicode::Direction direction,
509 ConfigParserData& data) :
512 m_textDirection(direction)
515 virtual void Accept(const Element& element)
518 m_lang = element.lang;
524 virtual void Accept(const Text& text)
527 *m_license += text.value;
531 virtual void Accept(const XmlAttribute& attribute)
534 if (attribute.name == L"href" && !m_licenseHref) {
535 m_licenseHref = attribute.value;
536 } else if (attribute.name == L"file" && !m_licenseFile) {
537 m_licenseFile = attribute.value;
538 } else if (attribute.name == L"dir") {
539 m_textDirection = Unicode::ParseDirAttribute(attribute);
544 virtual void Verify()
546 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
549 Unicode::UpdateTextWithDirectionMark(m_textDirection,
552 data.license = m_license;
553 data.licenseHref = m_licenseHref;
554 data.licenseFile = m_licenseFile;
558 ElementParserPtr Other()
560 return ElementParserPtr(new InnerElementsParser(
561 ElementParserPtr(shared_from_this())));
565 ConfigParserData& m_data;
569 DPL::OptionalString m_license;
570 DPL::OptionalString m_licenseFile;
571 DPL::OptionalString m_licenseHref;
572 Unicode::Direction m_textDirection;
575 class IconParser : public ElementParser
577 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
580 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
581 const DPL::String& /*name*/)
583 return &IgnoringParser::Create; //ignore unknown according to w3c
586 IconParser(ConfigParserData& data) : ElementParser(),
587 m_data(data), m_isSmall(false)
590 IconParser(ConfigParserData& data, bool isSmall) : ElementParser(),
591 m_data(data), m_isSmall(isSmall)
594 virtual void Accept(const Element& /*element*/) { }
596 virtual void Accept(const XmlAttribute& attribute)
598 if (attribute.name == L"src") {
599 if (attribute.value.size() > 0) {
600 m_src = attribute.value;
602 } else if (attribute.name == L"width") {
603 m_width = ParseSizeAttributeValue(attribute.value);
604 } else if (attribute.name == L"height") {
605 m_height = ParseSizeAttributeValue(attribute.value);
609 virtual void Accept(const Text& /*text*/)
611 ThrowMsg(Exception::ParseError, "Icon element must be empty");
614 virtual void Verify()
617 _W("src attribute of icon element is mandatory - ignoring");
623 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
624 icon.width = m_width;
625 icon.height = m_height;
626 icon.isSmall = m_isSmall;
628 ConfigParserData::IconsList::iterator it = std::find(
629 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
630 if (it == m_data.iconsList.end()) {
631 m_data.iconsList.push_front(icon);
636 _W("src attribute is invalid: %ls", (*m_src).c_str());
641 ConfigParserData& m_data;
642 DPL::OptionalString m_src;
643 DPL::OptionalInt m_width;
644 DPL::OptionalInt m_height;
647 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
649 DPL::OptionalString normalizedValue = value;
650 NormalizeString(normalizedValue);
651 if (!(*normalizedValue).empty()) {
655 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
657 std::string(reterr) == DPL::ToUTF8String(value) ||
660 return DPL::OptionalInt();
665 return DPL::OptionalInt();
669 * @brief delocalizePath removes locales folder from relative path if
671 * @param source source string
673 * @throw BadSrcError if string is bad value of src attribute
675 * @return corrected string
677 static DPL::String delocalizeSrcPath(const DPL::String & source)
679 static const DPL::String localeFolder(L"locales/");
680 static const int index = localeFolder.size();
682 DPL::String result = source;
684 if (source.substr(0, index) == localeFolder) {
685 size_t pos = result.find_first_of('/', index);
686 if (pos != std::string::npos && pos + 1 < source.size()) {
687 result = result.substr(pos + 1, source.size());
696 class ContentParser : public ElementParser
699 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
700 const DPL::String& /*name*/)
702 return &IgnoringParser::Create; //ignore unknown according to w3c
705 ContentParser(ConfigParserData& data) :
710 virtual void Accept(const Element& element)
712 m_namespace = element.ns;
715 virtual void Accept(const Text& /*text*/)
718 virtual void Accept(const XmlAttribute& attribute)
720 DPL::String value = attribute.value;
721 NormalizeString(value);
723 if (attribute.name == L"src") {
725 } else if (attribute.name == L"type") {
727 MimeTypeUtils::MimeAttributes mimeAttributes =
728 MimeTypeUtils::getMimeAttributes(value);
729 if ((mimeAttributes.count(L"charset") > 0) && !m_encoding)
731 m_encoding = mimeAttributes[L"charset"];
733 } else if (attribute.name == L"encoding") {
734 if (!value.empty()) {
740 virtual void Verify()
742 if(!!m_data.startFileEncountered)
744 if(m_data.startFileNamespace == m_namespace
745 || m_namespace != ConfigurationNamespace::TizenWebAppNamespaceName)
749 //else continue -> if previous item was not in tizen namespace
752 m_data.startFileEncountered = true;
753 m_data.startFileNamespace = m_namespace;
755 if (m_namespace == ConfigurationNamespace::TizenWebAppNamespaceName &&
756 (!m_src || m_src->empty())) {
757 ThrowMsg(Exception::ParseError, "content element must have correct src element");
761 m_data.startFile = m_src;
762 m_data.startFileContentType = m_type;
764 m_data.startFileEncoding = m_encoding;
766 m_data.startFileEncoding = L"UTF-8";
772 DPL::OptionalString m_src;
773 DPL::OptionalString m_type;
774 DPL::OptionalString m_encoding;
775 ConfigParserData& m_data;
776 DPL::String m_namespace;
779 class PreferenceParser : public ElementParser
782 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
783 const DPL::String& /*name*/)
785 return &IgnoringParser::Create; //ignore unknown according to w3c
788 virtual void Accept(const XmlAttribute& attribute)
790 if (attribute.name == L"name") {
791 m_name = attribute.value;
792 } else if (attribute.name == L"value") {
793 m_value = attribute.value;
794 } else if (attribute.name == L"readonly") {
795 if (attribute.value == L"true") {
803 virtual void Accept(const Element& /*element*/)
806 virtual void Accept(const Text& /*text*/)
808 ThrowMsg(Exception::ParseError, "param element must be empty");
811 virtual void Verify()
814 _W("preference element must have name attribute");
817 NormalizeString(m_name);
818 NormalizeString(m_value);
819 ConfigParserData::Preference preference(*m_name, m_required);
820 preference.value = m_value;
821 if (m_data.preferencesList.find(preference) ==
822 m_data.preferencesList.end())
824 m_data.preferencesList.insert(preference);
828 PreferenceParser(ConfigParserData& data) :
835 DPL::OptionalString m_name;
836 DPL::OptionalString m_value;
838 ConfigParserData& m_data;
841 class SettingParser : public ElementParser
844 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
845 const DPL::String& /*name*/)
847 return &IgnoringParser::Create; //ignore unknown according to w3c
850 virtual void Accept(const Text& /*text*/)
853 virtual void Accept(const Element& /*element*/)
856 virtual void Accept(const XmlAttribute& attribute)
858 m_setting.m_name = attribute.name;
859 m_setting.m_value = attribute.value;
860 m_data.settingsList.insert(m_setting);
863 virtual void Verify()
866 SettingParser(ConfigParserData& data) :
873 ConfigParserData& m_data;
874 ConfigParserData::Setting m_setting;
877 class AppControlParser : public ElementParser
880 struct SourceParser : public ElementParser
883 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
884 const DPL::String& /*name*/)
886 return &IgnoringParser::Create; //ignore unknown according to w3c
889 virtual void Accept(const Text& /*text*/)
892 virtual void Accept(const Element& /*element*/)
895 virtual void Accept(const XmlAttribute& attribute)
897 if (attribute.name == L"name") {
898 if (attribute.value.size() > 0) {
899 m_value = attribute.value;
900 NormalizeString(m_value);
905 virtual void Verify()
907 if (!m_value || *m_value == L"") {
911 m_data.m_src = *m_value;
914 SourceParser(ConfigParserData::AppControlInfo& data) :
916 m_properNamespace(false),
921 bool m_properNamespace;
922 DPL::OptionalString m_value;
923 ConfigParserData::AppControlInfo& m_data;
926 struct OperationParser : public ElementParser
929 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
930 const DPL::String& /*name*/)
932 return &IgnoringParser::Create; //ignore unknown according to w3c
935 virtual void Accept(const Text& /*text*/)
938 virtual void Accept(const Element& /*element*/)
941 virtual void Accept(const XmlAttribute& attribute)
943 if (attribute.name == L"name") {
944 if (attribute.value.size() > 0) {
945 m_value = attribute.value;
946 NormalizeString(m_value);
951 virtual void Verify()
953 if (!m_value || *m_value == L"") {
957 m_data.m_operation = *m_value;
960 OperationParser(ConfigParserData::AppControlInfo& data) :
962 m_properNamespace(false),
967 bool m_properNamespace;
968 DPL::OptionalString m_value;
969 ConfigParserData::AppControlInfo& m_data;
972 struct UriParser : public ElementParser
975 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
976 const DPL::String& /*name*/)
978 return &IgnoringParser::Create; //ignore unknown according to w3c
981 virtual void Accept(const Text& /*text*/)
984 virtual void Accept(const Element& /*element*/)
987 virtual void Accept(const XmlAttribute& attribute)
989 if (attribute.name == L"name") {
990 if (attribute.value.size() > 0) {
991 m_value = attribute.value;
992 NormalizeString(m_value);
997 virtual void Verify()
1000 DPL::String ignoreUri(L"file");
1002 if (!!m_value && *m_value == ignoreUri)
1004 _D("exception : '%ls' scheme will be ignored.", (*m_value).c_str());
1005 m_value = DPL::OptionalString();
1008 if (!m_value || *m_value == L"") {
1012 DPL::String wildString(L"*/*");
1013 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1014 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1016 m_data.m_uriList.insert(*m_value);
1018 _D("Ignoring uri with name %ls", (*m_value).c_str());
1022 UriParser(ConfigParserData::AppControlInfo& data) :
1024 m_properNamespace(false),
1029 bool m_properNamespace;
1030 DPL::OptionalString m_value;
1031 ConfigParserData::AppControlInfo& m_data;
1034 struct MimeParser : public ElementParser
1037 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1038 const DPL::String& /*name*/)
1040 return &IgnoringParser::Create; //ignore unknown according to w3c
1043 virtual void Accept(const Text& /*text*/)
1046 virtual void Accept(const Element& /*element*/)
1049 virtual void Accept(const XmlAttribute& attribute)
1051 if (attribute.name == L"name") {
1052 if (attribute.value.size() > 0) {
1053 m_value = attribute.value;
1054 NormalizeString(m_value);
1059 virtual void Verify()
1061 if (!m_value || *m_value == L"") {
1065 DPL::String wildString(L"*/*");
1066 if ((m_data.m_mimeList.find(wildString) ==
1067 m_data.m_mimeList.end())
1068 && (m_data.m_mimeList.find(*m_value) ==
1069 m_data.m_mimeList.end()))
1071 m_data.m_mimeList.insert(*m_value);
1073 _D("Ignoring mime with name %ls", (*m_value).c_str());
1077 MimeParser(ConfigParserData::AppControlInfo& data) :
1079 m_properNamespace(false),
1084 bool m_properNamespace;
1085 DPL::OptionalString m_value;
1086 ConfigParserData::AppControlInfo& m_data;
1089 struct DispositionParser : public ElementParser
1092 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1093 const DPL::String& /*name*/)
1095 return &IgnoringParser::Create;
1098 virtual void Accept(const Text& /*text*/)
1101 virtual void Accept(const Element& /*element*/)
1104 virtual void Accept(const XmlAttribute& attribute)
1106 if (attribute.name == L"name") {
1107 if (attribute.value.size() > 0) {
1108 m_value = attribute.value;
1109 NormalizeString(m_value);
1114 virtual void Verify()
1116 if (!m_value || *m_value == L"") {
1120 DPL::String windowString(L"window");
1121 DPL::String inlineString(L"inline");
1123 if (*m_value == L"window") {
1124 m_data.m_disposition =
1125 ConfigParserData::AppControlInfo::Disposition::WINDOW;
1126 } else if (*m_value == L"inline") {
1127 m_data.m_disposition =
1128 ConfigParserData::AppControlInfo::Disposition::INLINE;
1130 _D("Ignoring dispostion value %ls", (*m_value).c_str());
1134 DispositionParser(ConfigParserData::AppControlInfo& data) :
1136 m_properNamespace(false),
1141 bool m_properNamespace;
1142 DPL::OptionalString m_value;
1143 ConfigParserData::AppControlInfo& m_data;
1146 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1147 const DPL::String& name)
1149 if (name == L"src") {
1150 return std::bind(&AppControlParser::OnSourceElement, this);
1151 } else if (name == L"operation") {
1152 return std::bind(&AppControlParser::OnOperationElement, this);
1153 } else if (name == L"uri") {
1154 return std::bind(&AppControlParser::OnUriElement, this);
1155 } else if (name == L"mime") {
1156 return std::bind(&AppControlParser::OnMimeElement, this);
1157 } else if (name == L"disposition") {
1158 return std::bind(&AppControlParser::OnDispositionElement, this);
1160 return &IgnoringParser::Create; //ignore unknown according to w3c
1164 virtual void Accept(const XmlAttribute& /*attribute*/)
1167 virtual void Accept(const Element& element)
1169 _W("namespace for app service = %ls", element.ns.c_str());
1170 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1171 ThrowMsg(Exception::ParseError,
1172 "Wrong xml namespace for widget element");
1176 virtual void Accept(const Text& /*text*/)
1178 ThrowMsg(Exception::ParseError, "param element must be empty");
1181 virtual void Verify()
1183 if (m_appControl.m_src == L"") {
1184 ThrowMsg(Exception::ParseError, "service element must have src element");
1187 if (m_appControl.m_operation == L"") {
1188 ThrowMsg(Exception::ParseError, "service element must have operation element");
1191 auto res = std::find(m_data.appControlList.begin(), m_data.appControlList.end(), m_appControl);
1192 if(res != m_data.appControlList.end()) {
1193 ThrowMsg(Exception::ParseError, "service element must be unique");
1196 #ifdef NFC_EXCEPTION_HANDLING_FOR_TIZEN_2_2_ONLY
1197 // XXX This feature should be retained to Tizen 2.2 only.
1198 // NFC exception handling which was requested from Tizen Device API team.
1200 const DPL::String exceptionNfcOperation =
1201 L"http://tizen.org/appcontrol/operation/nfc/transaction";
1202 const DPL::String exceptionNfcUri = L"nfc://secure/aid/";
1203 const DPL::String divertingNfcUri1 = L"nfc://secure/SIM1/aid/";
1204 const DPL::String divertingNfcUri2 = L"nfc://secure/eSE/aid/";
1206 if (m_appControl.m_operation == exceptionNfcOperation
1207 && m_appControl.m_mimeList.empty()
1208 && m_appControl.m_uriList.size() == 1
1209 && (m_appControl.m_uriList.begin())->compare(0, exceptionNfcUri.length(), exceptionNfcUri) == 0)
1211 DPL::String originalUri = *m_appControl.m_uriList.begin();
1212 DPL::String newUri = originalUri;
1214 newUri.replace(0, exceptionNfcUri.length(), divertingNfcUri1);
1215 m_appControl.m_uriList.erase(m_appControl.m_uriList.begin());
1216 m_appControl.m_uriList.insert(newUri);
1217 m_data.appControlList.push_back(m_appControl);
1218 _D("NFC exception : %ls -> %ls", originalUri.c_str(), newUri.c_str());
1220 newUri = originalUri;
1221 newUri.replace(0, exceptionNfcUri.length(), divertingNfcUri2);
1222 m_appControl.m_uriList.erase(m_appControl.m_uriList.begin());
1223 m_appControl.m_uriList.insert(newUri);
1224 m_data.appControlList.push_back(m_appControl);
1225 _D("NFC exception : %ls -> %ls", originalUri.c_str(), newUri.c_str());
1229 #endif // NFC_EXCEPTION_HANDLING_FOR_TIZEN_2_2_ONLY
1231 m_data.appControlList.push_back(m_appControl);
1234 ElementParserPtr OnSourceElement()
1236 return ElementParserPtr(new SourceParser(m_appControl));
1239 ElementParserPtr OnOperationElement()
1241 return ElementParserPtr(new OperationParser(m_appControl));
1244 ElementParserPtr OnUriElement()
1246 return ElementParserPtr(new UriParser(m_appControl));
1249 ElementParserPtr OnMimeElement()
1251 return ElementParserPtr(new MimeParser(m_appControl));
1254 ElementParserPtr OnDispositionElement()
1256 return ElementParserPtr(new DispositionParser(m_appControl));
1259 AppControlParser(ConfigParserData& data) :
1266 ConfigParserData& m_data;
1267 ConfigParserData::AppControlInfo m_appControl;
1270 class ApplicationParser : public ElementParser
1273 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1274 const DPL::String& /*name*/)
1276 return &IgnoringParser::Create; //ignore unknown according to w3c
1279 virtual void Accept(const Text& /*text*/)
1281 if (m_properNamespace) {
1282 ThrowMsg(Exception::ParseError, "application element must be empty");
1286 virtual void Accept(const Element& element)
1289 ConfigurationNamespace::TizenWebAppNamespaceName)
1291 m_properNamespace = true;
1295 virtual void Accept(const XmlAttribute& attribute)
1297 if (m_properNamespace) {
1298 if (attribute.name == L"id") {
1299 m_id = attribute.value;
1300 NormalizeAndTrimSpaceString(m_id);
1301 } else if (attribute.name == L"package") {
1302 m_package = attribute.value;
1303 } else if (attribute.name == L"required_version") {
1304 m_version = attribute.value;
1305 NormalizeString(m_version);
1307 ThrowMsg(Exception::ParseError,
1308 "unknown attribute '" +
1309 DPL::ToUTF8String(attribute.name) +
1310 "' in application element");
1315 virtual void Verify()
1317 if(m_data.didFoundTizenApplicationElement)
1319 ThrowMsg(Exception::ParseError, "tizen:application element must occur only once");
1321 m_data.didFoundTizenApplicationElement = true;
1323 VerifyIdAndPackage();
1327 ApplicationParser(ConfigParserData& data) :
1330 m_id(DPL::OptionalString()),
1331 m_version(DPL::OptionalString()),
1332 m_properNamespace(false)
1335 static const char* const REGEXP_ID;
1338 void VerifyIdAndPackage()
1342 ThrowMsg(Exception::ParseError,
1343 "application element must have package attribute");
1347 pcrecpp::RE re(REGEXP_PACKAGE);
1348 if (!re.FullMatch(DPL::ToUTF8String(*m_package)))
1350 ThrowMsg(Exception::ParseError,
1351 "invalid format of package attribute");
1356 ThrowMsg(Exception::ParseError,
1357 "application element must have id attribute");
1361 std::string package;
1362 pcrecpp::RE re(REGEXP_ID);
1363 if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
1365 ThrowMsg(Exception::ParseError,
1366 "invalid format of id attribute");
1368 if (package != DPL::ToUTF8String(*m_package))
1370 ThrowMsg(Exception::ParseError,
1371 "invalid package prefix in id attribute");
1375 m_data.tizenAppId = m_id;
1376 m_data.tizenPkgId = m_package;
1379 void VerifyVersion()
1383 ThrowMsg(Exception::ParseError,
1384 "application element must have required_version attribute");
1388 pcrecpp::RE re(REGEXP_VERSION);
1389 if (!re.FullMatch(DPL::ToUTF8String(*m_version)))
1391 ThrowMsg(Exception::ParseError,
1392 "invalid format of version attribute");
1396 m_data.tizenMinVersionRequired = m_version;
1399 static const char* const REGEXP_PACKAGE;
1400 static const char* const REGEXP_VERSION;
1402 ConfigParserData& m_data;
1403 DPL::OptionalString m_id;
1404 DPL::OptionalString m_package;
1405 DPL::OptionalString m_version;
1406 bool m_properNamespace;
1409 const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}";
1410 const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\.[0-9A-Za-z]{1,52}";
1411 const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)*";
1413 class SplashParser : public ElementParser
1416 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1417 const DPL::String& /*name*/)
1419 return &IgnoringParser::Create; //ignore unknown according to w3c
1422 virtual void Accept(const XmlAttribute& attribute)
1424 if (m_properNamespace)
1426 if (attribute.name == L"src") {
1427 if (attribute.value.size() > 0) {
1428 m_src = attribute.value;
1434 virtual void Accept(const Element& element)
1437 ConfigurationNamespace::TizenWebAppNamespaceName)
1439 m_properNamespace = true;
1443 virtual void Accept(const Text& /*text*/)
1446 virtual void Verify()
1450 _W("src attribute of splash element is mandatory - ignoring");
1454 m_data.splashImgSrc = m_src;
1457 SplashParser(ConfigParserData& data) :
1460 m_properNamespace(false)
1464 DPL::OptionalString m_src;
1465 ConfigParserData& m_data;
1466 bool m_properNamespace;
1469 class BackgroundParser : public ElementParser
1472 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1473 const DPL::String& /*name*/)
1475 return &IgnoringParser::Create; //ignore unknown according to w3c
1478 virtual void Accept(const XmlAttribute& attribute)
1480 if (attribute.name == L"src") {
1481 if (attribute.value.size() > 0) {
1482 m_src = attribute.value;
1487 virtual void Accept(const Element& /*element*/)
1490 virtual void Accept(const Text& /*text*/)
1493 virtual void Verify()
1496 _W("src attribute of background element is mandatory - ignoring");
1500 m_data.backgroundPage = m_src;
1503 explicit BackgroundParser(ConfigParserData& data) :
1508 DPL::OptionalString m_src;
1509 ConfigParserData& m_data;
1512 class PrivilegeParser : public ElementParser
1515 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1516 const DPL::String& /*name*/)
1518 return &IgnoringParser::Create; //ignore unknown according to w3c
1521 virtual void Accept(const Text& /*text*/)
1524 virtual void Accept(const Element& element)
1527 ConfigurationNamespace::TizenWebAppNamespaceName)
1529 m_properNamespace = true;
1534 virtual void Accept(const XmlAttribute& attribute)
1536 if (m_properNamespace) {
1537 if (attribute.name == L"name") {
1538 m_feature.name = attribute.value;
1539 m_privilege.name = attribute.value;
1544 virtual void Verify()
1546 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1548 if (m_feature.name != L"") {
1549 if (iri.Validate()) {
1550 if (m_data.featuresList.find(m_feature) ==
1551 m_data.featuresList.end())
1553 m_data.featuresList.insert(m_feature);
1555 _D("Ignoring feature with name %ls", m_feature.name.c_str());
1560 LibIri::Wrapper iriPrivilege(
1561 DPL::ToUTF8String(m_privilege.name).c_str());
1563 if (m_privilege.name != L"") {
1564 if (iriPrivilege.Validate()) {
1565 if (m_data.privilegeList.find(m_privilege) ==
1566 m_data.privilegeList.end())
1568 m_data.privilegeList.insert(m_privilege);
1570 _D("Ignoring privilege with name %ls", m_privilege.name.c_str());
1576 PrivilegeParser(ConfigParserData& data) :
1581 m_properNamespace(false)
1585 ConfigParserData& m_data;
1586 ConfigParserData::Feature m_feature;
1587 ConfigParserData::Privilege m_privilege;
1588 bool m_properNamespace;
1591 class CategoryParser : public ElementParser
1594 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1595 const DPL::String& /*name*/)
1597 return &IgnoringParser::Create; //ignore unknown according to w3c
1600 virtual void Accept(const Element& element)
1603 ConfigurationNamespace::TizenWebAppNamespaceName)
1605 m_properNamespace = true;
1607 LogDebug("element");
1610 virtual void Accept(const XmlAttribute& attribute)
1612 if (m_properNamespace) {
1613 if (attribute.name == L"name") {
1614 if (attribute.value.size() > 0) {
1615 m_name = attribute.value;
1621 virtual void Accept(const Text& /*text*/)
1624 virtual void Verify()
1627 _W("name attribute of category element is mandatory - ignoring");
1631 if (m_data.categoryList.find(*m_name) ==
1632 m_data.categoryList.end())
1634 m_data.categoryList.insert(*m_name);
1639 explicit CategoryParser(ConfigParserData& data) :
1641 m_properNamespace(false)
1645 DPL::OptionalString m_name;
1646 ConfigParserData& m_data;
1647 bool m_properNamespace;
1651 class AppWidgetParser : public ElementParser
1655 struct BoxLabelParser : public ElementParser
1657 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1658 const DPL::String& /*name*/)
1660 return &IgnoringParser::Create; //ignore unknown according to w3c
1663 virtual void Accept(const XmlAttribute& attribute)
1665 if (m_properNamespace) {
1666 m_lang = attribute.lang;
1669 virtual void Accept(const Element& element)
1672 ConfigurationNamespace::TizenWebAppNamespaceName)
1674 m_properNamespace = true;
1678 virtual void Accept(const Text& text)
1680 if (m_properNamespace) {
1681 m_label = text.value;
1685 virtual void Verify()
1687 std::pair<DPL::String, DPL::String> boxLabel;
1688 if (m_label.empty()) {
1689 _W("box-label element is empty");
1690 boxLabel.first = DPL::FromUTF8String("");
1691 boxLabel.second = DPL::FromUTF8String("");
1692 m_data.m_label.push_back(boxLabel);
1695 boxLabel.first = m_lang;
1696 boxLabel.second = m_label;
1697 m_data.m_label.push_back(boxLabel);
1701 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1703 m_properNamespace(false),
1709 DPL::String m_label;
1710 bool m_properNamespace;
1711 ConfigParserData::LiveboxInfo& m_data;
1714 struct BoxIconParser : public ElementParser
1716 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1717 const DPL::String& /*name*/)
1719 return &IgnoringParser::Create; //ignore unknown according to w3c
1722 virtual void Accept(const XmlAttribute& attribute)
1724 if (m_properNamespace) {
1725 if (attribute.name == L"src") {
1726 m_icon = attribute.value;
1731 virtual void Accept(const Element& element)
1734 ConfigurationNamespace::TizenWebAppNamespaceName)
1736 m_properNamespace = true;
1740 virtual void Accept(const Text& /*text*/)
1743 virtual void Verify()
1745 if (m_icon.empty()) {
1746 ThrowMsg(Exception::ParseError,
1747 "src attribute of box-icon element is mandatory - ignoring");
1749 if (!m_data.m_icon.empty()) {
1750 ThrowMsg(Exception::ParseError,
1751 "<tizen:box-icon /> element should occur as 0 or 1 time");
1753 m_data.m_icon = m_icon;
1756 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1758 m_properNamespace(false),
1764 bool m_properNamespace;
1765 ConfigParserData::LiveboxInfo& m_data;
1768 struct BoxContentParser : public ElementParser
1770 struct BoxSizeParser : public ElementParser
1772 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1773 const DPL::String& /*name*/)
1775 return &IgnoringParser::Create; //ignore unknown according to w3c
1778 virtual void Accept(const XmlAttribute& attribute)
1780 if (m_properNamespace) {
1781 if (attribute.name == L"preview") {
1782 m_preview = attribute.value;
1784 if (attribute.name == L"use-decoration") {
1785 m_useDecoration = attribute.value;
1790 virtual void Accept(const Element& element)
1793 ConfigurationNamespace::TizenWebAppNamespaceName)
1795 m_properNamespace = true;
1799 virtual void Accept(const Text& text)
1801 if (m_properNamespace) {
1802 m_size = text.value;
1806 virtual void Verify()
1808 if(m_size.empty()) {
1809 ThrowMsg(Exception::ParseError,
1810 "size is mandatory - ignoring");
1813 if (m_useDecoration.empty() || CheckIfNotTrueNorFalse(m_useDecoration)) {
1814 m_useDecoration = L"true"; // default value
1817 ConfigParserData::LiveboxInfo::BoxSizeInfo boxSizeInfo;
1818 boxSizeInfo.m_size = m_size;
1819 boxSizeInfo.m_preview = m_preview;
1820 boxSizeInfo.m_useDecoration = m_useDecoration;
1821 m_data.m_boxSize.push_back(boxSizeInfo);
1824 explicit BoxSizeParser(
1825 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1827 m_properNamespace(false),
1833 DPL::String m_preview;
1834 DPL::String m_useDecoration;
1835 bool m_properNamespace;
1836 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1839 struct PdParser : public ElementParser
1841 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1842 const DPL::String& /*name*/)
1844 return &IgnoringParser::Create; //ignore unknown according to w3c
1847 virtual void Accept(const XmlAttribute& attribute)
1849 if (m_properNamespace) {
1850 if (attribute.name == L"src") {
1851 m_src = attribute.value;
1852 } else if (attribute.name == L"width") {
1853 m_width = attribute.value;
1854 } else if (attribute.name == L"height") {
1855 m_height = attribute.value;
1856 } else if (attribute.name == L"fast-open") {
1857 m_fastOpen= attribute.value;
1862 virtual void Accept(const Element& element)
1865 ConfigurationNamespace::TizenWebAppNamespaceName)
1867 m_properNamespace = true;
1871 virtual void Accept(const Text& /*text*/)
1874 virtual void Verify()
1876 if (m_src.empty()) {
1877 ThrowMsg(Exception::ParseError,
1878 "src attribute of pd element is mandatory - ignoring");
1881 if (m_width.empty()) {
1882 ThrowMsg(Exception::ParseError,
1883 "width attribute of pd element is mandatory - ignoring");
1886 if (m_height.empty()) {
1887 ThrowMsg(Exception::ParseError,
1888 "height attribute of pd element is mandatory - ignoring");
1891 if (!ConvertToInt(m_width)) {
1892 ThrowMsg(Exception::ParseError,
1893 "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width);
1897 DPL::OptionalInt height = ConvertToInt(m_height);
1900 ThrowMsg(Exception::ParseError,
1901 "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height);
1906 _D("height attribute of pd element shouldn't be less than 1. Changed to 1 from %d", *height);
1907 } else if (*height > 380){
1909 _D("height attribute of pd element shouldn't be greater than 380. Changed to 380 from %d", *height);
1912 if (!m_data.m_pdSrc.empty()) {
1913 ThrowMsg(Exception::ParseError, "<tizen:pd> element should occur as 0 or 1 time");
1916 m_data.m_pdSrc = m_src;
1917 m_data.m_pdWidth = m_width;
1918 m_data.m_pdHeight = m_height;
1919 m_data.m_pdFastOpen = m_fastOpen;
1923 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1925 m_properNamespace(false),
1930 DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
1933 std::string tempStr = DPL::ToUTF8String(intAsString);
1934 const char * intAsString_c = tempStr.c_str();
1936 long int intAsString_i = strtol(intAsString_c, &endptr, 10);
1938 if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
1939 || intAsString_i > INT_MAX || intAsString_i < INT_MIN
1940 || *endptr != '\0') {
1941 return DPL::OptionalInt();
1944 return static_cast<int>(intAsString_i);
1948 DPL::String m_width;
1949 DPL::String m_height;
1950 DPL::String m_fastOpen;
1952 bool m_properNamespace;
1953 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1956 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1957 const DPL::String& name)
1959 if (name == L"box-size") {
1960 return std::bind(&AppWidgetParser::BoxContentParser::OnBoxSizeElement, this);
1961 } else if (name == L"pd") {
1962 return std::bind(&AppWidgetParser::BoxContentParser::OnPdElement, this);
1964 ThrowMsg(Exception::ParseError,
1965 "No element parser for name: " << name);
1969 virtual void Accept(const XmlAttribute& attribute)
1971 if (m_properNamespace) {
1972 if (attribute.name == L"src") {
1973 m_box.m_boxSrc = attribute.value;
1975 if (attribute.name == L"mouse-event") {
1976 m_box.m_boxMouseEvent = attribute.value;
1978 if (attribute.name == L"touch-effect") {
1979 m_box.m_boxTouchEffect = attribute.value;
1984 virtual void Accept(const Element& element)
1987 ConfigurationNamespace::TizenWebAppNamespaceName)
1989 m_properNamespace = true;
1993 virtual void Accept(const Text& /*text*/)
1996 virtual void Verify()
1998 if (m_box.m_boxSrc.empty()) {
1999 ThrowMsg(Exception::ParseError,
2000 "src attribute of box-content element is mandatory - ignoring");
2003 if (m_box.m_boxMouseEvent.empty() || CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent)) {
2004 m_box.m_boxMouseEvent = L"false"; // default value
2007 if (m_box.m_boxTouchEffect.empty() || CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect)) {
2008 m_box.m_boxTouchEffect = L"true"; // default value
2011 if (m_box.m_boxSize.empty()) {
2012 ThrowMsg(Exception::ParseError,
2013 "box-size element of box-content element not found - ignoring");
2016 if (!m_data.m_boxInfo.m_boxSrc.empty()) {
2017 ThrowMsg(Exception::ParseError, "<tizen:box-content> element must occur exactly 1 time");
2020 m_data.m_boxInfo = m_box;
2023 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
2025 m_properNamespace(false),
2029 ElementParserPtr OnBoxSizeElement()
2031 return ElementParserPtr(new BoxSizeParser(m_box));
2034 ElementParserPtr OnPdElement()
2036 return ElementParserPtr(new PdParser(m_box));
2040 bool m_properNamespace;
2041 ConfigParserData::LiveboxInfo& m_data;
2042 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
2045 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2046 const DPL::String& name)
2048 if (name == L"box-label") {
2049 return std::bind(&AppWidgetParser::OnBoxLabelElement, this);
2050 } else if (name == L"box-icon") {
2051 return std::bind(&AppWidgetParser::OnBoxIconElement, this);
2052 } else if (name == L"box-content") {
2053 return std::bind(&AppWidgetParser::OnBoxContentElement, this);
2055 return &IgnoringParser::Create; //ignore unknown according to w3c
2059 virtual void Accept(const XmlAttribute& attribute)
2061 if (m_properNamespace) {
2062 if (attribute.name == L"id") {
2063 m_liveboxId = attribute.value;
2064 } else if (attribute.name == L"primary") {
2065 m_primary = attribute.value;
2066 } else if (attribute.name == L"auto-launch") {
2067 m_autoLaunch = attribute.value;
2068 } else if (attribute.name == L"update-period") {
2069 m_updatePeriod = attribute.value;
2070 } else if (attribute.name == L"type") {
2071 m_type = attribute.value;
2076 virtual void Accept(const Element& element)
2079 ConfigurationNamespace::TizenWebAppNamespaceName)
2081 m_properNamespace = true;
2085 virtual void Accept(const Text& /*text*/)
2088 virtual void Verify()
2090 if (m_liveboxId.empty()) {
2091 ThrowMsg(Exception::ParseError,
2092 "app-widget element must have id attribute");
2096 pcrecpp::RE re(REGEXP_ID_STRING.c_str());
2097 if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId)))
2099 ThrowMsg(Exception::ParseError,
2100 "invalid format of app-widget id attribute");
2104 if (m_primary.empty() || CheckIfNotTrueNorFalse(m_primary))
2106 m_primary = L"true"; //default value
2109 if (!m_updatePeriod.empty())
2113 std::string tempStr = DPL::ToUTF8String(m_updatePeriod);
2115 //set standard locale to fix decimal point mark - '.'
2116 std::string currentLocale = setlocale(LC_NUMERIC, NULL);
2117 if (NULL == setlocale(LC_NUMERIC, "C"))
2118 _W("Failed to change locale to \"C\"");
2119 double updatePeriod = strtod(tempStr.c_str(), &endptr);
2121 //go back to previous locale
2122 if (NULL == setlocale(LC_NUMERIC, currentLocale.c_str()))
2123 _W("Failed to set previous locale");
2125 if ((errno == ERANGE && (updatePeriod == -HUGE_VAL || updatePeriod == HUGE_VAL))
2126 || *endptr != '\0') {
2127 ThrowMsg(Exception::ParseError,
2128 "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod);
2129 } else if (updatePeriod < 1800.0) {
2130 _D("update-period attribute of app-widget element shouldn't be less than 1800.0 - changed to 1800 from value: %ls", m_updatePeriod.c_str());
2131 m_updatePeriod = L"1800.0";
2135 if (m_autoLaunch.empty() || CheckIfNotTrueNorFalse(m_autoLaunch))
2137 m_autoLaunch = L"false"; // default value
2140 if(m_livebox.m_label.empty()) {
2141 ThrowMsg(Exception::ParseError,
2142 "box-label element of app-widget element not found - ignoring");
2145 if(!m_boxContentFound) {
2146 ThrowMsg(Exception::ParseError,
2147 "box-content element of app-widget element not found - ignoring");
2150 m_livebox.m_liveboxId = m_liveboxId;
2151 m_livebox.m_primary = m_primary;
2152 m_livebox.m_autoLaunch = m_autoLaunch;
2153 m_livebox.m_updatePeriod = m_updatePeriod;
2154 m_livebox.m_type = m_type;
2156 m_data.m_livebox.push_back(m_livebox);
2159 explicit AppWidgetParser(ConfigParserData& data) :
2162 m_properNamespace(false),
2163 m_boxContentFound(false)
2165 m_livebox = ConfigParserData::LiveboxInfo();
2168 ElementParserPtr OnBoxLabelElement()
2171 return ElementParserPtr(new BoxLabelParser(m_livebox));
2174 ElementParserPtr OnBoxIconElement()
2176 return ElementParserPtr(new BoxIconParser(m_livebox));
2179 ElementParserPtr OnBoxContentElement()
2181 m_boxContentFound = true;
2182 return ElementParserPtr(new BoxContentParser(m_livebox));
2186 static std::string REGEXP_ID_STRING;
2187 ConfigParserData& m_data;
2188 ConfigParserData::LiveboxInfo m_livebox;
2189 DPL::String m_liveboxId;
2190 DPL::String m_primary;
2191 DPL::String m_autoLaunch;
2192 DPL::String m_updatePeriod;
2194 bool m_properNamespace;
2195 bool m_boxContentFound;
2197 static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck)
2199 return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0;
2203 std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+";
2206 class AllowNavigationParser : public ElementParser
2209 AllowNavigationParser(ConfigParserData& data) :
2212 m_properNamespace(false)
2215 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2216 const DPL::String& /*name*/)
2218 return &IgnoringParser::Create; //ignore unknown according to w3c
2221 virtual void Accept(const Element& element)
2223 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2224 m_properNamespace = true;
2228 virtual void Accept(const Text& text)
2230 if (m_properNamespace)
2232 m_origin = text.value;
2236 virtual void Accept(const XmlAttribute& /*attribute*/)
2240 virtual void Verify()
2242 if (m_data.allowNavigationEncountered || !m_properNamespace)
2246 m_data.allowNavigationEncountered = true;
2249 _W("data is empty");
2253 char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
2254 char* ptr = strtok(data," \n\r\t");
2255 while (ptr != NULL) {
2256 std::string origin = ptr;
2257 ptr = strtok(NULL," \n\r\t");
2259 ConfigParserData::AllowNavigationInfo info(L"*", L"*");
2260 m_data.allowNavigationInfoList.push_back(info);
2264 std::unique_ptr<iri_t, decltype(&iri_destroy)> iri(iri_parse(origin.c_str()), iri_destroy);
2265 if (!iri->host || strlen(iri->host) == 0) {
2266 // input origin should has schem and host
2267 // in case of file scheme path is filled
2269 _W("input origin isn't verified");
2272 DPL::String scheme = L"*";
2273 if (iri->scheme && strlen(iri->scheme) != 0) {
2274 scheme = DPL::FromUTF8String(iri->scheme);
2276 ConfigParserData::AllowNavigationInfo info(
2278 DPL::FromUTF8String(iri->host));
2279 m_data.allowNavigationInfoList.push_back(info);
2285 DPL::OptionalString m_origin;
2286 ConfigParserData& m_data;
2287 bool m_properNamespace;
2290 class CspParser : public ElementParser
2293 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2294 const DPL::String& /*name*/)
2296 return &IgnoringParser::Create; //ignore unknown according to w3c
2299 CspParser(ConfigParserData& data) :
2302 m_properNamespace(false)
2305 virtual void Accept(const Element& element)
2307 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2308 m_properNamespace = true;
2312 virtual void Accept(const XmlAttribute& /*attribute*/)
2315 virtual void Accept(const Text& text)
2317 if (m_properNamespace) {
2318 m_policy = text.value;
2322 virtual void Verify()
2324 if (m_data.cspPolicyEncountered) {
2327 m_data.cspPolicyEncountered = true;
2330 m_data.cspPolicy = *m_policy;
2335 ConfigParserData& m_data;
2336 bool m_properNamespace;
2337 DPL::OptionalString m_policy;
2340 class CspReportOnlyParser : public ElementParser
2343 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2344 const DPL::String& /*name*/)
2346 return &IgnoringParser::Create; //ignore unknown according to w3c
2349 CspReportOnlyParser(ConfigParserData& data) :
2352 m_properNamespace(false)
2355 virtual void Accept(const Element& element)
2357 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2358 m_properNamespace = true;
2362 virtual void Accept(const XmlAttribute& /*attribute*/)
2365 virtual void Accept(const Text& text)
2367 if (m_properNamespace) {
2368 m_policy = text.value;
2372 virtual void Verify()
2374 if (m_data.cspPolicyReportOnlyEncountered) {
2377 m_data.cspPolicyReportOnlyEncountered = true;
2380 m_data.cspPolicyReportOnly = *m_policy;
2385 ConfigParserData& m_data;
2386 bool m_properNamespace;
2387 DPL::OptionalString m_policy;
2390 class AccountParser : public ElementParser
2393 struct IconParser : public ElementParser
2396 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2397 const DPL::String& /*name*/)
2399 return &IgnoringParser::Create; //ignore unknown according to w3c
2402 virtual void Accept(const Text& text)
2404 if (text.value == L"") {
2407 m_value = text.value;
2410 virtual void Accept(const Element& /*element*/)
2413 virtual void Accept(const XmlAttribute& attribute)
2415 if (attribute.name == L"section") {
2416 if (attribute.value == L"Account") {
2417 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2418 } else if (attribute.value == L"AccountSmall") {
2419 m_type = ConfigParserData::IconSectionType::SmallIcon;
2424 virtual void Verify()
2426 if (!m_value || *m_value == L"") {
2430 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2431 icon.first = m_type;
2432 icon.second = *m_value;
2434 m_data.m_iconSet.insert(icon);
2437 IconParser(ConfigParserData::AccountProvider& data) :
2439 m_properNamespace(false),
2440 m_type(ConfigParserData::DefaultIcon),
2445 bool m_properNamespace;
2446 ConfigParserData::IconSectionType m_type;
2447 ConfigParserData::AccountProvider& m_data;
2448 DPL::OptionalString m_value;
2451 struct DisplayNameParser : public ElementParser
2454 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2455 const DPL::String& /*name*/)
2457 return &IgnoringParser::Create; //ignore unknown according to w3c
2460 virtual void Accept(const Text& text)
2462 if (text.value == L"") {
2465 m_value = text.value;
2468 virtual void Accept(const Element& element)
2470 m_lang = element.lang;
2474 virtual void Accept(const XmlAttribute& /*attribute*/)
2477 virtual void Verify()
2479 if (!m_value || *m_value == L"") {
2483 std::pair<DPL::String, DPL::String> name;
2484 name.first = *m_lang;
2485 name.second = *m_value;
2487 m_data.m_displayNameSet.insert(name);
2490 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2492 m_properNamespace(false),
2497 bool m_properNamespace;
2498 DPL::OptionalString m_lang;
2499 DPL::OptionalString m_value;
2500 ConfigParserData::AccountProvider& m_data;
2503 struct CapabilityParser : public ElementParser
2506 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2507 const DPL::String& /*name*/)
2509 return &IgnoringParser::Create; //ignore unknown according to w3c
2512 virtual void Accept(const Text& text)
2514 if (text.value == L"") {
2517 m_value = text.value;
2520 virtual void Accept(const Element& /*element*/)
2523 virtual void Accept(const XmlAttribute& /*attribute*/)
2526 virtual void Verify()
2528 if (!m_value || *m_value == L"") {
2531 m_data.m_capabilityList.push_back(*m_value);
2534 CapabilityParser(ConfigParserData::AccountProvider& data) :
2536 m_properNamespace(false),
2541 bool m_properNamespace;
2542 DPL::OptionalString m_value;
2543 ConfigParserData::AccountProvider& m_data;
2545 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2546 const DPL::String& name)
2548 if (name == L"icon") {
2549 return std::bind(&AccountParser::OnIconElement, this);
2550 } else if (name == L"display-name") {
2551 return std::bind(&AccountParser::OnDisplayNameElement, this);
2552 } else if (name == L"capability") {
2553 return std::bind(&AccountParser::OnCapabilityElement, this);
2555 return &IgnoringParser::Create; //ignore unknown according to w3c
2559 virtual void Accept(const Text& /*text*/)
2562 virtual void Accept(const Element& /*element*/)
2565 virtual void Accept(const XmlAttribute& attribute)
2567 if (attribute.name == L"multiple-account-support") {
2568 if (attribute.value == L"true") {
2569 m_account.m_multiAccountSupport = true;
2574 virtual void Verify()
2578 ElementParserPtr OnIconElement()
2580 return ElementParserPtr(new IconParser(m_account));
2583 ElementParserPtr OnDisplayNameElement()
2585 return ElementParserPtr(new DisplayNameParser(m_account));
2588 ElementParserPtr OnCapabilityElement()
2590 return ElementParserPtr(new CapabilityParser(m_account));
2593 AccountParser(ConfigParserData& data) :
2595 m_properNamespace(false),
2596 m_multiSupport(false),
2598 m_account(data.accountProvider)
2603 bool m_properNamespace;
2604 bool m_multiSupport;
2605 ConfigParserData& m_data;
2606 ConfigParserData::AccountProvider& m_account;
2609 class MetadataParser : public ElementParser
2612 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2613 const DPL::String& /*name*/)
2615 return &IgnoringParser::Create; //ignore unknown according to w3c
2618 virtual void Accept(const XmlAttribute& attribute)
2620 if (m_properNamespace) {
2621 if (attribute.name == L"key") {
2622 m_key = attribute.value;
2623 } else if (attribute.name == L"value") {
2624 m_value = attribute.value;
2629 virtual void Accept(const Element& element)
2631 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2632 m_properNamespace = true;
2636 virtual void Accept(const Text& /*text*/)
2638 ThrowMsg(Exception::ParseError, "param element must be empty");
2641 virtual void Verify()
2644 _W("metadata element must have key attribute");
2647 NormalizeString(m_key);
2648 NormalizeString(m_value);
2649 ConfigParserData::Metadata metaData(m_key, m_value);
2650 FOREACH(it, m_data.metadataList) {
2651 if (!DPL::StringCompare(*it->key, *m_key)) {
2652 _E("Key isn't unique");
2656 m_data.metadataList.push_back(metaData);
2659 MetadataParser(ConfigParserData& data) :
2662 m_properNamespace(false)
2666 DPL::OptionalString m_key;
2667 DPL::OptionalString m_value;
2668 ConfigParserData& m_data;
2669 bool m_properNamespace;
2673 class ImeParser : public ElementParser
2676 struct UuidParser : public ElementParser
2679 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2680 const DPL::String& /*name*/)
2682 return &IgnoringParser::Create;
2685 virtual void Accept(const XmlAttribute& attribute)
2688 virtual void Accept(const Element& element)
2691 virtual void Accept(const Text& text)
2693 if (m_uuid.empty()) {
2694 m_uuid = text.value;
2696 m_uuid += text.value;
2700 virtual void Verify()
2702 if (m_uuid.empty()) {
2703 ThrowMsg(Exception::ParseError, "uuid text is empty");
2705 m_imeAppInfo.uuid = m_uuid;
2708 UuidParser(ConfigParserData::ImeAppInfo& data) :
2714 ConfigParserData::ImeAppInfo& m_imeAppInfo;
2718 struct LanguagesParser : public ElementParser
2721 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2722 const DPL::String& name)
2724 if (name == L"language") {
2725 return std::bind(&LanguagesParser::OnLanguageElement, this);
2727 return &IgnoringParser::Create;
2731 virtual void Accept(const XmlAttribute& attribute)
2734 virtual void Accept(const Element& element)
2737 virtual void Accept(const Text& text)
2739 ThrowMsg(Exception::ParseError, "param element must be empty");
2742 virtual void Verify()
2745 LanguagesParser(ConfigParserData::ImeAppInfo& data) :
2750 ElementParserPtr OnLanguageElement()
2752 return ElementParserPtr(new LanguageParser(m_imeAppInfo));
2756 ConfigParserData::ImeAppInfo& m_imeAppInfo;
2759 struct LanguageParser : public ElementParser
2762 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2763 const DPL::String& name)
2765 return &IgnoringParser::Create;
2768 virtual void Accept(const XmlAttribute& attribute)
2771 virtual void Accept(const Element& element)
2774 virtual void Accept(const Text& text)
2776 if (m_language.empty()) {
2777 m_language = text.value;
2779 m_language += text.value;
2783 virtual void Verify()
2785 if (m_language.empty()) {
2786 ThrowMsg(Exception::ParseError, "language text is empty");
2788 m_imeAppInfo.languageList.insert(m_language);
2791 LanguageParser(ConfigParserData::ImeAppInfo& data) :
2797 ConfigParserData::ImeAppInfo& m_imeAppInfo;
2798 DPL::String m_language;
2801 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2802 const DPL::String& name)
2804 if (name == L"uuid") {
2805 return std::bind(&ImeParser::OnUuidElement, this);
2806 } else if (name == L"languages") {
2807 return std::bind(&ImeParser::OnLanguagesElement, this);
2809 return &IgnoringParser::Create;
2813 virtual void Accept(const Text& /*text*/)
2815 ThrowMsg(Exception::ParseError, "param element must be empty");
2818 virtual void Accept(const Element& element)
2821 virtual void Accept(const XmlAttribute& attribute)
2824 virtual void Verify()
2826 if (m_imeAppInfo.uuid.empty()) {
2827 ThrowMsg(Exception::ParseError, "ime element must have uuid element");
2831 if (m_imeAppInfo.languageList.empty()) {
2832 ThrowMsg(Exception::ParseError, "ime element must have language element");
2835 m_data.imeAppInfoList.push_back(m_imeAppInfo);
2838 ImeParser(ConfigParserData& data) :
2844 ElementParserPtr OnLanguagesElement()
2846 return ElementParserPtr(new LanguagesParser(m_imeAppInfo));
2849 ElementParserPtr OnUuidElement()
2851 return ElementParserPtr(new UuidParser(m_imeAppInfo));
2855 ConfigParserData& m_data;
2856 ConfigParserData::ImeAppInfo m_imeAppInfo;
2860 #ifdef SERVICE_ENABLED
2861 class ServiceAppParser : public ElementParser
2864 struct ServiceContentParser : public ElementParser
2866 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2867 const DPL::String& /*name*/)
2869 return &IgnoringParser::Create; //ignore unknown according to w3c
2872 virtual void Accept(const XmlAttribute& attribute)
2874 if (attribute.name == L"src") {
2875 m_src = attribute.value;
2879 virtual void Accept(const Element& element)
2882 virtual void Accept(const Text& /*text*/)
2884 ThrowMsg(Exception::ParseError, "param element must be empty");
2887 virtual void Verify()
2889 if (m_src.empty()) {
2890 ThrowMsg(Exception::ParseError, "src attribute of service-content element is mandatory");
2893 if (!m_serviceAppInfo.serviceContent.empty()) {
2894 ThrowMsg(Exception::ParseError, "service-content element occurs more than 1 time");
2896 m_serviceAppInfo.serviceContent = m_src;
2899 explicit ServiceContentParser(ConfigParserData::ServiceAppInfo& data) :
2901 m_serviceAppInfo(data)
2906 ConfigParserData::ServiceAppInfo& m_serviceAppInfo;;
2909 struct ServiceNameParser : public ElementParser
2911 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2912 const DPL::String& /*name*/)
2914 return &IgnoringParser::Create;
2917 virtual void Accept(const XmlAttribute& attribute)
2919 m_lang = attribute.lang;
2922 virtual void Accept(const Element& element)
2925 virtual void Accept(const Text& text)
2927 m_name = text.value;
2930 virtual void Verify()
2932 ConfigParserData::LocalizedData& data = m_serviceAppInfo.m_localizedDataSet[m_lang];
2933 if (data.name.IsNull()) {
2934 NormalizeString(m_name);
2939 ServiceNameParser(ConfigParserData::ServiceAppInfo& data) :
2941 m_serviceAppInfo(data)
2947 ConfigParserData::ServiceAppInfo& m_serviceAppInfo;
2950 struct ServiceIconParser : public ElementParser
2952 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2953 const DPL::String& /*name*/)
2955 return &IgnoringParser::Create;
2958 virtual void Accept(const XmlAttribute& attribute)
2960 if (attribute.name == L"src") {
2961 m_icon.src = attribute.value;
2963 else if (attribute.name == L"width") {
2964 m_icon.width = ConvertToInt(attribute.value);
2966 else if (attribute.name == L"height") {
2967 m_icon.height = ConvertToInt(attribute.value);
2971 virtual void Accept(const Element& element)
2974 virtual void Accept(const Text& /*text*/)
2976 ThrowMsg(Exception::ParseError, "param element must be empty");
2979 virtual void Verify()
2981 if (m_icon.src.empty()) {
2982 ThrowMsg(Exception::ParseError,
2983 "src attribute of service-icon element is mandatory - ignoring");
2985 m_serviceAppInfo.m_iconsList.push_back(m_icon);
2988 explicit ServiceIconParser(ConfigParserData::ServiceAppInfo& data) :
2991 m_serviceAppInfo(data)
2995 DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
2998 std::string tempStr = DPL::ToUTF8String(intAsString);
2999 const char * intAsString_c = tempStr.c_str();
3001 long int intAsString_i = strtol(intAsString_c, &endptr, 10);
3003 if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
3004 || intAsString_i > INT_MAX || intAsString_i < INT_MIN
3005 || *endptr != '\0') {
3006 return DPL::OptionalInt();
3009 return static_cast<int>(intAsString_i);
3013 ConfigParserData::Icon m_icon;
3014 ConfigParserData::ServiceAppInfo& m_serviceAppInfo;
3017 struct ServiceDescriptionParser : public ElementParser
3019 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, const DPL::String& /*name*/)
3021 return &IgnoringParser::Create; //ignore unknown according to w3c
3024 virtual void Accept(const XmlAttribute& attribute)
3026 m_lang = attribute.lang;
3028 virtual void Accept(const Element& element)
3031 virtual void Accept(const Text& text)
3033 m_description = text.value;
3036 virtual void Verify()
3038 ConfigParserData::LocalizedData& data = m_serviceAppInfo.m_localizedDataSet[m_lang];
3039 if (data.description.IsNull()) {
3040 NormalizeString(m_description);
3041 data.description = m_description;
3045 ServiceDescriptionParser(ConfigParserData::ServiceAppInfo& data) :
3047 m_serviceAppInfo(data)
3052 DPL::String m_description;
3053 ConfigParserData::ServiceAppInfo& m_serviceAppInfo;
3056 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
3057 const DPL::String& name)
3059 if (name == L"service-content") {
3060 return std::bind(&ServiceAppParser::OnServiceContentElement, this);
3061 } else if (name == L"service-name") {
3062 return std::bind(&ServiceAppParser::OnServiceNameElement, this);
3063 } else if (name == L"service-icon") {
3064 return std::bind(&ServiceAppParser::OnServiceIconElement, this);
3065 } else if (name == L"service-description") {
3066 return std::bind(&ServiceAppParser::OnServiceDescriptionElement, this);
3068 return &IgnoringParser::Create;
3072 virtual void Accept(const Element& element)
3075 virtual void Accept(const XmlAttribute& attribute)
3077 if (attribute.name == L"id") {
3078 if (attribute.value.size() > 0) {
3079 m_serviceId = attribute.value;
3081 } else if (attribute.name == L"auto_restart") {
3082 if (attribute.value == L"true") {
3083 m_autoRestart = true;
3084 } else if (attribute.value == L"false") {
3085 m_autoRestart = false;
3087 ThrowMsg(Exception::ParseError, "Wrong boolean value");
3089 } else if (attribute.name == L"on_boot") {
3090 if (attribute.value == L"true") {
3092 } else if (attribute.value == L"false") {
3095 ThrowMsg(Exception::ParseError, "Wrong boolean value");
3100 virtual void Accept(const Text& /*text*/)
3102 ThrowMsg(Exception::ParseError, "param element must be empty");
3105 virtual void Verify()
3107 if (m_serviceAppInfo.serviceContent.empty()) {
3108 ThrowMsg(Exception::ParseError, "service element must have service-content element");
3112 if (m_serviceId.empty()) {
3113 ThrowMsg(Exception::ParseError, "service attribute must have id attribute");
3116 m_serviceAppInfo.serviceId = m_serviceId;
3118 m_serviceAppInfo.autoRestart = m_autoRestart;
3120 m_serviceAppInfo.onBoot = m_onBoot;
3122 m_data.serviceAppInfoList.push_back(m_serviceAppInfo);
3125 ServiceAppParser(ConfigParserData& data) :
3130 m_autoRestart(false)
3133 ElementParserPtr OnServiceContentElement()
3135 return ElementParserPtr(new ServiceContentParser(m_serviceAppInfo));
3138 ElementParserPtr OnServiceNameElement()
3140 return ElementParserPtr(new ServiceNameParser(m_serviceAppInfo));
3143 ElementParserPtr OnServiceIconElement()
3145 return ElementParserPtr(new ServiceIconParser(m_serviceAppInfo));
3148 ElementParserPtr OnServiceDescriptionElement()
3150 return ElementParserPtr(new ServiceDescriptionParser(m_serviceAppInfo));
3154 DPL::String m_serviceId;
3155 ConfigParserData& m_data;
3156 ConfigParserData::ServiceAppInfo m_serviceAppInfo;
3162 ElementParser::ActionFunc WidgetParser::GetElementParser(
3163 const DPL::String& /*ns*/,
3164 const DPL::String& name)
3166 FuncMap::const_iterator it = m_map.find(name);
3167 if (it != m_map.end()) {
3170 return &IgnoringParser::Create; //ignore unknown according to w3c
3174 WidgetParser::WidgetParser(ConfigParserData& data) :
3176 m_textDirection(Unicode::EMPTY)
3178 m_map[L"name"] = std::bind(&WidgetParser::OnNameElement, this);
3179 m_map[L"access"] = std::bind(&WidgetParser::OnAccessElement, this);
3180 m_map[L"description"] = std::bind(&WidgetParser::OnDescriptionElement, this);
3181 m_map[L"author"] = std::bind(&WidgetParser::OnAuthorElement, this);
3182 m_map[L"license"] = std::bind(&WidgetParser::OnLicenseElement, this);
3183 m_map[L"icon"] = std::bind(&WidgetParser::OnIconElement, this);
3184 m_map[L"small-icon"] = std::bind(&WidgetParser::OnSmallIconElement, this);
3185 m_map[L"content"] = std::bind(&WidgetParser::OnContentElement, this);
3186 m_map[L"preference"] = std::bind(&WidgetParser::OnPreferenceElement, this);
3187 m_map[L"setting"] = std::bind(&WidgetParser::OnSettingElement, this);
3188 m_map[L"application"] = std::bind(&WidgetParser::OnApplicationElement, this);
3190 m_map[L"ime"] = std::bind(&WidgetParser::OnImeElement, this);
3192 #ifdef SERVICE_ENABLED
3193 m_map[L"service"] = std::bind(&WidgetParser::OnServiceAppElement, this);
3195 m_map[L"splash"] = std::bind(&WidgetParser::OnSplashElement, this);
3196 m_map[L"background"] = std::bind(&WidgetParser::OnBackgroundElement, this);
3197 m_map[L"privilege"] = std::bind(&WidgetParser::OnPrivilegeElement, this);
3198 m_map[L"app-control"] = std::bind(&WidgetParser::OnAppControlElement, this);
3199 m_map[L"category"] = std::bind(&WidgetParser::OnCategoryElement, this);
3201 m_map[L"app-widget"] = std::bind(&WidgetParser::OnAppWidgetElement, this);
3203 #if ENABLE(CONTENT_SECURITY_POLICY)
3204 m_map[L"content-security-policy"] = std::bind(&WidgetParser::OnCspElement, this);
3205 m_map[L"content-security-policy-report-only"] = std::bind(&WidgetParser::OnCspReportOnlyElement, this);
3207 #if ENABLE(ALLOW_NAVIGATION)
3208 m_map[L"allow-navigation"] = std::bind(&WidgetParser::OnAllowNavigationElement, this);
3210 m_map[L"account"] = std::bind(&WidgetParser::OnAccountElement, this);
3211 m_map[L"metadata"] = std::bind(&WidgetParser::OnMetadataElement, this);
3214 ElementParserPtr WidgetParser::OnNameElement()
3216 return ElementParserPtr(new NameParser(m_textDirection, m_data));
3219 ElementParserPtr WidgetParser::OnAccessElement()
3221 return ElementParserPtr(new AccessParser(m_data));
3224 ElementParserPtr WidgetParser::OnDescriptionElement()
3226 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
3229 ElementParserPtr WidgetParser::OnAuthorElement()
3231 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
3234 ElementParserPtr WidgetParser::OnLicenseElement()
3236 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
3239 ElementParserPtr WidgetParser::OnIconElement()
3241 return ElementParserPtr(new IconParser(m_data));
3244 ElementParserPtr WidgetParser::OnSmallIconElement()
3246 return ElementParserPtr(new IconParser(m_data, true));
3249 ElementParserPtr WidgetParser::OnContentElement()
3251 return ElementParserPtr(new ContentParser(m_data));
3254 ElementParserPtr WidgetParser::OnPreferenceElement()
3256 return ElementParserPtr(new PreferenceParser(m_data));
3259 ElementParserPtr WidgetParser::OnSettingElement()
3261 return ElementParserPtr(new SettingParser(m_data));
3264 ElementParserPtr WidgetParser::OnApplicationElement()
3266 return ElementParserPtr(new ApplicationParser(m_data));
3269 ElementParserPtr WidgetParser::OnSplashElement()
3271 return ElementParserPtr(new SplashParser(m_data));
3274 ElementParserPtr WidgetParser::OnBackgroundElement()
3276 return ElementParserPtr(new BackgroundParser(m_data));
3279 ElementParserPtr WidgetParser::OnPrivilegeElement()
3281 return ElementParserPtr(new PrivilegeParser(m_data));
3284 ElementParserPtr WidgetParser::OnAppControlElement()
3286 return ElementParserPtr(new AppControlParser(m_data));
3289 ElementParserPtr WidgetParser::OnCategoryElement()
3291 return ElementParserPtr(new CategoryParser(m_data));
3295 ElementParserPtr WidgetParser::OnAppWidgetElement()
3297 return ElementParserPtr(new AppWidgetParser(m_data));
3301 ElementParserPtr WidgetParser::OnCspElement()
3303 return ElementParserPtr(new CspParser(m_data));
3306 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
3308 return ElementParserPtr(new CspReportOnlyParser(m_data));
3311 ElementParserPtr WidgetParser::OnAllowNavigationElement()
3313 return ElementParserPtr(new AllowNavigationParser(m_data));
3316 ElementParserPtr WidgetParser::OnAccountElement()
3318 return ElementParserPtr(new AccountParser(m_data));
3321 ElementParserPtr WidgetParser::OnMetadataElement()
3323 return ElementParserPtr(new MetadataParser(m_data));
3327 ElementParserPtr WidgetParser::OnImeElement()
3329 return ElementParserPtr(new ImeParser(m_data));
3333 #ifdef SERVICE_ENABLED
3334 ElementParserPtr WidgetParser::OnServiceAppElement()
3336 return ElementParserPtr(new ServiceAppParser(m_data));
3340 void WidgetParser::Accept(const Element& element)
3342 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
3343 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
3345 ThrowMsg(Exception::ParseError,
3346 "Wrong xml namespace for widget element");
3350 void WidgetParser::Accept(const Text& /*text*/)
3352 ThrowMsg(Exception::ParseError, "widged element must be empty");
3355 void WidgetParser::Accept(const XmlAttribute& attribute)
3357 if (attribute.name == L"id") {
3358 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
3359 //If may important tests starts to fail this test we will have
3360 //to consider commenting this test out again.
3361 if (iri.Validate()) {
3362 m_data.widget_id = attribute.value;
3363 NormalizeString(m_data.widget_id);
3365 _W("Widget id validation failed: %ls", attribute.value.c_str());
3367 } else if (attribute.name == L"version") {
3368 m_version = attribute.value;
3369 NormalizeString(m_version);
3370 } else if (attribute.name == L"min-version") {
3371 _D("min-version attribute was found. Value: %ls", attribute.value.c_str());
3372 m_minVersion = attribute.value;
3373 NormalizeString(m_minVersion);
3374 m_data.minVersionRequired = m_minVersion;
3375 } else if (attribute.name == L"height") {
3376 DPL::OptionalString value = attribute.value;
3377 NormalizeString(value);
3378 std::string v = DPL::ToUTF8String(*value);
3381 unsigned char c = v.c_str()[0];
3384 for (size_t i = 0; i < v.size(); ++i) {
3393 m_data.height = val;
3396 } else if (attribute.name == L"width") {
3397 DPL::OptionalString value = attribute.value;
3398 NormalizeString(value);
3399 std::string v = DPL::ToUTF8String(*value);
3402 unsigned char c = v.c_str()[0];
3403 if (c >= '0' && c <= '9') {
3405 for (size_t i = 0; i < v.size(); ++i) {
3407 if (c >= '0' && c <= '9') {
3417 } else if (attribute.name == L"viewmodes") {
3418 DPL::Tokenize(attribute.value,
3420 std::inserter(m_windowModes,
3421 m_windowModes.end()),
3423 } else if (attribute.name == L"dir") {
3424 m_textDirection = Unicode::ParseDirAttribute(attribute);
3425 } else if (L"defaultlocale" == attribute.name) {
3426 if (!m_defaultlocale) {
3427 m_defaultlocale = attribute.value;
3428 NormalizeString(m_defaultlocale);
3429 std::string dl = DPL::ToUTF8String(*m_defaultlocale);
3431 if (!LanguageSubtagRstTreeSingleton::Instance().
3432 ValidateLanguageTag(dl)) {
3433 _W("Language tag: %s is not valid", dl.c_str());
3434 m_defaultlocale = DPL::OptionalString();
3436 _D("Default locale found %s", dl.c_str());
3439 _W("Ignoring subsequent default locale");
3441 //Any other value consider as a namespace definition
3442 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
3443 _D("Namespace domain: %ls", attribute.name.c_str());
3444 _D("Namespace value: %ls", attribute.value.c_str());
3445 m_nameSpaces[attribute.name] = attribute.value;
3448 _E("Unknown attirbute: namespace=%ls, name=%ls, value=%ls",
3449 attribute.ns.c_str(), attribute.name.c_str(), attribute.value.c_str());
3453 void WidgetParser::Verify()
3455 FOREACH(mode, m_windowModes) {
3456 if (L"windowed" == *mode || L"floating" == *mode ||
3457 L"fullscreen" == *mode || L"maximized" == *mode ||
3458 L"minimized" == *mode)
3460 m_data.windowModes.insert(*mode);
3464 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
3465 m_data.version = m_version;
3467 m_data.defaultlocale = m_defaultlocale;
3468 FOREACH(ns, m_nameSpaces) {
3469 m_data.nameSpaces.insert(ns->second);