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 LogDebug("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 struct DispositionParser : public ElementParser
1077 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1078 const DPL::String& /*name*/)
1080 return &IgnoringParser::Create;
1083 virtual void Accept(const Text& /*text*/)
1086 virtual void Accept(const Element& /*element*/)
1089 virtual void Accept(const XmlAttribute& attribute)
1091 if (attribute.name == L"name") {
1092 if (attribute.value.size() > 0) {
1093 m_value = attribute.value;
1094 NormalizeString(m_value);
1099 virtual void Verify()
1101 if (m_value.IsNull() || *m_value == L"") {
1105 DPL::String windowString(L"window");
1106 DPL::String inlineString(L"inline");
1108 if (*m_value == L"window") {
1109 m_data.m_disposition =
1110 ConfigParserData::AppControlInfo::Disposition::WINDOW;
1111 } else if (*m_value == L"inline") {
1112 m_data.m_disposition =
1113 ConfigParserData::AppControlInfo::Disposition::INLINE;
1115 LogDebug("Ignoring dispostion value " <<
1116 DPL::ToUTF8String(*m_value));
1120 DispositionParser(ConfigParserData::AppControlInfo& data) :
1122 m_properNamespace(false),
1127 bool m_properNamespace;
1128 DPL::OptionalString m_value;
1129 ConfigParserData::AppControlInfo& m_data;
1132 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1133 const DPL::String& name)
1135 if (name == L"src") {
1136 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1137 } else if (name == L"operation") {
1138 return DPL::MakeDelegate(this,
1139 &AppControlParser::OnOperationElement);
1140 } else if (name == L"uri") {
1141 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1142 } else if (name == L"mime") {
1143 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1144 } else if (name == L"disposition") {
1145 return DPL::MakeDelegate(this,
1146 &AppControlParser::OnDispositionElement);
1148 return &IgnoringParser::Create; //ignore unknown according to w3c
1152 virtual void Accept(const XmlAttribute& /*attribute*/)
1155 virtual void Accept(const Element& element)
1157 LogWarning("namespace for app service = " << element.ns);
1158 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1159 ThrowMsg(Exception::ParseError,
1160 "Wrong xml namespace for widget element");
1164 virtual void Accept(const Text& /*text*/)
1166 ThrowMsg(Exception::ParseError, "param element must be empty");
1169 virtual void Verify()
1171 if (m_appControl.m_src == L"") {
1172 ThrowMsg(Exception::ParseError, "service element must have src element");
1175 if (m_appControl.m_operation == L"") {
1176 ThrowMsg(Exception::ParseError, "service element must have operation element");
1179 m_data.appControlList.push_back(m_appControl);
1182 ElementParserPtr OnSourceElement()
1184 return ElementParserPtr(new SourceParser(m_appControl));
1187 ElementParserPtr OnOperationElement()
1189 return ElementParserPtr(new OperationParser(m_appControl));
1192 ElementParserPtr OnUriElement()
1194 return ElementParserPtr(new UriParser(m_appControl));
1197 ElementParserPtr OnMimeElement()
1199 return ElementParserPtr(new MimeParser(m_appControl));
1202 ElementParserPtr OnDispositionElement()
1204 return ElementParserPtr(new DispositionParser(m_appControl));
1207 AppControlParser(ConfigParserData& data) :
1214 ConfigParserData& m_data;
1215 ConfigParserData::AppControlInfo m_appControl;
1218 class ApplicationParser : public ElementParser
1221 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1222 const DPL::String& /*name*/)
1224 return &IgnoringParser::Create; //ignore unknown according to w3c
1227 virtual void Accept(const Text& /*text*/)
1229 if (m_properNamespace) {
1230 ThrowMsg(Exception::ParseError, "application element must be empty");
1234 virtual void Accept(const Element& element)
1237 ConfigurationNamespace::TizenWebAppNamespaceName)
1239 m_properNamespace = true;
1243 virtual void Accept(const XmlAttribute& attribute)
1245 if (m_properNamespace) {
1246 if (attribute.name == L"id") {
1247 m_id = attribute.value;
1248 NormalizeAndTrimSpaceString(m_id);
1249 } else if (attribute.name == L"package") {
1250 m_package = attribute.value;
1251 } else if (attribute.name == L"required_version") {
1252 m_version = attribute.value;
1253 NormalizeString(m_version);
1255 ThrowMsg(Exception::ParseError,
1256 "unknown attribute '" +
1257 DPL::ToUTF8String(attribute.name) +
1258 "' in application element");
1263 virtual void Verify()
1265 VerifyIdAndPackage();
1269 ApplicationParser(ConfigParserData& data) :
1272 m_id(DPL::OptionalString::Null),
1273 m_version(DPL::OptionalString::Null),
1274 m_properNamespace(false)
1277 static const char* const REGEXP_ID;
1280 void VerifyIdAndPackage()
1284 ThrowMsg(Exception::ParseError,
1285 "application element must have package attribute");
1289 pcrecpp::RE re(REGEXP_PACKAGE);
1290 if (!re.FullMatch(DPL::ToUTF8String(*m_package)))
1292 ThrowMsg(Exception::ParseError,
1293 "invalid format of package attribute");
1298 ThrowMsg(Exception::ParseError,
1299 "application element must have id attribute");
1303 std::string package;
1304 pcrecpp::RE re(REGEXP_ID);
1305 if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
1307 ThrowMsg(Exception::ParseError,
1308 "invalid format of id attribute");
1310 if (package != DPL::ToUTF8String(*m_package))
1312 ThrowMsg(Exception::ParseError,
1313 "invalid package prefix in id attribute");
1317 m_data.tizenAppId = m_id;
1318 m_data.tizenPkgId = m_package;
1321 void VerifyVersion()
1325 ThrowMsg(Exception::ParseError,
1326 "application element must have required_version attribute");
1330 pcrecpp::RE re(REGEXP_VERSION);
1331 if (!re.FullMatch(DPL::ToUTF8String(*m_version)))
1333 ThrowMsg(Exception::ParseError,
1334 "invalid format of version attribute");
1338 m_data.tizenMinVersionRequired = m_version;
1341 static const char* const REGEXP_PACKAGE;
1342 static const char* const REGEXP_VERSION;
1344 ConfigParserData& m_data;
1345 DPL::OptionalString m_id;
1346 DPL::OptionalString m_package;
1347 DPL::OptionalString m_version;
1348 bool m_properNamespace;
1351 const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}";
1352 const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\.[0-9A-Za-z]{1,52}";
1353 const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?";
1355 class SplashParser : public ElementParser
1358 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1359 const DPL::String& /*name*/)
1361 return &IgnoringParser::Create; //ignore unknown according to w3c
1364 virtual void Accept(const XmlAttribute& attribute)
1366 if (m_properNamespace)
1368 if (attribute.name == L"src") {
1369 if (attribute.value.size() > 0) {
1370 m_src = attribute.value;
1376 virtual void Accept(const Element& element)
1379 ConfigurationNamespace::TizenWebAppNamespaceName)
1381 m_properNamespace = true;
1385 virtual void Accept(const Text& /*text*/)
1388 virtual void Verify()
1392 LogWarning("src attribute of splash element is mandatory - ignoring");
1396 m_data.splashImgSrc = m_src;
1399 SplashParser(ConfigParserData& data) :
1402 m_properNamespace(false)
1406 DPL::OptionalString m_src;
1407 ConfigParserData& m_data;
1408 bool m_properNamespace;
1411 class BackgroundParser : public ElementParser
1414 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1415 const DPL::String& /*name*/)
1417 return &IgnoringParser::Create; //ignore unknown according to w3c
1420 virtual void Accept(const XmlAttribute& attribute)
1422 if (attribute.name == L"src") {
1423 if (attribute.value.size() > 0) {
1424 m_src = attribute.value;
1429 virtual void Accept(const Element& /*element*/)
1432 virtual void Accept(const Text& /*text*/)
1435 virtual void Verify()
1437 if (m_src.IsNull()) {
1439 "src attribute of background element is mandatory - ignoring");
1443 m_data.backgroundPage = m_src;
1446 explicit BackgroundParser(ConfigParserData& data) :
1451 DPL::OptionalString m_src;
1452 ConfigParserData& m_data;
1455 class PrivilegeParser : public ElementParser
1458 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1459 const DPL::String& /*name*/)
1461 return &IgnoringParser::Create; //ignore unknown according to w3c
1464 virtual void Accept(const Text& /*text*/)
1467 virtual void Accept(const Element& element)
1470 ConfigurationNamespace::TizenWebAppNamespaceName)
1472 m_properNamespace = true;
1474 LogDebug("element");
1477 virtual void Accept(const XmlAttribute& attribute)
1479 if (m_properNamespace) {
1480 if (attribute.name == L"name") {
1481 m_feature.name = attribute.value;
1482 m_privilege.name = attribute.value;
1487 virtual void Verify()
1489 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1491 if (m_feature.name != L"") {
1492 if (iri.Validate()) {
1493 if (m_data.featuresList.find(m_feature) ==
1494 m_data.featuresList.end())
1496 m_data.featuresList.insert(m_feature);
1498 LogDebug("Ignoring feature with name" <<
1499 DPL::ToUTF8String(m_feature.name));
1504 LibIri::Wrapper iriPrivilege(
1505 DPL::ToUTF8String(m_privilege.name).c_str());
1507 if (m_privilege.name != L"") {
1508 if (iriPrivilege.Validate()) {
1509 if (m_data.privilegeList.find(m_privilege) ==
1510 m_data.privilegeList.end())
1512 m_data.privilegeList.insert(m_privilege);
1514 LogDebug("Ignoring privilege with name" <<
1515 DPL::ToUTF8String(m_privilege.name));
1521 PrivilegeParser(ConfigParserData& data) :
1526 m_properNamespace(false)
1530 ConfigParserData& m_data;
1531 ConfigParserData::Feature m_feature;
1532 ConfigParserData::Privilege m_privilege;
1533 bool m_properNamespace;
1536 class CategoryParser : public ElementParser
1539 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1540 const DPL::String& /*name*/)
1542 return &IgnoringParser::Create; //ignore unknown according to w3c
1545 virtual void Accept(const XmlAttribute& attribute)
1547 if (attribute.name == L"name") {
1548 if (attribute.value.size() > 0) {
1549 m_name = attribute.value;
1554 virtual void Accept(const Element& /*element*/)
1557 virtual void Accept(const Text& /*text*/)
1560 virtual void Verify()
1562 if (m_name.IsNull()) {
1564 "name attribute of category element is mandatory - ignoring");
1568 if (m_data.categoryList.find(*m_name) ==
1569 m_data.categoryList.end())
1571 m_data.categoryList.insert(*m_name);
1575 explicit CategoryParser(ConfigParserData& data) :
1580 DPL::OptionalString m_name;
1581 ConfigParserData& m_data;
1584 class AppWidgetParser : public ElementParser
1588 struct BoxLabelParser : public ElementParser
1590 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1591 const DPL::String& /*name*/)
1593 return &IgnoringParser::Create; //ignore unknown according to w3c
1596 virtual void Accept(const XmlAttribute& attribute)
1598 if (m_properNamespace) {
1599 m_lang = attribute.lang;
1602 virtual void Accept(const Element& element)
1605 ConfigurationNamespace::TizenWebAppNamespaceName)
1607 m_properNamespace = true;
1611 virtual void Accept(const Text& text)
1613 if (m_properNamespace) {
1614 m_label = text.value;
1618 virtual void Verify()
1620 std::pair<DPL::String, DPL::String> boxLabel;
1621 if (m_label.empty()) {
1622 LogWarning("box-label element is empty");
1623 boxLabel.first = DPL::FromUTF8String("");
1624 boxLabel.second = DPL::FromUTF8String("");
1625 m_data.m_label.push_back(boxLabel);
1628 boxLabel.first = m_lang;
1629 boxLabel.second = m_label;
1630 m_data.m_label.push_back(boxLabel);
1634 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1636 m_properNamespace(false),
1642 DPL::String m_label;
1643 bool m_properNamespace;
1644 ConfigParserData::LiveboxInfo& m_data;
1647 struct BoxIconParser : public ElementParser
1649 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1650 const DPL::String& /*name*/)
1652 return &IgnoringParser::Create; //ignore unknown according to w3c
1655 virtual void Accept(const XmlAttribute& attribute)
1657 if (m_properNamespace) {
1658 if (attribute.name == L"src") {
1659 m_icon = attribute.value;
1664 virtual void Accept(const Element& element)
1667 ConfigurationNamespace::TizenWebAppNamespaceName)
1669 m_properNamespace = true;
1673 virtual void Accept(const Text& /*text*/)
1676 virtual void Verify()
1678 if (m_icon.empty()) {
1679 ThrowMsg(Exception::ParseError,
1680 "src attribute of box-icon element is mandatory - ignoring");
1682 m_data.m_icon = m_icon;
1685 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1687 m_properNamespace(false),
1693 bool m_properNamespace;
1694 ConfigParserData::LiveboxInfo& m_data;
1697 struct BoxContentParser : public ElementParser
1699 struct BoxSizeParser : public ElementParser
1701 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1702 const DPL::String& /*name*/)
1704 return &IgnoringParser::Create; //ignore unknown according to w3c
1707 virtual void Accept(const XmlAttribute& attribute)
1709 if (m_properNamespace) {
1710 if (attribute.name == L"preview") {
1711 m_preview = attribute.value;
1713 if (attribute.name == L"use-decoration") {
1714 m_useDecoration = attribute.value;
1719 virtual void Accept(const Element& element)
1722 ConfigurationNamespace::TizenWebAppNamespaceName)
1724 m_properNamespace = true;
1728 virtual void Accept(const Text& text)
1730 if (m_properNamespace) {
1731 m_size = text.value;
1735 virtual void Verify()
1737 if(m_size.empty()) {
1738 ThrowMsg(Exception::ParseError,
1739 "size is mandatory - ignoring");
1742 ConfigParserData::LiveboxInfo::BoxSizeInfo boxSizeInfo;
1743 boxSizeInfo.m_size = m_size;
1744 boxSizeInfo.m_preview = m_preview;
1745 boxSizeInfo.m_useDecoration = m_useDecoration;
1746 m_data.m_boxSize.push_back(boxSizeInfo);
1749 explicit BoxSizeParser(
1750 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1752 m_properNamespace(false),
1758 DPL::String m_preview;
1759 DPL::String m_useDecoration;
1760 bool m_properNamespace;
1761 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1764 struct PdParser : public ElementParser
1766 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1767 const DPL::String& /*name*/)
1769 return &IgnoringParser::Create; //ignore unknown according to w3c
1772 virtual void Accept(const XmlAttribute& attribute)
1774 if (m_properNamespace) {
1775 if (attribute.name == L"src") {
1776 m_src = attribute.value;
1777 } else if (attribute.name == L"width") {
1778 m_width = attribute.value;
1779 } else if (attribute.name == L"height") {
1780 m_height = attribute.value;
1781 } else if (attribute.name == L"fast-open") {
1782 m_fastOpen= attribute.value;
1787 virtual void Accept(const Element& element)
1790 ConfigurationNamespace::TizenWebAppNamespaceName)
1792 m_properNamespace = true;
1796 virtual void Accept(const Text& /*text*/)
1799 virtual void Verify()
1801 if (m_src.empty()) {
1802 ThrowMsg(Exception::ParseError,
1803 "src attribute of pd element is mandatory - ignoring");
1806 if (m_width.empty()) {
1807 ThrowMsg(Exception::ParseError,
1808 "width attribute of pd element is mandatory - ignoring");
1811 if (m_height.empty()) {
1812 ThrowMsg(Exception::ParseError,
1813 "height attribute of pd element is mandatory - ignoring");
1816 if (ConvertToInt(m_width).IsNull()) {
1817 ThrowMsg(Exception::ParseError,
1818 "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width);
1822 DPL::OptionalInt height = ConvertToInt(m_height);
1824 if (height.IsNull()) {
1825 ThrowMsg(Exception::ParseError,
1826 "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height);
1831 LogDebug("height attribute of pd element shouldn't be less than 1. Changed to 1 from " << *height);
1832 } else if (*height > 380){
1834 LogDebug("height attribute of pd element shouldn't be greater than 380. Changed to 380 from " << *height);
1837 m_data.m_pdSrc = m_src;
1838 m_data.m_pdWidth = m_width;
1839 m_data.m_pdHeight = m_height;
1840 m_data.m_pdFastOpen = m_fastOpen;
1844 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1846 m_properNamespace(false),
1851 DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
1854 std::string tempStr = DPL::ToUTF8String(intAsString);
1855 const char * intAsString_c = tempStr.c_str();
1857 long int intAsString_i = strtol(intAsString_c, &endptr, 10);
1859 if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
1860 || intAsString_i > INT_MAX || intAsString_i < INT_MIN
1861 || *endptr != '\0') {
1862 return DPL::OptionalInt::Null;
1865 return static_cast<int>(intAsString_i);
1869 DPL::String m_width;
1870 DPL::String m_height;
1871 DPL::String m_fastOpen;
1873 bool m_properNamespace;
1874 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1877 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1878 const DPL::String& name)
1880 if (name == L"box-size") {
1881 return DPL::MakeDelegate(
1883 &AppWidgetParser::BoxContentParser::
1885 } else if (name == L"pd") {
1886 return DPL::MakeDelegate(
1888 &AppWidgetParser::BoxContentParser::
1891 ThrowMsg(Exception::ParseError,
1892 "No element parser for name: " << name);
1896 virtual void Accept(const XmlAttribute& attribute)
1898 if (m_properNamespace) {
1899 if (attribute.name == L"src") {
1900 m_box.m_boxSrc = attribute.value;
1902 if (attribute.name == L"mouse-event") {
1903 m_box.m_boxMouseEvent = attribute.value;
1905 if (attribute.name == L"touch-effect") {
1906 m_box.m_boxTouchEffect = attribute.value;
1911 virtual void Accept(const Element& element)
1914 ConfigurationNamespace::TizenWebAppNamespaceName)
1916 m_properNamespace = true;
1920 virtual void Accept(const Text& /*text*/)
1923 virtual void Verify()
1925 if (m_box.m_boxSrc.empty()) {
1926 ThrowMsg(Exception::ParseError,
1927 "src attribute of box-content element is mandatory - ignoring");
1930 if (!m_box.m_boxMouseEvent.empty() &&
1931 CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent))
1933 ThrowMsg(Exception::ParseError,
1934 "mouse-event attribute of box-content element should be true or false - ignoring");
1937 if (!m_box.m_boxTouchEffect.empty() &&
1938 CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect))
1940 ThrowMsg(Exception::ParseError,
1941 "touch-effect attribute of box-content element should be true or false - ignoring");
1944 if (m_box.m_boxMouseEvent.empty()) {
1945 m_box.m_boxMouseEvent = L"false";
1948 if (m_box.m_boxTouchEffect.empty()) {
1949 m_box.m_boxTouchEffect = L"true";
1952 if (m_box.m_boxSize.empty()) {
1953 ThrowMsg(Exception::ParseError,
1954 "box-size element of box-content element not found - ignoring");
1957 m_data.m_boxInfo = m_box;
1960 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1962 m_properNamespace(false),
1966 ElementParserPtr OnBoxSizeElement()
1968 return ElementParserPtr(new BoxSizeParser(m_box));
1971 ElementParserPtr OnPdElement()
1973 return ElementParserPtr(new PdParser(m_box));
1977 bool m_properNamespace;
1978 ConfigParserData::LiveboxInfo& m_data;
1979 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1982 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1983 const DPL::String& name)
1985 if (name == L"box-label") {
1986 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1987 } else if (name == L"box-icon") {
1988 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1989 } else if (name == L"box-content") {
1990 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1992 return &IgnoringParser::Create; //ignore unknown according to w3c
1996 virtual void Accept(const XmlAttribute& attribute)
1998 if (m_properNamespace) {
1999 if (attribute.name == L"id") {
2000 m_liveboxId = attribute.value;
2001 } else if (attribute.name == L"primary") {
2002 m_primary = attribute.value;
2003 } else if (attribute.name == L"auto-launch") {
2004 m_autoLaunch = attribute.value;
2005 } else if (attribute.name == L"update-period") {
2006 m_updatePeriod = attribute.value;
2007 } else if (attribute.name == L"type") {
2008 m_type = attribute.value;
2013 virtual void Accept(const Element& element)
2016 ConfigurationNamespace::TizenWebAppNamespaceName)
2018 m_properNamespace = true;
2022 virtual void Accept(const Text& /*text*/)
2025 virtual void Verify()
2027 if (m_liveboxId.empty()) {
2028 ThrowMsg(Exception::ParseError,
2029 "app-widget element must have id attribute");
2033 pcrecpp::RE re(REGEXP_ID_STRING.c_str());
2034 if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId)))
2036 ThrowMsg(Exception::ParseError,
2037 "invalid format of app-widget id attribute");
2041 if (m_primary.empty())
2043 ThrowMsg(Exception::ParseError,
2044 "app-widget element must have primary attribute");
2045 } else if (CheckIfNotTrueNorFalse(m_primary))
2047 ThrowMsg(Exception::ParseError,
2048 "auto-launch attribute of app-widget element should be true or false - ignoring");
2051 if (!m_autoLaunch.empty() &&
2052 CheckIfNotTrueNorFalse(m_autoLaunch))
2054 ThrowMsg(Exception::ParseError,
2055 "auto-launch attribute of app-widget element should be true or false - ignoring");
2058 if (!m_updatePeriod.empty())
2062 std::string tempStr = DPL::ToUTF8String(m_updatePeriod);
2064 //set standard locale to fix decimal point mark - '.'
2065 std::string currentLocale = setlocale(LC_NUMERIC, NULL);
2066 if (NULL == setlocale(LC_NUMERIC, "C"))
2067 LogWarning("Failed to change locale to \"C\"");
2068 double updatePeriod = strtod(tempStr.c_str(), &endptr);
2070 //go back to previous locale
2071 if (NULL == setlocale(LC_NUMERIC, currentLocale.c_str()))
2072 LogWarning("Failed to set previous locale");
2074 if ((errno == ERANGE && (updatePeriod == -HUGE_VAL || updatePeriod == HUGE_VAL))
2075 || *endptr != '\0') {
2076 ThrowMsg(Exception::ParseError,
2077 "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod);
2078 } else if (updatePeriod < 1800.0) {
2079 LogDebug("update-period attribute of app-widget element shouldn't be less than 1800.0 - changed to 1800 from value: " << m_updatePeriod);
2080 m_updatePeriod = L"1800.0";
2084 if (m_autoLaunch.empty()) {
2085 m_autoLaunch = L"false";
2088 if(m_livebox.m_label.empty()) {
2089 ThrowMsg(Exception::ParseError,
2090 "box-label element of app-widget element not found - ignoring");
2093 if(!m_boxContentFound) {
2094 ThrowMsg(Exception::ParseError,
2095 "box-content element of app-widget element not found - ignoring");
2098 m_livebox.m_liveboxId = m_liveboxId;
2099 m_livebox.m_primary = m_primary;
2100 m_livebox.m_autoLaunch = m_autoLaunch;
2101 m_livebox.m_updatePeriod = m_updatePeriod;
2102 m_livebox.m_type = m_type;
2104 m_data.m_livebox.push_back(m_livebox);
2107 explicit AppWidgetParser(ConfigParserData& data) :
2110 m_properNamespace(false),
2111 m_boxContentFound(false)
2113 m_livebox = ConfigParserData::LiveboxInfo();
2116 ElementParserPtr OnBoxLabelElement()
2119 return ElementParserPtr(new BoxLabelParser(m_livebox));
2122 ElementParserPtr OnBoxIconElement()
2124 return ElementParserPtr(new BoxIconParser(m_livebox));
2127 ElementParserPtr OnBoxContentElement()
2129 m_boxContentFound = true;
2130 return ElementParserPtr(new BoxContentParser(m_livebox));
2134 static std::string REGEXP_ID_STRING;
2135 ConfigParserData& m_data;
2136 ConfigParserData::LiveboxInfo m_livebox;
2137 DPL::String m_liveboxId;
2138 DPL::String m_primary;
2139 DPL::String m_autoLaunch;
2140 DPL::String m_updatePeriod;
2142 bool m_properNamespace;
2143 bool m_boxContentFound;
2145 static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck)
2147 return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0;
2151 std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+";
2153 class AllowNavigationParser : public ElementParser
2156 AllowNavigationParser(ConfigParserData& data) :
2159 m_properNamespace(false)
2162 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2163 const DPL::String& /*name*/)
2165 return &IgnoringParser::Create; //ignore unknown according to w3c
2168 virtual void Accept(const Element& element)
2170 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2171 m_properNamespace = true;
2175 virtual void Accept(const Text& text)
2177 if (m_properNamespace)
2179 m_origin = text.value;
2183 virtual void Accept(const XmlAttribute& /*attribute*/)
2187 virtual void Verify()
2189 if (m_data.allowNavigationEncountered || !m_properNamespace)
2193 m_data.allowNavigationEncountered = true;
2195 if (m_origin.IsNull()) {
2196 LogWarning("data is empty");
2200 char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
2201 char* ptr = strtok(data," ");
2202 while (ptr != NULL) {
2203 std::string origin = ptr;
2204 ptr = strtok(NULL," ");
2206 ConfigParserData::AllowNavigationInfo info(L"*", L"*");
2207 m_data.allowNavigationInfoList.push_back(info);
2211 DPL::ScopedPtr<iri_t> iri(iri_parse(origin.c_str()));
2212 if (!iri->host || strlen(iri->host) == 0) {
2213 // input origin should has schem and host
2214 // in case of file scheme path is filled
2216 LogWarning("input origin isn't verified");
2219 DPL::String scheme = L"*";
2220 if (iri->scheme && strlen(iri->scheme) != 0) {
2221 scheme = DPL::FromUTF8String(iri->scheme);
2223 ConfigParserData::AllowNavigationInfo info(
2225 DPL::FromUTF8String(iri->host));
2226 m_data.allowNavigationInfoList.push_back(info);
2232 DPL::OptionalString m_origin;
2233 ConfigParserData& m_data;
2234 bool m_properNamespace;
2237 class CspParser : public ElementParser
2240 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2241 const DPL::String& /*name*/)
2243 return &IgnoringParser::Create; //ignore unknown according to w3c
2246 CspParser(ConfigParserData& data) :
2249 m_properNamespace(false)
2252 virtual void Accept(const Element& element)
2254 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2255 m_properNamespace = true;
2259 virtual void Accept(const XmlAttribute& /*attribute*/)
2262 virtual void Accept(const Text& text)
2264 if (m_properNamespace) {
2265 m_policy = text.value;
2269 virtual void Verify()
2271 if (!m_policy.IsNull()) {
2272 m_data.cspPolicy = *m_policy;
2277 ConfigParserData& m_data;
2278 bool m_properNamespace;
2279 DPL::OptionalString m_policy;
2282 class CspReportOnlyParser : public ElementParser
2285 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2286 const DPL::String& /*name*/)
2288 return &IgnoringParser::Create; //ignore unknown according to w3c
2291 CspReportOnlyParser(ConfigParserData& data) :
2294 m_properNamespace(false)
2297 virtual void Accept(const Element& element)
2299 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2300 m_properNamespace = true;
2304 virtual void Accept(const XmlAttribute& /*attribute*/)
2307 virtual void Accept(const Text& text)
2309 if (m_properNamespace) {
2310 m_policy = text.value;
2314 virtual void Verify()
2316 if (!m_policy.IsNull()) {
2317 m_data.cspPolicyReportOnly = *m_policy;
2322 ConfigParserData& m_data;
2323 bool m_properNamespace;
2324 DPL::OptionalString m_policy;
2327 class AccountParser : public ElementParser
2330 struct AccountProviderParser : public ElementParser
2334 struct IconParser : public ElementParser
2337 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2338 const DPL::String& /*name*/)
2340 return &IgnoringParser::Create; //ignore unknown according to w3c
2343 virtual void Accept(const Text& text)
2345 if (text.value == L"") {
2348 m_value = text.value;
2351 virtual void Accept(const Element& /*element*/)
2354 virtual void Accept(const XmlAttribute& attribute)
2356 if (attribute.name == L"section") {
2357 if (attribute.value == L"account") {
2358 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2359 } else if (attribute.value == L"account-small") {
2360 m_type = ConfigParserData::IconSectionType::SmallIcon;
2365 virtual void Verify()
2367 if (m_value.IsNull() || *m_value == L"") {
2371 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2372 icon.first = m_type;
2373 icon.second = *m_value;
2375 m_data.m_iconSet.insert(icon);
2378 IconParser(ConfigParserData::AccountProvider& data) :
2380 m_properNamespace(false),
2381 m_type(ConfigParserData::DefaultIcon),
2386 bool m_properNamespace;
2387 ConfigParserData::IconSectionType m_type;
2388 ConfigParserData::AccountProvider& m_data;
2389 DPL::OptionalString m_value;
2392 struct DisplayNameParser : public ElementParser
2395 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2396 const DPL::String& /*name*/)
2398 return &IgnoringParser::Create; //ignore unknown according to w3c
2401 virtual void Accept(const Text& text)
2403 if (text.value == L"") {
2406 m_value = text.value;
2409 virtual void Accept(const Element& element)
2411 m_lang = element.lang;
2415 virtual void Accept(const XmlAttribute& /*attribute*/)
2418 virtual void Verify()
2420 if (m_value.IsNull() || *m_value == L"") {
2424 std::pair<DPL::String, DPL::String> name;
2425 name.first = *m_lang;
2426 name.second = *m_value;
2428 m_data.m_displayNameSet.insert(name);
2431 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2433 m_properNamespace(false),
2438 bool m_properNamespace;
2439 DPL::OptionalString m_lang;
2440 DPL::OptionalString m_value;
2441 ConfigParserData::AccountProvider& m_data;
2444 struct CapabilityParser : public ElementParser
2447 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2448 const DPL::String& /*name*/)
2450 return &IgnoringParser::Create; //ignore unknown according to w3c
2453 virtual void Accept(const Text& text)
2455 if (text.value == L"") {
2458 m_value = text.value;
2461 virtual void Accept(const Element& /*element*/)
2464 virtual void Accept(const XmlAttribute& /*attribute*/)
2467 virtual void Verify()
2469 if (m_value.IsNull() || *m_value == L"") {
2472 m_data.m_capabilityList.push_back(*m_value);
2475 CapabilityParser(ConfigParserData::AccountProvider& data) :
2477 m_properNamespace(false),
2482 bool m_properNamespace;
2483 DPL::OptionalString m_value;
2484 ConfigParserData::AccountProvider& m_data;
2486 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2487 const DPL::String& name)
2489 if (name == L"icon") {
2490 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2491 } else if (name == L"display-name") {
2492 return DPL::MakeDelegate(this,
2493 &AccountProviderParser::OnDisplayNameElement);
2494 } else if (name == L"capability") {
2495 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2497 return &IgnoringParser::Create; //ignore unknown according to w3c
2501 virtual void Accept(const Text& /*text*/)
2504 virtual void Accept(const Element& /*element*/)
2507 virtual void Accept(const XmlAttribute& attribute)
2509 if (attribute.name == L"multiple-accounts-support") {
2510 if (attribute.value == L"true") {
2511 m_multiSupport = true;
2516 virtual void Verify()
2518 m_data.m_multiAccountSupport = m_multiSupport;
2521 ElementParserPtr OnIconElement()
2523 return ElementParserPtr(new IconParser(m_data));
2526 ElementParserPtr OnDisplayNameElement()
2528 return ElementParserPtr(new DisplayNameParser(m_data));
2531 ElementParserPtr OnCapabilityElement()
2533 return ElementParserPtr(new CapabilityParser(m_data));
2536 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2538 m_properNamespace(false),
2539 m_multiSupport(false),
2544 bool m_properNamespace;
2545 bool m_multiSupport;
2546 ConfigParserData::AccountProvider& m_data;
2549 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2550 const DPL::String& name)
2552 if (name == L"account-provider") {
2553 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2555 return &IgnoringParser::Create; //ignore unknown according to w3c
2559 virtual void Accept(const Element& element)
2561 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2562 m_properNamespace = true;
2566 virtual void Accept(const XmlAttribute& /*attribute*/)
2569 virtual void Accept(const Text& /*text*/)
2572 virtual void Verify()
2575 ElementParserPtr OnProviderElement()
2577 return ElementParserPtr(new AccountProviderParser(m_account));
2580 AccountParser(ConfigParserData& data) :
2583 m_account(data.accountProvider),
2584 m_properNamespace(false),
2585 m_multiSupport(false)
2589 ConfigParserData& m_data;
2590 ConfigParserData::AccountProvider& m_account;
2591 bool m_properNamespace;
2592 bool m_multiSupport;
2595 class MetadataParser : public ElementParser
2598 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2599 const DPL::String& /*name*/)
2601 return &IgnoringParser::Create; //ignore unknown according to w3c
2604 virtual void Accept(const XmlAttribute& attribute)
2606 if (m_properNamespace) {
2607 if (attribute.name == L"key") {
2608 m_key = attribute.value;
2609 } else if (attribute.name == L"value") {
2610 m_value = attribute.value;
2615 virtual void Accept(const Element& element)
2617 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2618 m_properNamespace = true;
2622 virtual void Accept(const Text& /*text*/)
2624 ThrowMsg(Exception::ParseError, "param element must be empty");
2627 virtual void Verify()
2629 if (m_key.IsNull()) {
2630 LogWarning("metadata element must have key attribute");
2633 NormalizeString(m_key);
2634 NormalizeString(m_value);
2635 ConfigParserData::Metadata metaData(m_key, m_value);
2636 FOREACH(it, m_data.metadataList) {
2637 if (!DPL::StringCompare(*it->key, *m_key)) {
2638 LogError("Key isn't unique");
2642 m_data.metadataList.push_back(metaData);
2645 MetadataParser(ConfigParserData& data) :
2648 m_properNamespace(false)
2652 DPL::OptionalString m_key;
2653 DPL::OptionalString m_value;
2654 ConfigParserData& m_data;
2655 bool m_properNamespace;
2658 ElementParser::ActionFunc WidgetParser::GetElementParser(
2659 const DPL::String& /*ns*/,
2660 const DPL::String& name)
2662 FuncMap::const_iterator it = m_map.find(name);
2663 if (it != m_map.end()) {
2666 return &IgnoringParser::Create; //ignore unknown according to w3c
2670 WidgetParser::WidgetParser(ConfigParserData& data) :
2672 m_textDirection(Unicode::EMPTY)
2674 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2675 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2676 m_map[L"description"] =
2677 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2678 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2680 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2681 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2683 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2684 m_map[L"preference"] =
2685 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2687 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2688 m_map[L"application"] = DPL::MakeDelegate(
2691 OnApplicationElement);
2692 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2693 m_map[L"background"] = DPL::MakeDelegate(this,
2694 &WidgetParser::OnBackgroundElement);
2695 m_map[L"privilege"] = DPL::MakeDelegate(this,
2696 &WidgetParser::OnPrivilegeElement);
2697 m_map[L"app-control"] = DPL::MakeDelegate(
2700 OnAppControlElement);
2701 m_map[L"category"] = DPL::MakeDelegate(this,
2702 &WidgetParser::OnCategoryElement);
2703 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2705 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2709 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2712 OnCspReportOnlyElement);
2714 #ifdef ALLOW_NAVIGATION_ENABLED
2715 m_map[L"allow-navigation"] =
2716 DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
2718 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2719 m_map[L"metadata"] = DPL::MakeDelegate(this, &WidgetParser::OnMetadataElement);
2722 ElementParserPtr WidgetParser::OnNameElement()
2724 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2727 ElementParserPtr WidgetParser::OnAccessElement()
2729 return ElementParserPtr(new AccessParser(m_data));
2732 ElementParserPtr WidgetParser::OnDescriptionElement()
2734 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2737 ElementParserPtr WidgetParser::OnAuthorElement()
2739 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2742 ElementParserPtr WidgetParser::OnLicenseElement()
2744 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2747 ElementParserPtr WidgetParser::OnIconElement()
2749 return ElementParserPtr(new IconParser(m_data));
2752 ElementParserPtr WidgetParser::OnContentElement()
2754 return ElementParserPtr(new ContentParser(m_data));
2757 ElementParserPtr WidgetParser::OnPreferenceElement()
2759 return ElementParserPtr(new PreferenceParser(m_data));
2762 ElementParserPtr WidgetParser::OnSettingElement()
2764 return ElementParserPtr(new SettingParser(m_data));
2767 ElementParserPtr WidgetParser::OnApplicationElement()
2769 return ElementParserPtr(new ApplicationParser(m_data));
2772 ElementParserPtr WidgetParser::OnSplashElement()
2774 return ElementParserPtr(new SplashParser(m_data));
2777 ElementParserPtr WidgetParser::OnBackgroundElement()
2779 return ElementParserPtr(new BackgroundParser(m_data));
2782 ElementParserPtr WidgetParser::OnPrivilegeElement()
2784 return ElementParserPtr(new PrivilegeParser(m_data));
2787 ElementParserPtr WidgetParser::OnAppControlElement()
2789 return ElementParserPtr(new AppControlParser(m_data));
2792 ElementParserPtr WidgetParser::OnCategoryElement()
2794 return ElementParserPtr(new CategoryParser(m_data));
2797 ElementParserPtr WidgetParser::OnAppWidgetElement()
2799 return ElementParserPtr(new AppWidgetParser(m_data));
2802 ElementParserPtr WidgetParser::OnCspElement()
2804 return ElementParserPtr(new CspParser(m_data));
2807 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2809 return ElementParserPtr(new CspReportOnlyParser(m_data));
2812 ElementParserPtr WidgetParser::OnAllowNavigationElement()
2814 return ElementParserPtr(new AllowNavigationParser(m_data));
2817 ElementParserPtr WidgetParser::OnAccountElement()
2819 return ElementParserPtr(new AccountParser(m_data));
2822 ElementParserPtr WidgetParser::OnMetadataElement()
2824 return ElementParserPtr(new MetadataParser(m_data));
2827 void WidgetParser::Accept(const Element& element)
2829 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2830 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2832 ThrowMsg(Exception::ParseError,
2833 "Wrong xml namespace for widget element");
2837 void WidgetParser::Accept(const Text& /*text*/)
2839 ThrowMsg(Exception::ParseError, "widged element must be empty");
2842 void WidgetParser::Accept(const XmlAttribute& attribute)
2844 if (attribute.name == L"id") {
2845 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2846 //If may important tests starts to fail this test we will have
2847 //to consider commenting this test out again.
2848 if (iri.Validate()) {
2849 m_data.widget_id = attribute.value;
2850 NormalizeString(m_data.widget_id);
2852 LogWarning("Widget id validation failed: " << attribute.value);
2854 } else if (attribute.name == L"version") {
2855 m_version = attribute.value;
2856 NormalizeString(m_version);
2857 } else if (attribute.name == L"min-version") {
2858 LogDebug("min-version attribute was found. Value: " << attribute.value);
2859 m_minVersion = attribute.value;
2860 NormalizeString(m_minVersion);
2861 m_data.minVersionRequired = m_minVersion;
2862 } else if (attribute.name == L"height") {
2863 DPL::OptionalString value = attribute.value;
2864 NormalizeString(value);
2865 std::string v = DPL::ToUTF8String(*value);
2868 unsigned char c = v.c_str()[0];
2871 for (size_t i = 0; i < v.size(); ++i) {
2880 m_data.height = val;
2883 } else if (attribute.name == L"width") {
2884 DPL::OptionalString value = attribute.value;
2885 NormalizeString(value);
2886 std::string v = DPL::ToUTF8String(*value);
2889 unsigned char c = v.c_str()[0];
2890 if (c >= '0' && c <= '9') {
2892 for (size_t i = 0; i < v.size(); ++i) {
2894 if (c >= '0' && c <= '9') {
2904 } else if (attribute.name == L"viewmodes") {
2905 DPL::Tokenize(attribute.value,
2907 std::inserter(m_windowModes,
2908 m_windowModes.end()),
2910 } else if (attribute.name == L"dir") {
2911 m_textDirection = Unicode::ParseDirAttribute(attribute);
2912 } else if (L"defaultlocale" == attribute.name) {
2913 if (!m_defaultlocale) {
2914 m_defaultlocale = attribute.value;
2915 NormalizeString(m_defaultlocale);
2916 /* TODO : should check valid defaultlocale */
2917 LogDebug("Default Locale Found " << m_defaultlocale);
2919 LogWarning("Ignoring subsequent default locale");
2922 //Any other value consider as a namespace definition
2923 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2924 LogDebug("Namespace domain: " << attribute.name);
2925 LogDebug("Namespace value: " << attribute.value);
2926 m_nameSpaces[attribute.name] = attribute.value;
2928 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2929 ", name=" << attribute.name <<
2930 ", value=" << attribute.value);
2934 void WidgetParser::Verify()
2936 FOREACH(mode, m_windowModes) {
2937 if (L"windowed" == *mode || L"floating" == *mode ||
2938 L"fullscreen" == *mode || L"maximized" == *mode ||
2939 L"minimized" == *mode)
2941 m_data.windowModes.insert(*mode);
2944 if (!m_version.IsNull()) {
2945 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2946 m_data.version = m_version;
2948 m_data.defaultlocale = m_defaultlocale;
2949 FOREACH(ns, m_nameSpaces) {
2950 m_data.nameSpaces.insert(ns->second);