2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * This file have been implemented in compliance with W3C WARP SPEC.
18 * but there are some patent issue between W3C WARP SPEC and APPLE.
19 * so if you want to use this file, refer to the README file in root directory
22 * @file widget_parser.cpp
23 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
27 #include "widget_parser.h"
28 #include "ignoring_parser.h"
29 #include "deny_all_parser.h"
30 #include <dpl/wrt-dao-ro/config_parser_data.h>
31 #include "libiriwrapper.h"
32 #include <dpl/utils/warp_iri.h>
33 #include <dpl/utils/mime_type_utils.h>
34 #include <language_subtag_rst_tree.h>
37 #include <dpl/log/log.h>
38 #include <dpl/fast_delegate.h>
39 #include <dpl/foreach.h>
44 using namespace WrtDB;
47 static const DPL::String UTF_LRE = L"\x0202a";
48 static const DPL::String UTF_LRO = L"\x0202d";
49 static const DPL::String UTF_RLE = L"\x0202b";
50 static const DPL::String UTF_RLO = L"\x0202e";
51 static const DPL::String UTF_PDF = L"\x0202c";
53 Direction ParseDirAttribute(const XmlAttribute& attribute)
55 Assert(L"dir" == attribute.name);
56 if (L"ltr" == attribute.value) {
58 } else if (L"rtl" == attribute.value) {
60 } else if (L"lro" == attribute.value) {
62 } else if (L"rlo" == attribute.value) {
65 LogWarning("dir attribute has wrong value:" << attribute.value);
70 void UpdateTextWithDirectionMark(Direction direction,
76 *text = UTF_RLO + *text + UTF_PDF;
79 *text = UTF_RLE + *text + UTF_PDF;
82 *text = UTF_LRE + *text + UTF_PDF;
85 *text = UTF_LRO + *text + UTF_PDF;
94 } // namespace Unicode
96 class InnerElementsParser : public ElementParser
99 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
100 const DPL::String& /*name*/)
102 return DPL::MakeDelegate(this, &InnerElementsParser::Other);
105 virtual void Accept(const Element& /*element*/)
108 virtual void Accept(const Text& text)
110 if (m_text.IsNull()) {
113 m_text->value += text.value;
117 virtual void Accept(const XmlAttribute& attribute)
119 if (attribute.name == L"dir") {
120 m_textDirection = Unicode::ParseDirAttribute(attribute);
124 virtual void Verify()
126 if (!m_text.IsNull()) {
127 Unicode::UpdateTextWithDirectionMark(m_textDirection,
129 m_parentParser->Accept(*m_text);
133 InnerElementsParser(ElementParserPtr parent) :
134 m_parentParser(parent),
135 m_textDirection(Unicode::EMPTY)
138 ElementParserPtr Other()
140 return ElementParserPtr(new InnerElementsParser(
141 std::static_pointer_cast<ElementParser>(
142 shared_from_this())));
146 DPL::Optional<Text> m_text;
147 ElementParserPtr m_parentParser;
148 Unicode::Direction m_textDirection;
151 class NameParser : public ElementParser
154 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
155 const DPL::String& /*name*/)
157 return DPL::MakeDelegate(this, &NameParser::Other);
160 virtual void Accept(const Element& element)
162 m_lang = element.lang;
166 virtual void Accept(const Text& text)
168 if (m_name.IsNull()) {
171 *m_name += text.value;
175 virtual void Accept(const XmlAttribute& attribute)
177 if (attribute.name == L"short") {
178 if (m_shortName.IsNull()) {
179 m_shortName = attribute.value;
181 } else if (attribute.name == L"dir") {
182 m_textDirection = Unicode::ParseDirAttribute(attribute);
186 virtual void Verify()
188 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
189 if (data.name.IsNull()) {
190 NormalizeString(m_name);
191 NormalizeString(m_shortName);
192 if (!m_name.IsNull()) {
193 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
196 if (!m_shortName.IsNull()) {
197 Unicode::UpdateTextWithDirectionMark(m_textDirection,
200 data.shortName = m_shortName;
204 NameParser(Unicode::Direction direction,
205 ConfigParserData& data) :
207 m_textDirection(direction)
210 ElementParserPtr Other()
212 return ElementParserPtr(new InnerElementsParser(
213 std::static_pointer_cast<ElementParser>(
214 shared_from_this())));
218 ConfigParserData& m_data;
219 DPL::OptionalString m_name;
220 DPL::OptionalString m_shortName;
221 DPL::OptionalString m_dir;
223 Unicode::Direction m_textDirection;
226 class AccessParser : public ElementParser
235 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
236 const DPL::String& /*name*/)
238 return DPL::MakeDelegate(this, &AccessParser::Other);
241 virtual void Accept(const Element& element)
243 // for tizen web apps WARP should be used
244 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
245 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
247 m_standardType = STANDARD_TYPE_WARP;
251 virtual void Accept(const Text& /*text*/)
254 void AcceptWac(const XmlAttribute& attribute)
256 if (attribute.name == L"origin") {
257 m_strIRIOrigin = attribute.value;
258 NormalizeString(m_strIRIOrigin);
259 } else if (attribute.name == L"subdomains") {
260 DPL::String normalizedValue = attribute.value;
261 NormalizeString(normalizedValue);
263 if (normalizedValue == L"true") {
264 m_bSubDomainAccess = true;
265 } else if (normalizedValue == L"false") {
266 m_bSubDomainAccess = false;
271 virtual void Accept(const XmlAttribute& attribute)
273 switch (m_standardType) {
274 case STANDARD_TYPE_WARP:
275 AcceptWac(attribute);
278 LogError("Error in Access tag - unknown standard.");
286 iri.set(m_strIRIOrigin, false);
288 if (!iri.isAccessDefinition()) {
289 LogWarning("Access list element: " <<
291 " is not acceptable by WARP" <<
292 "standard and will be ignored!");
296 if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains
298 m_bSubDomainAccess = true;
301 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
303 //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
304 m_data.accessInfoSet.insert(accessInfo);
307 virtual void Verify()
309 switch (m_standardType) {
310 case STANDARD_TYPE_WARP:
314 LogError("Error in Access tag - unknown standard.");
319 AccessParser(ConfigParserData& data) :
321 m_bSubDomainAccess(false),
322 m_standardType(STANDARD_TYPE_NONE),
327 ElementParserPtr Other()
329 return ElementParserPtr(new InnerElementsParser(
330 ElementParserPtr(shared_from_this())));
334 DPL::String m_strIRIOrigin;
335 bool m_bSubDomainAccess;
336 StandardType m_standardType;
338 ConfigParserData& m_data;
341 class DescriptionParser : public ElementParser
344 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
345 const DPL::String& /*name*/)
347 return DPL::MakeDelegate(this, &DescriptionParser::Other);
350 virtual void Accept(const Element& element)
352 m_lang = element.lang;
356 ElementParserPtr Other()
358 return ElementParserPtr(new InnerElementsParser(
359 std::static_pointer_cast<ElementParser>(
360 shared_from_this())));
363 virtual void Accept(const Text& text)
365 if (m_description.IsNull()) {
366 m_description = text.value;
368 *m_description += text.value;
372 virtual void Accept(const XmlAttribute& attribute)
374 if (attribute.name == L"dir") {
375 m_textDirection = Unicode::ParseDirAttribute(attribute);
379 virtual void Verify()
381 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
382 if (data.description.IsNull()) {
383 if (!m_description.IsNull()) {
384 Unicode::UpdateTextWithDirectionMark(m_textDirection,
387 data.description = m_description;
391 DescriptionParser(Unicode::Direction direction,
392 ConfigParserData& data) :
396 m_textDirection(direction)
400 ConfigParserData& m_data;
402 DPL::OptionalString m_description;
403 Unicode::Direction m_textDirection;
406 class AuthorParser : public ElementParser
409 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
410 const DPL::String& /*name*/)
412 return DPL::MakeDelegate(this, &AuthorParser::Other);
415 AuthorParser(Unicode::Direction direction,
416 ConfigParserData& data) :
418 m_textDirection(direction)
421 virtual void Accept(const Element& /*element*/)
426 virtual void Accept(const Text& text)
428 *(m_authorName) += text.value;
431 virtual void Accept(const XmlAttribute& attribute)
433 if (attribute.name == L"href") {
434 //Validate href IRI and ignore it if invalid
435 //See also test: ta-argMozRiC-an
436 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
437 if (iri.Validate()) {
438 m_authorHref = attribute.value;
440 } else if (attribute.name == L"email") {
441 m_authorEmail = attribute.value;
442 } else if (attribute.name == L"dir") {
443 m_textDirection = Unicode::ParseDirAttribute(attribute);
447 virtual void Verify()
449 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
450 NormalizeString(m_authorName);
451 NormalizeString(m_authorHref);
452 NormalizeString(m_authorEmail);
453 if (!!m_authorName) {
454 Unicode::UpdateTextWithDirectionMark(m_textDirection,
456 m_data.authorName = m_authorName;
458 if (!!m_authorHref) {
459 m_data.authorHref = m_authorHref;
461 if (!!m_authorEmail) {
462 m_data.authorEmail = m_authorEmail;
467 ElementParserPtr Other()
469 return ElementParserPtr(new InnerElementsParser(
470 std::static_pointer_cast<ElementParser>(
471 shared_from_this())));
475 ConfigParserData& m_data;
476 DPL::OptionalString m_authorEmail;
477 DPL::OptionalString m_authorHref;
478 DPL::OptionalString m_authorName;
479 Unicode::Direction m_textDirection;
482 class LicenseParser : public ElementParser
485 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
486 const DPL::String& /*name*/)
488 return DPL::MakeDelegate(this, &LicenseParser::Other);
491 LicenseParser(Unicode::Direction direction,
492 ConfigParserData& data) :
495 m_textDirection(direction)
498 virtual void Accept(const Element& element)
500 if (m_license.IsNull()) {
501 m_lang = element.lang;
507 virtual void Accept(const Text& text)
510 *m_license += text.value;
514 virtual void Accept(const XmlAttribute& attribute)
517 if (attribute.name == L"href" && m_licenseHref.IsNull()) {
518 m_licenseHref = attribute.value;
519 } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
520 m_licenseFile = attribute.value;
521 } else if (attribute.name == L"dir") {
522 m_textDirection = Unicode::ParseDirAttribute(attribute);
527 virtual void Verify()
529 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
530 if (data.license.IsNull()) {
531 if (!m_license.IsNull()) {
532 Unicode::UpdateTextWithDirectionMark(m_textDirection,
535 data.license = m_license;
536 data.licenseHref = m_licenseHref;
537 data.licenseFile = m_licenseFile;
541 ElementParserPtr Other()
543 return ElementParserPtr(new InnerElementsParser(
544 ElementParserPtr(shared_from_this())));
548 ConfigParserData& m_data;
552 DPL::OptionalString m_license;
553 DPL::OptionalString m_licenseFile;
554 DPL::OptionalString m_licenseHref;
555 Unicode::Direction m_textDirection;
558 class IconParser : public ElementParser
560 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
563 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
564 const DPL::String& /*name*/)
566 return &IgnoringParser::Create;
569 IconParser(ConfigParserData& data) : ElementParser(),
573 virtual void Accept(const Element& /*element*/)
576 virtual void Accept(const XmlAttribute& attribute)
578 if (attribute.name == L"src") {
579 if (attribute.value.size() > 0) {
580 m_src = attribute.value;
582 } else if (attribute.name == L"width") {
583 m_width = ParseSizeAttributeValue(attribute.value);
584 } else if (attribute.name == L"height") {
585 m_height = ParseSizeAttributeValue(attribute.value);
589 virtual void Accept(const Text& /*text*/)
591 ThrowMsg(Exception::ParseError, "Icon element must be empty");
594 virtual void Verify()
596 if (m_src.IsNull()) {
597 LogWarning("src attribute of icon element is mandatory - ignoring");
603 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
604 icon.width = m_width;
605 icon.height = m_height;
607 ConfigParserData::IconsList::iterator it = std::find(
608 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
609 if (it == m_data.iconsList.end()) {
610 m_data.iconsList.push_front(icon);
615 LogWarning("src attribute is invalid: " << m_src);
620 ConfigParserData& m_data;
621 DPL::OptionalString m_src;
622 DPL::OptionalInt m_width;
623 DPL::OptionalInt m_height;
625 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
627 DPL::OptionalString normalizedValue = value;
628 NormalizeString(normalizedValue);
629 if (!(*normalizedValue).empty()) {
633 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
635 std::string(reterr) == DPL::ToUTF8String(value) ||
638 return DPL::OptionalInt::Null;
643 return DPL::OptionalInt::Null;
647 * @brief delocalizePath removes locales folder from relative path if
649 * @param source source string
651 * @throw BadSrcError if string is bad value of src attribute
653 * @return corrected string
655 static DPL::String delocalizeSrcPath(const DPL::String & source)
657 static const DPL::String localeFolder(L"locales/");
658 static const int index = localeFolder.size();
660 DPL::String result = source;
662 if (source.substr(0, index) == localeFolder) {
663 size_t pos = result.find_first_of('/', index);
664 if (pos != std::string::npos && pos + 1 < source.size()) {
665 result = result.substr(pos + 1, source.size());
674 class ContentParser : public ElementParser
677 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
678 const DPL::String& /*name*/)
680 return &IgnoringParser::Create;
683 ContentParser(ConfigParserData& data) :
688 virtual void Accept(const Element& /*element*/)
691 virtual void Accept(const Text& /*text*/)
694 virtual void Accept(const XmlAttribute& attribute)
696 DPL::String value = attribute.value;
697 NormalizeString(value);
699 if (attribute.name == L"src") {
701 } else if (attribute.name == L"type") {
703 MimeTypeUtils::MimeAttributes mimeAttributes =
704 MimeTypeUtils::getMimeAttributes(value);
705 if (mimeAttributes.count(L"charset") > 0) {
706 m_encoding = mimeAttributes[L"charset"];
708 } else if (attribute.name == L"encoding") {
709 if (!value.empty()) {
715 virtual void Verify()
717 if (m_data.startFileEncountered) {
718 LogWarning("This is not the first encountered "
719 "'content' element - ignoring.");
723 m_data.startFileEncountered = true;
725 //we're consciously setting startFile even if m_src is null or invalid.
726 //WidgetConfigurationManager will deal with this.
727 m_data.startFile = m_src;
730 m_data.startFileContentType = m_type;
732 m_data.startFileEncoding = m_encoding;
734 m_data.startFileEncoding = L"UTF-8";
740 DPL::OptionalString m_src;
741 DPL::OptionalString m_type;
742 DPL::OptionalString m_encoding;
743 ConfigParserData& m_data;
746 class PreferenceParser : public ElementParser
749 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
750 const DPL::String& /*name*/)
752 return &IgnoringParser::Create;
755 virtual void Accept(const XmlAttribute& attribute)
757 if (attribute.name == L"name") {
758 m_name = attribute.value;
759 } else if (attribute.name == L"value") {
760 m_value = attribute.value;
761 } else if (attribute.name == L"readonly") {
762 if (attribute.value == L"true") {
770 virtual void Accept(const Element& /*element*/)
773 virtual void Accept(const Text& /*text*/)
775 ThrowMsg(Exception::ParseError, "param element must be empty");
778 virtual void Verify()
780 if (m_name.IsNull()) {
781 LogWarning("preference element must have name attribute");
784 NormalizeString(m_name);
785 NormalizeString(m_value);
786 ConfigParserData::Preference preference(*m_name, m_required);
787 preference.value = m_value;
788 if (m_data.preferencesList.find(preference) ==
789 m_data.preferencesList.end())
791 m_data.preferencesList.insert(preference);
795 PreferenceParser(ConfigParserData& data) :
802 DPL::OptionalString m_name;
803 DPL::OptionalString m_value;
805 ConfigParserData& m_data;
808 class LinkParser : public ElementParser
811 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
812 const DPL::String& /*name*/)
814 return &DenyAllParser::Create;
817 virtual void Accept(const XmlAttribute& attribute)
819 if (m_properNamespace) {
820 LogDebug("attribute");
821 if (attribute.name == L"rel") {
822 if (attribute.value != L"describedby") {
823 ThrowMsg(Exception::ParseError,
824 "rel attribute must have describedby value");
826 } else if (attribute.name == L"type") {} else if (attribute.name ==
829 LogDebug("here is href");
830 m_href = attribute.value;
832 ThrowMsg(Exception::ParseError,
833 "unknown attribute '" +
834 DPL::ToUTF8String(attribute.name) +
835 "' in link element");
840 virtual void Accept(const Element& element)
843 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
845 m_properNamespace = true;
850 virtual void Accept(const Text&)
852 if (m_properNamespace) {
854 ThrowMsg(Exception::ParseError, "link element must be empty");
858 virtual void Verify()
861 ThrowMsg(Exception::ParseError,
862 "link element must have href attribute");
865 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
866 if (!iri.Validate()) { // TODO: Better uri validator ?
867 ThrowMsg(Exception::ParseError,
868 "href attribute must be a valid iri/uri/url");
872 LinkParser(ConfigParserData& data) :
874 m_properNamespace(false),
876 m_href(DPL::OptionalString::Null)
880 bool m_properNamespace;
881 ConfigParserData& m_data;
882 DPL::OptionalString m_href;
885 class SettingParser : public ElementParser
888 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
889 const DPL::String& /*name*/)
891 return &IgnoringParser::Create;
894 virtual void Accept(const Text& /*text*/)
897 virtual void Accept(const Element& /*element*/)
900 virtual void Accept(const XmlAttribute& attribute)
902 m_setting.m_name = attribute.name;
903 m_setting.m_value = attribute.value;
904 m_data.settingsList.insert(m_setting);
907 virtual void Verify()
910 SettingParser(ConfigParserData& data) :
917 ConfigParserData& m_data;
918 ConfigParserData::Setting m_setting;
921 class AppServiceParser : public ElementParser
924 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
925 const DPL::String& /*name*/)
927 return &IgnoringParser::Create;
930 virtual void Accept(const XmlAttribute& attribute)
932 if (attribute.name == L"src") {
933 m_src = attribute.value;
934 } else if (attribute.name == L"operation") {
935 m_operation = attribute.value;
936 } else if (attribute.name == L"scheme") {
937 m_scheme = attribute.value;
938 } else if (attribute.name == L"mime") {
939 m_mime = attribute.value;
940 } else if (attribute.name == L"disposition") {
941 if (attribute.value == L"inline")
943 ConfigParserData::ServiceInfo::Disposition::INLINE;
947 virtual void Accept(const Element& element)
949 LogWarning("namespace for app service = " << element.ns);
950 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
951 ThrowMsg(Exception::ParseError,
952 "Wrong xml namespace for widget element");
956 virtual void Accept(const Text& /*text*/)
958 ThrowMsg(Exception::ParseError, "param element must be empty");
961 virtual void Verify()
963 if (m_src.IsNull()) {
964 LogWarning("service element must have target attribute");
966 } else if (m_operation.IsNull()) {
967 LogWarning("service element must have operation attribute");
970 NormalizeString(m_src);
971 NormalizeString(m_operation);
972 NormalizeString(m_scheme);
973 NormalizeString(m_mime);
976 DPL::String ignoreUri(L"file");
978 if (!m_scheme.IsNull() && *m_scheme == ignoreUri)
980 LogInfo("exception : '" << *m_scheme << "' scheme will be ignored.");
981 m_scheme = DPL::OptionalString::Null;
984 // verify duplicate element
985 DPL::String wildString(L"*/*");
986 DPL::String nullString(L"");
987 ConfigParserData::ServiceInfo serviceInfo(
988 m_src.IsNull() ? nullString : *m_src,
989 m_operation.IsNull() ? nullString : *m_operation,
990 m_scheme.IsNull() ? nullString : *m_scheme,
991 m_mime.IsNull() ? nullString : *m_mime,
994 FOREACH(iterator, m_data.appServiceList) {
995 if (iterator->m_operation == serviceInfo.m_operation &&
997 (iterator->m_scheme == serviceInfo.m_scheme ||
998 // check input scheme is "*/*" case
999 (iterator->m_scheme == wildString &&
1000 serviceInfo.m_scheme != nullString) ||
1001 // check iterator scheme is "*/*" case
1002 (serviceInfo.m_scheme == wildString &&
1003 iterator->m_scheme != nullString)) &&
1005 (iterator->m_mime == serviceInfo.m_mime ||
1006 // check input mime is "*/*" case
1007 (iterator->m_mime == wildString &&
1008 serviceInfo.m_mime != nullString) ||
1009 // check iterator mime is "*/*" case
1010 (serviceInfo.m_mime == wildString &&
1011 iterator->m_mime != nullString)))
1013 ThrowMsg(Exception::ParseError,
1014 "service operation is duplicated " +
1015 DPL::ToUTF8String(*m_operation));
1018 m_data.appServiceList.push_back(serviceInfo);
1021 AppServiceParser(ConfigParserData& data) :
1023 m_src(DPL::OptionalString::Null),
1024 m_operation(DPL::OptionalString::Null),
1025 m_scheme(DPL::OptionalString::Null),
1026 m_mime(DPL::OptionalString::Null),
1027 m_disposition(ConfigParserData::ServiceInfo::Disposition::WINDOW),
1032 DPL::OptionalString m_src;
1033 DPL::OptionalString m_operation;
1034 DPL::OptionalString m_scheme;
1035 DPL::OptionalString m_mime;
1036 ConfigParserData::ServiceInfo::Disposition m_disposition;
1037 ConfigParserData& m_data;
1040 class AppControlParser : public ElementParser
1043 struct SourceParser : public ElementParser
1046 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1047 const DPL::String& /*name*/)
1049 return &IgnoringParser::Create;
1052 virtual void Accept(const Text& /*text*/)
1055 virtual void Accept(const Element& /*element*/)
1058 virtual void Accept(const XmlAttribute& attribute)
1060 if (attribute.name == L"name") {
1061 if (attribute.value.size() > 0) {
1062 m_value = attribute.value;
1063 NormalizeString(m_value);
1068 virtual void Verify()
1070 if (m_value.IsNull() || *m_value == L"") {
1074 m_data.m_src = *m_value;
1077 SourceParser(ConfigParserData::AppControlInfo& data) :
1079 m_properNamespace(false),
1084 bool m_properNamespace;
1085 DPL::OptionalString m_value;
1086 ConfigParserData::AppControlInfo& m_data;
1089 struct OperationParser : public ElementParser
1092 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1093 const DPL::String& /*name*/)
1095 return &IgnoringParser::Create;
1098 virtual void Accept(const Text& /*text*/)
1101 virtual void Accept(const Element& /*element*/)
1104 virtual void Accept(const XmlAttribute& attribute)
1106 if (attribute.name == L"name") {
1107 if (attribute.value.size() > 0) {
1108 m_value = attribute.value;
1109 NormalizeString(m_value);
1114 virtual void Verify()
1116 if (m_value.IsNull() || *m_value == L"") {
1120 m_data.m_operation = *m_value;
1123 OperationParser(ConfigParserData::AppControlInfo& data) :
1125 m_properNamespace(false),
1130 bool m_properNamespace;
1131 DPL::OptionalString m_value;
1132 ConfigParserData::AppControlInfo& m_data;
1135 struct UriParser : public ElementParser
1138 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1139 const DPL::String& /*name*/)
1141 return &IgnoringParser::Create;
1144 virtual void Accept(const Text& /*text*/)
1147 virtual void Accept(const Element& /*element*/)
1150 virtual void Accept(const XmlAttribute& attribute)
1152 if (attribute.name == L"name") {
1153 if (attribute.value.size() > 0) {
1154 m_value = attribute.value;
1155 NormalizeString(m_value);
1160 virtual void Verify()
1163 DPL::String ignoreUri(L"file");
1165 if (!m_value.IsNull() && *m_value == ignoreUri)
1167 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
1168 m_value = DPL::OptionalString::Null;
1171 if (m_value.IsNull() || *m_value == L"") {
1175 DPL::String wildString(L"*/*");
1176 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1177 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1179 m_data.m_uriList.insert(*m_value);
1181 LogDebug("Ignoring uri with name" <<
1182 DPL::ToUTF8String(*m_value));
1186 UriParser(ConfigParserData::AppControlInfo& data) :
1188 m_properNamespace(false),
1193 bool m_properNamespace;
1194 DPL::OptionalString m_value;
1195 ConfigParserData::AppControlInfo& m_data;
1198 struct MimeParser : public ElementParser
1201 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1202 const DPL::String& /*name*/)
1204 return &IgnoringParser::Create;
1207 virtual void Accept(const Text& /*text*/)
1210 virtual void Accept(const Element& /*element*/)
1213 virtual void Accept(const XmlAttribute& attribute)
1215 if (attribute.name == L"name") {
1216 if (attribute.value.size() > 0) {
1217 m_value = attribute.value;
1218 NormalizeString(m_value);
1223 virtual void Verify()
1225 if (m_value.IsNull() || *m_value == L"") {
1229 DPL::String wildString(L"*/*");
1230 if ((m_data.m_mimeList.find(wildString) ==
1231 m_data.m_mimeList.end())
1232 && (m_data.m_mimeList.find(*m_value) ==
1233 m_data.m_mimeList.end()))
1235 m_data.m_mimeList.insert(*m_value);
1237 LogDebug("Ignoring mime with name" <<
1238 DPL::ToUTF8String(*m_value));
1242 MimeParser(ConfigParserData::AppControlInfo& data) :
1244 m_properNamespace(false),
1249 bool m_properNamespace;
1250 DPL::OptionalString m_value;
1251 ConfigParserData::AppControlInfo& m_data;
1254 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1255 const DPL::String& name)
1257 if (name == L"src") {
1258 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1259 } else if (name == L"operation") {
1260 return DPL::MakeDelegate(this,
1261 &AppControlParser::OnOperationElement);
1262 } else if (name == L"uri") {
1263 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1264 } else if (name == L"mime") {
1265 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1267 return &IgnoringParser::Create;
1271 virtual void Accept(const XmlAttribute& /*attribute*/)
1274 virtual void Accept(const Element& element)
1276 LogWarning("namespace for app service = " << element.ns);
1277 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1278 ThrowMsg(Exception::ParseError,
1279 "Wrong xml namespace for widget element");
1283 virtual void Accept(const Text& /*text*/)
1285 ThrowMsg(Exception::ParseError, "param element must be empty");
1288 virtual void Verify()
1290 if (m_appControl.m_src == L"") {
1291 LogWarning("service element must have src element");
1295 if (m_appControl.m_operation == L"") {
1296 LogWarning("service element must have operation element");
1300 m_data.appControlList.push_back(m_appControl);
1303 ElementParserPtr OnSourceElement()
1305 return ElementParserPtr(new SourceParser(m_appControl));
1308 ElementParserPtr OnOperationElement()
1310 return ElementParserPtr(new OperationParser(m_appControl));
1313 ElementParserPtr OnUriElement()
1315 return ElementParserPtr(new UriParser(m_appControl));
1318 ElementParserPtr OnMimeElement()
1320 return ElementParserPtr(new MimeParser(m_appControl));
1323 AppControlParser(ConfigParserData& data) :
1330 ConfigParserData& m_data;
1331 ConfigParserData::AppControlInfo m_appControl;
1334 class ApplicationParser : public ElementParser
1337 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1338 const DPL::String& /*name*/)
1340 return &IgnoringParser::Create;
1343 virtual void Accept(const Text& /*text*/)
1345 if (m_properNamespace) {
1347 ThrowMsg(Exception::ParseError, "application element must be empty");
1351 virtual void Accept(const Element& element)
1354 ConfigurationNamespace::TizenWebAppNamespaceName)
1356 m_properNamespace = true;
1358 LogDebug("element");
1361 virtual void Accept(const XmlAttribute& attribute)
1363 if (m_properNamespace) {
1364 LogDebug("attribute");
1365 if (attribute.name == L"id") {
1366 m_id = attribute.value;
1367 NormalizeAndTrimSpaceString(m_id);
1368 } else if (attribute.name == L"package") {
1369 m_package = attribute.value;
1370 } else if (attribute.name == L"required_version") {
1371 m_version = attribute.value;
1372 NormalizeString(m_version);
1374 ThrowMsg(Exception::ParseError,
1375 "unknown attribute '" +
1376 DPL::ToUTF8String(attribute.name) +
1377 "' in application element");
1382 virtual void Verify()
1385 ThrowMsg(Exception::ParseError,
1386 "application element must have id attribute");
1390 m_data.tizenPkgId = m_package;
1394 ThrowMsg(Exception::ParseError,
1395 "application element must have required_version attribute");
1398 //TODO check if id and version format is right
1399 m_data.tizenAppId = m_id;
1400 m_data.tizenMinVersionRequired = m_version;
1403 ApplicationParser(ConfigParserData& data) :
1406 m_id(DPL::OptionalString::Null),
1407 m_version(DPL::OptionalString::Null),
1408 m_properNamespace(false)
1412 ConfigParserData& m_data;
1413 DPL::OptionalString m_id;
1414 DPL::OptionalString m_package;
1415 DPL::OptionalString m_version;
1416 bool m_properNamespace;
1419 class SplashParser : public ElementParser
1422 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1423 const DPL::String& /*name*/)
1425 return &IgnoringParser::Create;
1428 virtual void Accept(const XmlAttribute& attribute)
1430 if (attribute.name == L"src") {
1431 if (attribute.value.size() > 0) {
1432 m_src = attribute.value;
1437 virtual void Accept(const Element& /*element*/)
1440 virtual void Accept(const Text& /*text*/)
1443 virtual void Verify()
1445 if (m_src.IsNull()) {
1447 "src attribute of splash element is mandatory - ignoring");
1451 m_data.splashImgSrc = m_src;
1454 SplashParser(ConfigParserData& data) :
1460 DPL::OptionalString m_src;
1461 ConfigParserData& m_data;
1464 class BackgroundParser : public ElementParser
1467 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1468 const DPL::String& /*name*/)
1470 return &IgnoringParser::Create;
1473 virtual void Accept(const XmlAttribute& attribute)
1475 if (attribute.name == L"src") {
1476 if (attribute.value.size() > 0) {
1477 m_src = attribute.value;
1482 virtual void Accept(const Element& /*element*/)
1485 virtual void Accept(const Text& /*text*/)
1488 virtual void Verify()
1490 if (m_src.IsNull()) {
1492 "src attribute of background element is mandatory - ignoring");
1496 m_data.backgroundPage = m_src;
1499 explicit BackgroundParser(ConfigParserData& data) :
1504 DPL::OptionalString m_src;
1505 ConfigParserData& m_data;
1508 class PrivilegeParser : public ElementParser
1511 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1512 const DPL::String& /*name*/)
1514 return &IgnoringParser::Create;
1517 virtual void Accept(const Text& /*text*/)
1520 virtual void Accept(const Element& element)
1523 ConfigurationNamespace::TizenWebAppNamespaceName)
1525 m_properNamespace = true;
1527 LogDebug("element");
1530 virtual void Accept(const XmlAttribute& attribute)
1532 if (m_properNamespace) {
1533 if (attribute.name == L"name") {
1534 m_feature.name = attribute.value;
1535 m_privilege.name = attribute.value;
1540 virtual void Verify()
1542 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1544 if (m_feature.name != L"") {
1545 if (iri.Validate()) {
1546 if (m_data.featuresList.find(m_feature) ==
1547 m_data.featuresList.end())
1549 m_data.featuresList.insert(m_feature);
1551 LogDebug("Ignoring feature with name" <<
1552 DPL::ToUTF8String(m_feature.name));
1557 LibIri::Wrapper iriPrivilege(
1558 DPL::ToUTF8String(m_privilege.name).c_str());
1560 if (m_privilege.name != L"") {
1561 if (iriPrivilege.Validate()) {
1562 if (m_data.privilegeList.find(m_privilege) ==
1563 m_data.privilegeList.end())
1565 m_data.privilegeList.insert(m_privilege);
1567 LogDebug("Ignoring privilege with name" <<
1568 DPL::ToUTF8String(m_privilege.name));
1574 PrivilegeParser(ConfigParserData& data) :
1579 m_properNamespace(false)
1583 ConfigParserData& m_data;
1584 ConfigParserData::Feature m_feature;
1585 ConfigParserData::Privilege m_privilege;
1586 bool m_properNamespace;
1589 class CategoryParser : public ElementParser
1592 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1593 const DPL::String& /*name*/)
1595 return &IgnoringParser::Create;
1598 virtual void Accept(const XmlAttribute& attribute)
1600 if (attribute.name == L"name") {
1601 if (attribute.value.size() > 0) {
1602 m_name = attribute.value;
1607 virtual void Accept(const Element& /*element*/)
1610 virtual void Accept(const Text& /*text*/)
1613 virtual void Verify()
1615 if (m_name.IsNull()) {
1617 "name attribute of category element is mandatory - ignoring");
1621 if (m_data.categoryList.find(*m_name) ==
1622 m_data.categoryList.end())
1624 m_data.categoryList.insert(*m_name);
1628 explicit CategoryParser(ConfigParserData& data) :
1633 DPL::OptionalString m_name;
1634 ConfigParserData& m_data;
1637 class AppWidgetParser : public ElementParser
1641 struct BoxLabelParser : public ElementParser
1643 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1644 const DPL::String& /*name*/)
1646 return &IgnoringParser::Create;
1649 virtual void Accept(const XmlAttribute& /*attribute*/)
1652 virtual void Accept(const Element& element)
1655 ConfigurationNamespace::TizenWebAppNamespaceName)
1657 m_properNamespace = true;
1661 virtual void Accept(const Text& text)
1663 if (m_properNamespace) {
1664 m_label = text.value;
1668 virtual void Verify()
1670 m_data.m_label = m_label;
1673 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1675 m_properNamespace(false),
1680 DPL::String m_label;
1681 bool m_properNamespace;
1682 ConfigParserData::LiveboxInfo& m_data;
1685 struct BoxIconParser : public ElementParser
1687 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1688 const DPL::String& /*name*/)
1690 return &IgnoringParser::Create;
1693 virtual void Accept(const XmlAttribute& attribute)
1695 if (m_properNamespace) {
1696 if (attribute.name == L"src") {
1697 m_icon = attribute.value;
1702 virtual void Accept(const Element& element)
1705 ConfigurationNamespace::TizenWebAppNamespaceName)
1707 m_properNamespace = true;
1711 virtual void Accept(const Text& /*text*/)
1714 virtual void Verify()
1716 m_data.m_icon = m_icon;
1719 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1721 m_properNamespace(false),
1727 bool m_properNamespace;
1728 ConfigParserData::LiveboxInfo& m_data;
1731 struct BoxContentParser : public ElementParser
1733 struct BoxSizeParser : public ElementParser
1735 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1736 const DPL::String& /*name*/)
1738 return &IgnoringParser::Create;
1741 virtual void Accept(const XmlAttribute& attribute)
1743 if (m_properNamespace) {
1744 if (attribute.name == L"preview") {
1745 m_preview = attribute.value;
1750 virtual void Accept(const Element& element)
1753 ConfigurationNamespace::TizenWebAppNamespaceName)
1755 m_properNamespace = true;
1759 virtual void Accept(const Text& text)
1761 if (m_properNamespace) {
1762 m_size = text.value;
1766 virtual void Verify()
1768 std::pair<DPL::String, DPL::String> boxSize;
1769 boxSize.first = m_size;
1770 boxSize.second = m_preview;
1771 m_data.m_boxSize.push_back(boxSize);
1774 explicit BoxSizeParser(
1775 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1777 m_properNamespace(false),
1783 DPL::String m_preview;
1784 bool m_properNamespace;
1785 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1788 struct PdParser : public ElementParser
1790 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1791 const DPL::String& /*name*/)
1793 return &IgnoringParser::Create;
1796 virtual void Accept(const XmlAttribute& attribute)
1798 if (m_properNamespace) {
1799 if (attribute.name == L"src") {
1800 m_src = attribute.value;
1801 } else if (attribute.name == L"width") {
1802 m_width = attribute.value;
1803 } else if (attribute.name == L"height") {
1804 m_height = attribute.value;
1809 virtual void Accept(const Element& element)
1812 ConfigurationNamespace::TizenWebAppNamespaceName)
1814 m_properNamespace = true;
1818 virtual void Accept(const Text& /*text*/)
1821 virtual void Verify()
1823 m_data.m_pdSrc = m_src;
1824 m_data.m_pdWidth = m_width;
1825 m_data.m_pdHeight = m_height;
1829 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1831 m_properNamespace(false),
1837 DPL::String m_width;
1838 DPL::String m_height;
1840 bool m_properNamespace;
1841 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1844 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1845 const DPL::String& name)
1847 if (name == L"box-size") {
1848 return DPL::MakeDelegate(
1850 &AppWidgetParser::BoxContentParser::
1852 } else if (name == L"pd") {
1853 return DPL::MakeDelegate(
1855 &AppWidgetParser::BoxContentParser::
1858 ThrowMsg(Exception::ParseError,
1859 "No element parser for name: " << name);
1863 virtual void Accept(const XmlAttribute& attribute)
1865 if (m_properNamespace) {
1866 if (attribute.name == L"src") {
1867 m_box.m_boxSrc = attribute.value;
1869 if (attribute.name == L"mouse-event") {
1870 m_box.m_boxMouseEvent = attribute.value;
1872 if (attribute.name == L"touch-effect") {
1873 m_box.m_boxTouchEffect = attribute.value;
1878 virtual void Accept(const Element& element)
1881 ConfigurationNamespace::TizenWebAppNamespaceName)
1883 m_properNamespace = true;
1887 virtual void Accept(const Text& /*text*/)
1890 virtual void Verify()
1892 m_data.m_boxInfo = m_box;
1895 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1897 m_properNamespace(false),
1901 ElementParserPtr OnBoxSizeElement()
1903 return ElementParserPtr(new BoxSizeParser(m_box));
1906 ElementParserPtr OnPdElement()
1908 return ElementParserPtr(new PdParser(m_box));
1913 bool m_properNamespace;
1914 ConfigParserData::LiveboxInfo& m_data;
1915 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1918 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1919 const DPL::String& name)
1921 if (name == L"box-label") {
1922 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1923 } else if (name == L"box-icon") {
1924 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1925 } else if (name == L"box-content") {
1926 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1928 return &IgnoringParser::Create;
1932 virtual void Accept(const XmlAttribute& attribute)
1934 if (m_properNamespace) {
1935 if (attribute.name == L"id") {
1936 m_liveboxId = attribute.value;
1937 } else if (attribute.name == L"primary") {
1938 m_primary = attribute.value;
1939 } else if (attribute.name == L"auto-launch") {
1940 m_autoLaunch = attribute.value;
1941 } else if (attribute.name == L"update-period") {
1942 m_updatePeriod = attribute.value;
1943 } else if (attribute.name == L"type") {
1944 m_type = attribute.value;
1949 virtual void Accept(const Element& element)
1952 ConfigurationNamespace::TizenWebAppNamespaceName)
1954 m_properNamespace = true;
1958 virtual void Accept(const Text& /*text*/)
1961 virtual void Verify()
1963 m_livebox.m_liveboxId = m_liveboxId;
1964 m_livebox.m_primary = m_primary;
1965 m_livebox.m_autoLaunch = m_autoLaunch;
1966 m_livebox.m_updatePeriod = m_updatePeriod;
1967 m_livebox.m_type = m_type;
1969 m_data.m_livebox.push_back(m_livebox);
1972 explicit AppWidgetParser(ConfigParserData& data) :
1975 m_properNamespace(false)
1977 m_livebox = ConfigParserData::LiveboxInfo();
1980 ElementParserPtr OnBoxLabelElement()
1982 return ElementParserPtr(new BoxLabelParser(m_livebox));
1985 ElementParserPtr OnBoxIconElement()
1987 return ElementParserPtr(new BoxIconParser(m_livebox));
1990 ElementParserPtr OnBoxContentElement()
1992 return ElementParserPtr(new BoxContentParser(m_livebox));
1996 ConfigParserData& m_data;
1997 ConfigParserData::LiveboxInfo m_livebox;
1998 DPL::String m_liveboxId;
1999 DPL::String m_primary;
2000 DPL::String m_autoLaunch;
2001 DPL::String m_updatePeriod;
2003 bool m_properNamespace;
2006 class CspParser : public ElementParser
2009 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2010 const DPL::String& /*name*/)
2012 return &IgnoringParser::Create;
2015 CspParser(ConfigParserData& data) :
2018 m_properNamespace(false)
2021 virtual void Accept(const Element& element)
2023 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2024 m_properNamespace = true;
2028 virtual void Accept(const XmlAttribute& /*attribute*/)
2031 virtual void Accept(const Text& text)
2033 if (m_properNamespace) {
2034 m_policy = text.value;
2038 virtual void Verify()
2040 if (!m_policy.IsNull()) {
2041 m_data.cspPolicy = *m_policy;
2046 ConfigParserData& m_data;
2047 bool m_properNamespace;
2048 DPL::OptionalString m_policy;
2051 class CspReportOnlyParser : public ElementParser
2054 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2055 const DPL::String& /*name*/)
2057 return &IgnoringParser::Create;
2060 CspReportOnlyParser(ConfigParserData& data) :
2063 m_properNamespace(false)
2066 virtual void Accept(const Element& element)
2068 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2069 m_properNamespace = true;
2073 virtual void Accept(const XmlAttribute& /*attribute*/)
2076 virtual void Accept(const Text& text)
2078 if (m_properNamespace) {
2079 m_policy = text.value;
2083 virtual void Verify()
2085 if (!m_policy.IsNull()) {
2086 m_data.cspPolicyReportOnly = *m_policy;
2091 ConfigParserData& m_data;
2092 bool m_properNamespace;
2093 DPL::OptionalString m_policy;
2096 class AccountParser : public ElementParser
2099 struct AccountProviderParser : public ElementParser
2103 struct IconParser : public ElementParser
2106 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2107 const DPL::String& /*name*/)
2109 return &IgnoringParser::Create;
2112 virtual void Accept(const Text& text)
2114 if (text.value == L"") {
2117 m_value = text.value;
2120 virtual void Accept(const Element& /*element*/)
2123 virtual void Accept(const XmlAttribute& attribute)
2125 if (attribute.name == L"section") {
2126 if (attribute.value == L"account") {
2127 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2128 } else if (attribute.value == L"account-small") {
2129 m_type = ConfigParserData::IconSectionType::SmallIcon;
2134 virtual void Verify()
2136 if (m_value.IsNull() || *m_value == L"") {
2140 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2141 icon.first = m_type;
2142 icon.second = *m_value;
2144 m_data.m_iconSet.insert(icon);
2147 IconParser(ConfigParserData::AccountProvider& data) :
2149 m_properNamespace(false),
2150 m_type(ConfigParserData::DefaultIcon),
2155 bool m_properNamespace;
2156 ConfigParserData::IconSectionType m_type;
2157 ConfigParserData::AccountProvider& m_data;
2158 DPL::OptionalString m_value;
2161 struct DisplayNameParser : public ElementParser
2164 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2165 const DPL::String& /*name*/)
2167 return &IgnoringParser::Create;
2170 virtual void Accept(const Text& text)
2172 if (text.value == L"") {
2175 m_value = text.value;
2178 virtual void Accept(const Element& element)
2180 m_lang = element.lang;
2184 virtual void Accept(const XmlAttribute& /*attribute*/)
2187 virtual void Verify()
2189 if (m_value.IsNull() || *m_value == L"") {
2193 std::pair<DPL::String, DPL::String> name;
2194 name.first = *m_lang;
2195 name.second = *m_value;
2197 m_data.m_displayNameSet.insert(name);
2200 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2202 m_properNamespace(false),
2207 bool m_properNamespace;
2208 DPL::OptionalString m_lang;
2209 DPL::OptionalString m_value;
2210 ConfigParserData::AccountProvider& m_data;
2213 struct CapabilityParser : public ElementParser
2216 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2217 const DPL::String& /*name*/)
2219 return &IgnoringParser::Create;
2222 virtual void Accept(const Text& text)
2224 if (text.value == L"") {
2227 m_value = text.value;
2230 virtual void Accept(const Element& /*element*/)
2233 virtual void Accept(const XmlAttribute& /*attribute*/)
2236 virtual void Verify()
2238 if (m_value.IsNull() || *m_value == L"") {
2241 m_data.m_capabilityList.push_back(*m_value);
2244 CapabilityParser(ConfigParserData::AccountProvider& data) :
2246 m_properNamespace(false),
2251 bool m_properNamespace;
2252 DPL::OptionalString m_value;
2253 ConfigParserData::AccountProvider& m_data;
2255 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2256 const DPL::String& name)
2258 if (name == L"icon") {
2259 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2260 } else if (name == L"display-name") {
2261 return DPL::MakeDelegate(this,
2262 &AccountProviderParser::OnDisplayNameElement);
2263 } else if (name == L"capability") {
2264 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2266 return &IgnoringParser::Create;
2270 virtual void Accept(const Text& /*text*/)
2273 virtual void Accept(const Element& /*element*/)
2276 virtual void Accept(const XmlAttribute& attribute)
2278 if (attribute.name == L"multiple-accounts-support") {
2279 if (attribute.value == L"") {
2283 if (attribute.value == L"ture") {
2284 m_multiSupport = true;
2289 virtual void Verify()
2291 m_data.m_multiAccountSupport = m_multiSupport;
2294 ElementParserPtr OnIconElement()
2296 return ElementParserPtr(new IconParser(m_data));
2299 ElementParserPtr OnDisplayNameElement()
2301 return ElementParserPtr(new DisplayNameParser(m_data));
2304 ElementParserPtr OnCapabilityElement()
2306 return ElementParserPtr(new CapabilityParser(m_data));
2309 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2311 m_properNamespace(false),
2312 m_multiSupport(false),
2317 bool m_properNamespace;
2318 bool m_multiSupport;
2319 ConfigParserData::AccountProvider& m_data;
2322 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2323 const DPL::String& name)
2325 if (name == L"account-provider") {
2326 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2328 return &IgnoringParser::Create;
2332 virtual void Accept(const Element& element)
2334 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2335 m_properNamespace = true;
2339 virtual void Accept(const XmlAttribute& /*attribute*/)
2342 virtual void Accept(const Text& /*text*/)
2345 virtual void Verify()
2348 ElementParserPtr OnProviderElement()
2350 return ElementParserPtr(new AccountProviderParser(m_account));
2353 AccountParser(ConfigParserData& data) :
2356 m_account(data.accountProvider),
2357 m_properNamespace(false),
2358 m_multiSupport(false)
2362 ConfigParserData& m_data;
2363 ConfigParserData::AccountProvider& m_account;
2364 bool m_properNamespace;
2365 bool m_multiSupport;
2368 ElementParser::ActionFunc WidgetParser::GetElementParser(
2369 const DPL::String& /*ns*/,
2373 FuncMap::const_iterator it = m_map.find(name);
2374 if (it != m_map.end()) {
2377 return &IgnoringParser::Create;
2381 WidgetParser::WidgetParser(ConfigParserData& data) :
2383 m_textDirection(Unicode::EMPTY)
2385 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2386 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2387 m_map[L"description"] =
2388 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2389 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2391 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2392 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2394 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2395 m_map[L"preference"] =
2396 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2397 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2399 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2400 // TODO: appservice will be removed
2401 m_map[L"appservice"] = DPL::MakeDelegate(this,
2402 &WidgetParser::OnAppServiceElement);
2403 m_map[L"application"] = DPL::MakeDelegate(
2406 OnApplicationElement);
2407 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2408 m_map[L"background"] = DPL::MakeDelegate(this,
2409 &WidgetParser::OnBackgroundElement);
2410 m_map[L"privilege"] = DPL::MakeDelegate(this,
2411 &WidgetParser::OnPrivilegeElement);
2412 m_map[L"app-control"] = DPL::MakeDelegate(
2415 OnAppControlElement);
2416 m_map[L"category"] = DPL::MakeDelegate(this,
2417 &WidgetParser::OnCategoryElement);
2418 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2420 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2424 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2427 OnCspReportOnlyElement);
2429 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2432 ElementParserPtr WidgetParser::OnNameElement()
2434 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2437 ElementParserPtr WidgetParser::OnAccessElement()
2439 return ElementParserPtr(new AccessParser(m_data));
2442 ElementParserPtr WidgetParser::OnDescriptionElement()
2444 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2447 ElementParserPtr WidgetParser::OnAuthorElement()
2449 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2452 ElementParserPtr WidgetParser::OnLicenseElement()
2454 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2457 ElementParserPtr WidgetParser::OnIconElement()
2459 return ElementParserPtr(new IconParser(m_data));
2462 ElementParserPtr WidgetParser::OnContentElement()
2464 return ElementParserPtr(new ContentParser(m_data));
2467 ElementParserPtr WidgetParser::OnPreferenceElement()
2469 return ElementParserPtr(new PreferenceParser(m_data));
2472 ElementParserPtr WidgetParser::OnLinkElement()
2474 return ElementParserPtr(new LinkParser(m_data));
2477 ElementParserPtr WidgetParser::OnSettingElement()
2479 return ElementParserPtr(new SettingParser(m_data));
2482 ElementParserPtr WidgetParser::OnApplicationElement()
2484 return ElementParserPtr(new ApplicationParser(m_data));
2487 ElementParserPtr WidgetParser::OnSplashElement()
2489 return ElementParserPtr(new SplashParser(m_data));
2492 ElementParserPtr WidgetParser::OnBackgroundElement()
2494 return ElementParserPtr(new BackgroundParser(m_data));
2497 ElementParserPtr WidgetParser::OnPrivilegeElement()
2499 return ElementParserPtr(new PrivilegeParser(m_data));
2502 ElementParserPtr WidgetParser::OnAppServiceElement()
2504 return ElementParserPtr(new AppServiceParser(m_data));
2507 ElementParserPtr WidgetParser::OnAppControlElement()
2509 return ElementParserPtr(new AppControlParser(m_data));
2512 ElementParserPtr WidgetParser::OnCategoryElement()
2514 return ElementParserPtr(new CategoryParser(m_data));
2517 ElementParserPtr WidgetParser::OnAppWidgetElement()
2519 return ElementParserPtr(new AppWidgetParser(m_data));
2522 ElementParserPtr WidgetParser::OnCspElement()
2524 return ElementParserPtr(new CspParser(m_data));
2527 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2529 return ElementParserPtr(new CspReportOnlyParser(m_data));
2532 ElementParserPtr WidgetParser::OnAccountElement()
2534 return ElementParserPtr(new AccountParser(m_data));
2537 void WidgetParser::Accept(const Element& element)
2539 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2540 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2542 ThrowMsg(Exception::ParseError,
2543 "Wrong xml namespace for widget element");
2547 void WidgetParser::Accept(const Text& /*text*/)
2549 ThrowMsg(Exception::ParseError, "widged element must be empty");
2552 void WidgetParser::Accept(const XmlAttribute& attribute)
2554 if (attribute.name == L"id") {
2555 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2556 //If may important tests starts to fail this test we will have
2557 //to consider commenting this test out again.
2558 if (iri.Validate()) {
2559 m_data.widget_id = attribute.value;
2560 NormalizeString(m_data.widget_id);
2562 LogWarning("Widget id validation failed: " << attribute.value);
2564 } else if (attribute.name == L"version") {
2565 m_version = attribute.value;
2566 NormalizeString(m_version);
2567 } else if (attribute.name == L"min-version") {
2568 LogInfo("min-version attribute was found. Value: " << attribute.value);
2569 m_minVersion = attribute.value;
2570 NormalizeString(m_minVersion);
2571 m_data.minVersionRequired = m_minVersion;
2572 } else if (attribute.name == L"height") {
2573 DPL::OptionalString value = attribute.value;
2574 NormalizeString(value);
2575 std::string v = DPL::ToUTF8String(*value);
2578 unsigned char c = v.c_str()[0];
2579 if (c >= '0' && c <= '9') {
2581 for (size_t i = 0; i < v.size(); ++i) {
2583 if (c >= '0' && c <= '9') {
2590 m_data.height = val;
2593 } else if (attribute.name == L"width") {
2594 DPL::OptionalString value = attribute.value;
2595 NormalizeString(value);
2596 std::string v = DPL::ToUTF8String(*value);
2599 unsigned char c = v.c_str()[0];
2600 if (c >= '0' && c <= '9') {
2602 for (size_t i = 0; i < v.size(); ++i) {
2604 if (c >= '0' && c <= '9') {
2614 } else if (attribute.name == L"viewmodes") {
2615 DPL::Tokenize(attribute.value,
2617 std::inserter(m_windowModes,
2618 m_windowModes.end()),
2620 } else if (attribute.name == L"dir") {
2621 m_textDirection = Unicode::ParseDirAttribute(attribute);
2622 } else if (L"defaultlocale" == attribute.name) {
2623 if (!m_defaultlocale) {
2624 m_defaultlocale = attribute.value;
2625 NormalizeString(m_defaultlocale);
2626 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2627 DPL::ToUTF8String(*m_defaultlocale)))
2629 LogWarning("Language tag: " <<
2630 m_defaultlocale << " is not valid");
2631 m_defaultlocale = DPL::OptionalString::Null;
2633 LogDebug("Default Locale Found " << m_defaultlocale);
2636 LogWarning("Ignoring subsequent default locale");
2639 //Any other value consider as a namespace definition
2640 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2641 LogInfo("Namespace domain: " << attribute.name);
2642 LogInfo("Namespace value: " << attribute.value);
2643 m_nameSpaces[attribute.name] = attribute.value;
2645 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2646 ", name=" << attribute.name <<
2647 ", value=" << attribute.value);
2651 void WidgetParser::Verify()
2653 FOREACH(mode, m_windowModes) {
2654 if (L"windowed" == *mode || L"floating" == *mode ||
2655 L"fullscreen" == *mode || L"maximized" == *mode ||
2656 L"minimized" == *mode)
2658 m_data.windowModes.insert(*mode);
2661 if (!m_version.IsNull()) {
2662 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2663 m_data.version = m_version;
2665 m_data.defaultlocale = m_defaultlocale;
2666 FOREACH(ns, m_nameSpaces) {
2667 m_data.nameSpaces.insert(ns->second);