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 SettingParser : public ElementParser
827 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
828 const DPL::String& /*name*/)
830 return &IgnoringParser::Create; //ignore unknown according to w3c
833 virtual void Accept(const Text& /*text*/)
836 virtual void Accept(const Element& /*element*/)
839 virtual void Accept(const XmlAttribute& attribute)
841 m_setting.m_name = attribute.name;
842 m_setting.m_value = attribute.value;
843 m_data.settingsList.insert(m_setting);
846 virtual void Verify()
849 SettingParser(ConfigParserData& data) :
856 ConfigParserData& m_data;
857 ConfigParserData::Setting m_setting;
860 class AppControlParser : public ElementParser
863 struct SourceParser : public ElementParser
866 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
867 const DPL::String& /*name*/)
869 return &IgnoringParser::Create; //ignore unknown according to w3c
872 virtual void Accept(const Text& /*text*/)
875 virtual void Accept(const Element& /*element*/)
878 virtual void Accept(const XmlAttribute& attribute)
880 if (attribute.name == L"name") {
881 if (attribute.value.size() > 0) {
882 m_value = attribute.value;
883 NormalizeString(m_value);
888 virtual void Verify()
890 if (m_value.IsNull() || *m_value == L"") {
894 m_data.m_src = *m_value;
897 SourceParser(ConfigParserData::AppControlInfo& data) :
899 m_properNamespace(false),
904 bool m_properNamespace;
905 DPL::OptionalString m_value;
906 ConfigParserData::AppControlInfo& m_data;
909 struct OperationParser : public ElementParser
912 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
913 const DPL::String& /*name*/)
915 return &IgnoringParser::Create; //ignore unknown according to w3c
918 virtual void Accept(const Text& /*text*/)
921 virtual void Accept(const Element& /*element*/)
924 virtual void Accept(const XmlAttribute& attribute)
926 if (attribute.name == L"name") {
927 if (attribute.value.size() > 0) {
928 m_value = attribute.value;
929 NormalizeString(m_value);
934 virtual void Verify()
936 if (m_value.IsNull() || *m_value == L"") {
940 m_data.m_operation = *m_value;
943 OperationParser(ConfigParserData::AppControlInfo& data) :
945 m_properNamespace(false),
950 bool m_properNamespace;
951 DPL::OptionalString m_value;
952 ConfigParserData::AppControlInfo& m_data;
955 struct UriParser : public ElementParser
958 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
959 const DPL::String& /*name*/)
961 return &IgnoringParser::Create; //ignore unknown according to w3c
964 virtual void Accept(const Text& /*text*/)
967 virtual void Accept(const Element& /*element*/)
970 virtual void Accept(const XmlAttribute& attribute)
972 if (attribute.name == L"name") {
973 if (attribute.value.size() > 0) {
974 m_value = attribute.value;
975 NormalizeString(m_value);
980 virtual void Verify()
983 DPL::String ignoreUri(L"file");
985 if (!m_value.IsNull() && *m_value == ignoreUri)
987 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
988 m_value = DPL::OptionalString::Null;
991 if (m_value.IsNull() || *m_value == L"") {
995 DPL::String wildString(L"*/*");
996 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
997 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
999 m_data.m_uriList.insert(*m_value);
1001 LogDebug("Ignoring uri with name" <<
1002 DPL::ToUTF8String(*m_value));
1006 UriParser(ConfigParserData::AppControlInfo& data) :
1008 m_properNamespace(false),
1013 bool m_properNamespace;
1014 DPL::OptionalString m_value;
1015 ConfigParserData::AppControlInfo& m_data;
1018 struct MimeParser : public ElementParser
1021 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1022 const DPL::String& /*name*/)
1024 return &IgnoringParser::Create; //ignore unknown according to w3c
1027 virtual void Accept(const Text& /*text*/)
1030 virtual void Accept(const Element& /*element*/)
1033 virtual void Accept(const XmlAttribute& attribute)
1035 if (attribute.name == L"name") {
1036 if (attribute.value.size() > 0) {
1037 m_value = attribute.value;
1038 NormalizeString(m_value);
1043 virtual void Verify()
1045 if (m_value.IsNull() || *m_value == L"") {
1049 DPL::String wildString(L"*/*");
1050 if ((m_data.m_mimeList.find(wildString) ==
1051 m_data.m_mimeList.end())
1052 && (m_data.m_mimeList.find(*m_value) ==
1053 m_data.m_mimeList.end()))
1055 m_data.m_mimeList.insert(*m_value);
1057 LogDebug("Ignoring mime with name" <<
1058 DPL::ToUTF8String(*m_value));
1062 MimeParser(ConfigParserData::AppControlInfo& data) :
1064 m_properNamespace(false),
1069 bool m_properNamespace;
1070 DPL::OptionalString m_value;
1071 ConfigParserData::AppControlInfo& m_data;
1074 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1075 const DPL::String& name)
1077 if (name == L"src") {
1078 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1079 } else if (name == L"operation") {
1080 return DPL::MakeDelegate(this,
1081 &AppControlParser::OnOperationElement);
1082 } else if (name == L"uri") {
1083 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1084 } else if (name == L"mime") {
1085 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1087 return &IgnoringParser::Create; //ignore unknown according to w3c
1091 virtual void Accept(const XmlAttribute& /*attribute*/)
1094 virtual void Accept(const Element& element)
1096 LogWarning("namespace for app service = " << element.ns);
1097 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1098 ThrowMsg(Exception::ParseError,
1099 "Wrong xml namespace for widget element");
1103 virtual void Accept(const Text& /*text*/)
1105 ThrowMsg(Exception::ParseError, "param element must be empty");
1108 virtual void Verify()
1110 if (m_appControl.m_src == L"") {
1111 ThrowMsg(Exception::ParseError, "service element must have src element");
1114 if (m_appControl.m_operation == L"") {
1115 ThrowMsg(Exception::ParseError, "service element must have operation element");
1118 m_data.appControlList.push_back(m_appControl);
1121 ElementParserPtr OnSourceElement()
1123 return ElementParserPtr(new SourceParser(m_appControl));
1126 ElementParserPtr OnOperationElement()
1128 return ElementParserPtr(new OperationParser(m_appControl));
1131 ElementParserPtr OnUriElement()
1133 return ElementParserPtr(new UriParser(m_appControl));
1136 ElementParserPtr OnMimeElement()
1138 return ElementParserPtr(new MimeParser(m_appControl));
1141 AppControlParser(ConfigParserData& data) :
1148 ConfigParserData& m_data;
1149 ConfigParserData::AppControlInfo m_appControl;
1152 class ApplicationParser : public ElementParser
1155 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1156 const DPL::String& /*name*/)
1158 return &IgnoringParser::Create; //ignore unknown according to w3c
1161 virtual void Accept(const Text& /*text*/)
1163 if (m_properNamespace) {
1164 ThrowMsg(Exception::ParseError, "application element must be empty");
1168 virtual void Accept(const Element& element)
1171 ConfigurationNamespace::TizenWebAppNamespaceName)
1173 m_properNamespace = true;
1177 virtual void Accept(const XmlAttribute& attribute)
1179 if (m_properNamespace) {
1180 if (attribute.name == L"id") {
1181 m_id = attribute.value;
1182 NormalizeAndTrimSpaceString(m_id);
1183 } else if (attribute.name == L"package") {
1184 m_package = attribute.value;
1185 } else if (attribute.name == L"required_version") {
1186 m_version = attribute.value;
1187 NormalizeString(m_version);
1189 ThrowMsg(Exception::ParseError,
1190 "unknown attribute '" +
1191 DPL::ToUTF8String(attribute.name) +
1192 "' in application element");
1197 virtual void Verify()
1199 VerifyIdAndPackage();
1203 ApplicationParser(ConfigParserData& data) :
1206 m_id(DPL::OptionalString::Null),
1207 m_version(DPL::OptionalString::Null),
1208 m_properNamespace(false)
1211 static const char* const REGEXP_ID;
1214 void VerifyIdAndPackage()
1218 ThrowMsg(Exception::ParseError,
1219 "application element must have package attribute");
1223 pcrecpp::RE re(REGEXP_PACKAGE);
1224 if (!re.FullMatch(DPL::ToUTF8String(*m_package)))
1226 ThrowMsg(Exception::ParseError,
1227 "invalid format of package attribute");
1232 ThrowMsg(Exception::ParseError,
1233 "application element must have id attribute");
1237 std::string package;
1238 pcrecpp::RE re(REGEXP_ID);
1239 if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
1241 ThrowMsg(Exception::ParseError,
1242 "invalid format of id attribute");
1244 if (package != DPL::ToUTF8String(*m_package))
1246 ThrowMsg(Exception::ParseError,
1247 "invalid package prefix in id attribute");
1251 m_data.tizenAppId = m_id;
1252 m_data.tizenPkgId = m_package;
1255 void VerifyVersion()
1259 ThrowMsg(Exception::ParseError,
1260 "application element must have required_version attribute");
1264 pcrecpp::RE re(REGEXP_VERSION);
1265 if (!re.FullMatch(DPL::ToUTF8String(*m_version)))
1267 ThrowMsg(Exception::ParseError,
1268 "invalid format of version attribute");
1272 m_data.tizenMinVersionRequired = m_version;
1275 static const char* const REGEXP_PACKAGE;
1276 static const char* const REGEXP_VERSION;
1278 ConfigParserData& m_data;
1279 DPL::OptionalString m_id;
1280 DPL::OptionalString m_package;
1281 DPL::OptionalString m_version;
1282 bool m_properNamespace;
1285 const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}";
1286 const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\.[0-9A-Za-z]{1,52}";
1287 const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?";
1289 class SplashParser : public ElementParser
1292 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1293 const DPL::String& /*name*/)
1295 return &IgnoringParser::Create; //ignore unknown according to w3c
1298 virtual void Accept(const XmlAttribute& attribute)
1300 if (m_properNamespace)
1302 if (attribute.name == L"src") {
1303 if (attribute.value.size() > 0) {
1304 m_src = attribute.value;
1310 virtual void Accept(const Element& element)
1313 ConfigurationNamespace::TizenWebAppNamespaceName)
1315 m_properNamespace = true;
1319 virtual void Accept(const Text& /*text*/)
1322 virtual void Verify()
1326 LogWarning("src attribute of splash element is mandatory - ignoring");
1330 m_data.splashImgSrc = m_src;
1333 SplashParser(ConfigParserData& data) :
1336 m_properNamespace(false)
1340 DPL::OptionalString m_src;
1341 ConfigParserData& m_data;
1342 bool m_properNamespace;
1345 class BackgroundParser : public ElementParser
1348 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1349 const DPL::String& /*name*/)
1351 return &IgnoringParser::Create; //ignore unknown according to w3c
1354 virtual void Accept(const XmlAttribute& attribute)
1356 if (attribute.name == L"src") {
1357 if (attribute.value.size() > 0) {
1358 m_src = attribute.value;
1363 virtual void Accept(const Element& /*element*/)
1366 virtual void Accept(const Text& /*text*/)
1369 virtual void Verify()
1371 if (m_src.IsNull()) {
1373 "src attribute of background element is mandatory - ignoring");
1377 m_data.backgroundPage = m_src;
1380 explicit BackgroundParser(ConfigParserData& data) :
1385 DPL::OptionalString m_src;
1386 ConfigParserData& m_data;
1389 class PrivilegeParser : public ElementParser
1392 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1393 const DPL::String& /*name*/)
1395 return &IgnoringParser::Create; //ignore unknown according to w3c
1398 virtual void Accept(const Text& /*text*/)
1401 virtual void Accept(const Element& element)
1404 ConfigurationNamespace::TizenWebAppNamespaceName)
1406 m_properNamespace = true;
1408 LogDebug("element");
1411 virtual void Accept(const XmlAttribute& attribute)
1413 if (m_properNamespace) {
1414 if (attribute.name == L"name") {
1415 m_feature.name = attribute.value;
1416 m_privilege.name = attribute.value;
1421 virtual void Verify()
1423 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1425 if (m_feature.name != L"") {
1426 if (iri.Validate()) {
1427 if (m_data.featuresList.find(m_feature) ==
1428 m_data.featuresList.end())
1430 m_data.featuresList.insert(m_feature);
1432 LogDebug("Ignoring feature with name" <<
1433 DPL::ToUTF8String(m_feature.name));
1438 LibIri::Wrapper iriPrivilege(
1439 DPL::ToUTF8String(m_privilege.name).c_str());
1441 if (m_privilege.name != L"") {
1442 if (iriPrivilege.Validate()) {
1443 if (m_data.privilegeList.find(m_privilege) ==
1444 m_data.privilegeList.end())
1446 m_data.privilegeList.insert(m_privilege);
1448 LogDebug("Ignoring privilege with name" <<
1449 DPL::ToUTF8String(m_privilege.name));
1455 PrivilegeParser(ConfigParserData& data) :
1460 m_properNamespace(false)
1464 ConfigParserData& m_data;
1465 ConfigParserData::Feature m_feature;
1466 ConfigParserData::Privilege m_privilege;
1467 bool m_properNamespace;
1470 class CategoryParser : public ElementParser
1473 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1474 const DPL::String& /*name*/)
1476 return &IgnoringParser::Create; //ignore unknown according to w3c
1479 virtual void Accept(const XmlAttribute& attribute)
1481 if (attribute.name == L"name") {
1482 if (attribute.value.size() > 0) {
1483 m_name = attribute.value;
1488 virtual void Accept(const Element& /*element*/)
1491 virtual void Accept(const Text& /*text*/)
1494 virtual void Verify()
1496 if (m_name.IsNull()) {
1498 "name attribute of category element is mandatory - ignoring");
1502 if (m_data.categoryList.find(*m_name) ==
1503 m_data.categoryList.end())
1505 m_data.categoryList.insert(*m_name);
1509 explicit CategoryParser(ConfigParserData& data) :
1514 DPL::OptionalString m_name;
1515 ConfigParserData& m_data;
1518 class AppWidgetParser : public ElementParser
1522 struct BoxLabelParser : public ElementParser
1524 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1525 const DPL::String& /*name*/)
1527 return &IgnoringParser::Create; //ignore unknown according to w3c
1530 virtual void Accept(const XmlAttribute& attribute)
1532 if (m_properNamespace) {
1533 m_lang = attribute.lang;
1536 virtual void Accept(const Element& element)
1539 ConfigurationNamespace::TizenWebAppNamespaceName)
1541 m_properNamespace = true;
1545 virtual void Accept(const Text& text)
1547 if (m_properNamespace) {
1548 m_label = text.value;
1552 virtual void Verify()
1554 std::pair<DPL::String, DPL::String> boxLabel;
1555 if (m_label.empty()) {
1556 LogWarning("box-label element is empty");
1557 boxLabel.first = DPL::FromUTF8String("");
1558 boxLabel.second = DPL::FromUTF8String("");
1559 m_data.m_label.push_back(boxLabel);
1562 boxLabel.first = m_lang;
1563 boxLabel.second = m_label;
1564 m_data.m_label.push_back(boxLabel);
1568 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1570 m_properNamespace(false),
1576 DPL::String m_label;
1577 bool m_properNamespace;
1578 ConfigParserData::LiveboxInfo& m_data;
1581 struct BoxIconParser : public ElementParser
1583 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1584 const DPL::String& /*name*/)
1586 return &IgnoringParser::Create; //ignore unknown according to w3c
1589 virtual void Accept(const XmlAttribute& attribute)
1591 if (m_properNamespace) {
1592 if (attribute.name == L"src") {
1593 m_icon = attribute.value;
1598 virtual void Accept(const Element& element)
1601 ConfigurationNamespace::TizenWebAppNamespaceName)
1603 m_properNamespace = true;
1607 virtual void Accept(const Text& /*text*/)
1610 virtual void Verify()
1612 if (m_icon.empty()) {
1613 ThrowMsg(Exception::ParseError,
1614 "src attribute of box-icon element is mandatory - ignoring");
1616 m_data.m_icon = m_icon;
1619 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1621 m_properNamespace(false),
1627 bool m_properNamespace;
1628 ConfigParserData::LiveboxInfo& m_data;
1631 struct BoxContentParser : public ElementParser
1633 struct BoxSizeParser : public ElementParser
1635 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1636 const DPL::String& /*name*/)
1638 return &IgnoringParser::Create; //ignore unknown according to w3c
1641 virtual void Accept(const XmlAttribute& attribute)
1643 if (m_properNamespace) {
1644 if (attribute.name == L"preview") {
1645 m_preview = attribute.value;
1647 if (attribute.name == L"use-decoration") {
1648 m_useDecoration = attribute.value;
1653 virtual void Accept(const Element& element)
1656 ConfigurationNamespace::TizenWebAppNamespaceName)
1658 m_properNamespace = true;
1662 virtual void Accept(const Text& text)
1664 if (m_properNamespace) {
1665 m_size = text.value;
1669 virtual void Verify()
1671 if(m_size.empty()) {
1672 ThrowMsg(Exception::ParseError,
1673 "size is mandatory - ignoring");
1676 ConfigParserData::LiveboxInfo::BoxSizeInfo boxSizeInfo;
1677 boxSizeInfo.m_size = m_size;
1678 boxSizeInfo.m_preview = m_preview;
1679 boxSizeInfo.m_useDecoration = m_useDecoration;
1680 m_data.m_boxSize.push_back(boxSizeInfo);
1683 explicit BoxSizeParser(
1684 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1686 m_properNamespace(false),
1692 DPL::String m_preview;
1693 DPL::String m_useDecoration;
1694 bool m_properNamespace;
1695 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1698 struct PdParser : public ElementParser
1700 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1701 const DPL::String& /*name*/)
1703 return &IgnoringParser::Create; //ignore unknown according to w3c
1706 virtual void Accept(const XmlAttribute& attribute)
1708 if (m_properNamespace) {
1709 if (attribute.name == L"src") {
1710 m_src = attribute.value;
1711 } else if (attribute.name == L"width") {
1712 m_width = attribute.value;
1713 } else if (attribute.name == L"height") {
1714 m_height = attribute.value;
1715 } else if (attribute.name == L"fast-open") {
1716 m_fastOpen= attribute.value;
1721 virtual void Accept(const Element& element)
1724 ConfigurationNamespace::TizenWebAppNamespaceName)
1726 m_properNamespace = true;
1730 virtual void Accept(const Text& /*text*/)
1733 virtual void Verify()
1735 if (m_src.empty()) {
1736 ThrowMsg(Exception::ParseError,
1737 "src attribute of pd element is mandatory - ignoring");
1740 if (m_width.empty()) {
1741 ThrowMsg(Exception::ParseError,
1742 "width attribute of pd element is mandatory - ignoring");
1745 if (m_height.empty()) {
1746 ThrowMsg(Exception::ParseError,
1747 "height attribute of pd element is mandatory - ignoring");
1750 if (ConvertToInt(m_width).IsNull()) {
1751 ThrowMsg(Exception::ParseError,
1752 "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width);
1756 DPL::OptionalInt height = ConvertToInt(m_height);
1758 if (height.IsNull()) {
1759 ThrowMsg(Exception::ParseError,
1760 "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height);
1765 LogDebug("height attribute of pd element shouldn't be less than 1. Changed to 1 from " << *height);
1766 } else if (*height > 380){
1768 LogDebug("height attribute of pd element shouldn't be greater than 380. Changed to 380 from " << *height);
1771 m_data.m_pdSrc = m_src;
1772 m_data.m_pdWidth = m_width;
1773 m_data.m_pdHeight = m_height;
1774 m_data.m_pdFastOpen = m_fastOpen;
1778 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1780 m_properNamespace(false),
1785 DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
1788 std::string tempStr = DPL::ToUTF8String(intAsString);
1789 const char * intAsString_c = tempStr.c_str();
1791 long int intAsString_i = strtol(intAsString_c, &endptr, 10);
1793 if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
1794 || intAsString_i > INT_MAX || intAsString_i < INT_MIN
1795 || *endptr != '\0') {
1796 return DPL::OptionalInt::Null;
1799 return static_cast<int>(intAsString_i);
1803 DPL::String m_width;
1804 DPL::String m_height;
1805 DPL::String m_fastOpen;
1807 bool m_properNamespace;
1808 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1811 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1812 const DPL::String& name)
1814 if (name == L"box-size") {
1815 return DPL::MakeDelegate(
1817 &AppWidgetParser::BoxContentParser::
1819 } else if (name == L"pd") {
1820 return DPL::MakeDelegate(
1822 &AppWidgetParser::BoxContentParser::
1825 ThrowMsg(Exception::ParseError,
1826 "No element parser for name: " << name);
1830 virtual void Accept(const XmlAttribute& attribute)
1832 if (m_properNamespace) {
1833 if (attribute.name == L"src") {
1834 m_box.m_boxSrc = attribute.value;
1836 if (attribute.name == L"mouse-event") {
1837 m_box.m_boxMouseEvent = attribute.value;
1839 if (attribute.name == L"touch-effect") {
1840 m_box.m_boxTouchEffect = attribute.value;
1845 virtual void Accept(const Element& element)
1848 ConfigurationNamespace::TizenWebAppNamespaceName)
1850 m_properNamespace = true;
1854 virtual void Accept(const Text& /*text*/)
1857 virtual void Verify()
1859 if (m_box.m_boxSrc.empty()) {
1860 ThrowMsg(Exception::ParseError,
1861 "src attribute of box-content element is mandatory - ignoring");
1864 if (!m_box.m_boxMouseEvent.empty() &&
1865 CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent))
1867 ThrowMsg(Exception::ParseError,
1868 "mouse-event attribute of box-content element should be true or false - ignoring");
1871 if (!m_box.m_boxTouchEffect.empty() &&
1872 CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect))
1874 ThrowMsg(Exception::ParseError,
1875 "touch-effect attribute of box-content element should be true or false - ignoring");
1878 if (m_box.m_boxMouseEvent.empty()) {
1879 m_box.m_boxMouseEvent = L"false";
1882 if (m_box.m_boxTouchEffect.empty()) {
1883 m_box.m_boxTouchEffect = L"true";
1886 if (m_box.m_boxSize.empty()) {
1887 ThrowMsg(Exception::ParseError,
1888 "box-size element of box-content element not found - ignoring");
1891 m_data.m_boxInfo = m_box;
1894 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1896 m_properNamespace(false),
1900 ElementParserPtr OnBoxSizeElement()
1902 return ElementParserPtr(new BoxSizeParser(m_box));
1905 ElementParserPtr OnPdElement()
1907 return ElementParserPtr(new PdParser(m_box));
1911 bool m_properNamespace;
1912 ConfigParserData::LiveboxInfo& m_data;
1913 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1916 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1917 const DPL::String& name)
1919 if (name == L"box-label") {
1920 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1921 } else if (name == L"box-icon") {
1922 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1923 } else if (name == L"box-content") {
1924 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1926 return &IgnoringParser::Create; //ignore unknown according to w3c
1930 virtual void Accept(const XmlAttribute& attribute)
1932 if (m_properNamespace) {
1933 if (attribute.name == L"id") {
1934 m_liveboxId = attribute.value;
1935 } else if (attribute.name == L"primary") {
1936 m_primary = attribute.value;
1937 } else if (attribute.name == L"auto-launch") {
1938 m_autoLaunch = attribute.value;
1939 } else if (attribute.name == L"update-period") {
1940 m_updatePeriod = attribute.value;
1941 } else if (attribute.name == L"type") {
1942 m_type = attribute.value;
1947 virtual void Accept(const Element& element)
1950 ConfigurationNamespace::TizenWebAppNamespaceName)
1952 m_properNamespace = true;
1956 virtual void Accept(const Text& /*text*/)
1959 virtual void Verify()
1961 if (m_liveboxId.empty()) {
1962 ThrowMsg(Exception::ParseError,
1963 "app-widget element must have id attribute");
1967 pcrecpp::RE re(REGEXP_ID_STRING.c_str());
1968 if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId)))
1970 ThrowMsg(Exception::ParseError,
1971 "invalid format of app-widget id attribute");
1975 if (m_primary.empty())
1977 ThrowMsg(Exception::ParseError,
1978 "app-widget element must have primary attribute");
1979 } else if (CheckIfNotTrueNorFalse(m_primary))
1981 ThrowMsg(Exception::ParseError,
1982 "auto-launch attribute of app-widget element should be true or false - ignoring");
1985 if (!m_autoLaunch.empty() &&
1986 CheckIfNotTrueNorFalse(m_autoLaunch))
1988 ThrowMsg(Exception::ParseError,
1989 "auto-launch attribute of app-widget element should be true or false - ignoring");
1992 if (!m_updatePeriod.empty())
1996 std::string tempStr = DPL::ToUTF8String(m_updatePeriod);
1998 //set standard locale to fix decimal point mark - '.'
1999 std::string currentLocale = setlocale(LC_NUMERIC, NULL);
2000 if (NULL == setlocale(LC_NUMERIC, "C"))
2001 LogWarning("Failed to change locale to \"C\"");
2002 double updatePeriod = strtod(tempStr.c_str(), &endptr);
2004 //go back to previous locale
2005 if (NULL == setlocale(LC_NUMERIC, currentLocale.c_str()))
2006 LogWarning("Failed to set previous locale");
2008 if ((errno == ERANGE && (updatePeriod == -HUGE_VAL || updatePeriod == HUGE_VAL))
2009 || *endptr != '\0') {
2010 ThrowMsg(Exception::ParseError,
2011 "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod);
2012 } else if (updatePeriod < 1800.0) {
2013 LogDebug("update-period attribute of app-widget element shouldn't be less than 1800.0 - changed to 1800 from value: " << m_updatePeriod);
2014 m_updatePeriod = L"1800.0";
2018 if (m_autoLaunch.empty()) {
2019 m_autoLaunch = L"false";
2022 if(m_livebox.m_label.empty()) {
2023 ThrowMsg(Exception::ParseError,
2024 "box-label element of app-widget element not found - ignoring");
2027 if(!m_boxContentFound) {
2028 ThrowMsg(Exception::ParseError,
2029 "box-content element of app-widget element not found - ignoring");
2032 m_livebox.m_liveboxId = m_liveboxId;
2033 m_livebox.m_primary = m_primary;
2034 m_livebox.m_autoLaunch = m_autoLaunch;
2035 m_livebox.m_updatePeriod = m_updatePeriod;
2036 m_livebox.m_type = m_type;
2038 m_data.m_livebox.push_back(m_livebox);
2041 explicit AppWidgetParser(ConfigParserData& data) :
2044 m_properNamespace(false),
2045 m_boxContentFound(false)
2047 m_livebox = ConfigParserData::LiveboxInfo();
2050 ElementParserPtr OnBoxLabelElement()
2053 return ElementParserPtr(new BoxLabelParser(m_livebox));
2056 ElementParserPtr OnBoxIconElement()
2058 return ElementParserPtr(new BoxIconParser(m_livebox));
2061 ElementParserPtr OnBoxContentElement()
2063 m_boxContentFound = true;
2064 return ElementParserPtr(new BoxContentParser(m_livebox));
2068 static std::string REGEXP_ID_STRING;
2069 ConfigParserData& m_data;
2070 ConfigParserData::LiveboxInfo m_livebox;
2071 DPL::String m_liveboxId;
2072 DPL::String m_primary;
2073 DPL::String m_autoLaunch;
2074 DPL::String m_updatePeriod;
2076 bool m_properNamespace;
2077 bool m_boxContentFound;
2079 static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck)
2081 return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0;
2085 std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+";
2087 class AllowNavigationParser : public ElementParser
2090 AllowNavigationParser(ConfigParserData& data) :
2093 m_properNamespace(false)
2096 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2097 const DPL::String& /*name*/)
2099 return &IgnoringParser::Create; //ignore unknown according to w3c
2102 virtual void Accept(const Element& element)
2104 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2105 m_properNamespace = true;
2109 virtual void Accept(const Text& text)
2111 if (m_properNamespace) {
2112 m_origin = text.value;
2116 virtual void Accept(const XmlAttribute& /*attribute*/)
2120 virtual void Verify()
2122 if (m_origin.IsNull()) {
2123 LogWarning("data is empty");
2127 char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
2128 char* ptr = strtok(data," ");
2129 while (ptr != NULL) {
2130 std::string origin = ptr;
2131 ptr = strtok(NULL," ");
2133 ConfigParserData::AllowNavigationInfo info(L"*", L"*");
2134 m_data.allowNavigationInfoList.push_back(info);
2138 DPL::ScopedPtr<iri_t> iri(iri_parse(origin.c_str()));
2139 if (!iri->host || strlen(iri->host) == 0) {
2140 // input origin should has schem and host
2141 // in case of file scheme path is filled
2143 LogWarning("input origin isn't verified");
2146 DPL::String scheme = L"*";
2147 if (iri->scheme && strlen(iri->scheme) != 0) {
2148 scheme = DPL::FromUTF8String(iri->scheme);
2150 ConfigParserData::AllowNavigationInfo info(
2152 DPL::FromUTF8String(iri->host));
2153 m_data.allowNavigationInfoList.push_back(info);
2159 DPL::OptionalString m_origin;
2160 ConfigParserData& m_data;
2161 bool m_properNamespace;
2164 class CspParser : public ElementParser
2167 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2168 const DPL::String& /*name*/)
2170 return &IgnoringParser::Create; //ignore unknown according to w3c
2173 CspParser(ConfigParserData& data) :
2176 m_properNamespace(false)
2179 virtual void Accept(const Element& element)
2181 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2182 m_properNamespace = true;
2186 virtual void Accept(const XmlAttribute& /*attribute*/)
2189 virtual void Accept(const Text& text)
2191 if (m_properNamespace) {
2192 m_policy = text.value;
2196 virtual void Verify()
2198 if (!m_policy.IsNull()) {
2199 m_data.cspPolicy = *m_policy;
2204 ConfigParserData& m_data;
2205 bool m_properNamespace;
2206 DPL::OptionalString m_policy;
2209 class CspReportOnlyParser : public ElementParser
2212 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2213 const DPL::String& /*name*/)
2215 return &IgnoringParser::Create; //ignore unknown according to w3c
2218 CspReportOnlyParser(ConfigParserData& data) :
2221 m_properNamespace(false)
2224 virtual void Accept(const Element& element)
2226 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2227 m_properNamespace = true;
2231 virtual void Accept(const XmlAttribute& /*attribute*/)
2234 virtual void Accept(const Text& text)
2236 if (m_properNamespace) {
2237 m_policy = text.value;
2241 virtual void Verify()
2243 if (!m_policy.IsNull()) {
2244 m_data.cspPolicyReportOnly = *m_policy;
2249 ConfigParserData& m_data;
2250 bool m_properNamespace;
2251 DPL::OptionalString m_policy;
2254 class AccountParser : public ElementParser
2257 struct AccountProviderParser : public ElementParser
2261 struct IconParser : public ElementParser
2264 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2265 const DPL::String& /*name*/)
2267 return &IgnoringParser::Create; //ignore unknown according to w3c
2270 virtual void Accept(const Text& text)
2272 if (text.value == L"") {
2275 m_value = text.value;
2278 virtual void Accept(const Element& /*element*/)
2281 virtual void Accept(const XmlAttribute& attribute)
2283 if (attribute.name == L"section") {
2284 if (attribute.value == L"account") {
2285 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2286 } else if (attribute.value == L"account-small") {
2287 m_type = ConfigParserData::IconSectionType::SmallIcon;
2292 virtual void Verify()
2294 if (m_value.IsNull() || *m_value == L"") {
2298 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2299 icon.first = m_type;
2300 icon.second = *m_value;
2302 m_data.m_iconSet.insert(icon);
2305 IconParser(ConfigParserData::AccountProvider& data) :
2307 m_properNamespace(false),
2308 m_type(ConfigParserData::DefaultIcon),
2313 bool m_properNamespace;
2314 ConfigParserData::IconSectionType m_type;
2315 ConfigParserData::AccountProvider& m_data;
2316 DPL::OptionalString m_value;
2319 struct DisplayNameParser : public ElementParser
2322 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2323 const DPL::String& /*name*/)
2325 return &IgnoringParser::Create; //ignore unknown according to w3c
2328 virtual void Accept(const Text& text)
2330 if (text.value == L"") {
2333 m_value = text.value;
2336 virtual void Accept(const Element& element)
2338 m_lang = element.lang;
2342 virtual void Accept(const XmlAttribute& /*attribute*/)
2345 virtual void Verify()
2347 if (m_value.IsNull() || *m_value == L"") {
2351 std::pair<DPL::String, DPL::String> name;
2352 name.first = *m_lang;
2353 name.second = *m_value;
2355 m_data.m_displayNameSet.insert(name);
2358 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2360 m_properNamespace(false),
2365 bool m_properNamespace;
2366 DPL::OptionalString m_lang;
2367 DPL::OptionalString m_value;
2368 ConfigParserData::AccountProvider& m_data;
2371 struct CapabilityParser : public ElementParser
2374 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2375 const DPL::String& /*name*/)
2377 return &IgnoringParser::Create; //ignore unknown according to w3c
2380 virtual void Accept(const Text& text)
2382 if (text.value == L"") {
2385 m_value = text.value;
2388 virtual void Accept(const Element& /*element*/)
2391 virtual void Accept(const XmlAttribute& /*attribute*/)
2394 virtual void Verify()
2396 if (m_value.IsNull() || *m_value == L"") {
2399 m_data.m_capabilityList.push_back(*m_value);
2402 CapabilityParser(ConfigParserData::AccountProvider& data) :
2404 m_properNamespace(false),
2409 bool m_properNamespace;
2410 DPL::OptionalString m_value;
2411 ConfigParserData::AccountProvider& m_data;
2413 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2414 const DPL::String& name)
2416 if (name == L"icon") {
2417 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2418 } else if (name == L"display-name") {
2419 return DPL::MakeDelegate(this,
2420 &AccountProviderParser::OnDisplayNameElement);
2421 } else if (name == L"capability") {
2422 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2424 return &IgnoringParser::Create; //ignore unknown according to w3c
2428 virtual void Accept(const Text& /*text*/)
2431 virtual void Accept(const Element& /*element*/)
2434 virtual void Accept(const XmlAttribute& attribute)
2436 if (attribute.name == L"multiple-accounts-support") {
2437 if (attribute.value == L"true") {
2438 m_multiSupport = true;
2443 virtual void Verify()
2445 m_data.m_multiAccountSupport = m_multiSupport;
2448 ElementParserPtr OnIconElement()
2450 return ElementParserPtr(new IconParser(m_data));
2453 ElementParserPtr OnDisplayNameElement()
2455 return ElementParserPtr(new DisplayNameParser(m_data));
2458 ElementParserPtr OnCapabilityElement()
2460 return ElementParserPtr(new CapabilityParser(m_data));
2463 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2465 m_properNamespace(false),
2466 m_multiSupport(false),
2471 bool m_properNamespace;
2472 bool m_multiSupport;
2473 ConfigParserData::AccountProvider& m_data;
2476 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2477 const DPL::String& name)
2479 if (name == L"account-provider") {
2480 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2482 return &IgnoringParser::Create; //ignore unknown according to w3c
2486 virtual void Accept(const Element& element)
2488 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2489 m_properNamespace = true;
2493 virtual void Accept(const XmlAttribute& /*attribute*/)
2496 virtual void Accept(const Text& /*text*/)
2499 virtual void Verify()
2502 ElementParserPtr OnProviderElement()
2504 return ElementParserPtr(new AccountProviderParser(m_account));
2507 AccountParser(ConfigParserData& data) :
2510 m_account(data.accountProvider),
2511 m_properNamespace(false),
2512 m_multiSupport(false)
2516 ConfigParserData& m_data;
2517 ConfigParserData::AccountProvider& m_account;
2518 bool m_properNamespace;
2519 bool m_multiSupport;
2522 class MetadataParser : public ElementParser
2525 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2526 const DPL::String& /*name*/)
2528 return &IgnoringParser::Create; //ignore unknown according to w3c
2531 virtual void Accept(const XmlAttribute& attribute)
2533 if (m_properNamespace) {
2534 if (attribute.name == L"key") {
2535 m_key = attribute.value;
2536 } else if (attribute.name == L"value") {
2537 m_value = attribute.value;
2542 virtual void Accept(const Element& element)
2544 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2545 m_properNamespace = true;
2549 virtual void Accept(const Text& /*text*/)
2551 ThrowMsg(Exception::ParseError, "param element must be empty");
2554 virtual void Verify()
2556 if (m_key.IsNull()) {
2557 LogWarning("metadata element must have key attribute");
2560 NormalizeString(m_key);
2561 NormalizeString(m_value);
2562 ConfigParserData::Metadata metaData(m_key, m_value);
2563 FOREACH(it, m_data.metadataList) {
2564 if (!DPL::StringCompare(*it->key, *m_key)) {
2565 LogError("Key isn't unique");
2569 m_data.metadataList.push_back(metaData);
2572 MetadataParser(ConfigParserData& data) :
2575 m_properNamespace(false)
2579 DPL::OptionalString m_key;
2580 DPL::OptionalString m_value;
2581 ConfigParserData& m_data;
2582 bool m_properNamespace;
2585 ElementParser::ActionFunc WidgetParser::GetElementParser(
2586 const DPL::String& /*ns*/,
2587 const DPL::String& name)
2589 FuncMap::const_iterator it = m_map.find(name);
2590 if (it != m_map.end()) {
2593 return &IgnoringParser::Create; //ignore unknown according to w3c
2597 WidgetParser::WidgetParser(ConfigParserData& data) :
2599 m_textDirection(Unicode::EMPTY)
2601 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2602 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2603 m_map[L"description"] =
2604 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2605 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2607 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2608 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2610 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2611 m_map[L"preference"] =
2612 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2614 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2615 m_map[L"application"] = DPL::MakeDelegate(
2618 OnApplicationElement);
2619 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2620 m_map[L"background"] = DPL::MakeDelegate(this,
2621 &WidgetParser::OnBackgroundElement);
2622 m_map[L"privilege"] = DPL::MakeDelegate(this,
2623 &WidgetParser::OnPrivilegeElement);
2624 m_map[L"app-control"] = DPL::MakeDelegate(
2627 OnAppControlElement);
2628 m_map[L"category"] = DPL::MakeDelegate(this,
2629 &WidgetParser::OnCategoryElement);
2630 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2632 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2636 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2639 OnCspReportOnlyElement);
2641 #ifdef ALLOW_NAVIGATION_ENABLED
2642 m_map[L"allow-navigation"] =
2643 DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
2645 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2646 m_map[L"metadata"] = DPL::MakeDelegate(this, &WidgetParser::OnMetadataElement);
2649 ElementParserPtr WidgetParser::OnNameElement()
2651 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2654 ElementParserPtr WidgetParser::OnAccessElement()
2656 return ElementParserPtr(new AccessParser(m_data));
2659 ElementParserPtr WidgetParser::OnDescriptionElement()
2661 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2664 ElementParserPtr WidgetParser::OnAuthorElement()
2666 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2669 ElementParserPtr WidgetParser::OnLicenseElement()
2671 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2674 ElementParserPtr WidgetParser::OnIconElement()
2676 return ElementParserPtr(new IconParser(m_data));
2679 ElementParserPtr WidgetParser::OnContentElement()
2681 return ElementParserPtr(new ContentParser(m_data));
2684 ElementParserPtr WidgetParser::OnPreferenceElement()
2686 return ElementParserPtr(new PreferenceParser(m_data));
2689 ElementParserPtr WidgetParser::OnSettingElement()
2691 return ElementParserPtr(new SettingParser(m_data));
2694 ElementParserPtr WidgetParser::OnApplicationElement()
2696 return ElementParserPtr(new ApplicationParser(m_data));
2699 ElementParserPtr WidgetParser::OnSplashElement()
2701 return ElementParserPtr(new SplashParser(m_data));
2704 ElementParserPtr WidgetParser::OnBackgroundElement()
2706 return ElementParserPtr(new BackgroundParser(m_data));
2709 ElementParserPtr WidgetParser::OnPrivilegeElement()
2711 return ElementParserPtr(new PrivilegeParser(m_data));
2714 ElementParserPtr WidgetParser::OnAppControlElement()
2716 return ElementParserPtr(new AppControlParser(m_data));
2719 ElementParserPtr WidgetParser::OnCategoryElement()
2721 return ElementParserPtr(new CategoryParser(m_data));
2724 ElementParserPtr WidgetParser::OnAppWidgetElement()
2726 return ElementParserPtr(new AppWidgetParser(m_data));
2729 ElementParserPtr WidgetParser::OnCspElement()
2731 return ElementParserPtr(new CspParser(m_data));
2734 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2736 return ElementParserPtr(new CspReportOnlyParser(m_data));
2739 ElementParserPtr WidgetParser::OnAllowNavigationElement()
2741 return ElementParserPtr(new AllowNavigationParser(m_data));
2744 ElementParserPtr WidgetParser::OnAccountElement()
2746 return ElementParserPtr(new AccountParser(m_data));
2749 ElementParserPtr WidgetParser::OnMetadataElement()
2751 return ElementParserPtr(new MetadataParser(m_data));
2754 void WidgetParser::Accept(const Element& element)
2756 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2757 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2759 ThrowMsg(Exception::ParseError,
2760 "Wrong xml namespace for widget element");
2764 void WidgetParser::Accept(const Text& /*text*/)
2766 ThrowMsg(Exception::ParseError, "widged element must be empty");
2769 void WidgetParser::Accept(const XmlAttribute& attribute)
2771 if (attribute.name == L"id") {
2772 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2773 //If may important tests starts to fail this test we will have
2774 //to consider commenting this test out again.
2775 if (iri.Validate()) {
2776 m_data.widget_id = attribute.value;
2777 NormalizeString(m_data.widget_id);
2779 LogWarning("Widget id validation failed: " << attribute.value);
2781 } else if (attribute.name == L"version") {
2782 m_version = attribute.value;
2783 NormalizeString(m_version);
2784 } else if (attribute.name == L"min-version") {
2785 LogInfo("min-version attribute was found. Value: " << attribute.value);
2786 m_minVersion = attribute.value;
2787 NormalizeString(m_minVersion);
2788 m_data.minVersionRequired = m_minVersion;
2789 } else if (attribute.name == L"height") {
2790 DPL::OptionalString value = attribute.value;
2791 NormalizeString(value);
2792 std::string v = DPL::ToUTF8String(*value);
2795 unsigned char c = v.c_str()[0];
2798 for (size_t i = 0; i < v.size(); ++i) {
2807 m_data.height = val;
2810 } else if (attribute.name == L"width") {
2811 DPL::OptionalString value = attribute.value;
2812 NormalizeString(value);
2813 std::string v = DPL::ToUTF8String(*value);
2816 unsigned char c = v.c_str()[0];
2817 if (c >= '0' && c <= '9') {
2819 for (size_t i = 0; i < v.size(); ++i) {
2821 if (c >= '0' && c <= '9') {
2831 } else if (attribute.name == L"viewmodes") {
2832 DPL::Tokenize(attribute.value,
2834 std::inserter(m_windowModes,
2835 m_windowModes.end()),
2837 } else if (attribute.name == L"dir") {
2838 m_textDirection = Unicode::ParseDirAttribute(attribute);
2839 } else if (L"defaultlocale" == attribute.name) {
2840 if (!m_defaultlocale) {
2841 m_defaultlocale = attribute.value;
2842 NormalizeString(m_defaultlocale);
2843 /* TODO : should check valid defaultlocale */
2844 LogDebug("Default Locale Found " << m_defaultlocale);
2846 LogWarning("Ignoring subsequent default locale");
2849 //Any other value consider as a namespace definition
2850 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2851 LogInfo("Namespace domain: " << attribute.name);
2852 LogInfo("Namespace value: " << attribute.value);
2853 m_nameSpaces[attribute.name] = attribute.value;
2855 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2856 ", name=" << attribute.name <<
2857 ", value=" << attribute.value);
2861 void WidgetParser::Verify()
2863 FOREACH(mode, m_windowModes) {
2864 if (L"windowed" == *mode || L"floating" == *mode ||
2865 L"fullscreen" == *mode || L"maximized" == *mode ||
2866 L"minimized" == *mode)
2868 m_data.windowModes.insert(*mode);
2871 if (!m_version.IsNull()) {
2872 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2873 m_data.version = m_version;
2875 m_data.defaultlocale = m_defaultlocale;
2876 FOREACH(ns, m_nameSpaces) {
2877 m_data.nameSpaces.insert(ns->second);