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*/)
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)
139 ElementParserPtr Other()
141 return ElementParserPtr(new InnerElementsParser(
142 std::static_pointer_cast<ElementParser>(
143 shared_from_this())));
147 DPL::Optional<Text> m_text;
148 ElementParserPtr m_parentParser;
149 Unicode::Direction m_textDirection;
152 class NameParser : public ElementParser
155 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
156 const DPL::String& /*name*/)
158 return DPL::MakeDelegate(this, &NameParser::Other);
161 virtual void Accept(const Element& element)
163 m_lang = element.lang;
167 virtual void Accept(const Text& text)
169 if (m_name.IsNull()) {
172 *m_name += text.value;
176 virtual void Accept(const XmlAttribute& attribute)
178 if (attribute.name == L"short") {
179 if (m_shortName.IsNull()) {
180 m_shortName = attribute.value;
182 } else if (attribute.name == L"dir") {
183 m_textDirection = Unicode::ParseDirAttribute(attribute);
187 virtual void Verify()
189 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
190 if (data.name.IsNull()) {
191 NormalizeString(m_name);
192 NormalizeString(m_shortName);
193 if (!m_name.IsNull()) {
194 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
197 if (!m_shortName.IsNull()) {
198 Unicode::UpdateTextWithDirectionMark(m_textDirection,
201 data.shortName = m_shortName;
205 NameParser(Unicode::Direction direction,
206 ConfigParserData& data) :
208 m_textDirection(direction)
212 ElementParserPtr Other()
214 return ElementParserPtr(new InnerElementsParser(
215 std::static_pointer_cast<ElementParser>(
216 shared_from_this())));
220 ConfigParserData& m_data;
221 DPL::OptionalString m_name;
222 DPL::OptionalString m_shortName;
223 DPL::OptionalString m_dir;
225 Unicode::Direction m_textDirection;
228 class AccessParser : public ElementParser
237 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
238 const DPL::String& /*name*/)
240 return DPL::MakeDelegate(this, &AccessParser::Other);
243 virtual void Accept(const Element& element)
245 // for tizen web apps WARP should be used
246 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
247 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
249 m_standardType = STANDARD_TYPE_WARP;
253 virtual void Accept(const Text& /*text*/)
257 void AcceptWac(const XmlAttribute& attribute)
259 if (attribute.name == L"origin") {
260 m_strIRIOrigin = attribute.value;
261 NormalizeString(m_strIRIOrigin);
262 } else if (attribute.name == L"subdomains") {
263 DPL::String normalizedValue = attribute.value;
264 NormalizeString(normalizedValue);
266 if (normalizedValue == L"true") {
267 m_bSubDomainAccess = true;
268 } else if (normalizedValue == L"false") {
269 m_bSubDomainAccess = false;
274 virtual void Accept(const XmlAttribute& attribute)
276 switch (m_standardType) {
277 case STANDARD_TYPE_WARP:
278 AcceptWac(attribute);
281 LogError("Error in Access tag - unknown standard.");
288 iri.set(m_strIRIOrigin, false);
290 if (!iri.isAccessDefinition()) {
291 LogWarning("Access list element: " <<
293 " is not acceptable by WARP" <<
294 "standard and will be ignored!");
298 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
300 std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
301 m_data.accessInfoSet.insert(accessInfo);
304 virtual void Verify()
306 switch (m_standardType) {
307 case STANDARD_TYPE_WARP:
311 LogError("Error in Access tag - unknown standard.");
315 AccessParser(ConfigParserData& data) :
317 m_bSubDomainAccess(false),
318 m_standardType(STANDARD_TYPE_NONE),
324 ElementParserPtr Other()
326 return ElementParserPtr(new InnerElementsParser(
327 ElementParserPtr(shared_from_this())));
331 DPL::String m_strIRIOrigin;
332 bool m_bSubDomainAccess;
333 StandardType m_standardType;
335 ConfigParserData& m_data;
338 class DescriptionParser : public ElementParser
341 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
342 const DPL::String& /*name*/)
344 return DPL::MakeDelegate(this, &DescriptionParser::Other);
347 virtual void Accept(const Element& element)
349 m_lang = element.lang;
353 ElementParserPtr Other()
355 return ElementParserPtr(new InnerElementsParser(
356 std::static_pointer_cast<ElementParser>(
357 shared_from_this())));
360 virtual void Accept(const Text& text)
362 if (m_description.IsNull()) {
363 m_description = text.value;
365 *m_description += text.value;
369 virtual void Accept(const XmlAttribute& attribute)
371 if (attribute.name == L"dir") {
372 m_textDirection = Unicode::ParseDirAttribute(attribute);
376 virtual void Verify()
378 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
379 if (data.description.IsNull()) {
380 if (!m_description.IsNull()) {
381 Unicode::UpdateTextWithDirectionMark(m_textDirection,
384 data.description = m_description;
388 DescriptionParser(Unicode::Direction direction,
389 ConfigParserData& data) :
393 m_textDirection(direction)
398 ConfigParserData& m_data;
400 DPL::OptionalString m_description;
401 Unicode::Direction m_textDirection;
404 class AuthorParser : public ElementParser
407 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
408 const DPL::String& /*name*/)
410 return DPL::MakeDelegate(this, &AuthorParser::Other);
413 AuthorParser(Unicode::Direction direction,
414 ConfigParserData& data) :
416 m_textDirection(direction)
420 virtual void Accept(const Element& /*element*/)
425 virtual void Accept(const Text& text)
427 *(m_authorName) += text.value;
430 virtual void Accept(const XmlAttribute& attribute)
432 if (attribute.name == L"href") {
433 //Validate href IRI and ignore it if invalid
434 //See also test: ta-argMozRiC-an
435 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
436 if (iri.Validate()) {
437 m_authorHref = attribute.value;
439 } else if (attribute.name == L"email") {
440 m_authorEmail = attribute.value;
441 } else if (attribute.name == L"dir") {
442 m_textDirection = Unicode::ParseDirAttribute(attribute);
446 virtual void Verify()
448 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
449 NormalizeString(m_authorName);
450 NormalizeString(m_authorHref);
451 NormalizeString(m_authorEmail);
452 if (!!m_authorName) {
453 Unicode::UpdateTextWithDirectionMark(m_textDirection,
455 m_data.authorName = m_authorName;
457 if (!!m_authorHref) {
458 m_data.authorHref = m_authorHref;
460 if (!!m_authorEmail) {
461 m_data.authorEmail = m_authorEmail;
466 ElementParserPtr Other()
468 return ElementParserPtr(new InnerElementsParser(
469 std::static_pointer_cast<ElementParser>(
470 shared_from_this())));
474 ConfigParserData& m_data;
475 DPL::OptionalString m_authorEmail;
476 DPL::OptionalString m_authorHref;
477 DPL::OptionalString m_authorName;
478 Unicode::Direction m_textDirection;
481 class LicenseParser : public ElementParser
484 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
485 const DPL::String& /*name*/)
487 return DPL::MakeDelegate(this, &LicenseParser::Other);
490 LicenseParser(Unicode::Direction direction,
491 ConfigParserData& data) :
494 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(),
574 virtual void Accept(const Element& /*element*/)
578 virtual void Accept(const XmlAttribute& attribute)
580 if (attribute.name == L"src") {
581 if (attribute.value.size() > 0) {
582 m_src = attribute.value;
584 } else if (attribute.name == L"width") {
585 m_width = ParseSizeAttributeValue(attribute.value);
586 } else if (attribute.name == L"height") {
587 m_height = ParseSizeAttributeValue(attribute.value);
591 virtual void Accept(const Text& /*text*/)
593 ThrowMsg(Exception::ParseError, "Icon element must be empty");
596 virtual void Verify()
598 if (m_src.IsNull()) {
599 LogWarning("src attribute of icon element is mandatory - ignoring");
605 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
606 icon.width = m_width;
607 icon.height = m_height;
609 ConfigParserData::IconsList::iterator it = std::find(
610 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
611 if (it == m_data.iconsList.end()) {
612 m_data.iconsList.push_front(icon);
617 LogWarning("src attribute is invalid: " << m_src);
622 ConfigParserData& m_data;
623 DPL::OptionalString m_src;
624 DPL::OptionalInt m_width;
625 DPL::OptionalInt m_height;
627 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
629 DPL::OptionalString normalizedValue = value;
630 NormalizeString(normalizedValue);
631 if (!(*normalizedValue).empty()) {
635 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
637 std::string(reterr) == DPL::ToUTF8String(value) ||
639 return DPL::OptionalInt::Null;
644 return DPL::OptionalInt::Null;
648 * @brief delocalizePath removes locales folder from relative path if neccessary
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)
664 size_t pos = result.find_first_of('/',index);
665 if(pos != std::string::npos && pos + 1 < source.size())
667 result = result.substr(pos + 1,source.size());
678 class ContentParser : public ElementParser
681 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
682 const DPL::String& /*name*/)
684 return &IgnoringParser::Create;
687 ContentParser(ConfigParserData& data) :
693 virtual void Accept(const Element& /*element*/)
697 virtual void Accept(const Text& /*text*/)
701 virtual void Accept(const XmlAttribute& attribute)
703 DPL::String value = attribute.value;
704 NormalizeString(value);
706 if (attribute.name == L"src") {
708 } else if (attribute.name == L"type") {
710 MimeTypeUtils::MimeAttributes mimeAttributes =
711 MimeTypeUtils::getMimeAttributes(value);
712 if (mimeAttributes.count(L"charset") > 0) {
713 m_encoding = mimeAttributes[L"charset"];
715 } else if (attribute.name == L"encoding") {
716 if (!value.empty()) {
722 virtual void Verify()
724 if (m_data.startFileEncountered) {
725 LogWarning("This is not the first encountered "
726 "'content' element - ignoring.");
730 m_data.startFileEncountered = true;
732 //we're consciously setting startFile even if m_src is null or invalid.
733 //WidgetConfigurationManager will deal with this.
734 m_data.startFile = m_src;
737 m_data.startFileContentType = m_type;
739 m_data.startFileEncoding = m_encoding;
741 m_data.startFileEncoding = L"UTF-8";
747 DPL::OptionalString m_src;
748 DPL::OptionalString m_type;
749 DPL::OptionalString m_encoding;
750 ConfigParserData& m_data;
753 class FeatureParser : public ElementParser
756 struct ParamParser : public ElementParser
758 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
759 const DPL::String& /*name*/)
761 return &IgnoringParser::Create;
764 virtual void Accept(const XmlAttribute& attribute)
766 if (attribute.name == L"name") {
767 m_name = attribute.value;
768 NormalizeString(m_name);
769 } else if (attribute.name == L"value") {
770 m_value = attribute.value;
771 NormalizeString(m_value);
775 virtual void Accept(const Element& /*element*/)
779 virtual void Accept(const Text& /*text*/)
781 ThrowMsg(Exception::ParseError, "param element must be empty");
784 virtual void Verify()
786 if (m_name.IsNull() || *m_name == L"") {
789 if (m_value.IsNull() || *m_value == L"") {
793 ConfigParserData::Param param(*m_name);
794 param.value = *m_value;
796 if (m_data.paramsList.find(param) == m_data.paramsList.end()) {
797 m_data.paramsList.insert(param);
801 ParamParser(ConfigParserData::Feature& data) :
808 DPL::OptionalString m_name;
809 DPL::OptionalString m_value;
810 ConfigParserData::Feature& m_data;
813 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
814 const DPL::String& name)
816 if (name == L"param") {
817 return DPL::MakeDelegate(this, &FeatureParser::OnParamElement);
819 return &IgnoringParser::Create;
823 virtual void Accept(const Text& /*text*/)
827 virtual void Accept(const Element& /*element*/)
831 virtual void Accept(const XmlAttribute& attribute)
833 if (attribute.name == L"name") {
834 m_feature.name = attribute.value;
835 } else if (attribute.name == L"required") {
836 if (attribute.value == L"false") {
837 m_feature.required = false;
839 m_feature.required = true;
844 virtual void Verify()
846 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
848 if (m_feature.name != L"") {
849 if (iri.Validate()) {
850 if (m_data.featuresList.find(m_feature) ==
851 m_data.featuresList.end()) {
852 m_data.featuresList.insert(m_feature);
854 LogDebug("Ignoring feature with name" <<
855 DPL::ToUTF8String(m_feature.name));
858 if (m_feature.required) {
859 //Throw only if required
860 ThrowMsg(Exception::ParseError, "invalid feature IRI");
866 ElementParserPtr OnParamElement()
868 return ElementParserPtr(new ParamParser(m_feature));
871 FeatureParser(ConfigParserData& data) :
879 ConfigParserData& m_data;
880 ConfigParserData::Feature m_feature;
883 class PreferenceParser : public ElementParser
886 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
887 const DPL::String& /*name*/)
889 return &IgnoringParser::Create;
892 virtual void Accept(const XmlAttribute& attribute)
894 if (attribute.name == L"name") {
895 m_name = attribute.value;
896 } else if (attribute.name == L"value") {
897 m_value = attribute.value;
898 } else if (attribute.name == L"readonly") {
899 if (attribute.value == L"true") {
907 virtual void Accept(const Element& /*element*/)
911 virtual void Accept(const Text& /*text*/)
913 ThrowMsg(Exception::ParseError, "param element must be empty");
916 virtual void Verify()
918 if (m_name.IsNull()) {
919 LogWarning("preference element must have name attribute");
922 NormalizeString(m_name);
923 NormalizeString(m_value);
924 ConfigParserData::Preference preference(*m_name, m_required);
925 preference.value = m_value;
926 if (m_data.preferencesList.find(preference) ==
927 m_data.preferencesList.end()) {
928 m_data.preferencesList.insert(preference);
932 PreferenceParser(ConfigParserData& data) :
940 DPL::OptionalString m_name;
941 DPL::OptionalString m_value;
943 ConfigParserData& m_data;
946 class LinkParser : public ElementParser
949 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
950 const DPL::String& /*name*/)
952 return &DenyAllParser::Create;
955 virtual void Accept(const XmlAttribute& attribute)
957 if (m_properNamespace) {
958 LogDebug("attribute");
959 if (attribute.name == L"rel") {
960 if (attribute.value != L"describedby") {
961 ThrowMsg(Exception::ParseError,
962 "rel attribute must have describedby value");
964 } else if (attribute.name == L"type") {
965 } else if (attribute.name == L"href") {
966 LogDebug("here is href");
967 m_href = attribute.value;
969 ThrowMsg(Exception::ParseError,
970 "unknown attribute '" +
971 DPL::ToUTF8String(attribute.name) +
972 "' in link element");
977 virtual void Accept(const Element& element)
980 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
982 m_properNamespace = true;
987 virtual void Accept(const Text&)
989 if (m_properNamespace) {
991 ThrowMsg(Exception::ParseError, "link element must be empty");
995 virtual void Verify()
998 ThrowMsg(Exception::ParseError,
999 "link element must have href attribute");
1002 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
1003 if (!iri.Validate()) { // TODO: Better uri validator ?
1004 ThrowMsg(Exception::ParseError,
1005 "href attribute must be a valid iri/uri/url");
1009 LinkParser(ConfigParserData& data) :
1011 m_properNamespace(false),
1013 m_href(DPL::OptionalString::Null)
1018 bool m_properNamespace;
1019 ConfigParserData& m_data;
1020 DPL::OptionalString m_href;
1023 class SettingParser : public ElementParser
1026 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1027 const DPL::String& /*name*/)
1029 return &IgnoringParser::Create;
1032 virtual void Accept(const Text& /*text*/)
1036 virtual void Accept(const Element& /*element*/)
1040 virtual void Accept(const XmlAttribute& attribute)
1042 m_setting.m_name = attribute.name;
1043 m_setting.m_value = attribute.value;
1044 m_data.settingsList.insert(m_setting);
1047 virtual void Verify()
1051 SettingParser(ConfigParserData& data) :
1059 ConfigParserData& m_data;
1060 ConfigParserData::Setting m_setting;
1063 class AppServiceParser : public ElementParser
1066 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1067 const DPL::String& /*name*/)
1069 return &IgnoringParser::Create;
1072 virtual void Accept(const XmlAttribute& attribute)
1074 if (attribute.name == L"src") {
1075 m_src = attribute.value;
1076 } else if (attribute.name == L"operation") {
1077 m_operation = attribute.value;
1078 } else if (attribute.name == L"scheme") {
1079 m_scheme = attribute.value;
1080 } else if (attribute.name == L"mime") {
1081 m_mime = attribute.value;
1085 virtual void Accept(const Element& element)
1087 LogWarning("namespace for app service = " << element.ns);
1088 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1089 ThrowMsg(Exception::ParseError,
1090 "Wrong xml namespace for widget element");
1094 virtual void Accept(const Text& /*text*/)
1096 ThrowMsg(Exception::ParseError, "param element must be empty");
1099 virtual void Verify()
1101 if (m_src.IsNull()) {
1102 LogWarning("service element must have target attribute");
1104 } else if (m_operation.IsNull()) {
1105 LogWarning("service element must have operation attribute");
1108 NormalizeString(m_src);
1109 NormalizeString(m_operation);
1110 NormalizeString(m_scheme);
1111 NormalizeString(m_mime);
1113 // verify duplicate element
1114 DPL::String wildString(L"*/*");
1115 DPL::String nullString(L"");
1116 ConfigParserData::ServiceInfo serviceInfo(
1117 m_src.IsNull() ? nullString:*m_src,
1118 m_operation.IsNull() ? nullString:*m_operation,
1119 m_scheme.IsNull() ? nullString:*m_scheme,
1120 m_mime.IsNull() ? nullString:*m_mime);
1122 FOREACH(iterator, m_data.appServiceList) {
1123 if (iterator->m_operation == serviceInfo.m_operation &&
1125 (iterator->m_scheme == serviceInfo.m_scheme ||
1126 // check input scheme is "*/*" case
1127 (iterator->m_scheme == wildString &&
1128 serviceInfo.m_scheme != nullString) ||
1129 // check iterator scheme is "*/*" case
1130 (serviceInfo.m_scheme == wildString &&
1131 iterator->m_scheme != nullString)) &&
1133 (iterator->m_mime == serviceInfo.m_mime ||
1134 // check input mime is "*/*" case
1135 (iterator->m_mime == wildString &&
1136 serviceInfo.m_mime != nullString) ||
1137 // check iterator mime is "*/*" case
1138 (serviceInfo.m_mime == wildString &&
1139 iterator->m_mime != nullString)))
1141 ThrowMsg(Exception::ParseError,
1142 "service operation is duplicated " +
1143 DPL::ToUTF8String(*m_operation));
1146 m_data.appServiceList.push_back(serviceInfo);
1149 AppServiceParser(ConfigParserData& data) :
1151 m_src(DPL::OptionalString::Null),
1152 m_operation(DPL::OptionalString::Null),
1153 m_scheme(DPL::OptionalString::Null),
1154 m_mime(DPL::OptionalString::Null),
1160 DPL::OptionalString m_src;
1161 DPL::OptionalString m_operation;
1162 DPL::OptionalString m_scheme;
1163 DPL::OptionalString m_mime;
1164 ConfigParserData& m_data;
1167 class AppControlParser : public ElementParser
1170 struct SourceParser : public ElementParser
1173 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1174 const DPL::String& /*name*/)
1176 return &IgnoringParser::Create;
1179 virtual void Accept(const Text& /*text*/)
1183 virtual void Accept(const Element& /*element*/)
1187 virtual void Accept(const XmlAttribute& attribute)
1189 if (attribute.name == L"name") {
1190 if (attribute.value.size() > 0) {
1191 m_value = attribute.value;
1192 NormalizeString(m_value);
1197 virtual void Verify()
1199 if (m_value.IsNull() || *m_value== L"") {
1203 m_data.m_src = *m_value;
1206 SourceParser(ConfigParserData::AppControlInfo& data) :
1208 m_properNamespace(false),
1214 bool m_properNamespace;
1215 DPL::OptionalString m_value;
1216 ConfigParserData::AppControlInfo& m_data;
1219 struct OperationParser : public ElementParser
1222 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1223 const DPL::String& /*name*/)
1225 return &IgnoringParser::Create;
1228 virtual void Accept(const Text& /*text*/)
1232 virtual void Accept(const Element& /*element*/)
1236 virtual void Accept(const XmlAttribute& attribute)
1238 if (attribute.name == L"name") {
1239 if (attribute.value.size() > 0) {
1240 m_value = attribute.value;
1241 NormalizeString(m_value);
1246 virtual void Verify()
1248 if (m_value.IsNull() || *m_value== L"") {
1252 m_data.m_operation = *m_value;
1255 OperationParser(ConfigParserData::AppControlInfo& data) :
1257 m_properNamespace(false),
1263 bool m_properNamespace;
1264 DPL::OptionalString m_value;
1265 ConfigParserData::AppControlInfo& m_data;
1268 struct UriParser : public ElementParser
1271 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1272 const DPL::String& /*name*/)
1274 return &IgnoringParser::Create;
1277 virtual void Accept(const Text& /*text*/)
1281 virtual void Accept(const Element& /*element*/)
1285 virtual void Accept(const XmlAttribute& attribute)
1287 if (attribute.name == L"name") {
1288 if (attribute.value.size() > 0) {
1289 m_value = attribute.value;
1290 NormalizeString(m_value);
1295 virtual void Verify()
1297 if (m_value.IsNull() || *m_value == L"") {
1301 DPL::String wildString(L"*/*");
1302 if ((m_data.m_uriList.find(wildString) ==
1303 m_data.m_uriList.end())
1304 && (m_data.m_uriList.find(*m_value) ==
1305 m_data.m_uriList.end())) {
1307 m_data.m_uriList.insert(*m_value);
1309 LogDebug("Ignoring uri with name" <<
1310 DPL::ToUTF8String(*m_value));
1314 UriParser(ConfigParserData::AppControlInfo& data) :
1316 m_properNamespace(false),
1322 bool m_properNamespace;
1323 DPL::OptionalString m_value;
1324 ConfigParserData::AppControlInfo& m_data;
1327 struct MimeParser : public ElementParser
1330 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1331 const DPL::String& /*name*/)
1333 return &IgnoringParser::Create;
1336 virtual void Accept(const Text& /*text*/)
1340 virtual void Accept(const Element& /*element*/)
1344 virtual void Accept(const XmlAttribute& attribute)
1346 if (attribute.name == L"name") {
1347 if (attribute.value.size() > 0) {
1348 m_value = attribute.value;
1349 NormalizeString(m_value);
1354 virtual void Verify()
1356 if (m_value.IsNull() || *m_value == L"") {
1360 DPL::String wildString(L"*/*");
1361 if ((m_data.m_mimeList.find(wildString) ==
1362 m_data.m_mimeList.end())
1363 && (m_data.m_mimeList.find(*m_value) ==
1364 m_data.m_mimeList.end())) {
1365 m_data.m_mimeList.insert(*m_value);
1367 LogDebug("Ignoring mime with name" <<
1368 DPL::ToUTF8String(*m_value));
1372 MimeParser(ConfigParserData::AppControlInfo& data) :
1374 m_properNamespace(false),
1380 bool m_properNamespace;
1381 DPL::OptionalString m_value;
1382 ConfigParserData::AppControlInfo& m_data;
1385 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1386 const DPL::String& name)
1388 if (name == L"src") {
1389 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1390 } else if (name == L"operation") {
1391 return DPL::MakeDelegate(this, &AppControlParser::OnOperationElement);
1392 } else if (name == L"uri") {
1393 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1394 } else if (name == L"mime") {
1395 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1397 return &IgnoringParser::Create;
1401 virtual void Accept(const XmlAttribute& attribute)
1405 virtual void Accept(const Element& element)
1407 LogWarning("namespace for app service = " << element.ns);
1408 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1409 ThrowMsg(Exception::ParseError,
1410 "Wrong xml namespace for widget element");
1414 virtual void Accept(const Text& /*text*/)
1416 ThrowMsg(Exception::ParseError, "param element must be empty");
1419 virtual void Verify()
1421 if (m_appControl.m_src == L""){
1422 LogWarning("service element must have src element");
1426 if (m_appControl.m_operation == L""){
1427 LogWarning("service element must have operation element");
1431 FOREACH(iterator, m_data.appControlList) {
1432 if (iterator->m_src == m_appControl.m_src &&
1433 iterator->m_operation == m_appControl.m_operation )
1435 ThrowMsg(Exception::ParseError,
1436 "app control element is duplicated " +
1437 DPL::ToUTF8String(m_appControl.m_src) + ", " +
1438 DPL::ToUTF8String(m_appControl.m_operation));
1441 m_data.appControlList.push_back(m_appControl);
1444 ElementParserPtr OnSourceElement()
1446 return ElementParserPtr(new SourceParser(m_appControl));
1449 ElementParserPtr OnOperationElement()
1451 return ElementParserPtr(new OperationParser(m_appControl));
1454 ElementParserPtr OnUriElement()
1456 return ElementParserPtr(new UriParser(m_appControl));
1459 ElementParserPtr OnMimeElement()
1461 return ElementParserPtr(new MimeParser(m_appControl));
1464 AppControlParser(ConfigParserData& data) :
1472 ConfigParserData& m_data;
1473 ConfigParserData::AppControlInfo m_appControl;
1476 class ApplicationParser : public ElementParser
1479 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1480 const DPL::String& /*name*/)
1482 return &IgnoringParser::Create;
1485 virtual void Accept(const Text& text)
1487 if (m_properNamespace) {
1489 ThrowMsg(Exception::ParseError, "application element must be empty");
1493 virtual void Accept(const Element& element)
1496 ConfigurationNamespace::TizenWebAppNamespaceName)
1498 m_properNamespace = true;
1500 LogDebug("element");
1503 virtual void Accept(const XmlAttribute& attribute)
1505 if (m_properNamespace) {
1506 LogDebug("attribute");
1507 if (attribute.name == L"id") {
1508 m_id = attribute.value;
1509 } else if (attribute.name == L"package") {
1510 m_package = attribute.value;
1511 } else if (attribute.name == L"required_version") {
1512 m_version = attribute.value;
1513 NormalizeString(m_version);
1515 ThrowMsg(Exception::ParseError,
1516 "unknown attribute '" +
1517 DPL::ToUTF8String(attribute.name) +
1518 "' in application element");
1523 virtual void Verify()
1526 ThrowMsg(Exception::ParseError,
1527 "application element must have id attribute");
1531 m_data.tizenPkgId = m_package;
1535 ThrowMsg(Exception::ParseError,
1536 "application element must have required_version attribute");
1539 //TODO check if id and version format is right
1540 m_data.tizenAppId = m_id;
1541 m_data.tizenMinVersionRequired = m_version;
1544 ApplicationParser(ConfigParserData& data) :
1547 m_id(DPL::OptionalString::Null),
1548 m_version(DPL::OptionalString::Null),
1549 m_properNamespace(false)
1554 ConfigParserData& m_data;
1555 DPL::OptionalString m_id;
1556 DPL::OptionalString m_package;
1557 DPL::OptionalString m_version;
1558 bool m_properNamespace;
1561 class SplashParser : public ElementParser
1564 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1565 const DPL::String& /*name*/)
1567 return &IgnoringParser::Create;
1570 virtual void Accept(const XmlAttribute& attribute)
1572 if (attribute.name == L"src") {
1573 if (attribute.value.size() > 0) {
1574 m_src = attribute.value;
1579 virtual void Accept(const Element& element)
1583 virtual void Accept(const Text& /*text*/)
1587 virtual void Verify()
1589 if (m_src.IsNull()) {
1590 LogWarning("src attribute of splash element is mandatory - ignoring");
1594 m_data.splashImgSrc = m_src;
1597 SplashParser(ConfigParserData& data) :
1604 DPL::OptionalString m_src;
1605 ConfigParserData& m_data;
1608 class BackgroundParser : public ElementParser
1611 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1612 const DPL::String& /*name*/)
1614 return &IgnoringParser::Create;
1617 virtual void Accept(const XmlAttribute& attribute)
1619 if (attribute.name == L"src") {
1620 if (attribute.value.size() > 0) {
1621 m_src = attribute.value;
1626 virtual void Accept(const Element& /*element*/)
1630 virtual void Accept(const Text& /*text*/)
1634 virtual void Verify()
1636 if (m_src.IsNull()) {
1637 LogWarning("src attribute of background element is mandatory - ignoring");
1641 m_data.backgroundPage = m_src;
1644 explicit BackgroundParser(ConfigParserData& data) :
1650 DPL::OptionalString m_src;
1651 ConfigParserData& m_data;
1654 class PrivilegeParser : public ElementParser
1657 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1658 const DPL::String& name)
1660 return &IgnoringParser::Create;
1663 virtual void Accept(const Text& /*text*/)
1667 virtual void Accept(const Element& element)
1670 ConfigurationNamespace::TizenWebAppNamespaceName)
1672 m_properNamespace = true;
1674 LogDebug("element");
1677 virtual void Accept(const XmlAttribute& attribute)
1679 if (m_properNamespace) {
1680 if (attribute.name == L"name") {
1681 m_feature.name = attribute.value;
1682 m_privilege.name = attribute.value;
1685 m_feature.required = false;
1688 virtual void Verify()
1690 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1692 if (m_feature.name != L"") {
1693 if (iri.Validate()) {
1694 if (m_data.featuresList.find(m_feature) ==
1695 m_data.featuresList.end()) {
1696 m_data.featuresList.insert(m_feature);
1698 LogDebug("Ignoring feature with name" <<
1699 DPL::ToUTF8String(m_feature.name));
1704 LibIri::Wrapper iriPrivilege(
1705 DPL::ToUTF8String(m_privilege.name).c_str());
1707 if (m_privilege.name != L"") {
1708 if (iriPrivilege.Validate()) {
1709 if (m_data.privilegeList.find(m_privilege) ==
1710 m_data.privilegeList.end()) {
1711 m_data.privilegeList.insert(m_privilege);
1713 LogDebug("Ignoring privilege with name" <<
1714 DPL::ToUTF8String(m_privilege.name));
1720 PrivilegeParser(ConfigParserData& data) :
1725 m_properNamespace(false)
1730 ConfigParserData& m_data;
1731 ConfigParserData::Feature m_feature;
1732 ConfigParserData::Privilege m_privilege;
1733 bool m_properNamespace;
1736 class CategoryParser : public ElementParser
1739 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1740 const DPL::String& /*name*/)
1742 return &IgnoringParser::Create;
1745 virtual void Accept(const XmlAttribute& attribute)
1747 if (attribute.name == L"name") {
1748 if (attribute.value.size() > 0) {
1749 m_name = attribute.value;
1754 virtual void Accept(const Element& /*element*/)
1758 virtual void Accept(const Text& /*text*/)
1762 virtual void Verify()
1764 if (m_name.IsNull()) {
1765 LogWarning("name attribute of category element is mandatory - ignoring");
1769 if (m_data.categoryList.find(*m_name) ==
1770 m_data.categoryList.end()) {
1771 m_data.categoryList.insert(*m_name);
1775 explicit CategoryParser(ConfigParserData& data) :
1781 DPL::OptionalString m_name;
1782 ConfigParserData& m_data;
1785 class LiveboxParser : public ElementParser
1789 struct BoxLabelParser : public ElementParser
1791 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1792 const DPL::String& /*name*/)
1794 return &IgnoringParser::Create;
1797 virtual void Accept(const XmlAttribute& attribute)
1801 virtual void Accept(const Element& element)
1804 ConfigurationNamespace::TizenWebAppNamespaceName)
1806 m_properNamespace = true;
1810 virtual void Accept(const Text& text)
1812 if(m_properNamespace)
1813 m_label = text.value;
1816 virtual void Verify()
1818 m_data.m_label = m_label;
1821 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1823 m_properNamespace(false),
1829 DPL::String m_label;
1830 bool m_properNamespace;
1831 ConfigParserData::LiveboxInfo& m_data;
1834 struct BoxIconParser : public ElementParser
1836 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1837 const DPL::String& /*name*/)
1839 return &IgnoringParser::Create;
1842 virtual void Accept(const XmlAttribute& attribute)
1844 if(m_properNamespace) {
1845 if (attribute.name == L"src") {
1846 m_icon = attribute.value;
1851 virtual void Accept(const Element& element)
1854 ConfigurationNamespace::TizenWebAppNamespaceName)
1856 m_properNamespace = true;
1860 virtual void Accept(const Text& /*text*/)
1864 virtual void Verify()
1866 m_data.m_icon = m_icon;
1869 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1871 m_properNamespace(false),
1878 bool m_properNamespace;
1879 ConfigParserData::LiveboxInfo& m_data;
1882 struct BoxContentParser : public ElementParser
1884 struct BoxSizeParser : public ElementParser
1886 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1887 const DPL::String& /*name*/)
1889 return &IgnoringParser::Create;
1892 virtual void Accept(const XmlAttribute& attribute)
1894 if(m_properNamespace) {
1895 if (attribute.name == L"preview") {
1896 m_preview = attribute.value;
1901 virtual void Accept(const Element& element)
1904 ConfigurationNamespace::TizenWebAppNamespaceName)
1906 m_properNamespace = true;
1910 virtual void Accept(const Text& text)
1912 if(m_properNamespace)
1913 m_size = text.value;
1916 virtual void Verify()
1918 std::pair<DPL::String, DPL::String> boxSize;
1919 boxSize.first = m_size;
1920 boxSize.second = m_preview;
1921 m_data.m_boxSize.push_back(boxSize);
1924 explicit BoxSizeParser(ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1932 DPL::String m_preview;
1933 bool m_properNamespace;
1934 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1937 struct PdParser : public ElementParser
1939 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1940 const DPL::String& name)
1942 return &IgnoringParser::Create;
1945 virtual void Accept(const XmlAttribute& attribute)
1947 if(m_properNamespace) {
1948 if (attribute.name == L"src") {
1949 m_src = attribute.value;
1950 } else if (attribute.name == L"width") {
1951 m_width = attribute.value;
1952 } else if (attribute.name == L"height") {
1953 m_height = attribute.value;
1958 virtual void Accept(const Element& element)
1961 ConfigurationNamespace::TizenWebAppNamespaceName)
1963 m_properNamespace = true;
1967 virtual void Accept(const Text& /*text*/)
1971 virtual void Verify()
1973 m_data.m_pdSrc = m_src;
1974 m_data.m_pdWidth = m_width;
1975 m_data.m_pdHeight = m_height;
1978 explicit PdParser(ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1980 m_properNamespace(false),
1987 DPL::String m_width;
1988 DPL::String m_height;
1990 bool m_properNamespace;
1991 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1994 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1995 const DPL::String& name)
1997 if (name == L"box-size") {
1998 return DPL::MakeDelegate(this, &LiveboxParser::BoxContentParser::OnBoxSizeElement);
1999 } else if (name == L"pd") {
2000 return DPL::MakeDelegate(this, &LiveboxParser::BoxContentParser::OnPdElement);
2002 ThrowMsg(Exception::ParseError, "No element parser for name: " << name);
2006 virtual void Accept(const XmlAttribute& attribute)
2008 if (m_properNamespace) {
2009 if (attribute.name == L"src")
2010 m_box.m_boxSrc = attribute.value;
2014 virtual void Accept(const Element& element)
2017 ConfigurationNamespace::TizenWebAppNamespaceName)
2019 m_properNamespace = true;
2023 virtual void Accept(const Text& /*text*/)
2027 virtual void Verify()
2029 m_data.m_boxInfo = m_box;
2032 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
2034 m_properNamespace(false),
2039 ElementParserPtr OnBoxSizeElement()
2041 return ElementParserPtr(new BoxSizeParser(m_box));
2044 ElementParserPtr OnPdElement()
2046 return ElementParserPtr(new PdParser(m_box));
2051 bool m_properNamespace;
2052 ConfigParserData::LiveboxInfo& m_data;
2053 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
2056 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2057 const DPL::String& name)
2059 if (name == L"box-label") {
2060 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxLabelElement);
2061 } else if (name == L"box-icon") {
2062 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxIconElement);
2063 } else if (name == L"box-content") {
2064 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxContentElement);
2066 return &IgnoringParser::Create;
2070 virtual void Accept(const XmlAttribute& attribute)
2072 if (m_properNamespace) {
2073 if (attribute.name == L"id") {
2074 m_liveboxId = attribute.value;
2075 } else if (attribute.name == L"primary") {
2076 m_primary = attribute.value;
2077 } else if (attribute.name == L"auto-launch") {
2078 m_autoLaunch = attribute.value;
2079 } else if (attribute.name == L"update-period") {
2080 m_updatePeriod = attribute.value;
2085 virtual void Accept(const Element& element)
2088 ConfigurationNamespace::TizenWebAppNamespaceName)
2090 m_properNamespace = true;
2094 virtual void Accept(const Text& /*text*/)
2098 virtual void Verify()
2100 m_livebox.m_liveboxId = m_liveboxId;
2101 m_livebox.m_primary = m_primary;
2102 m_livebox.m_autoLaunch = m_autoLaunch;
2103 m_livebox.m_updatePeriod = m_updatePeriod;
2105 m_data.m_livebox.push_back(m_livebox);
2108 explicit LiveboxParser(ConfigParserData& data) :
2111 m_properNamespace(false)
2113 m_livebox = ConfigParserData::LiveboxInfo();
2116 ElementParserPtr OnBoxLabelElement()
2118 return ElementParserPtr(new BoxLabelParser(m_livebox));
2121 ElementParserPtr OnBoxIconElement()
2123 return ElementParserPtr(new BoxIconParser(m_livebox));
2126 ElementParserPtr OnBoxContentElement()
2128 return ElementParserPtr(new BoxContentParser(m_livebox));
2132 ConfigParserData& m_data;
2133 ConfigParserData::LiveboxInfo m_livebox;
2134 DPL::String m_liveboxId;
2135 DPL::String m_primary;
2136 DPL::String m_autoLaunch;
2137 DPL::String m_updatePeriod;
2138 bool m_properNamespace;
2143 ElementParser::ActionFunc WidgetParser::GetElementParser(const DPL::String& /*ns*/,
2144 const DPL::String& name)
2146 FuncMap::const_iterator it = m_map.find(name);
2147 if (it != m_map.end()) {
2150 return &IgnoringParser::Create;
2154 WidgetParser::WidgetParser(ConfigParserData& data) :
2156 m_textDirection(Unicode::EMPTY)
2158 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2159 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2160 m_map[L"description"] =
2161 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2162 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2164 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2165 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2167 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2169 DPL::MakeDelegate(this, &WidgetParser::OnFeatureElement);
2170 m_map[L"preference"] =
2171 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2172 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2174 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2175 // TODO: appservice will be removed
2176 m_map[L"appservice"] = DPL::MakeDelegate(this, &WidgetParser::OnAppServiceElement);
2177 m_map[L"application"] = DPL::MakeDelegate(this, &WidgetParser::OnApplicationElement);
2178 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2179 m_map[L"background"] = DPL::MakeDelegate(this, &WidgetParser::OnBackgroundElement);
2180 m_map[L"privilege"] = DPL::MakeDelegate(this, &WidgetParser::OnPrivilegeElement);
2181 m_map[L"app-control"] = DPL::MakeDelegate(this,
2182 &WidgetParser::OnAppControlElement);
2183 m_map[L"category"] = DPL::MakeDelegate(this,
2184 &WidgetParser::OnCategoryElement);
2185 m_map[L"livebox"] = DPL::MakeDelegate(this, &WidgetParser::OnLiveboxElement);
2189 ElementParserPtr WidgetParser::OnNameElement()
2191 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2194 ElementParserPtr WidgetParser::OnAccessElement()
2196 return ElementParserPtr(new AccessParser(m_data));
2199 ElementParserPtr WidgetParser::OnDescriptionElement()
2201 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2204 ElementParserPtr WidgetParser::OnAuthorElement()
2206 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2209 ElementParserPtr WidgetParser::OnLicenseElement()
2211 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2214 ElementParserPtr WidgetParser::OnIconElement()
2216 return ElementParserPtr(new IconParser(m_data));
2219 ElementParserPtr WidgetParser::OnContentElement()
2221 return ElementParserPtr(new ContentParser(m_data));
2224 ElementParserPtr WidgetParser::OnFeatureElement()
2226 return ElementParserPtr(new FeatureParser(m_data));
2229 ElementParserPtr WidgetParser::OnPreferenceElement()
2231 return ElementParserPtr(new PreferenceParser(m_data));
2234 ElementParserPtr WidgetParser::OnLinkElement()
2236 return ElementParserPtr(new LinkParser(m_data));
2239 ElementParserPtr WidgetParser::OnSettingElement()
2241 return ElementParserPtr(new SettingParser(m_data));
2244 ElementParserPtr WidgetParser::OnApplicationElement()
2246 return ElementParserPtr(new ApplicationParser(m_data));
2249 ElementParserPtr WidgetParser::OnSplashElement()
2251 return ElementParserPtr(new SplashParser(m_data));
2254 ElementParserPtr WidgetParser::OnBackgroundElement()
2256 return ElementParserPtr(new BackgroundParser(m_data));
2259 ElementParserPtr WidgetParser::OnPrivilegeElement()
2261 return ElementParserPtr(new PrivilegeParser(m_data));
2264 ElementParserPtr WidgetParser::OnAppServiceElement()
2266 return ElementParserPtr(new AppServiceParser(m_data));
2269 ElementParserPtr WidgetParser::OnAppControlElement()
2271 return ElementParserPtr(new AppControlParser(m_data));
2274 ElementParserPtr WidgetParser::OnCategoryElement()
2276 return ElementParserPtr(new CategoryParser(m_data));
2279 ElementParserPtr WidgetParser::OnLiveboxElement()
2281 return ElementParserPtr(new LiveboxParser(m_data));
2284 void WidgetParser::Accept(const Element& element)
2286 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2287 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2289 ThrowMsg(Exception::ParseError,
2290 "Wrong xml namespace for widget element");
2294 void WidgetParser::Accept(const Text& /*text*/)
2296 ThrowMsg(Exception::ParseError, "widged element must be empty");
2299 void WidgetParser::Accept(const XmlAttribute& attribute)
2301 if (attribute.name == L"id") {
2302 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2303 //If may important tests starts to fail this test we will have
2304 //to consider commenting this test out again.
2305 if (iri.Validate()) {
2306 m_data.widget_id = attribute.value;
2307 NormalizeString(m_data.widget_id);
2309 LogWarning("Widget id validation failed: " << attribute.value);
2311 } else if (attribute.name == L"version") {
2312 m_version = attribute.value;
2313 NormalizeString(m_version);
2314 } else if (attribute.name == L"min-version") {
2315 LogInfo("min-version attribute was found. Value: " << attribute.value);
2316 m_minVersion = attribute.value;
2317 NormalizeString(m_minVersion);
2318 m_data.minVersionRequired = m_minVersion;
2319 } else if (attribute.name == L"height") {
2320 DPL::OptionalString value = attribute.value;
2321 NormalizeString(value);
2322 std::string v = DPL::ToUTF8String(*value);
2325 unsigned char c = v.c_str()[0];
2326 if (c >= '0' && c <= '9') {
2328 for (size_t i = 0; i < v.size(); ++i) {
2330 if (c >= '0' && c <= '9') {
2337 m_data.height = val;
2340 } else if (attribute.name == L"width") {
2341 DPL::OptionalString value = attribute.value;
2342 NormalizeString(value);
2343 std::string v = DPL::ToUTF8String(*value);
2346 unsigned char c = v.c_str()[0];
2347 if (c >= '0' && c <= '9') {
2349 for (size_t i = 0; i < v.size(); ++i) {
2351 if (c >= '0' && c <= '9') {
2361 } else if (attribute.name == L"viewmodes") {
2362 DPL::Tokenize(attribute.value,
2364 std::inserter(m_windowModes,
2365 m_windowModes.end()),
2367 } else if (attribute.name == L"dir") {
2368 m_textDirection = Unicode::ParseDirAttribute(attribute);
2369 } else if (L"defaultlocale" == attribute.name) {
2370 if (!m_defaultlocale) {
2371 m_defaultlocale = attribute.value;
2372 NormalizeString(m_defaultlocale);
2373 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2374 DPL::ToUTF8String(*m_defaultlocale))) {
2375 LogWarning("Language tag: " <<
2376 m_defaultlocale << " is not valid");
2377 m_defaultlocale = DPL::OptionalString::Null;
2380 LogDebug("Default Locale Found " << m_defaultlocale);
2382 LogWarning("Ignoring subsequent default locale");
2385 //Any other value consider as a namespace definition
2386 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2387 LogInfo("Namespace domain: " << attribute.name);
2388 LogInfo("Namespace value: " << attribute.value);
2389 m_nameSpaces[attribute.name] = attribute.value;
2391 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2392 ", name=" << attribute.name <<
2393 ", value=" << attribute.value);
2397 void WidgetParser::Verify()
2399 FOREACH(mode, m_windowModes) {
2400 if (L"windowed" == *mode || L"floating" == *mode ||
2401 L"fullscreen" == *mode || L"maximized" == *mode ||
2402 L"minimized" == *mode) {
2403 m_data.windowModes.insert(*mode);
2406 if (!m_version.IsNull()) {
2407 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2408 m_data.version = m_version;
2410 m_data.defaultlocale = m_defaultlocale;
2411 FOREACH(ns, m_nameSpaces) {
2412 m_data.nameSpaces.insert(ns->second);