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>
40 #include <dpl/scoped_ptr.h>
51 using namespace WrtDB;
54 static const DPL::String UTF_LRE = L"\x0202a";
55 static const DPL::String UTF_LRO = L"\x0202d";
56 static const DPL::String UTF_RLE = L"\x0202b";
57 static const DPL::String UTF_RLO = L"\x0202e";
58 static const DPL::String UTF_PDF = L"\x0202c";
60 Direction ParseDirAttribute(const XmlAttribute& attribute)
62 Assert(L"dir" == attribute.name);
63 if (L"ltr" == attribute.value) {
65 } else if (L"rtl" == attribute.value) {
67 } else if (L"lro" == attribute.value) {
69 } else if (L"rlo" == attribute.value) {
72 LogWarning("dir attribute has wrong value:" << attribute.value);
77 void UpdateTextWithDirectionMark(Direction direction,
83 *text = UTF_RLO + *text + UTF_PDF;
86 *text = UTF_RLE + *text + UTF_PDF;
89 *text = UTF_LRE + *text + UTF_PDF;
92 *text = UTF_LRO + *text + UTF_PDF;
101 } // namespace Unicode
103 class InnerElementsParser : public ElementParser
106 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
107 const DPL::String& /*name*/)
109 return DPL::MakeDelegate(this, &InnerElementsParser::Other);
112 virtual void Accept(const Element& /*element*/)
115 virtual void Accept(const Text& text)
117 if (m_text.IsNull()) {
120 m_text->value += text.value;
124 virtual void Accept(const XmlAttribute& attribute)
126 if (attribute.name == L"dir") {
127 m_textDirection = Unicode::ParseDirAttribute(attribute);
131 virtual void Verify()
133 if (!m_text.IsNull()) {
134 Unicode::UpdateTextWithDirectionMark(m_textDirection,
136 m_parentParser->Accept(*m_text);
140 InnerElementsParser(ElementParserPtr parent) :
141 m_parentParser(parent),
142 m_textDirection(Unicode::EMPTY)
145 ElementParserPtr Other()
147 return ElementParserPtr(new InnerElementsParser(
148 std::static_pointer_cast<ElementParser>(
149 shared_from_this())));
153 DPL::Optional<Text> m_text;
154 ElementParserPtr m_parentParser;
155 Unicode::Direction m_textDirection;
158 class NameParser : public ElementParser
161 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
162 const DPL::String& /*name*/)
164 return DPL::MakeDelegate(this, &NameParser::Other);
167 virtual void Accept(const Element& element)
169 m_lang = element.lang;
173 virtual void Accept(const Text& text)
175 if (m_name.IsNull()) {
178 *m_name += text.value;
182 virtual void Accept(const XmlAttribute& attribute)
184 if (attribute.name == L"short") {
185 if (m_shortName.IsNull()) {
186 m_shortName = attribute.value;
188 } else if (attribute.name == L"dir") {
189 m_textDirection = Unicode::ParseDirAttribute(attribute);
193 virtual void Verify()
195 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
196 if (data.name.IsNull()) {
197 NormalizeString(m_name);
198 NormalizeString(m_shortName);
199 if (!m_name.IsNull()) {
200 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
203 if (!m_shortName.IsNull()) {
204 Unicode::UpdateTextWithDirectionMark(m_textDirection,
207 data.shortName = m_shortName;
211 NameParser(Unicode::Direction direction,
212 ConfigParserData& data) :
214 m_textDirection(direction)
217 ElementParserPtr Other()
219 return ElementParserPtr(new InnerElementsParser(
220 std::static_pointer_cast<ElementParser>(
221 shared_from_this())));
225 ConfigParserData& m_data;
226 DPL::OptionalString m_name;
227 DPL::OptionalString m_shortName;
228 DPL::OptionalString m_dir;
230 Unicode::Direction m_textDirection;
233 class AccessParser : public ElementParser
242 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
243 const DPL::String& /*name*/)
245 return DPL::MakeDelegate(this, &AccessParser::Other);
248 virtual void Accept(const Element& element)
250 // for tizen web apps WARP should be used
251 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
252 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
254 m_standardType = STANDARD_TYPE_WARP;
258 virtual void Accept(const Text& /*text*/)
261 void AcceptWac(const XmlAttribute& attribute)
263 if (attribute.name == L"origin") {
264 m_strIRIOrigin = attribute.value;
265 NormalizeString(m_strIRIOrigin);
266 } else if (attribute.name == L"subdomains") {
267 DPL::String normalizedValue = attribute.value;
268 NormalizeString(normalizedValue);
270 if (normalizedValue == L"true") {
271 m_bSubDomainAccess = true;
272 } else if (normalizedValue == L"false") {
273 m_bSubDomainAccess = false;
278 virtual void Accept(const XmlAttribute& attribute)
280 switch (m_standardType) {
281 case STANDARD_TYPE_WARP:
282 AcceptWac(attribute);
285 LogError("Error in Access tag - unknown standard.");
293 iri.set(m_strIRIOrigin, false);
295 if (!iri.isAccessDefinition()) {
296 LogWarning("Access list element: " <<
298 " is not acceptable by WARP" <<
299 "standard and will be ignored!");
303 if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains
305 m_bSubDomainAccess = true;
308 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
310 //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
311 m_data.accessInfoSet.insert(accessInfo);
314 virtual void Verify()
316 switch (m_standardType) {
317 case STANDARD_TYPE_WARP:
321 LogError("Error in Access tag - unknown standard.");
326 AccessParser(ConfigParserData& data) :
328 m_bSubDomainAccess(false),
329 m_standardType(STANDARD_TYPE_NONE),
334 ElementParserPtr Other()
336 return ElementParserPtr(new InnerElementsParser(
337 ElementParserPtr(shared_from_this())));
341 DPL::String m_strIRIOrigin;
342 bool m_bSubDomainAccess;
343 StandardType m_standardType;
345 ConfigParserData& m_data;
348 class DescriptionParser : public ElementParser
351 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
352 const DPL::String& /*name*/)
354 return DPL::MakeDelegate(this, &DescriptionParser::Other);
357 virtual void Accept(const Element& element)
359 m_lang = element.lang;
363 ElementParserPtr Other()
365 return ElementParserPtr(new InnerElementsParser(
366 std::static_pointer_cast<ElementParser>(
367 shared_from_this())));
370 virtual void Accept(const Text& text)
372 if (m_description.IsNull()) {
373 m_description = text.value;
375 *m_description += text.value;
379 virtual void Accept(const XmlAttribute& attribute)
381 if (attribute.name == L"dir") {
382 m_textDirection = Unicode::ParseDirAttribute(attribute);
386 virtual void Verify()
388 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
389 if (data.description.IsNull()) {
390 if (!m_description.IsNull()) {
391 Unicode::UpdateTextWithDirectionMark(m_textDirection,
394 data.description = m_description;
398 DescriptionParser(Unicode::Direction direction,
399 ConfigParserData& data) :
403 m_textDirection(direction)
407 ConfigParserData& m_data;
409 DPL::OptionalString m_description;
410 Unicode::Direction m_textDirection;
413 class AuthorParser : public ElementParser
416 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
417 const DPL::String& /*name*/)
419 return DPL::MakeDelegate(this, &AuthorParser::Other);
422 AuthorParser(Unicode::Direction direction,
423 ConfigParserData& data) :
425 m_textDirection(direction)
428 virtual void Accept(const Element& /*element*/)
433 virtual void Accept(const Text& text)
435 *(m_authorName) += text.value;
438 virtual void Accept(const XmlAttribute& attribute)
440 if (attribute.name == L"href") {
441 //Validate href IRI and ignore it if invalid
442 //See also test: ta-argMozRiC-an
443 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
444 if (iri.Validate()) {
445 m_authorHref = attribute.value;
447 } else if (attribute.name == L"email") {
448 m_authorEmail = attribute.value;
449 } else if (attribute.name == L"dir") {
450 m_textDirection = Unicode::ParseDirAttribute(attribute);
454 virtual void Verify()
456 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
457 NormalizeString(m_authorName);
458 NormalizeString(m_authorHref);
459 NormalizeString(m_authorEmail);
460 if (!!m_authorName) {
461 Unicode::UpdateTextWithDirectionMark(m_textDirection,
463 m_data.authorName = m_authorName;
465 if (!!m_authorHref) {
466 m_data.authorHref = m_authorHref;
468 if (!!m_authorEmail) {
469 m_data.authorEmail = m_authorEmail;
474 ElementParserPtr Other()
476 return ElementParserPtr(new InnerElementsParser(
477 std::static_pointer_cast<ElementParser>(
478 shared_from_this())));
482 ConfigParserData& m_data;
483 DPL::OptionalString m_authorEmail;
484 DPL::OptionalString m_authorHref;
485 DPL::OptionalString m_authorName;
486 Unicode::Direction m_textDirection;
489 class LicenseParser : public ElementParser
492 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
493 const DPL::String& /*name*/)
495 return DPL::MakeDelegate(this, &LicenseParser::Other);
498 LicenseParser(Unicode::Direction direction,
499 ConfigParserData& data) :
502 m_textDirection(direction)
505 virtual void Accept(const Element& element)
507 if (m_license.IsNull()) {
508 m_lang = element.lang;
514 virtual void Accept(const Text& text)
517 *m_license += text.value;
521 virtual void Accept(const XmlAttribute& attribute)
524 if (attribute.name == L"href" && m_licenseHref.IsNull()) {
525 m_licenseHref = attribute.value;
526 } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
527 m_licenseFile = attribute.value;
528 } else if (attribute.name == L"dir") {
529 m_textDirection = Unicode::ParseDirAttribute(attribute);
534 virtual void Verify()
536 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
537 if (data.license.IsNull()) {
538 if (!m_license.IsNull()) {
539 Unicode::UpdateTextWithDirectionMark(m_textDirection,
542 data.license = m_license;
543 data.licenseHref = m_licenseHref;
544 data.licenseFile = m_licenseFile;
548 ElementParserPtr Other()
550 return ElementParserPtr(new InnerElementsParser(
551 ElementParserPtr(shared_from_this())));
555 ConfigParserData& m_data;
559 DPL::OptionalString m_license;
560 DPL::OptionalString m_licenseFile;
561 DPL::OptionalString m_licenseHref;
562 Unicode::Direction m_textDirection;
565 class IconParser : public ElementParser
567 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
570 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
571 const DPL::String& /*name*/)
573 return &IgnoringParser::Create; //ignore unknown according to w3c
576 IconParser(ConfigParserData& data) : ElementParser(),
580 virtual void Accept(const Element& /*element*/)
583 virtual void Accept(const XmlAttribute& attribute)
585 if (attribute.name == L"src") {
586 if (attribute.value.size() > 0) {
587 m_src = attribute.value;
589 } else if (attribute.name == L"width") {
590 m_width = ParseSizeAttributeValue(attribute.value);
591 } else if (attribute.name == L"height") {
592 m_height = ParseSizeAttributeValue(attribute.value);
596 virtual void Accept(const Text& /*text*/)
598 ThrowMsg(Exception::ParseError, "Icon element must be empty");
601 virtual void Verify()
603 if (m_src.IsNull()) {
604 LogWarning("src attribute of icon element is mandatory - ignoring");
610 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
611 icon.width = m_width;
612 icon.height = m_height;
614 ConfigParserData::IconsList::iterator it = std::find(
615 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
616 if (it == m_data.iconsList.end()) {
617 m_data.iconsList.push_front(icon);
622 LogWarning("src attribute is invalid: " << m_src);
627 ConfigParserData& m_data;
628 DPL::OptionalString m_src;
629 DPL::OptionalInt m_width;
630 DPL::OptionalInt m_height;
632 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
634 DPL::OptionalString normalizedValue = value;
635 NormalizeString(normalizedValue);
636 if (!(*normalizedValue).empty()) {
640 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
642 std::string(reterr) == DPL::ToUTF8String(value) ||
645 return DPL::OptionalInt::Null;
650 return DPL::OptionalInt::Null;
654 * @brief delocalizePath removes locales folder from relative path if
656 * @param source source string
658 * @throw BadSrcError if string is bad value of src attribute
660 * @return corrected string
662 static DPL::String delocalizeSrcPath(const DPL::String & source)
664 static const DPL::String localeFolder(L"locales/");
665 static const int index = localeFolder.size();
667 DPL::String result = source;
669 if (source.substr(0, index) == localeFolder) {
670 size_t pos = result.find_first_of('/', index);
671 if (pos != std::string::npos && pos + 1 < source.size()) {
672 result = result.substr(pos + 1, source.size());
681 class ContentParser : public ElementParser
684 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
685 const DPL::String& /*name*/)
687 return &IgnoringParser::Create; //ignore unknown according to w3c
690 ContentParser(ConfigParserData& data) :
695 virtual void Accept(const Element& element)
697 m_namespace = element.ns;
700 virtual void Accept(const Text& /*text*/)
703 virtual void Accept(const XmlAttribute& attribute)
705 DPL::String value = attribute.value;
706 NormalizeString(value);
708 if (attribute.name == L"src") {
710 } else if (attribute.name == L"type") {
712 MimeTypeUtils::MimeAttributes mimeAttributes =
713 MimeTypeUtils::getMimeAttributes(value);
714 if ((mimeAttributes.count(L"charset") > 0) && m_encoding.IsNull())
716 m_encoding = mimeAttributes[L"charset"];
718 } else if (attribute.name == L"encoding") {
719 if (!value.empty()) {
725 virtual void Verify()
727 if(!!m_data.startFileEncountered)
729 if(m_data.startFileNamespace == m_namespace
730 || m_namespace != ConfigurationNamespace::TizenWebAppNamespaceName)
734 //else continue -> if previous item was not in tizen namespace
737 m_data.startFileEncountered = true;
738 m_data.startFileNamespace = m_namespace;
740 //we're consciously setting startFile even if m_src is null or invalid.
741 //WidgetConfigurationManager will deal with this.
742 m_data.startFile = m_src;
745 m_data.startFileContentType = m_type;
747 m_data.startFileEncoding = m_encoding;
749 m_data.startFileEncoding = L"UTF-8";
755 DPL::OptionalString m_src;
756 DPL::OptionalString m_type;
757 DPL::OptionalString m_encoding;
758 ConfigParserData& m_data;
759 DPL::String m_namespace;
762 class PreferenceParser : public ElementParser
765 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
766 const DPL::String& /*name*/)
768 return &IgnoringParser::Create; //ignore unknown according to w3c
771 virtual void Accept(const XmlAttribute& attribute)
773 if (attribute.name == L"name") {
774 m_name = attribute.value;
775 } else if (attribute.name == L"value") {
776 m_value = attribute.value;
777 } else if (attribute.name == L"readonly") {
778 if (attribute.value == L"true") {
786 virtual void Accept(const Element& /*element*/)
789 virtual void Accept(const Text& /*text*/)
791 ThrowMsg(Exception::ParseError, "param element must be empty");
794 virtual void Verify()
796 if (m_name.IsNull()) {
797 LogWarning("preference element must have name attribute");
800 NormalizeString(m_name);
801 NormalizeString(m_value);
802 ConfigParserData::Preference preference(*m_name, m_required);
803 preference.value = m_value;
804 if (m_data.preferencesList.find(preference) ==
805 m_data.preferencesList.end())
807 m_data.preferencesList.insert(preference);
811 PreferenceParser(ConfigParserData& data) :
818 DPL::OptionalString m_name;
819 DPL::OptionalString m_value;
821 ConfigParserData& m_data;
824 class LinkParser : public ElementParser
827 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
828 const DPL::String& /*name*/)
830 return &DenyAllParser::Create;
833 virtual void Accept(const XmlAttribute& attribute)
835 if (m_properNamespace) {
836 LogDebug("attribute");
837 if (attribute.name == L"rel") {
838 if (attribute.value != L"describedby") {
839 ThrowMsg(Exception::ParseError,
840 "rel attribute must have describedby value");
842 } else if (attribute.name == L"type") {} else if (attribute.name ==
845 LogDebug("here is href");
846 m_href = attribute.value;
848 ThrowMsg(Exception::ParseError,
849 "unknown attribute '" +
850 DPL::ToUTF8String(attribute.name) +
851 "' in link element");
856 virtual void Accept(const Element& element)
859 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
861 m_properNamespace = true;
866 virtual void Accept(const Text&)
868 if (m_properNamespace) {
870 ThrowMsg(Exception::ParseError, "link element must be empty");
874 virtual void Verify()
877 ThrowMsg(Exception::ParseError,
878 "link element must have href attribute");
881 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
882 if (!iri.Validate()) { // TODO: Better uri validator ?
883 ThrowMsg(Exception::ParseError,
884 "href attribute must be a valid iri/uri/url");
888 LinkParser(ConfigParserData& data) :
890 m_properNamespace(false),
892 m_href(DPL::OptionalString::Null)
896 bool m_properNamespace;
897 ConfigParserData& m_data;
898 DPL::OptionalString m_href;
901 class SettingParser : public ElementParser
904 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
905 const DPL::String& /*name*/)
907 return &IgnoringParser::Create; //ignore unknown according to w3c
910 virtual void Accept(const Text& /*text*/)
913 virtual void Accept(const Element& /*element*/)
916 virtual void Accept(const XmlAttribute& attribute)
918 m_setting.m_name = attribute.name;
919 m_setting.m_value = attribute.value;
920 m_data.settingsList.insert(m_setting);
923 virtual void Verify()
926 SettingParser(ConfigParserData& data) :
933 ConfigParserData& m_data;
934 ConfigParserData::Setting m_setting;
937 class AppControlParser : public ElementParser
940 struct SourceParser : public ElementParser
943 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
944 const DPL::String& /*name*/)
946 return &IgnoringParser::Create; //ignore unknown according to w3c
949 virtual void Accept(const Text& /*text*/)
952 virtual void Accept(const Element& /*element*/)
955 virtual void Accept(const XmlAttribute& attribute)
957 if (attribute.name == L"name") {
958 if (attribute.value.size() > 0) {
959 m_value = attribute.value;
960 NormalizeString(m_value);
965 virtual void Verify()
967 if (m_value.IsNull() || *m_value == L"") {
971 m_data.m_src = *m_value;
974 SourceParser(ConfigParserData::AppControlInfo& data) :
976 m_properNamespace(false),
981 bool m_properNamespace;
982 DPL::OptionalString m_value;
983 ConfigParserData::AppControlInfo& m_data;
986 struct OperationParser : public ElementParser
989 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
990 const DPL::String& /*name*/)
992 return &IgnoringParser::Create; //ignore unknown according to w3c
995 virtual void Accept(const Text& /*text*/)
998 virtual void Accept(const Element& /*element*/)
1001 virtual void Accept(const XmlAttribute& attribute)
1003 if (attribute.name == L"name") {
1004 if (attribute.value.size() > 0) {
1005 m_value = attribute.value;
1006 NormalizeString(m_value);
1011 virtual void Verify()
1013 if (m_value.IsNull() || *m_value == L"") {
1017 m_data.m_operation = *m_value;
1020 OperationParser(ConfigParserData::AppControlInfo& data) :
1022 m_properNamespace(false),
1027 bool m_properNamespace;
1028 DPL::OptionalString m_value;
1029 ConfigParserData::AppControlInfo& m_data;
1032 struct UriParser : public ElementParser
1035 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1036 const DPL::String& /*name*/)
1038 return &IgnoringParser::Create; //ignore unknown according to w3c
1041 virtual void Accept(const Text& /*text*/)
1044 virtual void Accept(const Element& /*element*/)
1047 virtual void Accept(const XmlAttribute& attribute)
1049 if (attribute.name == L"name") {
1050 if (attribute.value.size() > 0) {
1051 m_value = attribute.value;
1052 NormalizeString(m_value);
1057 virtual void Verify()
1060 DPL::String ignoreUri(L"file");
1062 if (!m_value.IsNull() && *m_value == ignoreUri)
1064 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
1065 m_value = DPL::OptionalString::Null;
1068 if (m_value.IsNull() || *m_value == L"") {
1072 DPL::String wildString(L"*/*");
1073 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1074 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1076 m_data.m_uriList.insert(*m_value);
1078 LogDebug("Ignoring uri with name" <<
1079 DPL::ToUTF8String(*m_value));
1083 UriParser(ConfigParserData::AppControlInfo& data) :
1085 m_properNamespace(false),
1090 bool m_properNamespace;
1091 DPL::OptionalString m_value;
1092 ConfigParserData::AppControlInfo& m_data;
1095 struct MimeParser : public ElementParser
1098 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1099 const DPL::String& /*name*/)
1101 return &IgnoringParser::Create; //ignore unknown according to w3c
1104 virtual void Accept(const Text& /*text*/)
1107 virtual void Accept(const Element& /*element*/)
1110 virtual void Accept(const XmlAttribute& attribute)
1112 if (attribute.name == L"name") {
1113 if (attribute.value.size() > 0) {
1114 m_value = attribute.value;
1115 NormalizeString(m_value);
1120 virtual void Verify()
1122 if (m_value.IsNull() || *m_value == L"") {
1126 DPL::String wildString(L"*/*");
1127 if ((m_data.m_mimeList.find(wildString) ==
1128 m_data.m_mimeList.end())
1129 && (m_data.m_mimeList.find(*m_value) ==
1130 m_data.m_mimeList.end()))
1132 m_data.m_mimeList.insert(*m_value);
1134 LogDebug("Ignoring mime with name" <<
1135 DPL::ToUTF8String(*m_value));
1139 MimeParser(ConfigParserData::AppControlInfo& data) :
1141 m_properNamespace(false),
1146 bool m_properNamespace;
1147 DPL::OptionalString m_value;
1148 ConfigParserData::AppControlInfo& m_data;
1151 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1152 const DPL::String& name)
1154 if (name == L"src") {
1155 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1156 } else if (name == L"operation") {
1157 return DPL::MakeDelegate(this,
1158 &AppControlParser::OnOperationElement);
1159 } else if (name == L"uri") {
1160 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1161 } else if (name == L"mime") {
1162 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1164 return &IgnoringParser::Create; //ignore unknown according to w3c
1168 virtual void Accept(const XmlAttribute& /*attribute*/)
1171 virtual void Accept(const Element& element)
1173 LogWarning("namespace for app service = " << element.ns);
1174 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1175 ThrowMsg(Exception::ParseError,
1176 "Wrong xml namespace for widget element");
1180 virtual void Accept(const Text& /*text*/)
1182 ThrowMsg(Exception::ParseError, "param element must be empty");
1185 virtual void Verify()
1187 if (m_appControl.m_src == L"") {
1188 ThrowMsg(Exception::ParseError, "service element must have src element");
1191 if (m_appControl.m_operation == L"") {
1192 ThrowMsg(Exception::ParseError, "service element must have operation element");
1195 m_data.appControlList.push_back(m_appControl);
1198 ElementParserPtr OnSourceElement()
1200 return ElementParserPtr(new SourceParser(m_appControl));
1203 ElementParserPtr OnOperationElement()
1205 return ElementParserPtr(new OperationParser(m_appControl));
1208 ElementParserPtr OnUriElement()
1210 return ElementParserPtr(new UriParser(m_appControl));
1213 ElementParserPtr OnMimeElement()
1215 return ElementParserPtr(new MimeParser(m_appControl));
1218 AppControlParser(ConfigParserData& data) :
1225 ConfigParserData& m_data;
1226 ConfigParserData::AppControlInfo m_appControl;
1229 class ApplicationParser : public ElementParser
1232 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1233 const DPL::String& /*name*/)
1235 return &IgnoringParser::Create; //ignore unknown according to w3c
1238 virtual void Accept(const Text& /*text*/)
1240 if (m_properNamespace) {
1241 ThrowMsg(Exception::ParseError, "application element must be empty");
1245 virtual void Accept(const Element& element)
1248 ConfigurationNamespace::TizenWebAppNamespaceName)
1250 m_properNamespace = true;
1254 virtual void Accept(const XmlAttribute& attribute)
1256 if (m_properNamespace) {
1257 if (attribute.name == L"id") {
1258 m_id = attribute.value;
1259 NormalizeAndTrimSpaceString(m_id);
1260 } else if (attribute.name == L"package") {
1261 m_package = attribute.value;
1262 } else if (attribute.name == L"required_version") {
1263 m_version = attribute.value;
1264 NormalizeString(m_version);
1266 ThrowMsg(Exception::ParseError,
1267 "unknown attribute '" +
1268 DPL::ToUTF8String(attribute.name) +
1269 "' in application element");
1274 virtual void Verify()
1276 VerifyIdAndPackage();
1280 ApplicationParser(ConfigParserData& data) :
1283 m_id(DPL::OptionalString::Null),
1284 m_version(DPL::OptionalString::Null),
1285 m_properNamespace(false)
1288 static const char* const REGEXP_ID;
1291 void VerifyIdAndPackage()
1295 ThrowMsg(Exception::ParseError,
1296 "application element must have package attribute");
1300 pcrecpp::RE re(REGEXP_PACKAGE);
1301 if (!re.FullMatch(DPL::ToUTF8String(*m_package)))
1303 ThrowMsg(Exception::ParseError,
1304 "invalid format of package attribute");
1309 ThrowMsg(Exception::ParseError,
1310 "application element must have id attribute");
1314 std::string package;
1315 pcrecpp::RE re(REGEXP_ID);
1316 if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
1318 ThrowMsg(Exception::ParseError,
1319 "invalid format of id attribute");
1321 if (package != DPL::ToUTF8String(*m_package))
1323 ThrowMsg(Exception::ParseError,
1324 "invalid package prefix in id attribute");
1328 m_data.tizenAppId = m_id;
1329 m_data.tizenPkgId = m_package;
1332 void VerifyVersion()
1336 ThrowMsg(Exception::ParseError,
1337 "application element must have required_version attribute");
1341 pcrecpp::RE re(REGEXP_VERSION);
1342 if (!re.FullMatch(DPL::ToUTF8String(*m_version)))
1344 ThrowMsg(Exception::ParseError,
1345 "invalid format of version attribute");
1349 m_data.tizenMinVersionRequired = m_version;
1352 static const char* const REGEXP_PACKAGE;
1353 static const char* const REGEXP_VERSION;
1355 ConfigParserData& m_data;
1356 DPL::OptionalString m_id;
1357 DPL::OptionalString m_package;
1358 DPL::OptionalString m_version;
1359 bool m_properNamespace;
1362 const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}";
1363 const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\.[0-9A-Za-z]{1,52}";
1364 const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?";
1366 class SplashParser : public ElementParser
1369 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1370 const DPL::String& /*name*/)
1372 return &IgnoringParser::Create; //ignore unknown according to w3c
1375 virtual void Accept(const XmlAttribute& attribute)
1377 if (m_properNamespace)
1379 if (attribute.name == L"src") {
1380 if (attribute.value.size() > 0) {
1381 m_src = attribute.value;
1387 virtual void Accept(const Element& element)
1390 ConfigurationNamespace::TizenWebAppNamespaceName)
1392 m_properNamespace = true;
1396 virtual void Accept(const Text& /*text*/)
1399 virtual void Verify()
1403 LogWarning("src attribute of splash element is mandatory - ignoring");
1407 m_data.splashImgSrc = m_src;
1410 SplashParser(ConfigParserData& data) :
1413 m_properNamespace(false)
1417 DPL::OptionalString m_src;
1418 ConfigParserData& m_data;
1419 bool m_properNamespace;
1422 class BackgroundParser : public ElementParser
1425 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1426 const DPL::String& /*name*/)
1428 return &IgnoringParser::Create; //ignore unknown according to w3c
1431 virtual void Accept(const XmlAttribute& attribute)
1433 if (attribute.name == L"src") {
1434 if (attribute.value.size() > 0) {
1435 m_src = attribute.value;
1440 virtual void Accept(const Element& /*element*/)
1443 virtual void Accept(const Text& /*text*/)
1446 virtual void Verify()
1448 if (m_src.IsNull()) {
1450 "src attribute of background element is mandatory - ignoring");
1454 m_data.backgroundPage = m_src;
1457 explicit BackgroundParser(ConfigParserData& data) :
1462 DPL::OptionalString m_src;
1463 ConfigParserData& m_data;
1466 class PrivilegeParser : public ElementParser
1469 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1470 const DPL::String& /*name*/)
1472 return &IgnoringParser::Create; //ignore unknown according to w3c
1475 virtual void Accept(const Text& /*text*/)
1478 virtual void Accept(const Element& element)
1481 ConfigurationNamespace::TizenWebAppNamespaceName)
1483 m_properNamespace = true;
1485 LogDebug("element");
1488 virtual void Accept(const XmlAttribute& attribute)
1490 if (m_properNamespace) {
1491 if (attribute.name == L"name") {
1492 m_feature.name = attribute.value;
1493 m_privilege.name = attribute.value;
1498 virtual void Verify()
1500 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1502 if (m_feature.name != L"") {
1503 if (iri.Validate()) {
1504 if (m_data.featuresList.find(m_feature) ==
1505 m_data.featuresList.end())
1507 m_data.featuresList.insert(m_feature);
1509 LogDebug("Ignoring feature with name" <<
1510 DPL::ToUTF8String(m_feature.name));
1515 LibIri::Wrapper iriPrivilege(
1516 DPL::ToUTF8String(m_privilege.name).c_str());
1518 if (m_privilege.name != L"") {
1519 if (iriPrivilege.Validate()) {
1520 if (m_data.privilegeList.find(m_privilege) ==
1521 m_data.privilegeList.end())
1523 m_data.privilegeList.insert(m_privilege);
1525 LogDebug("Ignoring privilege with name" <<
1526 DPL::ToUTF8String(m_privilege.name));
1532 PrivilegeParser(ConfigParserData& data) :
1537 m_properNamespace(false)
1541 ConfigParserData& m_data;
1542 ConfigParserData::Feature m_feature;
1543 ConfigParserData::Privilege m_privilege;
1544 bool m_properNamespace;
1547 class CategoryParser : public ElementParser
1550 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1551 const DPL::String& /*name*/)
1553 return &IgnoringParser::Create; //ignore unknown according to w3c
1556 virtual void Accept(const XmlAttribute& attribute)
1558 if (attribute.name == L"name") {
1559 if (attribute.value.size() > 0) {
1560 m_name = attribute.value;
1565 virtual void Accept(const Element& /*element*/)
1568 virtual void Accept(const Text& /*text*/)
1571 virtual void Verify()
1573 if (m_name.IsNull()) {
1575 "name attribute of category element is mandatory - ignoring");
1579 if (m_data.categoryList.find(*m_name) ==
1580 m_data.categoryList.end())
1582 m_data.categoryList.insert(*m_name);
1586 explicit CategoryParser(ConfigParserData& data) :
1591 DPL::OptionalString m_name;
1592 ConfigParserData& m_data;
1595 class AppWidgetParser : public ElementParser
1599 struct BoxLabelParser : public ElementParser
1601 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1602 const DPL::String& /*name*/)
1604 return &IgnoringParser::Create; //ignore unknown according to w3c
1607 virtual void Accept(const XmlAttribute& attribute)
1609 if (m_properNamespace) {
1610 m_lang = attribute.lang;
1613 virtual void Accept(const Element& element)
1616 ConfigurationNamespace::TizenWebAppNamespaceName)
1618 m_properNamespace = true;
1622 virtual void Accept(const Text& text)
1624 if (m_properNamespace) {
1625 m_label = text.value;
1629 virtual void Verify()
1631 if (m_label.empty()) {
1632 ThrowMsg(Exception::ParseError,
1633 "box-label element cannot be empty - ignoring");
1635 std::pair<DPL::String, DPL::String> boxLabel;
1636 boxLabel.first = m_lang;
1637 boxLabel.second = m_label;
1638 m_data.m_label.push_back(boxLabel);
1641 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1643 m_properNamespace(false),
1649 DPL::String m_label;
1650 bool m_properNamespace;
1651 ConfigParserData::LiveboxInfo& m_data;
1654 struct BoxIconParser : public ElementParser
1656 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1657 const DPL::String& /*name*/)
1659 return &IgnoringParser::Create; //ignore unknown according to w3c
1662 virtual void Accept(const XmlAttribute& attribute)
1664 if (m_properNamespace) {
1665 if (attribute.name == L"src") {
1666 m_icon = attribute.value;
1671 virtual void Accept(const Element& element)
1674 ConfigurationNamespace::TizenWebAppNamespaceName)
1676 m_properNamespace = true;
1680 virtual void Accept(const Text& /*text*/)
1683 virtual void Verify()
1685 if (m_icon.empty()) {
1686 ThrowMsg(Exception::ParseError,
1687 "src attribute of box-icon element is mandatory - ignoring");
1689 m_data.m_icon = m_icon;
1692 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1694 m_properNamespace(false),
1700 bool m_properNamespace;
1701 ConfigParserData::LiveboxInfo& m_data;
1704 struct BoxContentParser : public ElementParser
1706 struct BoxSizeParser : public ElementParser
1708 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1709 const DPL::String& /*name*/)
1711 return &IgnoringParser::Create; //ignore unknown according to w3c
1714 virtual void Accept(const XmlAttribute& attribute)
1716 if (m_properNamespace) {
1717 if (attribute.name == L"preview") {
1718 m_preview = attribute.value;
1723 virtual void Accept(const Element& element)
1726 ConfigurationNamespace::TizenWebAppNamespaceName)
1728 m_properNamespace = true;
1732 virtual void Accept(const Text& text)
1734 if (m_properNamespace) {
1735 m_size = text.value;
1739 virtual void Verify()
1741 if(m_size.empty()) {
1742 ThrowMsg(Exception::ParseError,
1743 "size is mandatory - ignoring");
1746 std::pair<DPL::String, DPL::String> boxSize;
1747 boxSize.first = m_size;
1748 boxSize.second = m_preview;
1749 m_data.m_boxSize.push_back(boxSize);
1752 explicit BoxSizeParser(
1753 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1755 m_properNamespace(false),
1761 DPL::String m_preview;
1762 bool m_properNamespace;
1763 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1766 struct PdParser : public ElementParser
1768 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1769 const DPL::String& /*name*/)
1771 return &IgnoringParser::Create; //ignore unknown according to w3c
1774 virtual void Accept(const XmlAttribute& attribute)
1776 if (m_properNamespace) {
1777 if (attribute.name == L"src") {
1778 m_src = attribute.value;
1779 } else if (attribute.name == L"width") {
1780 m_width = attribute.value;
1781 } else if (attribute.name == L"height") {
1782 m_height = attribute.value;
1783 } else if (attribute.name == L"fast-open") {
1784 m_fastOpen= attribute.value;
1789 virtual void Accept(const Element& element)
1792 ConfigurationNamespace::TizenWebAppNamespaceName)
1794 m_properNamespace = true;
1798 virtual void Accept(const Text& /*text*/)
1801 virtual void Verify()
1803 if (m_src.empty()) {
1804 ThrowMsg(Exception::ParseError,
1805 "src attribute of pd element is mandatory - ignoring");
1808 if (m_width.empty()) {
1809 ThrowMsg(Exception::ParseError,
1810 "width attribute of pd element is mandatory - ignoring");
1813 if (m_height.empty()) {
1814 ThrowMsg(Exception::ParseError,
1815 "height attribute of pd element is mandatory - ignoring");
1818 if (ConvertToInt(m_width).IsNull()) {
1819 ThrowMsg(Exception::ParseError,
1820 "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width);
1824 DPL::OptionalInt height = ConvertToInt(m_height);
1826 if (height.IsNull()) {
1827 ThrowMsg(Exception::ParseError,
1828 "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height);
1833 LogDebug("height attribute of pd element shouldn't be less than 1. Changed to 1 from " << *height);
1834 } else if (*height > 380){
1836 LogDebug("height attribute of pd element shouldn't be greater than 380. Changed to 380 from " << *height);
1839 m_data.m_pdSrc = m_src;
1840 m_data.m_pdWidth = m_width;
1841 m_data.m_pdHeight = m_height;
1842 m_data.m_pdFastOpen = m_fastOpen;
1846 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1848 m_properNamespace(false),
1853 DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
1856 std::string tempStr = DPL::ToUTF8String(intAsString);
1857 const char * intAsString_c = tempStr.c_str();
1859 long int intAsString_i = strtol(intAsString_c, &endptr, 10);
1861 if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
1862 || intAsString_i > INT_MAX || intAsString_i < INT_MIN
1863 || *endptr != '\0') {
1864 return DPL::OptionalInt::Null;
1867 return static_cast<int>(intAsString_i);
1871 DPL::String m_width;
1872 DPL::String m_height;
1873 DPL::String m_fastOpen;
1875 bool m_properNamespace;
1876 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1879 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1880 const DPL::String& name)
1882 if (name == L"box-size") {
1883 return DPL::MakeDelegate(
1885 &AppWidgetParser::BoxContentParser::
1887 } else if (name == L"pd") {
1888 return DPL::MakeDelegate(
1890 &AppWidgetParser::BoxContentParser::
1893 ThrowMsg(Exception::ParseError,
1894 "No element parser for name: " << name);
1898 virtual void Accept(const XmlAttribute& attribute)
1900 if (m_properNamespace) {
1901 if (attribute.name == L"src") {
1902 m_box.m_boxSrc = attribute.value;
1904 if (attribute.name == L"mouse-event") {
1905 m_box.m_boxMouseEvent = attribute.value;
1907 if (attribute.name == L"touch-effect") {
1908 m_box.m_boxTouchEffect = attribute.value;
1913 virtual void Accept(const Element& element)
1916 ConfigurationNamespace::TizenWebAppNamespaceName)
1918 m_properNamespace = true;
1922 virtual void Accept(const Text& /*text*/)
1925 virtual void Verify()
1927 if (m_box.m_boxSrc.empty()) {
1928 ThrowMsg(Exception::ParseError,
1929 "src attribute of box-content element is mandatory - ignoring");
1932 if (!m_box.m_boxMouseEvent.empty() &&
1933 CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent))
1935 ThrowMsg(Exception::ParseError,
1936 "mouse-event attribute of box-content element should be true or false - ignoring");
1939 if (!m_box.m_boxTouchEffect.empty() &&
1940 CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect))
1942 ThrowMsg(Exception::ParseError,
1943 "touch-effect attribute of box-content element should be true or false - ignoring");
1946 if (m_box.m_boxMouseEvent.empty()) {
1947 m_box.m_boxMouseEvent = L"false";
1950 if (m_box.m_boxTouchEffect.empty()) {
1951 m_box.m_boxTouchEffect = L"true";
1954 if (m_box.m_boxSize.empty()) {
1955 ThrowMsg(Exception::ParseError,
1956 "box-size element of box-content element not found - ignoring");
1959 m_data.m_boxInfo = m_box;
1962 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1964 m_properNamespace(false),
1968 ElementParserPtr OnBoxSizeElement()
1970 return ElementParserPtr(new BoxSizeParser(m_box));
1973 ElementParserPtr OnPdElement()
1975 return ElementParserPtr(new PdParser(m_box));
1979 bool m_properNamespace;
1980 ConfigParserData::LiveboxInfo& m_data;
1981 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1984 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1985 const DPL::String& name)
1987 if (name == L"box-label") {
1988 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1989 } else if (name == L"box-icon") {
1990 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1991 } else if (name == L"box-content") {
1992 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1994 return &IgnoringParser::Create; //ignore unknown according to w3c
1998 virtual void Accept(const XmlAttribute& attribute)
2000 if (m_properNamespace) {
2001 if (attribute.name == L"id") {
2002 m_liveboxId = attribute.value;
2003 } else if (attribute.name == L"primary") {
2004 m_primary = attribute.value;
2005 } else if (attribute.name == L"auto-launch") {
2006 m_autoLaunch = attribute.value;
2007 } else if (attribute.name == L"update-period") {
2008 m_updatePeriod = attribute.value;
2009 } else if (attribute.name == L"type") {
2010 m_type = attribute.value;
2015 virtual void Accept(const Element& element)
2018 ConfigurationNamespace::TizenWebAppNamespaceName)
2020 m_properNamespace = true;
2024 virtual void Accept(const Text& /*text*/)
2027 virtual void Verify()
2029 if (m_liveboxId.empty()) {
2030 ThrowMsg(Exception::ParseError,
2031 "app-widget element must have id attribute");
2035 pcrecpp::RE re(REGEXP_ID_STRING.c_str());
2036 if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId)))
2038 ThrowMsg(Exception::ParseError,
2039 "invalid format of app-widget id attribute");
2043 if (m_primary.empty())
2045 ThrowMsg(Exception::ParseError,
2046 "app-widget element must have primary attribute");
2047 } else if (CheckIfNotTrueNorFalse(m_primary))
2049 ThrowMsg(Exception::ParseError,
2050 "auto-launch attribute of app-widget element should be true or false - ignoring");
2053 if (!m_autoLaunch.empty() &&
2054 CheckIfNotTrueNorFalse(m_autoLaunch))
2056 ThrowMsg(Exception::ParseError,
2057 "auto-launch attribute of app-widget element should be true or false - ignoring");
2060 if (!m_updatePeriod.empty())
2064 std::string tempStr = DPL::ToUTF8String(m_updatePeriod);
2066 //set standard locale to fix decimal point mark - '.'
2067 std::string currentLocale = setlocale(LC_NUMERIC, NULL);
2068 if (NULL == setlocale(LC_NUMERIC, "C"))
2069 LogWarning("Failed to change locale to \"C\"");
2070 double updatePeriod = strtod(tempStr.c_str(), &endptr);
2072 //go back to previous locale
2073 if (NULL == setlocale(LC_NUMERIC, currentLocale.c_str()))
2074 LogWarning("Failed to set previous locale");
2076 if ((errno == ERANGE && (updatePeriod == -HUGE_VAL || updatePeriod == HUGE_VAL))
2077 || *endptr != '\0') {
2078 ThrowMsg(Exception::ParseError,
2079 "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod);
2080 } else if (updatePeriod < 1800.0) {
2081 LogDebug("update-period attribute of app-widget element shouldn't be less than 1800.0 - changed to 1800 from value: " << m_updatePeriod);
2082 m_updatePeriod = L"1800.0";
2086 if (m_autoLaunch.empty()) {
2087 m_autoLaunch = L"false";
2090 if(m_livebox.m_label.empty()) {
2091 ThrowMsg(Exception::ParseError,
2092 "box-label element of app-widget element not found - ignoring");
2095 if(!m_boxContentFound) {
2096 ThrowMsg(Exception::ParseError,
2097 "box-content element of app-widget element not found - ignoring");
2100 m_livebox.m_liveboxId = m_liveboxId;
2101 m_livebox.m_primary = m_primary;
2102 m_livebox.m_autoLaunch = m_autoLaunch;
2103 m_livebox.m_updatePeriod = m_updatePeriod;
2104 m_livebox.m_type = m_type;
2106 m_data.m_livebox.push_back(m_livebox);
2109 explicit AppWidgetParser(ConfigParserData& data) :
2112 m_properNamespace(false),
2113 m_boxContentFound(false)
2115 m_livebox = ConfigParserData::LiveboxInfo();
2118 ElementParserPtr OnBoxLabelElement()
2121 return ElementParserPtr(new BoxLabelParser(m_livebox));
2124 ElementParserPtr OnBoxIconElement()
2126 return ElementParserPtr(new BoxIconParser(m_livebox));
2129 ElementParserPtr OnBoxContentElement()
2131 m_boxContentFound = true;
2132 return ElementParserPtr(new BoxContentParser(m_livebox));
2136 static std::string REGEXP_ID_STRING;
2137 ConfigParserData& m_data;
2138 ConfigParserData::LiveboxInfo m_livebox;
2139 DPL::String m_liveboxId;
2140 DPL::String m_primary;
2141 DPL::String m_autoLaunch;
2142 DPL::String m_updatePeriod;
2144 bool m_properNamespace;
2145 bool m_boxContentFound;
2147 static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck)
2149 return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0;
2153 std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+";
2155 class AllowNavigationParser : public ElementParser
2158 AllowNavigationParser(ConfigParserData& data) :
2161 m_properNamespace(false)
2164 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2165 const DPL::String& /*name*/)
2167 return &IgnoringParser::Create; //ignore unknown according to w3c
2170 virtual void Accept(const Element& element)
2172 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2173 m_properNamespace = true;
2177 virtual void Accept(const Text& text)
2179 if (m_properNamespace) {
2180 m_origin = text.value;
2184 virtual void Accept(const XmlAttribute& /*attribute*/)
2188 virtual void Verify()
2190 if (m_origin.IsNull()) {
2191 LogWarning("data is empty");
2195 char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
2196 char* ptr = strtok(data," ");
2197 while (ptr != NULL) {
2198 std::string origin = ptr;
2199 ptr = strtok(NULL," ");
2201 ConfigParserData::AllowNavigationInfo info(L"*", L"*");
2202 m_data.allowNavigationInfoList.push_back(info);
2206 DPL::ScopedPtr<iri_t> iri(iri_parse(origin.c_str()));
2207 if (!iri->host || strlen(iri->host) == 0) {
2208 // input origin should has schem and host
2209 // in case of file scheme path is filled
2211 LogWarning("input origin isn't verified");
2214 DPL::String scheme = L"*";
2215 if (iri->scheme && strlen(iri->scheme) != 0) {
2216 scheme = DPL::FromUTF8String(iri->scheme);
2218 ConfigParserData::AllowNavigationInfo info(
2220 DPL::FromUTF8String(iri->host));
2221 m_data.allowNavigationInfoList.push_back(info);
2227 DPL::OptionalString m_origin;
2228 ConfigParserData& m_data;
2229 bool m_properNamespace;
2232 class CspParser : public ElementParser
2235 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2236 const DPL::String& /*name*/)
2238 return &IgnoringParser::Create; //ignore unknown according to w3c
2241 CspParser(ConfigParserData& data) :
2244 m_properNamespace(false)
2247 virtual void Accept(const Element& element)
2249 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2250 m_properNamespace = true;
2254 virtual void Accept(const XmlAttribute& /*attribute*/)
2257 virtual void Accept(const Text& text)
2259 if (m_properNamespace) {
2260 m_policy = text.value;
2264 virtual void Verify()
2266 if (!m_policy.IsNull()) {
2267 m_data.cspPolicy = *m_policy;
2272 ConfigParserData& m_data;
2273 bool m_properNamespace;
2274 DPL::OptionalString m_policy;
2277 class CspReportOnlyParser : public ElementParser
2280 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2281 const DPL::String& /*name*/)
2283 return &IgnoringParser::Create; //ignore unknown according to w3c
2286 CspReportOnlyParser(ConfigParserData& data) :
2289 m_properNamespace(false)
2292 virtual void Accept(const Element& element)
2294 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2295 m_properNamespace = true;
2299 virtual void Accept(const XmlAttribute& /*attribute*/)
2302 virtual void Accept(const Text& text)
2304 if (m_properNamespace) {
2305 m_policy = text.value;
2309 virtual void Verify()
2311 if (!m_policy.IsNull()) {
2312 m_data.cspPolicyReportOnly = *m_policy;
2317 ConfigParserData& m_data;
2318 bool m_properNamespace;
2319 DPL::OptionalString m_policy;
2322 class AccountParser : public ElementParser
2325 struct AccountProviderParser : public ElementParser
2329 struct IconParser : public ElementParser
2332 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2333 const DPL::String& /*name*/)
2335 return &IgnoringParser::Create; //ignore unknown according to w3c
2338 virtual void Accept(const Text& text)
2340 if (text.value == L"") {
2343 m_value = text.value;
2346 virtual void Accept(const Element& /*element*/)
2349 virtual void Accept(const XmlAttribute& attribute)
2351 if (attribute.name == L"section") {
2352 if (attribute.value == L"account") {
2353 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2354 } else if (attribute.value == L"account-small") {
2355 m_type = ConfigParserData::IconSectionType::SmallIcon;
2360 virtual void Verify()
2362 if (m_value.IsNull() || *m_value == L"") {
2366 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2367 icon.first = m_type;
2368 icon.second = *m_value;
2370 m_data.m_iconSet.insert(icon);
2373 IconParser(ConfigParserData::AccountProvider& data) :
2375 m_properNamespace(false),
2376 m_type(ConfigParserData::DefaultIcon),
2381 bool m_properNamespace;
2382 ConfigParserData::IconSectionType m_type;
2383 ConfigParserData::AccountProvider& m_data;
2384 DPL::OptionalString m_value;
2387 struct DisplayNameParser : public ElementParser
2390 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2391 const DPL::String& /*name*/)
2393 return &IgnoringParser::Create; //ignore unknown according to w3c
2396 virtual void Accept(const Text& text)
2398 if (text.value == L"") {
2401 m_value = text.value;
2404 virtual void Accept(const Element& element)
2406 m_lang = element.lang;
2410 virtual void Accept(const XmlAttribute& /*attribute*/)
2413 virtual void Verify()
2415 if (m_value.IsNull() || *m_value == L"") {
2419 std::pair<DPL::String, DPL::String> name;
2420 name.first = *m_lang;
2421 name.second = *m_value;
2423 m_data.m_displayNameSet.insert(name);
2426 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2428 m_properNamespace(false),
2433 bool m_properNamespace;
2434 DPL::OptionalString m_lang;
2435 DPL::OptionalString m_value;
2436 ConfigParserData::AccountProvider& m_data;
2439 struct CapabilityParser : public ElementParser
2442 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2443 const DPL::String& /*name*/)
2445 return &IgnoringParser::Create; //ignore unknown according to w3c
2448 virtual void Accept(const Text& text)
2450 if (text.value == L"") {
2453 m_value = text.value;
2456 virtual void Accept(const Element& /*element*/)
2459 virtual void Accept(const XmlAttribute& /*attribute*/)
2462 virtual void Verify()
2464 if (m_value.IsNull() || *m_value == L"") {
2467 m_data.m_capabilityList.push_back(*m_value);
2470 CapabilityParser(ConfigParserData::AccountProvider& data) :
2472 m_properNamespace(false),
2477 bool m_properNamespace;
2478 DPL::OptionalString m_value;
2479 ConfigParserData::AccountProvider& m_data;
2481 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2482 const DPL::String& name)
2484 if (name == L"icon") {
2485 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2486 } else if (name == L"display-name") {
2487 return DPL::MakeDelegate(this,
2488 &AccountProviderParser::OnDisplayNameElement);
2489 } else if (name == L"capability") {
2490 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2492 return &IgnoringParser::Create; //ignore unknown according to w3c
2496 virtual void Accept(const Text& /*text*/)
2499 virtual void Accept(const Element& /*element*/)
2502 virtual void Accept(const XmlAttribute& attribute)
2504 if (attribute.name == L"multiple-accounts-support") {
2505 if (attribute.value == L"true") {
2506 m_multiSupport = true;
2511 virtual void Verify()
2513 m_data.m_multiAccountSupport = m_multiSupport;
2516 ElementParserPtr OnIconElement()
2518 return ElementParserPtr(new IconParser(m_data));
2521 ElementParserPtr OnDisplayNameElement()
2523 return ElementParserPtr(new DisplayNameParser(m_data));
2526 ElementParserPtr OnCapabilityElement()
2528 return ElementParserPtr(new CapabilityParser(m_data));
2531 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2533 m_properNamespace(false),
2534 m_multiSupport(false),
2539 bool m_properNamespace;
2540 bool m_multiSupport;
2541 ConfigParserData::AccountProvider& m_data;
2544 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2545 const DPL::String& name)
2547 if (name == L"account-provider") {
2548 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2550 return &IgnoringParser::Create; //ignore unknown according to w3c
2554 virtual void Accept(const Element& element)
2556 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2557 m_properNamespace = true;
2561 virtual void Accept(const XmlAttribute& /*attribute*/)
2564 virtual void Accept(const Text& /*text*/)
2567 virtual void Verify()
2570 ElementParserPtr OnProviderElement()
2572 return ElementParserPtr(new AccountProviderParser(m_account));
2575 AccountParser(ConfigParserData& data) :
2578 m_account(data.accountProvider),
2579 m_properNamespace(false),
2580 m_multiSupport(false)
2584 ConfigParserData& m_data;
2585 ConfigParserData::AccountProvider& m_account;
2586 bool m_properNamespace;
2587 bool m_multiSupport;
2590 class MetadataParser : public ElementParser
2593 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2594 const DPL::String& /*name*/)
2596 return &IgnoringParser::Create; //ignore unknown according to w3c
2599 virtual void Accept(const XmlAttribute& attribute)
2601 if (m_properNamespace) {
2602 if (attribute.name == L"key") {
2603 m_key = attribute.value;
2604 } else if (attribute.name == L"value") {
2605 m_value = attribute.value;
2610 virtual void Accept(const Element& element)
2612 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2613 m_properNamespace = true;
2617 virtual void Accept(const Text& /*text*/)
2619 ThrowMsg(Exception::ParseError, "param element must be empty");
2622 virtual void Verify()
2624 if (m_key.IsNull()) {
2625 LogWarning("metadata element must have key attribute");
2628 NormalizeString(m_key);
2629 NormalizeString(m_value);
2630 ConfigParserData::Metadata metaData(*m_key, *m_value);
2631 FOREACH(it, m_data.metadataList) {
2632 if (!DPL::StringCompare(it->key, *m_key)) {
2633 LogError("Key isn't unique");
2637 m_data.metadataList.push_back(metaData);
2640 MetadataParser(ConfigParserData& data) :
2643 m_properNamespace(false)
2647 DPL::OptionalString m_key;
2648 DPL::OptionalString m_value;
2649 ConfigParserData& m_data;
2650 bool m_properNamespace;
2653 ElementParser::ActionFunc WidgetParser::GetElementParser(
2654 const DPL::String& /*ns*/,
2655 const DPL::String& name)
2657 FuncMap::const_iterator it = m_map.find(name);
2658 if (it != m_map.end()) {
2661 return &IgnoringParser::Create; //ignore unknown according to w3c
2665 WidgetParser::WidgetParser(ConfigParserData& data) :
2667 m_textDirection(Unicode::EMPTY)
2669 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2670 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2671 m_map[L"description"] =
2672 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2673 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2675 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2676 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2678 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2679 m_map[L"preference"] =
2680 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2681 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2683 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2684 m_map[L"application"] = DPL::MakeDelegate(
2687 OnApplicationElement);
2688 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2689 m_map[L"background"] = DPL::MakeDelegate(this,
2690 &WidgetParser::OnBackgroundElement);
2691 m_map[L"privilege"] = DPL::MakeDelegate(this,
2692 &WidgetParser::OnPrivilegeElement);
2693 m_map[L"app-control"] = DPL::MakeDelegate(
2696 OnAppControlElement);
2697 m_map[L"category"] = DPL::MakeDelegate(this,
2698 &WidgetParser::OnCategoryElement);
2699 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2701 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2705 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2708 OnCspReportOnlyElement);
2710 #ifdef ALLOW_NAVIGATION_ENABLED
2711 m_map[L"allow-navigation"] =
2712 DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
2714 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2715 m_map[L"metadata"] = DPL::MakeDelegate(this, &WidgetParser::OnMetadataElement);
2718 ElementParserPtr WidgetParser::OnNameElement()
2720 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2723 ElementParserPtr WidgetParser::OnAccessElement()
2725 return ElementParserPtr(new AccessParser(m_data));
2728 ElementParserPtr WidgetParser::OnDescriptionElement()
2730 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2733 ElementParserPtr WidgetParser::OnAuthorElement()
2735 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2738 ElementParserPtr WidgetParser::OnLicenseElement()
2740 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2743 ElementParserPtr WidgetParser::OnIconElement()
2745 return ElementParserPtr(new IconParser(m_data));
2748 ElementParserPtr WidgetParser::OnContentElement()
2750 return ElementParserPtr(new ContentParser(m_data));
2753 ElementParserPtr WidgetParser::OnPreferenceElement()
2755 return ElementParserPtr(new PreferenceParser(m_data));
2758 ElementParserPtr WidgetParser::OnLinkElement()
2760 return ElementParserPtr(new LinkParser(m_data));
2763 ElementParserPtr WidgetParser::OnSettingElement()
2765 return ElementParserPtr(new SettingParser(m_data));
2768 ElementParserPtr WidgetParser::OnApplicationElement()
2770 return ElementParserPtr(new ApplicationParser(m_data));
2773 ElementParserPtr WidgetParser::OnSplashElement()
2775 return ElementParserPtr(new SplashParser(m_data));
2778 ElementParserPtr WidgetParser::OnBackgroundElement()
2780 return ElementParserPtr(new BackgroundParser(m_data));
2783 ElementParserPtr WidgetParser::OnPrivilegeElement()
2785 return ElementParserPtr(new PrivilegeParser(m_data));
2788 ElementParserPtr WidgetParser::OnAppControlElement()
2790 return ElementParserPtr(new AppControlParser(m_data));
2793 ElementParserPtr WidgetParser::OnCategoryElement()
2795 return ElementParserPtr(new CategoryParser(m_data));
2798 ElementParserPtr WidgetParser::OnAppWidgetElement()
2800 return ElementParserPtr(new AppWidgetParser(m_data));
2803 ElementParserPtr WidgetParser::OnCspElement()
2805 return ElementParserPtr(new CspParser(m_data));
2808 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2810 return ElementParserPtr(new CspReportOnlyParser(m_data));
2813 ElementParserPtr WidgetParser::OnAllowNavigationElement()
2815 return ElementParserPtr(new AllowNavigationParser(m_data));
2818 ElementParserPtr WidgetParser::OnAccountElement()
2820 return ElementParserPtr(new AccountParser(m_data));
2823 ElementParserPtr WidgetParser::OnMetadataElement()
2825 return ElementParserPtr(new MetadataParser(m_data));
2828 void WidgetParser::Accept(const Element& element)
2830 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2831 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2833 ThrowMsg(Exception::ParseError,
2834 "Wrong xml namespace for widget element");
2838 void WidgetParser::Accept(const Text& /*text*/)
2840 ThrowMsg(Exception::ParseError, "widged element must be empty");
2843 void WidgetParser::Accept(const XmlAttribute& attribute)
2845 if (attribute.name == L"id") {
2846 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2847 //If may important tests starts to fail this test we will have
2848 //to consider commenting this test out again.
2849 if (iri.Validate()) {
2850 m_data.widget_id = attribute.value;
2851 NormalizeString(m_data.widget_id);
2853 LogWarning("Widget id validation failed: " << attribute.value);
2855 } else if (attribute.name == L"version") {
2856 m_version = attribute.value;
2857 NormalizeString(m_version);
2858 } else if (attribute.name == L"min-version") {
2859 LogInfo("min-version attribute was found. Value: " << attribute.value);
2860 m_minVersion = attribute.value;
2861 NormalizeString(m_minVersion);
2862 m_data.minVersionRequired = m_minVersion;
2863 } else if (attribute.name == L"height") {
2864 DPL::OptionalString value = attribute.value;
2865 NormalizeString(value);
2866 std::string v = DPL::ToUTF8String(*value);
2869 unsigned char c = v.c_str()[0];
2872 for (size_t i = 0; i < v.size(); ++i) {
2881 m_data.height = val;
2884 } else if (attribute.name == L"width") {
2885 DPL::OptionalString value = attribute.value;
2886 NormalizeString(value);
2887 std::string v = DPL::ToUTF8String(*value);
2890 unsigned char c = v.c_str()[0];
2891 if (c >= '0' && c <= '9') {
2893 for (size_t i = 0; i < v.size(); ++i) {
2895 if (c >= '0' && c <= '9') {
2905 } else if (attribute.name == L"viewmodes") {
2906 DPL::Tokenize(attribute.value,
2908 std::inserter(m_windowModes,
2909 m_windowModes.end()),
2911 } else if (attribute.name == L"dir") {
2912 m_textDirection = Unicode::ParseDirAttribute(attribute);
2913 } else if (L"defaultlocale" == attribute.name) {
2914 if (!m_defaultlocale) {
2915 m_defaultlocale = attribute.value;
2916 NormalizeString(m_defaultlocale);
2917 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2918 DPL::ToUTF8String(*m_defaultlocale)))
2920 LogWarning("Language tag: " <<
2921 m_defaultlocale << " is not valid");
2922 m_defaultlocale = DPL::OptionalString::Null;
2924 LogDebug("Default Locale Found " << m_defaultlocale);
2927 LogWarning("Ignoring subsequent default locale");
2930 //Any other value consider as a namespace definition
2931 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2932 LogInfo("Namespace domain: " << attribute.name);
2933 LogInfo("Namespace value: " << attribute.value);
2934 m_nameSpaces[attribute.name] = attribute.value;
2936 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2937 ", name=" << attribute.name <<
2938 ", value=" << attribute.value);
2942 void WidgetParser::Verify()
2944 FOREACH(mode, m_windowModes) {
2945 if (L"windowed" == *mode || L"floating" == *mode ||
2946 L"fullscreen" == *mode || L"maximized" == *mode ||
2947 L"minimized" == *mode)
2949 m_data.windowModes.insert(*mode);
2952 if (!m_version.IsNull()) {
2953 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2954 m_data.version = m_version;
2956 m_data.defaultlocale = m_defaultlocale;
2957 FOREACH(ns, m_nameSpaces) {
2958 m_data.nameSpaces.insert(ns->second);