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 FeatureParser : public ElementParser
749 struct ParamParser : public ElementParser
751 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
752 const DPL::String& /*name*/)
754 return &IgnoringParser::Create;
757 virtual void Accept(const XmlAttribute& attribute)
759 if (attribute.name == L"name") {
760 m_name = attribute.value;
761 NormalizeString(m_name);
762 } else if (attribute.name == L"value") {
763 m_value = attribute.value;
764 NormalizeString(m_value);
768 virtual void Accept(const Element& /*element*/)
771 virtual void Accept(const Text& /*text*/)
773 ThrowMsg(Exception::ParseError, "param element must be empty");
776 virtual void Verify()
778 if (m_name.IsNull() || *m_name == L"") {
781 if (m_value.IsNull() || *m_value == L"") {
785 ConfigParserData::Param param(*m_name);
786 param.value = *m_value;
788 if (m_data.paramsList.find(param) == m_data.paramsList.end()) {
789 m_data.paramsList.insert(param);
793 ParamParser(ConfigParserData::Feature& data) :
799 DPL::OptionalString m_name;
800 DPL::OptionalString m_value;
801 ConfigParserData::Feature& m_data;
804 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
805 const DPL::String& name)
807 if (name == L"param") {
808 return DPL::MakeDelegate(this, &FeatureParser::OnParamElement);
810 return &IgnoringParser::Create;
814 virtual void Accept(const Text& /*text*/)
817 virtual void Accept(const Element& /*element*/)
820 virtual void Accept(const XmlAttribute& attribute)
822 if (attribute.name == L"name") {
823 m_feature.name = attribute.value;
824 } else if (attribute.name == L"required") {
825 if (attribute.value == L"false") {
826 m_feature.required = false;
828 m_feature.required = true;
833 virtual void Verify()
835 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
837 if (m_feature.name != L"") {
838 if (iri.Validate()) {
839 if (m_data.featuresList.find(m_feature) ==
840 m_data.featuresList.end())
842 m_data.featuresList.insert(m_feature);
844 LogDebug("Ignoring feature with name" <<
845 DPL::ToUTF8String(m_feature.name));
848 if (m_feature.required) {
849 //Throw only if required
850 ThrowMsg(Exception::ParseError, "invalid feature IRI");
856 ElementParserPtr OnParamElement()
858 return ElementParserPtr(new ParamParser(m_feature));
861 FeatureParser(ConfigParserData& data) :
868 ConfigParserData& m_data;
869 ConfigParserData::Feature m_feature;
872 class PreferenceParser : public ElementParser
875 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
876 const DPL::String& /*name*/)
878 return &IgnoringParser::Create;
881 virtual void Accept(const XmlAttribute& attribute)
883 if (attribute.name == L"name") {
884 m_name = attribute.value;
885 } else if (attribute.name == L"value") {
886 m_value = attribute.value;
887 } else if (attribute.name == L"readonly") {
888 if (attribute.value == L"true") {
896 virtual void Accept(const Element& /*element*/)
899 virtual void Accept(const Text& /*text*/)
901 ThrowMsg(Exception::ParseError, "param element must be empty");
904 virtual void Verify()
906 if (m_name.IsNull()) {
907 LogWarning("preference element must have name attribute");
910 NormalizeString(m_name);
911 NormalizeString(m_value);
912 ConfigParserData::Preference preference(*m_name, m_required);
913 preference.value = m_value;
914 if (m_data.preferencesList.find(preference) ==
915 m_data.preferencesList.end())
917 m_data.preferencesList.insert(preference);
921 PreferenceParser(ConfigParserData& data) :
928 DPL::OptionalString m_name;
929 DPL::OptionalString m_value;
931 ConfigParserData& m_data;
934 class LinkParser : public ElementParser
937 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
938 const DPL::String& /*name*/)
940 return &DenyAllParser::Create;
943 virtual void Accept(const XmlAttribute& attribute)
945 if (m_properNamespace) {
946 LogDebug("attribute");
947 if (attribute.name == L"rel") {
948 if (attribute.value != L"describedby") {
949 ThrowMsg(Exception::ParseError,
950 "rel attribute must have describedby value");
952 } else if (attribute.name == L"type") {} else if (attribute.name ==
955 LogDebug("here is href");
956 m_href = attribute.value;
958 ThrowMsg(Exception::ParseError,
959 "unknown attribute '" +
960 DPL::ToUTF8String(attribute.name) +
961 "' in link element");
966 virtual void Accept(const Element& element)
969 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
971 m_properNamespace = true;
976 virtual void Accept(const Text&)
978 if (m_properNamespace) {
980 ThrowMsg(Exception::ParseError, "link element must be empty");
984 virtual void Verify()
987 ThrowMsg(Exception::ParseError,
988 "link element must have href attribute");
991 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
992 if (!iri.Validate()) { // TODO: Better uri validator ?
993 ThrowMsg(Exception::ParseError,
994 "href attribute must be a valid iri/uri/url");
998 LinkParser(ConfigParserData& data) :
1000 m_properNamespace(false),
1002 m_href(DPL::OptionalString::Null)
1006 bool m_properNamespace;
1007 ConfigParserData& m_data;
1008 DPL::OptionalString m_href;
1011 class SettingParser : public ElementParser
1014 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1015 const DPL::String& /*name*/)
1017 return &IgnoringParser::Create;
1020 virtual void Accept(const Text& /*text*/)
1023 virtual void Accept(const Element& /*element*/)
1026 virtual void Accept(const XmlAttribute& attribute)
1028 m_setting.m_name = attribute.name;
1029 m_setting.m_value = attribute.value;
1030 m_data.settingsList.insert(m_setting);
1033 virtual void Verify()
1036 SettingParser(ConfigParserData& data) :
1043 ConfigParserData& m_data;
1044 ConfigParserData::Setting m_setting;
1047 class AppServiceParser : public ElementParser
1050 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1051 const DPL::String& /*name*/)
1053 return &IgnoringParser::Create;
1056 virtual void Accept(const XmlAttribute& attribute)
1058 if (attribute.name == L"src") {
1059 m_src = attribute.value;
1060 } else if (attribute.name == L"operation") {
1061 m_operation = attribute.value;
1062 } else if (attribute.name == L"scheme") {
1063 m_scheme = attribute.value;
1064 } else if (attribute.name == L"mime") {
1065 m_mime = attribute.value;
1066 } else if (attribute.name == L"disposition") {
1067 if (attribute.value == L"inline")
1069 ConfigParserData::ServiceInfo::Disposition::INLINE;
1073 virtual void Accept(const Element& element)
1075 LogWarning("namespace for app service = " << element.ns);
1076 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1077 ThrowMsg(Exception::ParseError,
1078 "Wrong xml namespace for widget element");
1082 virtual void Accept(const Text& /*text*/)
1084 ThrowMsg(Exception::ParseError, "param element must be empty");
1087 virtual void Verify()
1089 if (m_src.IsNull()) {
1090 LogWarning("service element must have target attribute");
1092 } else if (m_operation.IsNull()) {
1093 LogWarning("service element must have operation attribute");
1096 NormalizeString(m_src);
1097 NormalizeString(m_operation);
1098 NormalizeString(m_scheme);
1099 NormalizeString(m_mime);
1102 DPL::String ignoreUri(L"file");
1104 if (!m_scheme.IsNull() && *m_scheme == ignoreUri)
1106 LogInfo("exception : '" << *m_scheme << "' scheme will be ignored.");
1107 m_scheme = DPL::OptionalString::Null;
1110 // verify duplicate element
1111 DPL::String wildString(L"*/*");
1112 DPL::String nullString(L"");
1113 ConfigParserData::ServiceInfo serviceInfo(
1114 m_src.IsNull() ? nullString : *m_src,
1115 m_operation.IsNull() ? nullString : *m_operation,
1116 m_scheme.IsNull() ? nullString : *m_scheme,
1117 m_mime.IsNull() ? nullString : *m_mime,
1120 FOREACH(iterator, m_data.appServiceList) {
1121 if (iterator->m_operation == serviceInfo.m_operation &&
1123 (iterator->m_scheme == serviceInfo.m_scheme ||
1124 // check input scheme is "*/*" case
1125 (iterator->m_scheme == wildString &&
1126 serviceInfo.m_scheme != nullString) ||
1127 // check iterator scheme is "*/*" case
1128 (serviceInfo.m_scheme == wildString &&
1129 iterator->m_scheme != nullString)) &&
1131 (iterator->m_mime == serviceInfo.m_mime ||
1132 // check input mime is "*/*" case
1133 (iterator->m_mime == wildString &&
1134 serviceInfo.m_mime != nullString) ||
1135 // check iterator mime is "*/*" case
1136 (serviceInfo.m_mime == wildString &&
1137 iterator->m_mime != nullString)))
1139 ThrowMsg(Exception::ParseError,
1140 "service operation is duplicated " +
1141 DPL::ToUTF8String(*m_operation));
1144 m_data.appServiceList.push_back(serviceInfo);
1147 AppServiceParser(ConfigParserData& data) :
1149 m_src(DPL::OptionalString::Null),
1150 m_operation(DPL::OptionalString::Null),
1151 m_scheme(DPL::OptionalString::Null),
1152 m_mime(DPL::OptionalString::Null),
1153 m_disposition(ConfigParserData::ServiceInfo::Disposition::WINDOW),
1158 DPL::OptionalString m_src;
1159 DPL::OptionalString m_operation;
1160 DPL::OptionalString m_scheme;
1161 DPL::OptionalString m_mime;
1162 ConfigParserData::ServiceInfo::Disposition m_disposition;
1163 ConfigParserData& m_data;
1166 class AppControlParser : public ElementParser
1169 struct SourceParser : public ElementParser
1172 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1173 const DPL::String& /*name*/)
1175 return &IgnoringParser::Create;
1178 virtual void Accept(const Text& /*text*/)
1181 virtual void Accept(const Element& /*element*/)
1184 virtual void Accept(const XmlAttribute& attribute)
1186 if (attribute.name == L"name") {
1187 if (attribute.value.size() > 0) {
1188 m_value = attribute.value;
1189 NormalizeString(m_value);
1194 virtual void Verify()
1196 if (m_value.IsNull() || *m_value == L"") {
1200 m_data.m_src = *m_value;
1203 SourceParser(ConfigParserData::AppControlInfo& data) :
1205 m_properNamespace(false),
1210 bool m_properNamespace;
1211 DPL::OptionalString m_value;
1212 ConfigParserData::AppControlInfo& m_data;
1215 struct OperationParser : public ElementParser
1218 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1219 const DPL::String& /*name*/)
1221 return &IgnoringParser::Create;
1224 virtual void Accept(const Text& /*text*/)
1227 virtual void Accept(const Element& /*element*/)
1230 virtual void Accept(const XmlAttribute& attribute)
1232 if (attribute.name == L"name") {
1233 if (attribute.value.size() > 0) {
1234 m_value = attribute.value;
1235 NormalizeString(m_value);
1240 virtual void Verify()
1242 if (m_value.IsNull() || *m_value == L"") {
1246 m_data.m_operation = *m_value;
1249 OperationParser(ConfigParserData::AppControlInfo& data) :
1251 m_properNamespace(false),
1256 bool m_properNamespace;
1257 DPL::OptionalString m_value;
1258 ConfigParserData::AppControlInfo& m_data;
1261 struct UriParser : public ElementParser
1264 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1265 const DPL::String& /*name*/)
1267 return &IgnoringParser::Create;
1270 virtual void Accept(const Text& /*text*/)
1273 virtual void Accept(const Element& /*element*/)
1276 virtual void Accept(const XmlAttribute& attribute)
1278 if (attribute.name == L"name") {
1279 if (attribute.value.size() > 0) {
1280 m_value = attribute.value;
1281 NormalizeString(m_value);
1286 virtual void Verify()
1289 DPL::String ignoreUri(L"file");
1291 if (!m_value.IsNull() && *m_value == ignoreUri)
1293 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
1294 m_value = DPL::OptionalString::Null;
1297 if (m_value.IsNull() || *m_value == L"") {
1301 DPL::String wildString(L"*/*");
1302 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1303 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1305 m_data.m_uriList.insert(*m_value);
1307 LogDebug("Ignoring uri with name" <<
1308 DPL::ToUTF8String(*m_value));
1312 UriParser(ConfigParserData::AppControlInfo& data) :
1314 m_properNamespace(false),
1319 bool m_properNamespace;
1320 DPL::OptionalString m_value;
1321 ConfigParserData::AppControlInfo& m_data;
1324 struct MimeParser : public ElementParser
1327 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1328 const DPL::String& /*name*/)
1330 return &IgnoringParser::Create;
1333 virtual void Accept(const Text& /*text*/)
1336 virtual void Accept(const Element& /*element*/)
1339 virtual void Accept(const XmlAttribute& attribute)
1341 if (attribute.name == L"name") {
1342 if (attribute.value.size() > 0) {
1343 m_value = attribute.value;
1344 NormalizeString(m_value);
1349 virtual void Verify()
1351 if (m_value.IsNull() || *m_value == L"") {
1355 DPL::String wildString(L"*/*");
1356 if ((m_data.m_mimeList.find(wildString) ==
1357 m_data.m_mimeList.end())
1358 && (m_data.m_mimeList.find(*m_value) ==
1359 m_data.m_mimeList.end()))
1361 m_data.m_mimeList.insert(*m_value);
1363 LogDebug("Ignoring mime with name" <<
1364 DPL::ToUTF8String(*m_value));
1368 MimeParser(ConfigParserData::AppControlInfo& data) :
1370 m_properNamespace(false),
1375 bool m_properNamespace;
1376 DPL::OptionalString m_value;
1377 ConfigParserData::AppControlInfo& m_data;
1380 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1381 const DPL::String& name)
1383 if (name == L"src") {
1384 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1385 } else if (name == L"operation") {
1386 return DPL::MakeDelegate(this,
1387 &AppControlParser::OnOperationElement);
1388 } else if (name == L"uri") {
1389 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1390 } else if (name == L"mime") {
1391 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1393 return &IgnoringParser::Create;
1397 virtual void Accept(const XmlAttribute& /*attribute*/)
1400 virtual void Accept(const Element& element)
1402 LogWarning("namespace for app service = " << element.ns);
1403 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1404 ThrowMsg(Exception::ParseError,
1405 "Wrong xml namespace for widget element");
1409 virtual void Accept(const Text& /*text*/)
1411 ThrowMsg(Exception::ParseError, "param element must be empty");
1414 virtual void Verify()
1416 if (m_appControl.m_src == L"") {
1417 LogWarning("service element must have src element");
1421 if (m_appControl.m_operation == L"") {
1422 LogWarning("service element must have operation element");
1426 m_data.appControlList.push_back(m_appControl);
1429 ElementParserPtr OnSourceElement()
1431 return ElementParserPtr(new SourceParser(m_appControl));
1434 ElementParserPtr OnOperationElement()
1436 return ElementParserPtr(new OperationParser(m_appControl));
1439 ElementParserPtr OnUriElement()
1441 return ElementParserPtr(new UriParser(m_appControl));
1444 ElementParserPtr OnMimeElement()
1446 return ElementParserPtr(new MimeParser(m_appControl));
1449 AppControlParser(ConfigParserData& data) :
1456 ConfigParserData& m_data;
1457 ConfigParserData::AppControlInfo m_appControl;
1460 class ApplicationParser : public ElementParser
1463 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1464 const DPL::String& /*name*/)
1466 return &IgnoringParser::Create;
1469 virtual void Accept(const Text& /*text*/)
1471 if (m_properNamespace) {
1473 ThrowMsg(Exception::ParseError, "application element must be empty");
1477 virtual void Accept(const Element& element)
1480 ConfigurationNamespace::TizenWebAppNamespaceName)
1482 m_properNamespace = true;
1484 LogDebug("element");
1487 virtual void Accept(const XmlAttribute& attribute)
1489 if (m_properNamespace) {
1490 LogDebug("attribute");
1491 if (attribute.name == L"id") {
1492 m_id = attribute.value;
1493 NormalizeAndTrimSpaceString(m_id);
1494 } else if (attribute.name == L"package") {
1495 m_package = attribute.value;
1496 } else if (attribute.name == L"required_version") {
1497 m_version = attribute.value;
1498 NormalizeString(m_version);
1500 ThrowMsg(Exception::ParseError,
1501 "unknown attribute '" +
1502 DPL::ToUTF8String(attribute.name) +
1503 "' in application element");
1508 virtual void Verify()
1511 ThrowMsg(Exception::ParseError,
1512 "application element must have id attribute");
1516 m_data.tizenPkgId = m_package;
1520 ThrowMsg(Exception::ParseError,
1521 "application element must have required_version attribute");
1524 //TODO check if id and version format is right
1525 m_data.tizenAppId = m_id;
1526 m_data.tizenMinVersionRequired = m_version;
1529 ApplicationParser(ConfigParserData& data) :
1532 m_id(DPL::OptionalString::Null),
1533 m_version(DPL::OptionalString::Null),
1534 m_properNamespace(false)
1538 ConfigParserData& m_data;
1539 DPL::OptionalString m_id;
1540 DPL::OptionalString m_package;
1541 DPL::OptionalString m_version;
1542 bool m_properNamespace;
1545 class SplashParser : public ElementParser
1548 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1549 const DPL::String& /*name*/)
1551 return &IgnoringParser::Create;
1554 virtual void Accept(const XmlAttribute& attribute)
1556 if (attribute.name == L"src") {
1557 if (attribute.value.size() > 0) {
1558 m_src = attribute.value;
1563 virtual void Accept(const Element& /*element*/)
1566 virtual void Accept(const Text& /*text*/)
1569 virtual void Verify()
1571 if (m_src.IsNull()) {
1573 "src attribute of splash element is mandatory - ignoring");
1577 m_data.splashImgSrc = m_src;
1580 SplashParser(ConfigParserData& data) :
1586 DPL::OptionalString m_src;
1587 ConfigParserData& m_data;
1590 class BackgroundParser : public ElementParser
1593 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1594 const DPL::String& /*name*/)
1596 return &IgnoringParser::Create;
1599 virtual void Accept(const XmlAttribute& attribute)
1601 if (attribute.name == L"src") {
1602 if (attribute.value.size() > 0) {
1603 m_src = attribute.value;
1608 virtual void Accept(const Element& /*element*/)
1611 virtual void Accept(const Text& /*text*/)
1614 virtual void Verify()
1616 if (m_src.IsNull()) {
1618 "src attribute of background element is mandatory - ignoring");
1622 m_data.backgroundPage = m_src;
1625 explicit BackgroundParser(ConfigParserData& data) :
1630 DPL::OptionalString m_src;
1631 ConfigParserData& m_data;
1634 class PrivilegeParser : public ElementParser
1637 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1638 const DPL::String& /*name*/)
1640 return &IgnoringParser::Create;
1643 virtual void Accept(const Text& /*text*/)
1646 virtual void Accept(const Element& element)
1649 ConfigurationNamespace::TizenWebAppNamespaceName)
1651 m_properNamespace = true;
1653 LogDebug("element");
1656 virtual void Accept(const XmlAttribute& attribute)
1658 if (m_properNamespace) {
1659 if (attribute.name == L"name") {
1660 m_feature.name = attribute.value;
1661 m_privilege.name = attribute.value;
1664 m_feature.required = false;
1667 virtual void Verify()
1669 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1671 if (m_feature.name != L"") {
1672 if (iri.Validate()) {
1673 if (m_data.featuresList.find(m_feature) ==
1674 m_data.featuresList.end())
1676 m_data.featuresList.insert(m_feature);
1678 LogDebug("Ignoring feature with name" <<
1679 DPL::ToUTF8String(m_feature.name));
1684 LibIri::Wrapper iriPrivilege(
1685 DPL::ToUTF8String(m_privilege.name).c_str());
1687 if (m_privilege.name != L"") {
1688 if (iriPrivilege.Validate()) {
1689 if (m_data.privilegeList.find(m_privilege) ==
1690 m_data.privilegeList.end())
1692 m_data.privilegeList.insert(m_privilege);
1694 LogDebug("Ignoring privilege with name" <<
1695 DPL::ToUTF8String(m_privilege.name));
1701 PrivilegeParser(ConfigParserData& data) :
1706 m_properNamespace(false)
1710 ConfigParserData& m_data;
1711 ConfigParserData::Feature m_feature;
1712 ConfigParserData::Privilege m_privilege;
1713 bool m_properNamespace;
1716 class CategoryParser : public ElementParser
1719 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1720 const DPL::String& /*name*/)
1722 return &IgnoringParser::Create;
1725 virtual void Accept(const XmlAttribute& attribute)
1727 if (attribute.name == L"name") {
1728 if (attribute.value.size() > 0) {
1729 m_name = attribute.value;
1734 virtual void Accept(const Element& /*element*/)
1737 virtual void Accept(const Text& /*text*/)
1740 virtual void Verify()
1742 if (m_name.IsNull()) {
1744 "name attribute of category element is mandatory - ignoring");
1748 if (m_data.categoryList.find(*m_name) ==
1749 m_data.categoryList.end())
1751 m_data.categoryList.insert(*m_name);
1755 explicit CategoryParser(ConfigParserData& data) :
1760 DPL::OptionalString m_name;
1761 ConfigParserData& m_data;
1764 class LiveboxParser : public ElementParser
1768 struct BoxLabelParser : public ElementParser
1770 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1771 const DPL::String& /*name*/)
1773 return &IgnoringParser::Create;
1776 virtual void Accept(const XmlAttribute& /*attribute*/)
1779 virtual void Accept(const Element& element)
1782 ConfigurationNamespace::TizenWebAppNamespaceName)
1784 m_properNamespace = true;
1788 virtual void Accept(const Text& text)
1790 if (m_properNamespace) {
1791 m_label = text.value;
1795 virtual void Verify()
1797 m_data.m_label = m_label;
1800 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1802 m_properNamespace(false),
1807 DPL::String m_label;
1808 bool m_properNamespace;
1809 ConfigParserData::LiveboxInfo& m_data;
1812 struct BoxIconParser : public ElementParser
1814 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1815 const DPL::String& /*name*/)
1817 return &IgnoringParser::Create;
1820 virtual void Accept(const XmlAttribute& attribute)
1822 if (m_properNamespace) {
1823 if (attribute.name == L"src") {
1824 m_icon = attribute.value;
1829 virtual void Accept(const Element& element)
1832 ConfigurationNamespace::TizenWebAppNamespaceName)
1834 m_properNamespace = true;
1838 virtual void Accept(const Text& /*text*/)
1841 virtual void Verify()
1843 m_data.m_icon = m_icon;
1846 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1848 m_properNamespace(false),
1854 bool m_properNamespace;
1855 ConfigParserData::LiveboxInfo& m_data;
1858 struct BoxContentParser : public ElementParser
1860 struct BoxSizeParser : public ElementParser
1862 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1863 const DPL::String& /*name*/)
1865 return &IgnoringParser::Create;
1868 virtual void Accept(const XmlAttribute& attribute)
1870 if (m_properNamespace) {
1871 if (attribute.name == L"preview") {
1872 m_preview = attribute.value;
1877 virtual void Accept(const Element& element)
1880 ConfigurationNamespace::TizenWebAppNamespaceName)
1882 m_properNamespace = true;
1886 virtual void Accept(const Text& text)
1888 if (m_properNamespace) {
1889 m_size = text.value;
1893 virtual void Verify()
1895 std::pair<DPL::String, DPL::String> boxSize;
1896 boxSize.first = m_size;
1897 boxSize.second = m_preview;
1898 m_data.m_boxSize.push_back(boxSize);
1901 explicit BoxSizeParser(
1902 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1904 m_properNamespace(false),
1910 DPL::String m_preview;
1911 bool m_properNamespace;
1912 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1915 struct PdParser : public ElementParser
1917 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1918 const DPL::String& /*name*/)
1920 return &IgnoringParser::Create;
1923 virtual void Accept(const XmlAttribute& attribute)
1925 if (m_properNamespace) {
1926 if (attribute.name == L"src") {
1927 m_src = attribute.value;
1928 } else if (attribute.name == L"width") {
1929 m_width = attribute.value;
1930 } else if (attribute.name == L"height") {
1931 m_height = attribute.value;
1936 virtual void Accept(const Element& element)
1939 ConfigurationNamespace::TizenWebAppNamespaceName)
1941 m_properNamespace = true;
1945 virtual void Accept(const Text& /*text*/)
1948 virtual void Verify()
1950 m_data.m_pdSrc = m_src;
1951 m_data.m_pdWidth = m_width;
1952 m_data.m_pdHeight = m_height;
1956 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1958 m_properNamespace(false),
1964 DPL::String m_width;
1965 DPL::String m_height;
1967 bool m_properNamespace;
1968 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1971 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1972 const DPL::String& name)
1974 if (name == L"box-size") {
1975 return DPL::MakeDelegate(
1977 &LiveboxParser::BoxContentParser::
1979 } else if (name == L"pd") {
1980 return DPL::MakeDelegate(
1982 &LiveboxParser::BoxContentParser::
1985 ThrowMsg(Exception::ParseError,
1986 "No element parser for name: " << name);
1990 virtual void Accept(const XmlAttribute& attribute)
1992 if (m_properNamespace) {
1993 if (attribute.name == L"src") {
1994 m_box.m_boxSrc = attribute.value;
1996 if (attribute.name == L"mouse-event") {
1997 m_box.m_boxMouseEvent = attribute.value;
2002 virtual void Accept(const Element& element)
2005 ConfigurationNamespace::TizenWebAppNamespaceName)
2007 m_properNamespace = true;
2011 virtual void Accept(const Text& /*text*/)
2014 virtual void Verify()
2016 m_data.m_boxInfo = m_box;
2019 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
2021 m_properNamespace(false),
2025 ElementParserPtr OnBoxSizeElement()
2027 return ElementParserPtr(new BoxSizeParser(m_box));
2030 ElementParserPtr OnPdElement()
2032 return ElementParserPtr(new PdParser(m_box));
2037 bool m_properNamespace;
2038 ConfigParserData::LiveboxInfo& m_data;
2039 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
2042 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2043 const DPL::String& name)
2045 if (name == L"box-label") {
2046 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxLabelElement);
2047 } else if (name == L"box-icon") {
2048 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxIconElement);
2049 } else if (name == L"box-content") {
2050 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxContentElement);
2052 return &IgnoringParser::Create;
2056 virtual void Accept(const XmlAttribute& attribute)
2058 if (m_properNamespace) {
2059 if (attribute.name == L"id") {
2060 m_liveboxId = attribute.value;
2061 } else if (attribute.name == L"primary") {
2062 m_primary = attribute.value;
2063 } else if (attribute.name == L"auto-launch") {
2064 m_autoLaunch = attribute.value;
2065 } else if (attribute.name == L"update-period") {
2066 m_updatePeriod = attribute.value;
2067 } else if (attribute.name == L"type") {
2068 m_type = attribute.value;
2073 virtual void Accept(const Element& element)
2076 ConfigurationNamespace::TizenWebAppNamespaceName)
2078 m_properNamespace = true;
2082 virtual void Accept(const Text& /*text*/)
2085 virtual void Verify()
2087 m_livebox.m_liveboxId = m_liveboxId;
2088 m_livebox.m_primary = m_primary;
2089 m_livebox.m_autoLaunch = m_autoLaunch;
2090 m_livebox.m_updatePeriod = m_updatePeriod;
2091 m_livebox.m_type = m_type;
2093 m_data.m_livebox.push_back(m_livebox);
2096 explicit LiveboxParser(ConfigParserData& data) :
2099 m_properNamespace(false)
2101 m_livebox = ConfigParserData::LiveboxInfo();
2104 ElementParserPtr OnBoxLabelElement()
2106 return ElementParserPtr(new BoxLabelParser(m_livebox));
2109 ElementParserPtr OnBoxIconElement()
2111 return ElementParserPtr(new BoxIconParser(m_livebox));
2114 ElementParserPtr OnBoxContentElement()
2116 return ElementParserPtr(new BoxContentParser(m_livebox));
2120 ConfigParserData& m_data;
2121 ConfigParserData::LiveboxInfo m_livebox;
2122 DPL::String m_liveboxId;
2123 DPL::String m_primary;
2124 DPL::String m_autoLaunch;
2125 DPL::String m_updatePeriod;
2127 bool m_properNamespace;
2130 class CspParser : public ElementParser
2133 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2134 const DPL::String& /*name*/)
2136 return &IgnoringParser::Create;
2139 CspParser(ConfigParserData& data) :
2142 m_properNamespace(false)
2145 virtual void Accept(const Element& element)
2147 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2148 m_properNamespace = true;
2152 virtual void Accept(const XmlAttribute& /*attribute*/)
2155 virtual void Accept(const Text& text)
2157 if (m_properNamespace) {
2158 m_policy = text.value;
2162 virtual void Verify()
2164 if (!m_policy.IsNull()) {
2165 m_data.cspPolicy = *m_policy;
2170 ConfigParserData& m_data;
2171 bool m_properNamespace;
2172 DPL::OptionalString m_policy;
2175 class CspReportOnlyParser : public ElementParser
2178 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2179 const DPL::String& /*name*/)
2181 return &IgnoringParser::Create;
2184 CspReportOnlyParser(ConfigParserData& data) :
2187 m_properNamespace(false)
2190 virtual void Accept(const Element& element)
2192 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2193 m_properNamespace = true;
2197 virtual void Accept(const XmlAttribute& /*attribute*/)
2200 virtual void Accept(const Text& text)
2202 if (m_properNamespace) {
2203 m_policy = text.value;
2207 virtual void Verify()
2209 if (!m_policy.IsNull()) {
2210 m_data.cspPolicyReportOnly = *m_policy;
2215 ConfigParserData& m_data;
2216 bool m_properNamespace;
2217 DPL::OptionalString m_policy;
2220 ElementParser::ActionFunc WidgetParser::GetElementParser(
2221 const DPL::String& /*ns*/,
2225 FuncMap::const_iterator it = m_map.find(name);
2226 if (it != m_map.end()) {
2229 return &IgnoringParser::Create;
2233 WidgetParser::WidgetParser(ConfigParserData& data) :
2235 m_textDirection(Unicode::EMPTY)
2237 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2238 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2239 m_map[L"description"] =
2240 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2241 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2243 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2244 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2246 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2248 DPL::MakeDelegate(this, &WidgetParser::OnFeatureElement);
2249 m_map[L"preference"] =
2250 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2251 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2253 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2254 // TODO: appservice will be removed
2255 m_map[L"appservice"] = DPL::MakeDelegate(this,
2256 &WidgetParser::OnAppServiceElement);
2257 m_map[L"application"] = DPL::MakeDelegate(
2260 OnApplicationElement);
2261 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2262 m_map[L"background"] = DPL::MakeDelegate(this,
2263 &WidgetParser::OnBackgroundElement);
2264 m_map[L"privilege"] = DPL::MakeDelegate(this,
2265 &WidgetParser::OnPrivilegeElement);
2266 m_map[L"app-control"] = DPL::MakeDelegate(
2269 OnAppControlElement);
2270 m_map[L"category"] = DPL::MakeDelegate(this,
2271 &WidgetParser::OnCategoryElement);
2272 m_map[L"livebox"] = DPL::MakeDelegate(this, &WidgetParser::OnLiveboxElement);
2274 m_map[L"Content-Security-Policy"] = DPL::MakeDelegate(
2278 m_map[L"Content-Security-Policy-Report-Only"] = DPL::MakeDelegate(
2281 OnCspReportOnlyElement);
2285 ElementParserPtr WidgetParser::OnNameElement()
2287 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2290 ElementParserPtr WidgetParser::OnAccessElement()
2292 return ElementParserPtr(new AccessParser(m_data));
2295 ElementParserPtr WidgetParser::OnDescriptionElement()
2297 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2300 ElementParserPtr WidgetParser::OnAuthorElement()
2302 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2305 ElementParserPtr WidgetParser::OnLicenseElement()
2307 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2310 ElementParserPtr WidgetParser::OnIconElement()
2312 return ElementParserPtr(new IconParser(m_data));
2315 ElementParserPtr WidgetParser::OnContentElement()
2317 return ElementParserPtr(new ContentParser(m_data));
2320 ElementParserPtr WidgetParser::OnFeatureElement()
2322 return ElementParserPtr(new FeatureParser(m_data));
2325 ElementParserPtr WidgetParser::OnPreferenceElement()
2327 return ElementParserPtr(new PreferenceParser(m_data));
2330 ElementParserPtr WidgetParser::OnLinkElement()
2332 return ElementParserPtr(new LinkParser(m_data));
2335 ElementParserPtr WidgetParser::OnSettingElement()
2337 return ElementParserPtr(new SettingParser(m_data));
2340 ElementParserPtr WidgetParser::OnApplicationElement()
2342 return ElementParserPtr(new ApplicationParser(m_data));
2345 ElementParserPtr WidgetParser::OnSplashElement()
2347 return ElementParserPtr(new SplashParser(m_data));
2350 ElementParserPtr WidgetParser::OnBackgroundElement()
2352 return ElementParserPtr(new BackgroundParser(m_data));
2355 ElementParserPtr WidgetParser::OnPrivilegeElement()
2357 return ElementParserPtr(new PrivilegeParser(m_data));
2360 ElementParserPtr WidgetParser::OnAppServiceElement()
2362 return ElementParserPtr(new AppServiceParser(m_data));
2365 ElementParserPtr WidgetParser::OnAppControlElement()
2367 return ElementParserPtr(new AppControlParser(m_data));
2370 ElementParserPtr WidgetParser::OnCategoryElement()
2372 return ElementParserPtr(new CategoryParser(m_data));
2375 ElementParserPtr WidgetParser::OnLiveboxElement()
2377 return ElementParserPtr(new LiveboxParser(m_data));
2380 ElementParserPtr WidgetParser::OnCspElement()
2382 return ElementParserPtr(new CspParser(m_data));
2385 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2387 return ElementParserPtr(new CspReportOnlyParser(m_data));
2390 void WidgetParser::Accept(const Element& element)
2392 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2393 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2395 ThrowMsg(Exception::ParseError,
2396 "Wrong xml namespace for widget element");
2400 void WidgetParser::Accept(const Text& /*text*/)
2402 ThrowMsg(Exception::ParseError, "widged element must be empty");
2405 void WidgetParser::Accept(const XmlAttribute& attribute)
2407 if (attribute.name == L"id") {
2408 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2409 //If may important tests starts to fail this test we will have
2410 //to consider commenting this test out again.
2411 if (iri.Validate()) {
2412 m_data.widget_id = attribute.value;
2413 NormalizeString(m_data.widget_id);
2415 LogWarning("Widget id validation failed: " << attribute.value);
2417 } else if (attribute.name == L"version") {
2418 m_version = attribute.value;
2419 NormalizeString(m_version);
2420 } else if (attribute.name == L"min-version") {
2421 LogInfo("min-version attribute was found. Value: " << attribute.value);
2422 m_minVersion = attribute.value;
2423 NormalizeString(m_minVersion);
2424 m_data.minVersionRequired = m_minVersion;
2425 } else if (attribute.name == L"height") {
2426 DPL::OptionalString value = attribute.value;
2427 NormalizeString(value);
2428 std::string v = DPL::ToUTF8String(*value);
2431 unsigned char c = v.c_str()[0];
2432 if (c >= '0' && c <= '9') {
2434 for (size_t i = 0; i < v.size(); ++i) {
2436 if (c >= '0' && c <= '9') {
2443 m_data.height = val;
2446 } else if (attribute.name == L"width") {
2447 DPL::OptionalString value = attribute.value;
2448 NormalizeString(value);
2449 std::string v = DPL::ToUTF8String(*value);
2452 unsigned char c = v.c_str()[0];
2453 if (c >= '0' && c <= '9') {
2455 for (size_t i = 0; i < v.size(); ++i) {
2457 if (c >= '0' && c <= '9') {
2467 } else if (attribute.name == L"viewmodes") {
2468 DPL::Tokenize(attribute.value,
2470 std::inserter(m_windowModes,
2471 m_windowModes.end()),
2473 } else if (attribute.name == L"dir") {
2474 m_textDirection = Unicode::ParseDirAttribute(attribute);
2475 } else if (L"defaultlocale" == attribute.name) {
2476 if (!m_defaultlocale) {
2477 m_defaultlocale = attribute.value;
2478 NormalizeString(m_defaultlocale);
2479 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2480 DPL::ToUTF8String(*m_defaultlocale)))
2482 LogWarning("Language tag: " <<
2483 m_defaultlocale << " is not valid");
2484 m_defaultlocale = DPL::OptionalString::Null;
2486 LogDebug("Default Locale Found " << m_defaultlocale);
2489 LogWarning("Ignoring subsequent default locale");
2492 //Any other value consider as a namespace definition
2493 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2494 LogInfo("Namespace domain: " << attribute.name);
2495 LogInfo("Namespace value: " << attribute.value);
2496 m_nameSpaces[attribute.name] = attribute.value;
2498 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2499 ", name=" << attribute.name <<
2500 ", value=" << attribute.value);
2504 void WidgetParser::Verify()
2506 FOREACH(mode, m_windowModes) {
2507 if (L"windowed" == *mode || L"floating" == *mode ||
2508 L"fullscreen" == *mode || L"maximized" == *mode ||
2509 L"minimized" == *mode)
2511 m_data.windowModes.insert(*mode);
2514 if (!m_version.IsNull()) {
2515 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2516 m_data.version = m_version;
2518 m_data.defaultlocale = m_defaultlocale;
2519 FOREACH(ns, m_nameSpaces) {
2520 m_data.nameSpaces.insert(ns->second);