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;
93 } // namespace Unicode
95 class InnerElementsParser : public ElementParser
98 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
99 const DPL::String& /*name*/)
101 return DPL::MakeDelegate(this, &InnerElementsParser::Other);
104 virtual void Accept(const Element& /*element*/)
107 virtual void Accept(const Text& text)
109 if (m_text.IsNull()) {
112 m_text->value += text.value;
116 virtual void Accept(const XmlAttribute& attribute)
118 if (attribute.name == L"dir") {
119 m_textDirection = Unicode::ParseDirAttribute(attribute);
123 virtual void Verify()
125 if (!m_text.IsNull()) {
126 Unicode::UpdateTextWithDirectionMark(m_textDirection,
128 m_parentParser->Accept(*m_text);
132 InnerElementsParser(ElementParserPtr parent) :
133 m_parentParser(parent),
134 m_textDirection(Unicode::EMPTY)
137 ElementParserPtr Other()
139 return ElementParserPtr(new InnerElementsParser(
140 std::static_pointer_cast<ElementParser>(
141 shared_from_this())));
145 DPL::Optional<Text> m_text;
146 ElementParserPtr m_parentParser;
147 Unicode::Direction m_textDirection;
150 class NameParser : public ElementParser
153 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
154 const DPL::String& /*name*/)
156 return DPL::MakeDelegate(this, &NameParser::Other);
159 virtual void Accept(const Element& element)
161 m_lang = element.lang;
165 virtual void Accept(const Text& text)
167 if (m_name.IsNull()) {
170 *m_name += text.value;
174 virtual void Accept(const XmlAttribute& attribute)
176 if (attribute.name == L"short") {
177 if (m_shortName.IsNull()) {
178 m_shortName = attribute.value;
180 } else if (attribute.name == L"dir") {
181 m_textDirection = Unicode::ParseDirAttribute(attribute);
185 virtual void Verify()
187 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
188 if (data.name.IsNull()) {
189 NormalizeString(m_name);
190 NormalizeString(m_shortName);
191 if (!m_name.IsNull()) {
192 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
195 if (!m_shortName.IsNull()) {
196 Unicode::UpdateTextWithDirectionMark(m_textDirection,
199 data.shortName = m_shortName;
203 NameParser(Unicode::Direction direction,
204 ConfigParserData& data) :
206 m_textDirection(direction)
209 ElementParserPtr Other()
211 return ElementParserPtr(new InnerElementsParser(
212 std::static_pointer_cast<ElementParser>(
213 shared_from_this())));
217 ConfigParserData& m_data;
218 DPL::OptionalString m_name;
219 DPL::OptionalString m_shortName;
220 DPL::OptionalString m_dir;
222 Unicode::Direction m_textDirection;
225 class AccessParser : public ElementParser
234 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
235 const DPL::String& /*name*/)
237 return DPL::MakeDelegate(this, &AccessParser::Other);
240 virtual void Accept(const Element& element)
242 // for tizen web apps WARP should be used
243 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
244 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
246 m_standardType = STANDARD_TYPE_WARP;
250 virtual void Accept(const Text& /*text*/)
253 void AcceptWac(const XmlAttribute& attribute)
255 if (attribute.name == L"origin") {
256 m_strIRIOrigin = attribute.value;
257 NormalizeString(m_strIRIOrigin);
258 } else if (attribute.name == L"subdomains") {
259 DPL::String normalizedValue = attribute.value;
260 NormalizeString(normalizedValue);
262 if (normalizedValue == L"true") {
263 m_bSubDomainAccess = true;
264 } else if (normalizedValue == L"false") {
265 m_bSubDomainAccess = false;
270 virtual void Accept(const XmlAttribute& attribute)
272 switch (m_standardType) {
273 case STANDARD_TYPE_WARP:
274 AcceptWac(attribute);
277 LogError("Error in Access tag - unknown standard.");
284 iri.set(m_strIRIOrigin, false);
286 if (!iri.isAccessDefinition()) {
287 LogWarning("Access list element: " <<
289 " is not acceptable by WARP" <<
290 "standard and will be ignored!");
294 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
296 std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
297 m_data.accessInfoSet.insert(accessInfo);
300 virtual void Verify()
302 switch (m_standardType) {
303 case STANDARD_TYPE_WARP:
307 LogError("Error in Access tag - unknown standard.");
311 AccessParser(ConfigParserData& data) :
313 m_bSubDomainAccess(false),
314 m_standardType(STANDARD_TYPE_NONE),
319 ElementParserPtr Other()
321 return ElementParserPtr(new InnerElementsParser(
322 ElementParserPtr(shared_from_this())));
326 DPL::String m_strIRIOrigin;
327 bool m_bSubDomainAccess;
328 StandardType m_standardType;
330 ConfigParserData& m_data;
333 class DescriptionParser : public ElementParser
336 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
337 const DPL::String& /*name*/)
339 return DPL::MakeDelegate(this, &DescriptionParser::Other);
342 virtual void Accept(const Element& element)
344 m_lang = element.lang;
348 ElementParserPtr Other()
350 return ElementParserPtr(new InnerElementsParser(
351 std::static_pointer_cast<ElementParser>(
352 shared_from_this())));
355 virtual void Accept(const Text& text)
357 if (m_description.IsNull()) {
358 m_description = text.value;
360 *m_description += text.value;
364 virtual void Accept(const XmlAttribute& attribute)
366 if (attribute.name == L"dir") {
367 m_textDirection = Unicode::ParseDirAttribute(attribute);
371 virtual void Verify()
373 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
374 if (data.description.IsNull()) {
375 if (!m_description.IsNull()) {
376 Unicode::UpdateTextWithDirectionMark(m_textDirection,
379 data.description = m_description;
383 DescriptionParser(Unicode::Direction direction,
384 ConfigParserData& data) :
388 m_textDirection(direction)
392 ConfigParserData& m_data;
394 DPL::OptionalString m_description;
395 Unicode::Direction m_textDirection;
398 class AuthorParser : public ElementParser
401 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
402 const DPL::String& /*name*/)
404 return DPL::MakeDelegate(this, &AuthorParser::Other);
407 AuthorParser(Unicode::Direction direction,
408 ConfigParserData& data) :
410 m_textDirection(direction)
413 virtual void Accept(const Element& /*element*/)
418 virtual void Accept(const Text& text)
420 *(m_authorName) += text.value;
423 virtual void Accept(const XmlAttribute& attribute)
425 if (attribute.name == L"href") {
426 //Validate href IRI and ignore it if invalid
427 //See also test: ta-argMozRiC-an
428 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
429 if (iri.Validate()) {
430 m_authorHref = attribute.value;
432 } else if (attribute.name == L"email") {
433 m_authorEmail = attribute.value;
434 } else if (attribute.name == L"dir") {
435 m_textDirection = Unicode::ParseDirAttribute(attribute);
439 virtual void Verify()
441 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
442 NormalizeString(m_authorName);
443 NormalizeString(m_authorHref);
444 NormalizeString(m_authorEmail);
445 if (!!m_authorName) {
446 Unicode::UpdateTextWithDirectionMark(m_textDirection,
448 m_data.authorName = m_authorName;
450 if (!!m_authorHref) {
451 m_data.authorHref = m_authorHref;
453 if (!!m_authorEmail) {
454 m_data.authorEmail = m_authorEmail;
459 ElementParserPtr Other()
461 return ElementParserPtr(new InnerElementsParser(
462 std::static_pointer_cast<ElementParser>(
463 shared_from_this())));
467 ConfigParserData& m_data;
468 DPL::OptionalString m_authorEmail;
469 DPL::OptionalString m_authorHref;
470 DPL::OptionalString m_authorName;
471 Unicode::Direction m_textDirection;
474 class LicenseParser : public ElementParser
477 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
478 const DPL::String& /*name*/)
480 return DPL::MakeDelegate(this, &LicenseParser::Other);
483 LicenseParser(Unicode::Direction direction,
484 ConfigParserData& data) :
487 m_textDirection(direction)
490 virtual void Accept(const Element& element)
492 if (m_license.IsNull()) {
493 m_lang = element.lang;
499 virtual void Accept(const Text& text)
502 *m_license += text.value;
506 virtual void Accept(const XmlAttribute& attribute)
509 if (attribute.name == L"href" && m_licenseHref.IsNull()) {
510 m_licenseHref = attribute.value;
511 } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
512 m_licenseFile = attribute.value;
513 } else if (attribute.name == L"dir") {
514 m_textDirection = Unicode::ParseDirAttribute(attribute);
519 virtual void Verify()
521 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
522 if (data.license.IsNull()) {
523 if (!m_license.IsNull()) {
524 Unicode::UpdateTextWithDirectionMark(m_textDirection,
527 data.license = m_license;
528 data.licenseHref = m_licenseHref;
529 data.licenseFile = m_licenseFile;
533 ElementParserPtr Other()
535 return ElementParserPtr(new InnerElementsParser(
536 ElementParserPtr(shared_from_this())));
540 ConfigParserData& m_data;
544 DPL::OptionalString m_license;
545 DPL::OptionalString m_licenseFile;
546 DPL::OptionalString m_licenseHref;
547 Unicode::Direction m_textDirection;
550 class IconParser : public ElementParser
552 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
555 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
556 const DPL::String& /*name*/)
558 return &IgnoringParser::Create;
561 IconParser(ConfigParserData& data) : ElementParser(),
565 virtual void Accept(const Element& /*element*/)
568 virtual void Accept(const XmlAttribute& attribute)
570 if (attribute.name == L"src") {
571 if (attribute.value.size() > 0) {
572 m_src = attribute.value;
574 } else if (attribute.name == L"width") {
575 m_width = ParseSizeAttributeValue(attribute.value);
576 } else if (attribute.name == L"height") {
577 m_height = ParseSizeAttributeValue(attribute.value);
581 virtual void Accept(const Text& /*text*/)
583 ThrowMsg(Exception::ParseError, "Icon element must be empty");
586 virtual void Verify()
588 if (m_src.IsNull()) {
589 LogWarning("src attribute of icon element is mandatory - ignoring");
595 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
596 icon.width = m_width;
597 icon.height = m_height;
599 ConfigParserData::IconsList::iterator it = std::find(
600 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
601 if (it == m_data.iconsList.end()) {
602 m_data.iconsList.push_front(icon);
607 LogWarning("src attribute is invalid: " << m_src);
612 ConfigParserData& m_data;
613 DPL::OptionalString m_src;
614 DPL::OptionalInt m_width;
615 DPL::OptionalInt m_height;
617 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
619 DPL::OptionalString normalizedValue = value;
620 NormalizeString(normalizedValue);
621 if (!(*normalizedValue).empty()) {
625 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
627 std::string(reterr) == DPL::ToUTF8String(value) ||
630 return DPL::OptionalInt::Null;
635 return DPL::OptionalInt::Null;
639 * @brief delocalizePath removes locales folder from relative path if
641 * @param source source string
643 * @throw BadSrcError if string is bad value of src attribute
645 * @return corrected string
647 static DPL::String delocalizeSrcPath(const DPL::String & source)
649 static const DPL::String localeFolder(L"locales/");
650 static const int index = localeFolder.size();
652 DPL::String result = source;
654 if (source.substr(0, index) == localeFolder) {
655 size_t pos = result.find_first_of('/', index);
656 if (pos != std::string::npos && pos + 1 < source.size()) {
657 result = result.substr(pos + 1, source.size());
666 class ContentParser : public ElementParser
669 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
670 const DPL::String& /*name*/)
672 return &IgnoringParser::Create;
675 ContentParser(ConfigParserData& data) :
680 virtual void Accept(const Element& /*element*/)
683 virtual void Accept(const Text& /*text*/)
686 virtual void Accept(const XmlAttribute& attribute)
688 DPL::String value = attribute.value;
689 NormalizeString(value);
691 if (attribute.name == L"src") {
693 } else if (attribute.name == L"type") {
695 MimeTypeUtils::MimeAttributes mimeAttributes =
696 MimeTypeUtils::getMimeAttributes(value);
697 if (mimeAttributes.count(L"charset") > 0) {
698 m_encoding = mimeAttributes[L"charset"];
700 } else if (attribute.name == L"encoding") {
701 if (!value.empty()) {
707 virtual void Verify()
709 if (m_data.startFileEncountered) {
710 LogWarning("This is not the first encountered "
711 "'content' element - ignoring.");
715 m_data.startFileEncountered = true;
717 //we're consciously setting startFile even if m_src is null or invalid.
718 //WidgetConfigurationManager will deal with this.
719 m_data.startFile = m_src;
722 m_data.startFileContentType = m_type;
724 m_data.startFileEncoding = m_encoding;
726 m_data.startFileEncoding = L"UTF-8";
732 DPL::OptionalString m_src;
733 DPL::OptionalString m_type;
734 DPL::OptionalString m_encoding;
735 ConfigParserData& m_data;
738 class FeatureParser : public ElementParser
741 struct ParamParser : public ElementParser
743 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
744 const DPL::String& /*name*/)
746 return &IgnoringParser::Create;
749 virtual void Accept(const XmlAttribute& attribute)
751 if (attribute.name == L"name") {
752 m_name = attribute.value;
753 NormalizeString(m_name);
754 } else if (attribute.name == L"value") {
755 m_value = attribute.value;
756 NormalizeString(m_value);
760 virtual void Accept(const Element& /*element*/)
763 virtual void Accept(const Text& /*text*/)
765 ThrowMsg(Exception::ParseError, "param element must be empty");
768 virtual void Verify()
770 if (m_name.IsNull() || *m_name == L"") {
773 if (m_value.IsNull() || *m_value == L"") {
777 ConfigParserData::Param param(*m_name);
778 param.value = *m_value;
780 if (m_data.paramsList.find(param) == m_data.paramsList.end()) {
781 m_data.paramsList.insert(param);
785 ParamParser(ConfigParserData::Feature& data) :
791 DPL::OptionalString m_name;
792 DPL::OptionalString m_value;
793 ConfigParserData::Feature& m_data;
796 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
797 const DPL::String& name)
799 if (name == L"param") {
800 return DPL::MakeDelegate(this, &FeatureParser::OnParamElement);
802 return &IgnoringParser::Create;
806 virtual void Accept(const Text& /*text*/)
809 virtual void Accept(const Element& /*element*/)
812 virtual void Accept(const XmlAttribute& attribute)
814 if (attribute.name == L"name") {
815 m_feature.name = attribute.value;
816 } else if (attribute.name == L"required") {
817 if (attribute.value == L"false") {
818 m_feature.required = false;
820 m_feature.required = true;
825 virtual void Verify()
827 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
829 if (m_feature.name != L"") {
830 if (iri.Validate()) {
831 if (m_data.featuresList.find(m_feature) ==
832 m_data.featuresList.end())
834 m_data.featuresList.insert(m_feature);
836 LogDebug("Ignoring feature with name" <<
837 DPL::ToUTF8String(m_feature.name));
840 if (m_feature.required) {
841 //Throw only if required
842 ThrowMsg(Exception::ParseError, "invalid feature IRI");
848 ElementParserPtr OnParamElement()
850 return ElementParserPtr(new ParamParser(m_feature));
853 FeatureParser(ConfigParserData& data) :
860 ConfigParserData& m_data;
861 ConfigParserData::Feature m_feature;
864 class PreferenceParser : public ElementParser
867 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
868 const DPL::String& /*name*/)
870 return &IgnoringParser::Create;
873 virtual void Accept(const XmlAttribute& attribute)
875 if (attribute.name == L"name") {
876 m_name = attribute.value;
877 } else if (attribute.name == L"value") {
878 m_value = attribute.value;
879 } else if (attribute.name == L"readonly") {
880 if (attribute.value == L"true") {
888 virtual void Accept(const Element& /*element*/)
891 virtual void Accept(const Text& /*text*/)
893 ThrowMsg(Exception::ParseError, "param element must be empty");
896 virtual void Verify()
898 if (m_name.IsNull()) {
899 LogWarning("preference element must have name attribute");
902 NormalizeString(m_name);
903 NormalizeString(m_value);
904 ConfigParserData::Preference preference(*m_name, m_required);
905 preference.value = m_value;
906 if (m_data.preferencesList.find(preference) ==
907 m_data.preferencesList.end())
909 m_data.preferencesList.insert(preference);
913 PreferenceParser(ConfigParserData& data) :
920 DPL::OptionalString m_name;
921 DPL::OptionalString m_value;
923 ConfigParserData& m_data;
926 class LinkParser : public ElementParser
929 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
930 const DPL::String& /*name*/)
932 return &DenyAllParser::Create;
935 virtual void Accept(const XmlAttribute& attribute)
937 if (m_properNamespace) {
938 LogDebug("attribute");
939 if (attribute.name == L"rel") {
940 if (attribute.value != L"describedby") {
941 ThrowMsg(Exception::ParseError,
942 "rel attribute must have describedby value");
944 } else if (attribute.name == L"type") {} else if (attribute.name ==
947 LogDebug("here is href");
948 m_href = attribute.value;
950 ThrowMsg(Exception::ParseError,
951 "unknown attribute '" +
952 DPL::ToUTF8String(attribute.name) +
953 "' in link element");
958 virtual void Accept(const Element& element)
961 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
963 m_properNamespace = true;
968 virtual void Accept(const Text&)
970 if (m_properNamespace) {
972 ThrowMsg(Exception::ParseError, "link element must be empty");
976 virtual void Verify()
979 ThrowMsg(Exception::ParseError,
980 "link element must have href attribute");
983 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
984 if (!iri.Validate()) { // TODO: Better uri validator ?
985 ThrowMsg(Exception::ParseError,
986 "href attribute must be a valid iri/uri/url");
990 LinkParser(ConfigParserData& data) :
992 m_properNamespace(false),
994 m_href(DPL::OptionalString::Null)
998 bool m_properNamespace;
999 ConfigParserData& m_data;
1000 DPL::OptionalString m_href;
1003 class SettingParser : public ElementParser
1006 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1007 const DPL::String& /*name*/)
1009 return &IgnoringParser::Create;
1012 virtual void Accept(const Text& /*text*/)
1015 virtual void Accept(const Element& /*element*/)
1018 virtual void Accept(const XmlAttribute& attribute)
1020 m_setting.m_name = attribute.name;
1021 m_setting.m_value = attribute.value;
1022 m_data.settingsList.insert(m_setting);
1025 virtual void Verify()
1028 SettingParser(ConfigParserData& data) :
1035 ConfigParserData& m_data;
1036 ConfigParserData::Setting m_setting;
1039 class AppServiceParser : public ElementParser
1042 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1043 const DPL::String& /*name*/)
1045 return &IgnoringParser::Create;
1048 virtual void Accept(const XmlAttribute& attribute)
1050 if (attribute.name == L"src") {
1051 m_src = attribute.value;
1052 } else if (attribute.name == L"operation") {
1053 m_operation = attribute.value;
1054 } else if (attribute.name == L"scheme") {
1055 m_scheme = attribute.value;
1056 } else if (attribute.name == L"mime") {
1057 m_mime = attribute.value;
1061 virtual void Accept(const Element& element)
1063 LogWarning("namespace for app service = " << element.ns);
1064 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1065 ThrowMsg(Exception::ParseError,
1066 "Wrong xml namespace for widget element");
1070 virtual void Accept(const Text& /*text*/)
1072 ThrowMsg(Exception::ParseError, "param element must be empty");
1075 virtual void Verify()
1077 if (m_src.IsNull()) {
1078 LogWarning("service element must have target attribute");
1080 } else if (m_operation.IsNull()) {
1081 LogWarning("service element must have operation attribute");
1084 NormalizeString(m_src);
1085 NormalizeString(m_operation);
1086 NormalizeString(m_scheme);
1087 NormalizeString(m_mime);
1089 // verify duplicate element
1090 DPL::String wildString(L"*/*");
1091 DPL::String nullString(L"");
1092 ConfigParserData::ServiceInfo serviceInfo(
1093 m_src.IsNull() ? nullString : *m_src,
1094 m_operation.IsNull() ? nullString : *m_operation,
1095 m_scheme.IsNull() ? nullString : *m_scheme,
1096 m_mime.IsNull() ? nullString : *m_mime);
1098 FOREACH(iterator, m_data.appServiceList) {
1099 if (iterator->m_operation == serviceInfo.m_operation &&
1101 (iterator->m_scheme == serviceInfo.m_scheme ||
1102 // check input scheme is "*/*" case
1103 (iterator->m_scheme == wildString &&
1104 serviceInfo.m_scheme != nullString) ||
1105 // check iterator scheme is "*/*" case
1106 (serviceInfo.m_scheme == wildString &&
1107 iterator->m_scheme != nullString)) &&
1109 (iterator->m_mime == serviceInfo.m_mime ||
1110 // check input mime is "*/*" case
1111 (iterator->m_mime == wildString &&
1112 serviceInfo.m_mime != nullString) ||
1113 // check iterator mime is "*/*" case
1114 (serviceInfo.m_mime == wildString &&
1115 iterator->m_mime != nullString)))
1117 ThrowMsg(Exception::ParseError,
1118 "service operation is duplicated " +
1119 DPL::ToUTF8String(*m_operation));
1122 m_data.appServiceList.push_back(serviceInfo);
1125 AppServiceParser(ConfigParserData& data) :
1127 m_src(DPL::OptionalString::Null),
1128 m_operation(DPL::OptionalString::Null),
1129 m_scheme(DPL::OptionalString::Null),
1130 m_mime(DPL::OptionalString::Null),
1135 DPL::OptionalString m_src;
1136 DPL::OptionalString m_operation;
1137 DPL::OptionalString m_scheme;
1138 DPL::OptionalString m_mime;
1139 ConfigParserData& m_data;
1142 class AppControlParser : public ElementParser
1145 struct SourceParser : public ElementParser
1148 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1149 const DPL::String& /*name*/)
1151 return &IgnoringParser::Create;
1154 virtual void Accept(const Text& /*text*/)
1157 virtual void Accept(const Element& /*element*/)
1160 virtual void Accept(const XmlAttribute& attribute)
1162 if (attribute.name == L"name") {
1163 if (attribute.value.size() > 0) {
1164 m_value = attribute.value;
1165 NormalizeString(m_value);
1170 virtual void Verify()
1172 if (m_value.IsNull() || *m_value == L"") {
1176 m_data.m_src = *m_value;
1179 SourceParser(ConfigParserData::AppControlInfo& data) :
1181 m_properNamespace(false),
1186 bool m_properNamespace;
1187 DPL::OptionalString m_value;
1188 ConfigParserData::AppControlInfo& m_data;
1191 struct OperationParser : public ElementParser
1194 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1195 const DPL::String& /*name*/)
1197 return &IgnoringParser::Create;
1200 virtual void Accept(const Text& /*text*/)
1203 virtual void Accept(const Element& /*element*/)
1206 virtual void Accept(const XmlAttribute& attribute)
1208 if (attribute.name == L"name") {
1209 if (attribute.value.size() > 0) {
1210 m_value = attribute.value;
1211 NormalizeString(m_value);
1216 virtual void Verify()
1218 if (m_value.IsNull() || *m_value == L"") {
1222 m_data.m_operation = *m_value;
1225 OperationParser(ConfigParserData::AppControlInfo& data) :
1227 m_properNamespace(false),
1232 bool m_properNamespace;
1233 DPL::OptionalString m_value;
1234 ConfigParserData::AppControlInfo& m_data;
1237 struct UriParser : public ElementParser
1240 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1241 const DPL::String& /*name*/)
1243 return &IgnoringParser::Create;
1246 virtual void Accept(const Text& /*text*/)
1249 virtual void Accept(const Element& /*element*/)
1252 virtual void Accept(const XmlAttribute& attribute)
1254 if (attribute.name == L"name") {
1255 if (attribute.value.size() > 0) {
1256 m_value = attribute.value;
1257 NormalizeString(m_value);
1262 virtual void Verify()
1264 if (m_value.IsNull() || *m_value == L"") {
1268 DPL::String wildString(L"*/*");
1269 if ((m_data.m_uriList.find(wildString) ==
1270 m_data.m_uriList.end())
1271 && (m_data.m_uriList.find(*m_value) ==
1272 m_data.m_uriList.end()))
1274 m_data.m_uriList.insert(*m_value);
1276 LogDebug("Ignoring uri with name" <<
1277 DPL::ToUTF8String(*m_value));
1281 UriParser(ConfigParserData::AppControlInfo& data) :
1283 m_properNamespace(false),
1288 bool m_properNamespace;
1289 DPL::OptionalString m_value;
1290 ConfigParserData::AppControlInfo& m_data;
1293 struct MimeParser : public ElementParser
1296 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1297 const DPL::String& /*name*/)
1299 return &IgnoringParser::Create;
1302 virtual void Accept(const Text& /*text*/)
1305 virtual void Accept(const Element& /*element*/)
1308 virtual void Accept(const XmlAttribute& attribute)
1310 if (attribute.name == L"name") {
1311 if (attribute.value.size() > 0) {
1312 m_value = attribute.value;
1313 NormalizeString(m_value);
1318 virtual void Verify()
1320 if (m_value.IsNull() || *m_value == L"") {
1324 DPL::String wildString(L"*/*");
1325 if ((m_data.m_mimeList.find(wildString) ==
1326 m_data.m_mimeList.end())
1327 && (m_data.m_mimeList.find(*m_value) ==
1328 m_data.m_mimeList.end()))
1330 m_data.m_mimeList.insert(*m_value);
1332 LogDebug("Ignoring mime with name" <<
1333 DPL::ToUTF8String(*m_value));
1337 MimeParser(ConfigParserData::AppControlInfo& data) :
1339 m_properNamespace(false),
1344 bool m_properNamespace;
1345 DPL::OptionalString m_value;
1346 ConfigParserData::AppControlInfo& m_data;
1349 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1350 const DPL::String& name)
1352 if (name == L"src") {
1353 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1354 } else if (name == L"operation") {
1355 return DPL::MakeDelegate(this,
1356 &AppControlParser::OnOperationElement);
1357 } else if (name == L"uri") {
1358 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1359 } else if (name == L"mime") {
1360 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1362 return &IgnoringParser::Create;
1366 virtual void Accept(const XmlAttribute& attribute)
1369 virtual void Accept(const Element& element)
1371 LogWarning("namespace for app service = " << element.ns);
1372 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1373 ThrowMsg(Exception::ParseError,
1374 "Wrong xml namespace for widget element");
1378 virtual void Accept(const Text& /*text*/)
1380 ThrowMsg(Exception::ParseError, "param element must be empty");
1383 virtual void Verify()
1385 if (m_appControl.m_src == L"") {
1386 LogWarning("service element must have src element");
1390 if (m_appControl.m_operation == L"") {
1391 LogWarning("service element must have operation element");
1395 FOREACH(iterator, m_data.appControlList) {
1396 if (iterator->m_src == m_appControl.m_src &&
1397 iterator->m_operation == m_appControl.m_operation)
1399 ThrowMsg(Exception::ParseError,
1400 "app control element is duplicated " +
1401 DPL::ToUTF8String(m_appControl.m_src) + ", " +
1402 DPL::ToUTF8String(m_appControl.m_operation));
1405 m_data.appControlList.push_back(m_appControl);
1408 ElementParserPtr OnSourceElement()
1410 return ElementParserPtr(new SourceParser(m_appControl));
1413 ElementParserPtr OnOperationElement()
1415 return ElementParserPtr(new OperationParser(m_appControl));
1418 ElementParserPtr OnUriElement()
1420 return ElementParserPtr(new UriParser(m_appControl));
1423 ElementParserPtr OnMimeElement()
1425 return ElementParserPtr(new MimeParser(m_appControl));
1428 AppControlParser(ConfigParserData& data) :
1435 ConfigParserData& m_data;
1436 ConfigParserData::AppControlInfo m_appControl;
1439 class ApplicationParser : public ElementParser
1442 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1443 const DPL::String& /*name*/)
1445 return &IgnoringParser::Create;
1448 virtual void Accept(const Text& text)
1450 if (m_properNamespace) {
1452 ThrowMsg(Exception::ParseError, "application element must be empty");
1456 virtual void Accept(const Element& element)
1459 ConfigurationNamespace::TizenWebAppNamespaceName)
1461 m_properNamespace = true;
1463 LogDebug("element");
1466 virtual void Accept(const XmlAttribute& attribute)
1468 if (m_properNamespace) {
1469 LogDebug("attribute");
1470 if (attribute.name == L"id") {
1471 m_id = attribute.value;
1472 NormalizeAndTrimSpaceString(m_id);
1473 } else if (attribute.name == L"package") {
1474 m_package = attribute.value;
1475 } else if (attribute.name == L"required_version") {
1476 m_version = attribute.value;
1477 NormalizeString(m_version);
1479 ThrowMsg(Exception::ParseError,
1480 "unknown attribute '" +
1481 DPL::ToUTF8String(attribute.name) +
1482 "' in application element");
1487 virtual void Verify()
1490 ThrowMsg(Exception::ParseError,
1491 "application element must have id attribute");
1495 m_data.tizenPkgId = m_package;
1499 ThrowMsg(Exception::ParseError,
1500 "application element must have required_version attribute");
1503 //TODO check if id and version format is right
1504 m_data.tizenAppId = m_id;
1505 m_data.tizenMinVersionRequired = m_version;
1508 ApplicationParser(ConfigParserData& data) :
1511 m_id(DPL::OptionalString::Null),
1512 m_version(DPL::OptionalString::Null),
1513 m_properNamespace(false)
1517 ConfigParserData& m_data;
1518 DPL::OptionalString m_id;
1519 DPL::OptionalString m_package;
1520 DPL::OptionalString m_version;
1521 bool m_properNamespace;
1524 class SplashParser : public ElementParser
1527 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1528 const DPL::String& /*name*/)
1530 return &IgnoringParser::Create;
1533 virtual void Accept(const XmlAttribute& attribute)
1535 if (attribute.name == L"src") {
1536 if (attribute.value.size() > 0) {
1537 m_src = attribute.value;
1542 virtual void Accept(const Element& element)
1545 virtual void Accept(const Text& /*text*/)
1548 virtual void Verify()
1550 if (m_src.IsNull()) {
1552 "src attribute of splash element is mandatory - ignoring");
1556 m_data.splashImgSrc = m_src;
1559 SplashParser(ConfigParserData& data) :
1565 DPL::OptionalString m_src;
1566 ConfigParserData& m_data;
1569 class BackgroundParser : public ElementParser
1572 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1573 const DPL::String& /*name*/)
1575 return &IgnoringParser::Create;
1578 virtual void Accept(const XmlAttribute& attribute)
1580 if (attribute.name == L"src") {
1581 if (attribute.value.size() > 0) {
1582 m_src = attribute.value;
1587 virtual void Accept(const Element& /*element*/)
1590 virtual void Accept(const Text& /*text*/)
1593 virtual void Verify()
1595 if (m_src.IsNull()) {
1597 "src attribute of background element is mandatory - ignoring");
1601 m_data.backgroundPage = m_src;
1604 explicit BackgroundParser(ConfigParserData& data) :
1609 DPL::OptionalString m_src;
1610 ConfigParserData& m_data;
1613 class PrivilegeParser : public ElementParser
1616 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1617 const DPL::String& name)
1619 return &IgnoringParser::Create;
1622 virtual void Accept(const Text& /*text*/)
1625 virtual void Accept(const Element& element)
1628 ConfigurationNamespace::TizenWebAppNamespaceName)
1630 m_properNamespace = true;
1632 LogDebug("element");
1635 virtual void Accept(const XmlAttribute& attribute)
1637 if (m_properNamespace) {
1638 if (attribute.name == L"name") {
1639 m_feature.name = attribute.value;
1640 m_privilege.name = attribute.value;
1643 m_feature.required = false;
1646 virtual void Verify()
1648 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1650 if (m_feature.name != L"") {
1651 if (iri.Validate()) {
1652 if (m_data.featuresList.find(m_feature) ==
1653 m_data.featuresList.end())
1655 m_data.featuresList.insert(m_feature);
1657 LogDebug("Ignoring feature with name" <<
1658 DPL::ToUTF8String(m_feature.name));
1663 LibIri::Wrapper iriPrivilege(
1664 DPL::ToUTF8String(m_privilege.name).c_str());
1666 if (m_privilege.name != L"") {
1667 if (iriPrivilege.Validate()) {
1668 if (m_data.privilegeList.find(m_privilege) ==
1669 m_data.privilegeList.end())
1671 m_data.privilegeList.insert(m_privilege);
1673 LogDebug("Ignoring privilege with name" <<
1674 DPL::ToUTF8String(m_privilege.name));
1680 PrivilegeParser(ConfigParserData& data) :
1685 m_properNamespace(false)
1689 ConfigParserData& m_data;
1690 ConfigParserData::Feature m_feature;
1691 ConfigParserData::Privilege m_privilege;
1692 bool m_properNamespace;
1695 class CategoryParser : public ElementParser
1698 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1699 const DPL::String& /*name*/)
1701 return &IgnoringParser::Create;
1704 virtual void Accept(const XmlAttribute& attribute)
1706 if (attribute.name == L"name") {
1707 if (attribute.value.size() > 0) {
1708 m_name = attribute.value;
1713 virtual void Accept(const Element& /*element*/)
1716 virtual void Accept(const Text& /*text*/)
1719 virtual void Verify()
1721 if (m_name.IsNull()) {
1723 "name attribute of category element is mandatory - ignoring");
1727 if (m_data.categoryList.find(*m_name) ==
1728 m_data.categoryList.end())
1730 m_data.categoryList.insert(*m_name);
1734 explicit CategoryParser(ConfigParserData& data) :
1739 DPL::OptionalString m_name;
1740 ConfigParserData& m_data;
1743 class LiveboxParser : public ElementParser
1747 struct BoxLabelParser : public ElementParser
1749 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1750 const DPL::String& /*name*/)
1752 return &IgnoringParser::Create;
1755 virtual void Accept(const XmlAttribute& attribute)
1758 virtual void Accept(const Element& element)
1761 ConfigurationNamespace::TizenWebAppNamespaceName)
1763 m_properNamespace = true;
1767 virtual void Accept(const Text& text)
1769 if (m_properNamespace) {
1770 m_label = text.value;
1774 virtual void Verify()
1776 m_data.m_label = m_label;
1779 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1781 m_properNamespace(false),
1786 DPL::String m_label;
1787 bool m_properNamespace;
1788 ConfigParserData::LiveboxInfo& m_data;
1791 struct BoxIconParser : public ElementParser
1793 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1794 const DPL::String& /*name*/)
1796 return &IgnoringParser::Create;
1799 virtual void Accept(const XmlAttribute& attribute)
1801 if (m_properNamespace) {
1802 if (attribute.name == L"src") {
1803 m_icon = attribute.value;
1808 virtual void Accept(const Element& element)
1811 ConfigurationNamespace::TizenWebAppNamespaceName)
1813 m_properNamespace = true;
1817 virtual void Accept(const Text& /*text*/)
1820 virtual void Verify()
1822 m_data.m_icon = m_icon;
1825 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1827 m_properNamespace(false),
1833 bool m_properNamespace;
1834 ConfigParserData::LiveboxInfo& m_data;
1837 struct BoxContentParser : public ElementParser
1839 struct BoxSizeParser : public ElementParser
1841 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1842 const DPL::String& /*name*/)
1844 return &IgnoringParser::Create;
1847 virtual void Accept(const XmlAttribute& attribute)
1849 if (m_properNamespace) {
1850 if (attribute.name == L"preview") {
1851 m_preview = attribute.value;
1856 virtual void Accept(const Element& element)
1859 ConfigurationNamespace::TizenWebAppNamespaceName)
1861 m_properNamespace = true;
1865 virtual void Accept(const Text& text)
1867 if (m_properNamespace) {
1868 m_size = text.value;
1872 virtual void Verify()
1874 std::pair<DPL::String, DPL::String> boxSize;
1875 boxSize.first = m_size;
1876 boxSize.second = m_preview;
1877 m_data.m_boxSize.push_back(boxSize);
1880 explicit BoxSizeParser(
1881 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1888 DPL::String m_preview;
1889 bool m_properNamespace;
1890 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1893 struct PdParser : public ElementParser
1895 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1896 const DPL::String& name)
1898 return &IgnoringParser::Create;
1901 virtual void Accept(const XmlAttribute& attribute)
1903 if (m_properNamespace) {
1904 if (attribute.name == L"src") {
1905 m_src = attribute.value;
1906 } else if (attribute.name == L"width") {
1907 m_width = attribute.value;
1908 } else if (attribute.name == L"height") {
1909 m_height = attribute.value;
1914 virtual void Accept(const Element& element)
1917 ConfigurationNamespace::TizenWebAppNamespaceName)
1919 m_properNamespace = true;
1923 virtual void Accept(const Text& /*text*/)
1926 virtual void Verify()
1928 m_data.m_pdSrc = m_src;
1929 m_data.m_pdWidth = m_width;
1930 m_data.m_pdHeight = m_height;
1934 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1936 m_properNamespace(false),
1942 DPL::String m_width;
1943 DPL::String m_height;
1945 bool m_properNamespace;
1946 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1949 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1950 const DPL::String& name)
1952 if (name == L"box-size") {
1953 return DPL::MakeDelegate(
1955 &LiveboxParser::BoxContentParser::
1957 } else if (name == L"pd") {
1958 return DPL::MakeDelegate(
1960 &LiveboxParser::BoxContentParser::
1963 ThrowMsg(Exception::ParseError,
1964 "No element parser for name: " << name);
1968 virtual void Accept(const XmlAttribute& attribute)
1970 if (m_properNamespace) {
1971 if (attribute.name == L"src") {
1972 m_box.m_boxSrc = attribute.value;
1974 if (attribute.name == L"mouse-event") {
1975 m_box.m_boxMouseEvent = attribute.value;
1980 virtual void Accept(const Element& element)
1983 ConfigurationNamespace::TizenWebAppNamespaceName)
1985 m_properNamespace = true;
1989 virtual void Accept(const Text& /*text*/)
1992 virtual void Verify()
1994 m_data.m_boxInfo = m_box;
1997 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1999 m_properNamespace(false),
2003 ElementParserPtr OnBoxSizeElement()
2005 return ElementParserPtr(new BoxSizeParser(m_box));
2008 ElementParserPtr OnPdElement()
2010 return ElementParserPtr(new PdParser(m_box));
2015 bool m_properNamespace;
2016 ConfigParserData::LiveboxInfo& m_data;
2017 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
2020 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2021 const DPL::String& name)
2023 if (name == L"box-label") {
2024 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxLabelElement);
2025 } else if (name == L"box-icon") {
2026 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxIconElement);
2027 } else if (name == L"box-content") {
2028 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxContentElement);
2030 return &IgnoringParser::Create;
2034 virtual void Accept(const XmlAttribute& attribute)
2036 if (m_properNamespace) {
2037 if (attribute.name == L"id") {
2038 m_liveboxId = attribute.value;
2039 } else if (attribute.name == L"primary") {
2040 m_primary = attribute.value;
2041 } else if (attribute.name == L"auto-launch") {
2042 m_autoLaunch = attribute.value;
2043 } else if (attribute.name == L"update-period") {
2044 m_updatePeriod = attribute.value;
2045 } else if (attribute.name == L"type") {
2046 m_type = attribute.value;
2051 virtual void Accept(const Element& element)
2054 ConfigurationNamespace::TizenWebAppNamespaceName)
2056 m_properNamespace = true;
2060 virtual void Accept(const Text& /*text*/)
2063 virtual void Verify()
2065 m_livebox.m_liveboxId = m_liveboxId;
2066 m_livebox.m_primary = m_primary;
2067 m_livebox.m_autoLaunch = m_autoLaunch;
2068 m_livebox.m_updatePeriod = m_updatePeriod;
2069 m_livebox.m_type = m_type;
2071 m_data.m_livebox.push_back(m_livebox);
2074 explicit LiveboxParser(ConfigParserData& data) :
2077 m_properNamespace(false)
2079 m_livebox = ConfigParserData::LiveboxInfo();
2082 ElementParserPtr OnBoxLabelElement()
2084 return ElementParserPtr(new BoxLabelParser(m_livebox));
2087 ElementParserPtr OnBoxIconElement()
2089 return ElementParserPtr(new BoxIconParser(m_livebox));
2092 ElementParserPtr OnBoxContentElement()
2094 return ElementParserPtr(new BoxContentParser(m_livebox));
2098 ConfigParserData& m_data;
2099 ConfigParserData::LiveboxInfo m_livebox;
2100 DPL::String m_liveboxId;
2101 DPL::String m_primary;
2102 DPL::String m_autoLaunch;
2103 DPL::String m_updatePeriod;
2105 bool m_properNamespace;
2108 class CspParser : public ElementParser
2111 virtual ActionFunc GetElementParser(const DPL::String& ns,
2112 const DPL::String& name)
2114 return &IgnoringParser::Create;
2117 CspParser(ConfigParserData& data) :
2120 m_properNamespace(false)
2123 virtual void Accept(const Element& element)
2125 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2126 m_properNamespace = true;
2130 virtual void Accept(const XmlAttribute& attribute)
2133 virtual void Accept(const Text& text)
2135 if (m_properNamespace) {
2136 m_policy = text.value;
2140 virtual void Verify()
2142 if (!m_policy.IsNull()) {
2143 m_data.cspPolicy = *m_policy;
2148 ConfigParserData& m_data;
2149 bool m_properNamespace;
2150 DPL::OptionalString m_policy;
2153 ElementParser::ActionFunc WidgetParser::GetElementParser(
2154 const DPL::String& /*ns*/,
2158 FuncMap::const_iterator it = m_map.find(name);
2159 if (it != m_map.end()) {
2162 return &IgnoringParser::Create;
2166 WidgetParser::WidgetParser(ConfigParserData& data) :
2168 m_textDirection(Unicode::EMPTY)
2170 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2171 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2172 m_map[L"description"] =
2173 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2174 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2176 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2177 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2179 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2181 DPL::MakeDelegate(this, &WidgetParser::OnFeatureElement);
2182 m_map[L"preference"] =
2183 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2184 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2186 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2187 // TODO: appservice will be removed
2188 m_map[L"appservice"] = DPL::MakeDelegate(this,
2189 &WidgetParser::OnAppServiceElement);
2190 m_map[L"application"] = DPL::MakeDelegate(
2193 OnApplicationElement);
2194 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2195 m_map[L"background"] = DPL::MakeDelegate(this,
2196 &WidgetParser::OnBackgroundElement);
2197 m_map[L"privilege"] = DPL::MakeDelegate(this,
2198 &WidgetParser::OnPrivilegeElement);
2199 m_map[L"app-control"] = DPL::MakeDelegate(
2202 OnAppControlElement);
2203 m_map[L"category"] = DPL::MakeDelegate(this,
2204 &WidgetParser::OnCategoryElement);
2205 m_map[L"livebox"] = DPL::MakeDelegate(this, &WidgetParser::OnLiveboxElement);
2207 m_map[L"Content-Security-Policy"] = DPL::MakeDelegate(
2214 ElementParserPtr WidgetParser::OnNameElement()
2216 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2219 ElementParserPtr WidgetParser::OnAccessElement()
2221 return ElementParserPtr(new AccessParser(m_data));
2224 ElementParserPtr WidgetParser::OnDescriptionElement()
2226 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2229 ElementParserPtr WidgetParser::OnAuthorElement()
2231 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2234 ElementParserPtr WidgetParser::OnLicenseElement()
2236 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2239 ElementParserPtr WidgetParser::OnIconElement()
2241 return ElementParserPtr(new IconParser(m_data));
2244 ElementParserPtr WidgetParser::OnContentElement()
2246 return ElementParserPtr(new ContentParser(m_data));
2249 ElementParserPtr WidgetParser::OnFeatureElement()
2251 return ElementParserPtr(new FeatureParser(m_data));
2254 ElementParserPtr WidgetParser::OnPreferenceElement()
2256 return ElementParserPtr(new PreferenceParser(m_data));
2259 ElementParserPtr WidgetParser::OnLinkElement()
2261 return ElementParserPtr(new LinkParser(m_data));
2264 ElementParserPtr WidgetParser::OnSettingElement()
2266 return ElementParserPtr(new SettingParser(m_data));
2269 ElementParserPtr WidgetParser::OnApplicationElement()
2271 return ElementParserPtr(new ApplicationParser(m_data));
2274 ElementParserPtr WidgetParser::OnSplashElement()
2276 return ElementParserPtr(new SplashParser(m_data));
2279 ElementParserPtr WidgetParser::OnBackgroundElement()
2281 return ElementParserPtr(new BackgroundParser(m_data));
2284 ElementParserPtr WidgetParser::OnPrivilegeElement()
2286 return ElementParserPtr(new PrivilegeParser(m_data));
2289 ElementParserPtr WidgetParser::OnAppServiceElement()
2291 return ElementParserPtr(new AppServiceParser(m_data));
2294 ElementParserPtr WidgetParser::OnAppControlElement()
2296 return ElementParserPtr(new AppControlParser(m_data));
2299 ElementParserPtr WidgetParser::OnCategoryElement()
2301 return ElementParserPtr(new CategoryParser(m_data));
2304 ElementParserPtr WidgetParser::OnLiveboxElement()
2306 return ElementParserPtr(new LiveboxParser(m_data));
2309 ElementParserPtr WidgetParser::OnCspElement()
2311 return ElementParserPtr(new CspParser(m_data));
2314 void WidgetParser::Accept(const Element& element)
2316 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2317 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2319 ThrowMsg(Exception::ParseError,
2320 "Wrong xml namespace for widget element");
2324 void WidgetParser::Accept(const Text& /*text*/)
2326 ThrowMsg(Exception::ParseError, "widged element must be empty");
2329 void WidgetParser::Accept(const XmlAttribute& attribute)
2331 if (attribute.name == L"id") {
2332 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2333 //If may important tests starts to fail this test we will have
2334 //to consider commenting this test out again.
2335 if (iri.Validate()) {
2336 m_data.widget_id = attribute.value;
2337 NormalizeString(m_data.widget_id);
2339 LogWarning("Widget id validation failed: " << attribute.value);
2341 } else if (attribute.name == L"version") {
2342 m_version = attribute.value;
2343 NormalizeString(m_version);
2344 } else if (attribute.name == L"min-version") {
2345 LogInfo("min-version attribute was found. Value: " << attribute.value);
2346 m_minVersion = attribute.value;
2347 NormalizeString(m_minVersion);
2348 m_data.minVersionRequired = m_minVersion;
2349 } else if (attribute.name == L"height") {
2350 DPL::OptionalString value = attribute.value;
2351 NormalizeString(value);
2352 std::string v = DPL::ToUTF8String(*value);
2355 unsigned char c = v.c_str()[0];
2356 if (c >= '0' && c <= '9') {
2358 for (size_t i = 0; i < v.size(); ++i) {
2360 if (c >= '0' && c <= '9') {
2367 m_data.height = val;
2370 } else if (attribute.name == L"width") {
2371 DPL::OptionalString value = attribute.value;
2372 NormalizeString(value);
2373 std::string v = DPL::ToUTF8String(*value);
2376 unsigned char c = v.c_str()[0];
2377 if (c >= '0' && c <= '9') {
2379 for (size_t i = 0; i < v.size(); ++i) {
2381 if (c >= '0' && c <= '9') {
2391 } else if (attribute.name == L"viewmodes") {
2392 DPL::Tokenize(attribute.value,
2394 std::inserter(m_windowModes,
2395 m_windowModes.end()),
2397 } else if (attribute.name == L"dir") {
2398 m_textDirection = Unicode::ParseDirAttribute(attribute);
2399 } else if (L"defaultlocale" == attribute.name) {
2400 if (!m_defaultlocale) {
2401 m_defaultlocale = attribute.value;
2402 NormalizeString(m_defaultlocale);
2403 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2404 DPL::ToUTF8String(*m_defaultlocale)))
2406 LogWarning("Language tag: " <<
2407 m_defaultlocale << " is not valid");
2408 m_defaultlocale = DPL::OptionalString::Null;
2410 LogDebug("Default Locale Found " << m_defaultlocale);
2413 LogWarning("Ignoring subsequent default locale");
2416 //Any other value consider as a namespace definition
2417 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2418 LogInfo("Namespace domain: " << attribute.name);
2419 LogInfo("Namespace value: " << attribute.value);
2420 m_nameSpaces[attribute.name] = attribute.value;
2422 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2423 ", name=" << attribute.name <<
2424 ", value=" << attribute.value);
2428 void WidgetParser::Verify()
2430 FOREACH(mode, m_windowModes) {
2431 if (L"windowed" == *mode || L"floating" == *mode ||
2432 L"fullscreen" == *mode || L"maximized" == *mode ||
2433 L"minimized" == *mode)
2435 m_data.windowModes.insert(*mode);
2438 if (!m_version.IsNull()) {
2439 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2440 m_data.version = m_version;
2442 m_data.defaultlocale = m_defaultlocale;
2443 FOREACH(ns, m_nameSpaces) {
2444 m_data.nameSpaces.insert(ns->second);