2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * This file have been implemented in compliance with W3C WARP SPEC.
18 * but there are some patent issue between W3C WARP SPEC and APPLE.
19 * so if you want to use this file, refer to the README file in root directory
22 * @file widget_parser.cpp
23 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
27 #include "widget_parser.h"
28 #include "ignoring_parser.h"
29 #include "deny_all_parser.h"
30 #include <dpl/wrt-dao-ro/config_parser_data.h>
31 #include "libiriwrapper.h"
32 #include <dpl/utils/warp_iri.h>
33 #include <dpl/utils/mime_type_utils.h>
34 #include <language_subtag_rst_tree.h>
37 #include <dpl/log/log.h>
38 #include <dpl/fast_delegate.h>
39 #include <dpl/foreach.h>
44 using namespace WrtDB;
47 static const DPL::String UTF_LRE = L"\x0202a";
48 static const DPL::String UTF_LRO = L"\x0202d";
49 static const DPL::String UTF_RLE = L"\x0202b";
50 static const DPL::String UTF_RLO = L"\x0202e";
51 static const DPL::String UTF_PDF = L"\x0202c";
53 Direction ParseDirAttribute(const XmlAttribute& attribute)
55 Assert(L"dir" == attribute.name);
56 if (L"ltr" == attribute.value) {
58 } else if (L"rtl" == attribute.value) {
60 } else if (L"lro" == attribute.value) {
62 } else if (L"rlo" == attribute.value) {
65 LogWarning("dir attribute has wrong value:" << attribute.value);
70 void UpdateTextWithDirectionMark(Direction direction,
76 *text = UTF_RLO + *text + UTF_PDF;
79 *text = UTF_RLE + *text + UTF_PDF;
82 *text = UTF_LRE + *text + UTF_PDF;
85 *text = UTF_LRO + *text + UTF_PDF;
94 } // namespace Unicode
96 class InnerElementsParser : public ElementParser
99 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
100 const DPL::String& /*name*/)
102 return DPL::MakeDelegate(this, &InnerElementsParser::Other);
105 virtual void Accept(const Element& /*element*/)
108 virtual void Accept(const Text& text)
110 if (m_text.IsNull()) {
113 m_text->value += text.value;
117 virtual void Accept(const XmlAttribute& attribute)
119 if (attribute.name == L"dir") {
120 m_textDirection = Unicode::ParseDirAttribute(attribute);
124 virtual void Verify()
126 if (!m_text.IsNull()) {
127 Unicode::UpdateTextWithDirectionMark(m_textDirection,
129 m_parentParser->Accept(*m_text);
133 InnerElementsParser(ElementParserPtr parent) :
134 m_parentParser(parent),
135 m_textDirection(Unicode::EMPTY)
138 ElementParserPtr Other()
140 return ElementParserPtr(new InnerElementsParser(
141 std::static_pointer_cast<ElementParser>(
142 shared_from_this())));
146 DPL::Optional<Text> m_text;
147 ElementParserPtr m_parentParser;
148 Unicode::Direction m_textDirection;
151 class NameParser : public ElementParser
154 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
155 const DPL::String& /*name*/)
157 return DPL::MakeDelegate(this, &NameParser::Other);
160 virtual void Accept(const Element& element)
162 m_lang = element.lang;
166 virtual void Accept(const Text& text)
168 if (m_name.IsNull()) {
171 *m_name += text.value;
175 virtual void Accept(const XmlAttribute& attribute)
177 if (attribute.name == L"short") {
178 if (m_shortName.IsNull()) {
179 m_shortName = attribute.value;
181 } else if (attribute.name == L"dir") {
182 m_textDirection = Unicode::ParseDirAttribute(attribute);
186 virtual void Verify()
188 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
189 if (data.name.IsNull()) {
190 NormalizeString(m_name);
191 NormalizeString(m_shortName);
192 if (!m_name.IsNull()) {
193 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
196 if (!m_shortName.IsNull()) {
197 Unicode::UpdateTextWithDirectionMark(m_textDirection,
200 data.shortName = m_shortName;
204 NameParser(Unicode::Direction direction,
205 ConfigParserData& data) :
207 m_textDirection(direction)
210 ElementParserPtr Other()
212 return ElementParserPtr(new InnerElementsParser(
213 std::static_pointer_cast<ElementParser>(
214 shared_from_this())));
218 ConfigParserData& m_data;
219 DPL::OptionalString m_name;
220 DPL::OptionalString m_shortName;
221 DPL::OptionalString m_dir;
223 Unicode::Direction m_textDirection;
226 class AccessParser : public ElementParser
235 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
236 const DPL::String& /*name*/)
238 return DPL::MakeDelegate(this, &AccessParser::Other);
241 virtual void Accept(const Element& element)
243 // for tizen web apps WARP should be used
244 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
245 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
247 m_standardType = STANDARD_TYPE_WARP;
251 virtual void Accept(const Text& /*text*/)
254 void AcceptWac(const XmlAttribute& attribute)
256 if (attribute.name == L"origin") {
257 m_strIRIOrigin = attribute.value;
258 NormalizeString(m_strIRIOrigin);
259 } else if (attribute.name == L"subdomains") {
260 DPL::String normalizedValue = attribute.value;
261 NormalizeString(normalizedValue);
263 if (normalizedValue == L"true") {
264 m_bSubDomainAccess = true;
265 } else if (normalizedValue == L"false") {
266 m_bSubDomainAccess = false;
271 virtual void Accept(const XmlAttribute& attribute)
273 switch (m_standardType) {
274 case STANDARD_TYPE_WARP:
275 AcceptWac(attribute);
278 LogError("Error in Access tag - unknown standard.");
286 iri.set(m_strIRIOrigin, false);
288 if (!iri.isAccessDefinition()) {
289 LogWarning("Access list element: " <<
291 " is not acceptable by WARP" <<
292 "standard and will be ignored!");
296 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
298 //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
299 m_data.accessInfoSet.insert(accessInfo);
302 virtual void Verify()
304 switch (m_standardType) {
305 case STANDARD_TYPE_WARP:
309 LogError("Error in Access tag - unknown standard.");
314 AccessParser(ConfigParserData& data) :
316 m_bSubDomainAccess(false),
317 m_standardType(STANDARD_TYPE_NONE),
322 ElementParserPtr Other()
324 return ElementParserPtr(new InnerElementsParser(
325 ElementParserPtr(shared_from_this())));
329 DPL::String m_strIRIOrigin;
330 bool m_bSubDomainAccess;
331 StandardType m_standardType;
333 ConfigParserData& m_data;
336 class DescriptionParser : public ElementParser
339 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
340 const DPL::String& /*name*/)
342 return DPL::MakeDelegate(this, &DescriptionParser::Other);
345 virtual void Accept(const Element& element)
347 m_lang = element.lang;
351 ElementParserPtr Other()
353 return ElementParserPtr(new InnerElementsParser(
354 std::static_pointer_cast<ElementParser>(
355 shared_from_this())));
358 virtual void Accept(const Text& text)
360 if (m_description.IsNull()) {
361 m_description = text.value;
363 *m_description += text.value;
367 virtual void Accept(const XmlAttribute& attribute)
369 if (attribute.name == L"dir") {
370 m_textDirection = Unicode::ParseDirAttribute(attribute);
374 virtual void Verify()
376 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
377 if (data.description.IsNull()) {
378 if (!m_description.IsNull()) {
379 Unicode::UpdateTextWithDirectionMark(m_textDirection,
382 data.description = m_description;
386 DescriptionParser(Unicode::Direction direction,
387 ConfigParserData& data) :
391 m_textDirection(direction)
395 ConfigParserData& m_data;
397 DPL::OptionalString m_description;
398 Unicode::Direction m_textDirection;
401 class AuthorParser : public ElementParser
404 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
405 const DPL::String& /*name*/)
407 return DPL::MakeDelegate(this, &AuthorParser::Other);
410 AuthorParser(Unicode::Direction direction,
411 ConfigParserData& data) :
413 m_textDirection(direction)
416 virtual void Accept(const Element& /*element*/)
421 virtual void Accept(const Text& text)
423 *(m_authorName) += text.value;
426 virtual void Accept(const XmlAttribute& attribute)
428 if (attribute.name == L"href") {
429 //Validate href IRI and ignore it if invalid
430 //See also test: ta-argMozRiC-an
431 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
432 if (iri.Validate()) {
433 m_authorHref = attribute.value;
435 } else if (attribute.name == L"email") {
436 m_authorEmail = attribute.value;
437 } else if (attribute.name == L"dir") {
438 m_textDirection = Unicode::ParseDirAttribute(attribute);
442 virtual void Verify()
444 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
445 NormalizeString(m_authorName);
446 NormalizeString(m_authorHref);
447 NormalizeString(m_authorEmail);
448 if (!!m_authorName) {
449 Unicode::UpdateTextWithDirectionMark(m_textDirection,
451 m_data.authorName = m_authorName;
453 if (!!m_authorHref) {
454 m_data.authorHref = m_authorHref;
456 if (!!m_authorEmail) {
457 m_data.authorEmail = m_authorEmail;
462 ElementParserPtr Other()
464 return ElementParserPtr(new InnerElementsParser(
465 std::static_pointer_cast<ElementParser>(
466 shared_from_this())));
470 ConfigParserData& m_data;
471 DPL::OptionalString m_authorEmail;
472 DPL::OptionalString m_authorHref;
473 DPL::OptionalString m_authorName;
474 Unicode::Direction m_textDirection;
477 class LicenseParser : public ElementParser
480 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
481 const DPL::String& /*name*/)
483 return DPL::MakeDelegate(this, &LicenseParser::Other);
486 LicenseParser(Unicode::Direction direction,
487 ConfigParserData& data) :
490 m_textDirection(direction)
493 virtual void Accept(const Element& element)
495 if (m_license.IsNull()) {
496 m_lang = element.lang;
502 virtual void Accept(const Text& text)
505 *m_license += text.value;
509 virtual void Accept(const XmlAttribute& attribute)
512 if (attribute.name == L"href" && m_licenseHref.IsNull()) {
513 m_licenseHref = attribute.value;
514 } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
515 m_licenseFile = attribute.value;
516 } else if (attribute.name == L"dir") {
517 m_textDirection = Unicode::ParseDirAttribute(attribute);
522 virtual void Verify()
524 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
525 if (data.license.IsNull()) {
526 if (!m_license.IsNull()) {
527 Unicode::UpdateTextWithDirectionMark(m_textDirection,
530 data.license = m_license;
531 data.licenseHref = m_licenseHref;
532 data.licenseFile = m_licenseFile;
536 ElementParserPtr Other()
538 return ElementParserPtr(new InnerElementsParser(
539 ElementParserPtr(shared_from_this())));
543 ConfigParserData& m_data;
547 DPL::OptionalString m_license;
548 DPL::OptionalString m_licenseFile;
549 DPL::OptionalString m_licenseHref;
550 Unicode::Direction m_textDirection;
553 class IconParser : public ElementParser
555 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
558 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
559 const DPL::String& /*name*/)
561 return &IgnoringParser::Create;
564 IconParser(ConfigParserData& data) : ElementParser(),
568 virtual void Accept(const Element& /*element*/)
571 virtual void Accept(const XmlAttribute& attribute)
573 if (attribute.name == L"src") {
574 if (attribute.value.size() > 0) {
575 m_src = attribute.value;
577 } else if (attribute.name == L"width") {
578 m_width = ParseSizeAttributeValue(attribute.value);
579 } else if (attribute.name == L"height") {
580 m_height = ParseSizeAttributeValue(attribute.value);
584 virtual void Accept(const Text& /*text*/)
586 ThrowMsg(Exception::ParseError, "Icon element must be empty");
589 virtual void Verify()
591 if (m_src.IsNull()) {
592 LogWarning("src attribute of icon element is mandatory - ignoring");
598 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
599 icon.width = m_width;
600 icon.height = m_height;
602 ConfigParserData::IconsList::iterator it = std::find(
603 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
604 if (it == m_data.iconsList.end()) {
605 m_data.iconsList.push_front(icon);
610 LogWarning("src attribute is invalid: " << m_src);
615 ConfigParserData& m_data;
616 DPL::OptionalString m_src;
617 DPL::OptionalInt m_width;
618 DPL::OptionalInt m_height;
620 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
622 DPL::OptionalString normalizedValue = value;
623 NormalizeString(normalizedValue);
624 if (!(*normalizedValue).empty()) {
628 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
630 std::string(reterr) == DPL::ToUTF8String(value) ||
633 return DPL::OptionalInt::Null;
638 return DPL::OptionalInt::Null;
642 * @brief delocalizePath removes locales folder from relative path if
644 * @param source source string
646 * @throw BadSrcError if string is bad value of src attribute
648 * @return corrected string
650 static DPL::String delocalizeSrcPath(const DPL::String & source)
652 static const DPL::String localeFolder(L"locales/");
653 static const int index = localeFolder.size();
655 DPL::String result = source;
657 if (source.substr(0, index) == localeFolder) {
658 size_t pos = result.find_first_of('/', index);
659 if (pos != std::string::npos && pos + 1 < source.size()) {
660 result = result.substr(pos + 1, source.size());
669 class ContentParser : public ElementParser
672 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
673 const DPL::String& /*name*/)
675 return &IgnoringParser::Create;
678 ContentParser(ConfigParserData& data) :
683 virtual void Accept(const Element& /*element*/)
686 virtual void Accept(const Text& /*text*/)
689 virtual void Accept(const XmlAttribute& attribute)
691 DPL::String value = attribute.value;
692 NormalizeString(value);
694 if (attribute.name == L"src") {
696 } else if (attribute.name == L"type") {
698 MimeTypeUtils::MimeAttributes mimeAttributes =
699 MimeTypeUtils::getMimeAttributes(value);
700 if (mimeAttributes.count(L"charset") > 0) {
701 m_encoding = mimeAttributes[L"charset"];
703 } else if (attribute.name == L"encoding") {
704 if (!value.empty()) {
710 virtual void Verify()
712 if (m_data.startFileEncountered) {
713 LogWarning("This is not the first encountered "
714 "'content' element - ignoring.");
718 m_data.startFileEncountered = true;
720 //we're consciously setting startFile even if m_src is null or invalid.
721 //WidgetConfigurationManager will deal with this.
722 m_data.startFile = m_src;
725 m_data.startFileContentType = m_type;
727 m_data.startFileEncoding = m_encoding;
729 m_data.startFileEncoding = L"UTF-8";
735 DPL::OptionalString m_src;
736 DPL::OptionalString m_type;
737 DPL::OptionalString m_encoding;
738 ConfigParserData& m_data;
741 class FeatureParser : public ElementParser
744 struct ParamParser : public ElementParser
746 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
747 const DPL::String& /*name*/)
749 return &IgnoringParser::Create;
752 virtual void Accept(const XmlAttribute& attribute)
754 if (attribute.name == L"name") {
755 m_name = attribute.value;
756 NormalizeString(m_name);
757 } else if (attribute.name == L"value") {
758 m_value = attribute.value;
759 NormalizeString(m_value);
763 virtual void Accept(const Element& /*element*/)
766 virtual void Accept(const Text& /*text*/)
768 ThrowMsg(Exception::ParseError, "param element must be empty");
771 virtual void Verify()
773 if (m_name.IsNull() || *m_name == L"") {
776 if (m_value.IsNull() || *m_value == L"") {
780 ConfigParserData::Param param(*m_name);
781 param.value = *m_value;
783 if (m_data.paramsList.find(param) == m_data.paramsList.end()) {
784 m_data.paramsList.insert(param);
788 ParamParser(ConfigParserData::Feature& data) :
794 DPL::OptionalString m_name;
795 DPL::OptionalString m_value;
796 ConfigParserData::Feature& m_data;
799 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
800 const DPL::String& name)
802 if (name == L"param") {
803 return DPL::MakeDelegate(this, &FeatureParser::OnParamElement);
805 return &IgnoringParser::Create;
809 virtual void Accept(const Text& /*text*/)
812 virtual void Accept(const Element& /*element*/)
815 virtual void Accept(const XmlAttribute& attribute)
817 if (attribute.name == L"name") {
818 m_feature.name = attribute.value;
819 } else if (attribute.name == L"required") {
820 if (attribute.value == L"false") {
821 m_feature.required = false;
823 m_feature.required = true;
828 virtual void Verify()
830 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
832 if (m_feature.name != L"") {
833 if (iri.Validate()) {
834 if (m_data.featuresList.find(m_feature) ==
835 m_data.featuresList.end())
837 m_data.featuresList.insert(m_feature);
839 LogDebug("Ignoring feature with name" <<
840 DPL::ToUTF8String(m_feature.name));
843 if (m_feature.required) {
844 //Throw only if required
845 ThrowMsg(Exception::ParseError, "invalid feature IRI");
851 ElementParserPtr OnParamElement()
853 return ElementParserPtr(new ParamParser(m_feature));
856 FeatureParser(ConfigParserData& data) :
863 ConfigParserData& m_data;
864 ConfigParserData::Feature m_feature;
867 class PreferenceParser : public ElementParser
870 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
871 const DPL::String& /*name*/)
873 return &IgnoringParser::Create;
876 virtual void Accept(const XmlAttribute& attribute)
878 if (attribute.name == L"name") {
879 m_name = attribute.value;
880 } else if (attribute.name == L"value") {
881 m_value = attribute.value;
882 } else if (attribute.name == L"readonly") {
883 if (attribute.value == L"true") {
891 virtual void Accept(const Element& /*element*/)
894 virtual void Accept(const Text& /*text*/)
896 ThrowMsg(Exception::ParseError, "param element must be empty");
899 virtual void Verify()
901 if (m_name.IsNull()) {
902 LogWarning("preference element must have name attribute");
905 NormalizeString(m_name);
906 NormalizeString(m_value);
907 ConfigParserData::Preference preference(*m_name, m_required);
908 preference.value = m_value;
909 if (m_data.preferencesList.find(preference) ==
910 m_data.preferencesList.end())
912 m_data.preferencesList.insert(preference);
916 PreferenceParser(ConfigParserData& data) :
923 DPL::OptionalString m_name;
924 DPL::OptionalString m_value;
926 ConfigParserData& m_data;
929 class LinkParser : public ElementParser
932 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
933 const DPL::String& /*name*/)
935 return &DenyAllParser::Create;
938 virtual void Accept(const XmlAttribute& attribute)
940 if (m_properNamespace) {
941 LogDebug("attribute");
942 if (attribute.name == L"rel") {
943 if (attribute.value != L"describedby") {
944 ThrowMsg(Exception::ParseError,
945 "rel attribute must have describedby value");
947 } else if (attribute.name == L"type") {} else if (attribute.name ==
950 LogDebug("here is href");
951 m_href = attribute.value;
953 ThrowMsg(Exception::ParseError,
954 "unknown attribute '" +
955 DPL::ToUTF8String(attribute.name) +
956 "' in link element");
961 virtual void Accept(const Element& element)
964 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
966 m_properNamespace = true;
971 virtual void Accept(const Text&)
973 if (m_properNamespace) {
975 ThrowMsg(Exception::ParseError, "link element must be empty");
979 virtual void Verify()
982 ThrowMsg(Exception::ParseError,
983 "link element must have href attribute");
986 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
987 if (!iri.Validate()) { // TODO: Better uri validator ?
988 ThrowMsg(Exception::ParseError,
989 "href attribute must be a valid iri/uri/url");
993 LinkParser(ConfigParserData& data) :
995 m_properNamespace(false),
997 m_href(DPL::OptionalString::Null)
1001 bool m_properNamespace;
1002 ConfigParserData& m_data;
1003 DPL::OptionalString m_href;
1006 class SettingParser : public ElementParser
1009 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1010 const DPL::String& /*name*/)
1012 return &IgnoringParser::Create;
1015 virtual void Accept(const Text& /*text*/)
1018 virtual void Accept(const Element& /*element*/)
1021 virtual void Accept(const XmlAttribute& attribute)
1023 m_setting.m_name = attribute.name;
1024 m_setting.m_value = attribute.value;
1025 m_data.settingsList.insert(m_setting);
1028 virtual void Verify()
1031 SettingParser(ConfigParserData& data) :
1038 ConfigParserData& m_data;
1039 ConfigParserData::Setting m_setting;
1042 class AppServiceParser : public ElementParser
1045 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1046 const DPL::String& /*name*/)
1048 return &IgnoringParser::Create;
1051 virtual void Accept(const XmlAttribute& attribute)
1053 if (attribute.name == L"src") {
1054 m_src = attribute.value;
1055 } else if (attribute.name == L"operation") {
1056 m_operation = attribute.value;
1057 } else if (attribute.name == L"scheme") {
1058 m_scheme = attribute.value;
1059 } else if (attribute.name == L"mime") {
1060 m_mime = attribute.value;
1061 } else if (attribute.name == L"disposition") {
1062 if (attribute.value == L"inline")
1064 ConfigParserData::ServiceInfo::Disposition::INLINE;
1068 virtual void Accept(const Element& element)
1070 LogWarning("namespace for app service = " << element.ns);
1071 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1072 ThrowMsg(Exception::ParseError,
1073 "Wrong xml namespace for widget element");
1077 virtual void Accept(const Text& /*text*/)
1079 ThrowMsg(Exception::ParseError, "param element must be empty");
1082 virtual void Verify()
1084 if (m_src.IsNull()) {
1085 LogWarning("service element must have target attribute");
1087 } else if (m_operation.IsNull()) {
1088 LogWarning("service element must have operation attribute");
1091 NormalizeString(m_src);
1092 NormalizeString(m_operation);
1093 NormalizeString(m_scheme);
1094 NormalizeString(m_mime);
1096 // verify duplicate element
1097 DPL::String wildString(L"*/*");
1098 DPL::String nullString(L"");
1099 ConfigParserData::ServiceInfo serviceInfo(
1100 m_src.IsNull() ? nullString : *m_src,
1101 m_operation.IsNull() ? nullString : *m_operation,
1102 m_scheme.IsNull() ? nullString : *m_scheme,
1103 m_mime.IsNull() ? nullString : *m_mime,
1106 FOREACH(iterator, m_data.appServiceList) {
1107 if (iterator->m_operation == serviceInfo.m_operation &&
1109 (iterator->m_scheme == serviceInfo.m_scheme ||
1110 // check input scheme is "*/*" case
1111 (iterator->m_scheme == wildString &&
1112 serviceInfo.m_scheme != nullString) ||
1113 // check iterator scheme is "*/*" case
1114 (serviceInfo.m_scheme == wildString &&
1115 iterator->m_scheme != nullString)) &&
1117 (iterator->m_mime == serviceInfo.m_mime ||
1118 // check input mime is "*/*" case
1119 (iterator->m_mime == wildString &&
1120 serviceInfo.m_mime != nullString) ||
1121 // check iterator mime is "*/*" case
1122 (serviceInfo.m_mime == wildString &&
1123 iterator->m_mime != nullString)))
1125 ThrowMsg(Exception::ParseError,
1126 "service operation is duplicated " +
1127 DPL::ToUTF8String(*m_operation));
1130 m_data.appServiceList.push_back(serviceInfo);
1133 AppServiceParser(ConfigParserData& data) :
1135 m_src(DPL::OptionalString::Null),
1136 m_operation(DPL::OptionalString::Null),
1137 m_scheme(DPL::OptionalString::Null),
1138 m_mime(DPL::OptionalString::Null),
1139 m_disposition(ConfigParserData::ServiceInfo::Disposition::WINDOW),
1144 DPL::OptionalString m_src;
1145 DPL::OptionalString m_operation;
1146 DPL::OptionalString m_scheme;
1147 DPL::OptionalString m_mime;
1148 ConfigParserData::ServiceInfo::Disposition m_disposition;
1149 ConfigParserData& m_data;
1152 class AppControlParser : public ElementParser
1155 struct SourceParser : public ElementParser
1158 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1159 const DPL::String& /*name*/)
1161 return &IgnoringParser::Create;
1164 virtual void Accept(const Text& /*text*/)
1167 virtual void Accept(const Element& /*element*/)
1170 virtual void Accept(const XmlAttribute& attribute)
1172 if (attribute.name == L"name") {
1173 if (attribute.value.size() > 0) {
1174 m_value = attribute.value;
1175 NormalizeString(m_value);
1180 virtual void Verify()
1182 if (m_value.IsNull() || *m_value == L"") {
1186 m_data.m_src = *m_value;
1189 SourceParser(ConfigParserData::AppControlInfo& data) :
1191 m_properNamespace(false),
1196 bool m_properNamespace;
1197 DPL::OptionalString m_value;
1198 ConfigParserData::AppControlInfo& m_data;
1201 struct OperationParser : public ElementParser
1204 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1205 const DPL::String& /*name*/)
1207 return &IgnoringParser::Create;
1210 virtual void Accept(const Text& /*text*/)
1213 virtual void Accept(const Element& /*element*/)
1216 virtual void Accept(const XmlAttribute& attribute)
1218 if (attribute.name == L"name") {
1219 if (attribute.value.size() > 0) {
1220 m_value = attribute.value;
1221 NormalizeString(m_value);
1226 virtual void Verify()
1228 if (m_value.IsNull() || *m_value == L"") {
1232 m_data.m_operation = *m_value;
1235 OperationParser(ConfigParserData::AppControlInfo& data) :
1237 m_properNamespace(false),
1242 bool m_properNamespace;
1243 DPL::OptionalString m_value;
1244 ConfigParserData::AppControlInfo& m_data;
1247 struct UriParser : public ElementParser
1250 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1251 const DPL::String& /*name*/)
1253 return &IgnoringParser::Create;
1256 virtual void Accept(const Text& /*text*/)
1259 virtual void Accept(const Element& /*element*/)
1262 virtual void Accept(const XmlAttribute& attribute)
1264 if (attribute.name == L"name") {
1265 if (attribute.value.size() > 0) {
1266 m_value = attribute.value;
1267 NormalizeString(m_value);
1272 virtual void Verify()
1274 if (m_value.IsNull() || *m_value == L"") {
1278 DPL::String wildString(L"*/*");
1279 if ((m_data.m_uriList.find(wildString) ==
1280 m_data.m_uriList.end())
1281 && (m_data.m_uriList.find(*m_value) ==
1282 m_data.m_uriList.end()))
1284 m_data.m_uriList.insert(*m_value);
1286 LogDebug("Ignoring uri with name" <<
1287 DPL::ToUTF8String(*m_value));
1291 UriParser(ConfigParserData::AppControlInfo& data) :
1293 m_properNamespace(false),
1298 bool m_properNamespace;
1299 DPL::OptionalString m_value;
1300 ConfigParserData::AppControlInfo& m_data;
1303 struct MimeParser : public ElementParser
1306 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1307 const DPL::String& /*name*/)
1309 return &IgnoringParser::Create;
1312 virtual void Accept(const Text& /*text*/)
1315 virtual void Accept(const Element& /*element*/)
1318 virtual void Accept(const XmlAttribute& attribute)
1320 if (attribute.name == L"name") {
1321 if (attribute.value.size() > 0) {
1322 m_value = attribute.value;
1323 NormalizeString(m_value);
1328 virtual void Verify()
1330 if (m_value.IsNull() || *m_value == L"") {
1334 DPL::String wildString(L"*/*");
1335 if ((m_data.m_mimeList.find(wildString) ==
1336 m_data.m_mimeList.end())
1337 && (m_data.m_mimeList.find(*m_value) ==
1338 m_data.m_mimeList.end()))
1340 m_data.m_mimeList.insert(*m_value);
1342 LogDebug("Ignoring mime with name" <<
1343 DPL::ToUTF8String(*m_value));
1347 MimeParser(ConfigParserData::AppControlInfo& data) :
1349 m_properNamespace(false),
1354 bool m_properNamespace;
1355 DPL::OptionalString m_value;
1356 ConfigParserData::AppControlInfo& m_data;
1359 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1360 const DPL::String& name)
1362 if (name == L"src") {
1363 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1364 } else if (name == L"operation") {
1365 return DPL::MakeDelegate(this,
1366 &AppControlParser::OnOperationElement);
1367 } else if (name == L"uri") {
1368 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1369 } else if (name == L"mime") {
1370 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1372 return &IgnoringParser::Create;
1376 virtual void Accept(const XmlAttribute& /*attribute*/)
1379 virtual void Accept(const Element& element)
1381 LogWarning("namespace for app service = " << element.ns);
1382 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1383 ThrowMsg(Exception::ParseError,
1384 "Wrong xml namespace for widget element");
1388 virtual void Accept(const Text& /*text*/)
1390 ThrowMsg(Exception::ParseError, "param element must be empty");
1393 virtual void Verify()
1395 if (m_appControl.m_src == L"") {
1396 LogWarning("service element must have src element");
1400 if (m_appControl.m_operation == L"") {
1401 LogWarning("service element must have operation element");
1405 FOREACH(iterator, m_data.appControlList) {
1406 if (iterator->m_src == m_appControl.m_src &&
1407 iterator->m_operation == m_appControl.m_operation)
1409 ThrowMsg(Exception::ParseError,
1410 "app control element is duplicated " +
1411 DPL::ToUTF8String(m_appControl.m_src) + ", " +
1412 DPL::ToUTF8String(m_appControl.m_operation));
1415 m_data.appControlList.push_back(m_appControl);
1418 ElementParserPtr OnSourceElement()
1420 return ElementParserPtr(new SourceParser(m_appControl));
1423 ElementParserPtr OnOperationElement()
1425 return ElementParserPtr(new OperationParser(m_appControl));
1428 ElementParserPtr OnUriElement()
1430 return ElementParserPtr(new UriParser(m_appControl));
1433 ElementParserPtr OnMimeElement()
1435 return ElementParserPtr(new MimeParser(m_appControl));
1438 AppControlParser(ConfigParserData& data) :
1445 ConfigParserData& m_data;
1446 ConfigParserData::AppControlInfo m_appControl;
1449 class ApplicationParser : public ElementParser
1452 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1453 const DPL::String& /*name*/)
1455 return &IgnoringParser::Create;
1458 virtual void Accept(const Text& /*text*/)
1460 if (m_properNamespace) {
1462 ThrowMsg(Exception::ParseError, "application element must be empty");
1466 virtual void Accept(const Element& element)
1469 ConfigurationNamespace::TizenWebAppNamespaceName)
1471 m_properNamespace = true;
1473 LogDebug("element");
1476 virtual void Accept(const XmlAttribute& attribute)
1478 if (m_properNamespace) {
1479 LogDebug("attribute");
1480 if (attribute.name == L"id") {
1481 m_id = attribute.value;
1482 NormalizeAndTrimSpaceString(m_id);
1483 } else if (attribute.name == L"package") {
1484 m_package = attribute.value;
1485 } else if (attribute.name == L"required_version") {
1486 m_version = attribute.value;
1487 NormalizeString(m_version);
1489 ThrowMsg(Exception::ParseError,
1490 "unknown attribute '" +
1491 DPL::ToUTF8String(attribute.name) +
1492 "' in application element");
1497 virtual void Verify()
1500 ThrowMsg(Exception::ParseError,
1501 "application element must have id attribute");
1505 m_data.tizenPkgId = m_package;
1509 ThrowMsg(Exception::ParseError,
1510 "application element must have required_version attribute");
1513 //TODO check if id and version format is right
1514 m_data.tizenAppId = m_id;
1515 m_data.tizenMinVersionRequired = m_version;
1518 ApplicationParser(ConfigParserData& data) :
1521 m_id(DPL::OptionalString::Null),
1522 m_version(DPL::OptionalString::Null),
1523 m_properNamespace(false)
1527 ConfigParserData& m_data;
1528 DPL::OptionalString m_id;
1529 DPL::OptionalString m_package;
1530 DPL::OptionalString m_version;
1531 bool m_properNamespace;
1534 class SplashParser : public ElementParser
1537 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1538 const DPL::String& /*name*/)
1540 return &IgnoringParser::Create;
1543 virtual void Accept(const XmlAttribute& attribute)
1545 if (attribute.name == L"src") {
1546 if (attribute.value.size() > 0) {
1547 m_src = attribute.value;
1552 virtual void Accept(const Element& /*element*/)
1555 virtual void Accept(const Text& /*text*/)
1558 virtual void Verify()
1560 if (m_src.IsNull()) {
1562 "src attribute of splash element is mandatory - ignoring");
1566 m_data.splashImgSrc = m_src;
1569 SplashParser(ConfigParserData& data) :
1575 DPL::OptionalString m_src;
1576 ConfigParserData& m_data;
1579 class BackgroundParser : public ElementParser
1582 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1583 const DPL::String& /*name*/)
1585 return &IgnoringParser::Create;
1588 virtual void Accept(const XmlAttribute& attribute)
1590 if (attribute.name == L"src") {
1591 if (attribute.value.size() > 0) {
1592 m_src = attribute.value;
1597 virtual void Accept(const Element& /*element*/)
1600 virtual void Accept(const Text& /*text*/)
1603 virtual void Verify()
1605 if (m_src.IsNull()) {
1607 "src attribute of background element is mandatory - ignoring");
1611 m_data.backgroundPage = m_src;
1614 explicit BackgroundParser(ConfigParserData& data) :
1619 DPL::OptionalString m_src;
1620 ConfigParserData& m_data;
1623 class PrivilegeParser : public ElementParser
1626 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1627 const DPL::String& /*name*/)
1629 return &IgnoringParser::Create;
1632 virtual void Accept(const Text& /*text*/)
1635 virtual void Accept(const Element& element)
1638 ConfigurationNamespace::TizenWebAppNamespaceName)
1640 m_properNamespace = true;
1642 LogDebug("element");
1645 virtual void Accept(const XmlAttribute& attribute)
1647 if (m_properNamespace) {
1648 if (attribute.name == L"name") {
1649 m_feature.name = attribute.value;
1650 m_privilege.name = attribute.value;
1653 m_feature.required = false;
1656 virtual void Verify()
1658 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1660 if (m_feature.name != L"") {
1661 if (iri.Validate()) {
1662 if (m_data.featuresList.find(m_feature) ==
1663 m_data.featuresList.end())
1665 m_data.featuresList.insert(m_feature);
1667 LogDebug("Ignoring feature with name" <<
1668 DPL::ToUTF8String(m_feature.name));
1673 LibIri::Wrapper iriPrivilege(
1674 DPL::ToUTF8String(m_privilege.name).c_str());
1676 if (m_privilege.name != L"") {
1677 if (iriPrivilege.Validate()) {
1678 if (m_data.privilegeList.find(m_privilege) ==
1679 m_data.privilegeList.end())
1681 m_data.privilegeList.insert(m_privilege);
1683 LogDebug("Ignoring privilege with name" <<
1684 DPL::ToUTF8String(m_privilege.name));
1690 PrivilegeParser(ConfigParserData& data) :
1695 m_properNamespace(false)
1699 ConfigParserData& m_data;
1700 ConfigParserData::Feature m_feature;
1701 ConfigParserData::Privilege m_privilege;
1702 bool m_properNamespace;
1705 class CategoryParser : public ElementParser
1708 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1709 const DPL::String& /*name*/)
1711 return &IgnoringParser::Create;
1714 virtual void Accept(const XmlAttribute& attribute)
1716 if (attribute.name == L"name") {
1717 if (attribute.value.size() > 0) {
1718 m_name = attribute.value;
1723 virtual void Accept(const Element& /*element*/)
1726 virtual void Accept(const Text& /*text*/)
1729 virtual void Verify()
1731 if (m_name.IsNull()) {
1733 "name attribute of category element is mandatory - ignoring");
1737 if (m_data.categoryList.find(*m_name) ==
1738 m_data.categoryList.end())
1740 m_data.categoryList.insert(*m_name);
1744 explicit CategoryParser(ConfigParserData& data) :
1749 DPL::OptionalString m_name;
1750 ConfigParserData& m_data;
1753 class LiveboxParser : public ElementParser
1757 struct BoxLabelParser : public ElementParser
1759 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1760 const DPL::String& /*name*/)
1762 return &IgnoringParser::Create;
1765 virtual void Accept(const XmlAttribute& /*attribute*/)
1768 virtual void Accept(const Element& element)
1771 ConfigurationNamespace::TizenWebAppNamespaceName)
1773 m_properNamespace = true;
1777 virtual void Accept(const Text& text)
1779 if (m_properNamespace) {
1780 m_label = text.value;
1784 virtual void Verify()
1786 m_data.m_label = m_label;
1789 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1791 m_properNamespace(false),
1796 DPL::String m_label;
1797 bool m_properNamespace;
1798 ConfigParserData::LiveboxInfo& m_data;
1801 struct BoxIconParser : public ElementParser
1803 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1804 const DPL::String& /*name*/)
1806 return &IgnoringParser::Create;
1809 virtual void Accept(const XmlAttribute& attribute)
1811 if (m_properNamespace) {
1812 if (attribute.name == L"src") {
1813 m_icon = attribute.value;
1818 virtual void Accept(const Element& element)
1821 ConfigurationNamespace::TizenWebAppNamespaceName)
1823 m_properNamespace = true;
1827 virtual void Accept(const Text& /*text*/)
1830 virtual void Verify()
1832 m_data.m_icon = m_icon;
1835 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1837 m_properNamespace(false),
1843 bool m_properNamespace;
1844 ConfigParserData::LiveboxInfo& m_data;
1847 struct BoxContentParser : public ElementParser
1849 struct BoxSizeParser : public ElementParser
1851 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1852 const DPL::String& /*name*/)
1854 return &IgnoringParser::Create;
1857 virtual void Accept(const XmlAttribute& attribute)
1859 if (m_properNamespace) {
1860 if (attribute.name == L"preview") {
1861 m_preview = attribute.value;
1866 virtual void Accept(const Element& element)
1869 ConfigurationNamespace::TizenWebAppNamespaceName)
1871 m_properNamespace = true;
1875 virtual void Accept(const Text& text)
1877 if (m_properNamespace) {
1878 m_size = text.value;
1882 virtual void Verify()
1884 std::pair<DPL::String, DPL::String> boxSize;
1885 boxSize.first = m_size;
1886 boxSize.second = m_preview;
1887 m_data.m_boxSize.push_back(boxSize);
1890 explicit BoxSizeParser(
1891 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1893 m_properNamespace(false),
1899 DPL::String m_preview;
1900 bool m_properNamespace;
1901 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1904 struct PdParser : public ElementParser
1906 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1907 const DPL::String& /*name*/)
1909 return &IgnoringParser::Create;
1912 virtual void Accept(const XmlAttribute& attribute)
1914 if (m_properNamespace) {
1915 if (attribute.name == L"src") {
1916 m_src = attribute.value;
1917 } else if (attribute.name == L"width") {
1918 m_width = attribute.value;
1919 } else if (attribute.name == L"height") {
1920 m_height = attribute.value;
1925 virtual void Accept(const Element& element)
1928 ConfigurationNamespace::TizenWebAppNamespaceName)
1930 m_properNamespace = true;
1934 virtual void Accept(const Text& /*text*/)
1937 virtual void Verify()
1939 m_data.m_pdSrc = m_src;
1940 m_data.m_pdWidth = m_width;
1941 m_data.m_pdHeight = m_height;
1945 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1947 m_properNamespace(false),
1953 DPL::String m_width;
1954 DPL::String m_height;
1956 bool m_properNamespace;
1957 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1960 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1961 const DPL::String& name)
1963 if (name == L"box-size") {
1964 return DPL::MakeDelegate(
1966 &LiveboxParser::BoxContentParser::
1968 } else if (name == L"pd") {
1969 return DPL::MakeDelegate(
1971 &LiveboxParser::BoxContentParser::
1974 ThrowMsg(Exception::ParseError,
1975 "No element parser for name: " << name);
1979 virtual void Accept(const XmlAttribute& attribute)
1981 if (m_properNamespace) {
1982 if (attribute.name == L"src") {
1983 m_box.m_boxSrc = attribute.value;
1985 if (attribute.name == L"mouse-event") {
1986 m_box.m_boxMouseEvent = attribute.value;
1991 virtual void Accept(const Element& element)
1994 ConfigurationNamespace::TizenWebAppNamespaceName)
1996 m_properNamespace = true;
2000 virtual void Accept(const Text& /*text*/)
2003 virtual void Verify()
2005 m_data.m_boxInfo = m_box;
2008 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
2010 m_properNamespace(false),
2014 ElementParserPtr OnBoxSizeElement()
2016 return ElementParserPtr(new BoxSizeParser(m_box));
2019 ElementParserPtr OnPdElement()
2021 return ElementParserPtr(new PdParser(m_box));
2026 bool m_properNamespace;
2027 ConfigParserData::LiveboxInfo& m_data;
2028 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
2031 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2032 const DPL::String& name)
2034 if (name == L"box-label") {
2035 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxLabelElement);
2036 } else if (name == L"box-icon") {
2037 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxIconElement);
2038 } else if (name == L"box-content") {
2039 return DPL::MakeDelegate(this, &LiveboxParser::OnBoxContentElement);
2041 return &IgnoringParser::Create;
2045 virtual void Accept(const XmlAttribute& attribute)
2047 if (m_properNamespace) {
2048 if (attribute.name == L"id") {
2049 m_liveboxId = attribute.value;
2050 } else if (attribute.name == L"primary") {
2051 m_primary = attribute.value;
2052 } else if (attribute.name == L"auto-launch") {
2053 m_autoLaunch = attribute.value;
2054 } else if (attribute.name == L"update-period") {
2055 m_updatePeriod = attribute.value;
2056 } else if (attribute.name == L"type") {
2057 m_type = attribute.value;
2062 virtual void Accept(const Element& element)
2065 ConfigurationNamespace::TizenWebAppNamespaceName)
2067 m_properNamespace = true;
2071 virtual void Accept(const Text& /*text*/)
2074 virtual void Verify()
2076 m_livebox.m_liveboxId = m_liveboxId;
2077 m_livebox.m_primary = m_primary;
2078 m_livebox.m_autoLaunch = m_autoLaunch;
2079 m_livebox.m_updatePeriod = m_updatePeriod;
2080 m_livebox.m_type = m_type;
2082 m_data.m_livebox.push_back(m_livebox);
2085 explicit LiveboxParser(ConfigParserData& data) :
2088 m_properNamespace(false)
2090 m_livebox = ConfigParserData::LiveboxInfo();
2093 ElementParserPtr OnBoxLabelElement()
2095 return ElementParserPtr(new BoxLabelParser(m_livebox));
2098 ElementParserPtr OnBoxIconElement()
2100 return ElementParserPtr(new BoxIconParser(m_livebox));
2103 ElementParserPtr OnBoxContentElement()
2105 return ElementParserPtr(new BoxContentParser(m_livebox));
2109 ConfigParserData& m_data;
2110 ConfigParserData::LiveboxInfo m_livebox;
2111 DPL::String m_liveboxId;
2112 DPL::String m_primary;
2113 DPL::String m_autoLaunch;
2114 DPL::String m_updatePeriod;
2116 bool m_properNamespace;
2119 class CspParser : public ElementParser
2122 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2123 const DPL::String& /*name*/)
2125 return &IgnoringParser::Create;
2128 CspParser(ConfigParserData& data) :
2131 m_properNamespace(false)
2134 virtual void Accept(const Element& element)
2136 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2137 m_properNamespace = true;
2141 virtual void Accept(const XmlAttribute& /*attribute*/)
2144 virtual void Accept(const Text& text)
2146 if (m_properNamespace) {
2147 m_policy = text.value;
2151 virtual void Verify()
2153 if (!m_policy.IsNull()) {
2154 m_data.cspPolicy = *m_policy;
2159 ConfigParserData& m_data;
2160 bool m_properNamespace;
2161 DPL::OptionalString m_policy;
2164 ElementParser::ActionFunc WidgetParser::GetElementParser(
2165 const DPL::String& /*ns*/,
2169 FuncMap::const_iterator it = m_map.find(name);
2170 if (it != m_map.end()) {
2173 return &IgnoringParser::Create;
2177 WidgetParser::WidgetParser(ConfigParserData& data) :
2179 m_textDirection(Unicode::EMPTY)
2181 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2182 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2183 m_map[L"description"] =
2184 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2185 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2187 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2188 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2190 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2192 DPL::MakeDelegate(this, &WidgetParser::OnFeatureElement);
2193 m_map[L"preference"] =
2194 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2195 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2197 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2198 // TODO: appservice will be removed
2199 m_map[L"appservice"] = DPL::MakeDelegate(this,
2200 &WidgetParser::OnAppServiceElement);
2201 m_map[L"application"] = DPL::MakeDelegate(
2204 OnApplicationElement);
2205 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2206 m_map[L"background"] = DPL::MakeDelegate(this,
2207 &WidgetParser::OnBackgroundElement);
2208 m_map[L"privilege"] = DPL::MakeDelegate(this,
2209 &WidgetParser::OnPrivilegeElement);
2210 m_map[L"app-control"] = DPL::MakeDelegate(
2213 OnAppControlElement);
2214 m_map[L"category"] = DPL::MakeDelegate(this,
2215 &WidgetParser::OnCategoryElement);
2216 m_map[L"livebox"] = DPL::MakeDelegate(this, &WidgetParser::OnLiveboxElement);
2218 m_map[L"Content-Security-Policy"] = DPL::MakeDelegate(
2225 ElementParserPtr WidgetParser::OnNameElement()
2227 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2230 ElementParserPtr WidgetParser::OnAccessElement()
2232 return ElementParserPtr(new AccessParser(m_data));
2235 ElementParserPtr WidgetParser::OnDescriptionElement()
2237 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2240 ElementParserPtr WidgetParser::OnAuthorElement()
2242 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2245 ElementParserPtr WidgetParser::OnLicenseElement()
2247 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2250 ElementParserPtr WidgetParser::OnIconElement()
2252 return ElementParserPtr(new IconParser(m_data));
2255 ElementParserPtr WidgetParser::OnContentElement()
2257 return ElementParserPtr(new ContentParser(m_data));
2260 ElementParserPtr WidgetParser::OnFeatureElement()
2262 return ElementParserPtr(new FeatureParser(m_data));
2265 ElementParserPtr WidgetParser::OnPreferenceElement()
2267 return ElementParserPtr(new PreferenceParser(m_data));
2270 ElementParserPtr WidgetParser::OnLinkElement()
2272 return ElementParserPtr(new LinkParser(m_data));
2275 ElementParserPtr WidgetParser::OnSettingElement()
2277 return ElementParserPtr(new SettingParser(m_data));
2280 ElementParserPtr WidgetParser::OnApplicationElement()
2282 return ElementParserPtr(new ApplicationParser(m_data));
2285 ElementParserPtr WidgetParser::OnSplashElement()
2287 return ElementParserPtr(new SplashParser(m_data));
2290 ElementParserPtr WidgetParser::OnBackgroundElement()
2292 return ElementParserPtr(new BackgroundParser(m_data));
2295 ElementParserPtr WidgetParser::OnPrivilegeElement()
2297 return ElementParserPtr(new PrivilegeParser(m_data));
2300 ElementParserPtr WidgetParser::OnAppServiceElement()
2302 return ElementParserPtr(new AppServiceParser(m_data));
2305 ElementParserPtr WidgetParser::OnAppControlElement()
2307 return ElementParserPtr(new AppControlParser(m_data));
2310 ElementParserPtr WidgetParser::OnCategoryElement()
2312 return ElementParserPtr(new CategoryParser(m_data));
2315 ElementParserPtr WidgetParser::OnLiveboxElement()
2317 return ElementParserPtr(new LiveboxParser(m_data));
2320 ElementParserPtr WidgetParser::OnCspElement()
2322 return ElementParserPtr(new CspParser(m_data));
2325 void WidgetParser::Accept(const Element& element)
2327 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2328 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2330 ThrowMsg(Exception::ParseError,
2331 "Wrong xml namespace for widget element");
2335 void WidgetParser::Accept(const Text& /*text*/)
2337 ThrowMsg(Exception::ParseError, "widged element must be empty");
2340 void WidgetParser::Accept(const XmlAttribute& attribute)
2342 if (attribute.name == L"id") {
2343 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2344 //If may important tests starts to fail this test we will have
2345 //to consider commenting this test out again.
2346 if (iri.Validate()) {
2347 m_data.widget_id = attribute.value;
2348 NormalizeString(m_data.widget_id);
2350 LogWarning("Widget id validation failed: " << attribute.value);
2352 } else if (attribute.name == L"version") {
2353 m_version = attribute.value;
2354 NormalizeString(m_version);
2355 } else if (attribute.name == L"min-version") {
2356 LogInfo("min-version attribute was found. Value: " << attribute.value);
2357 m_minVersion = attribute.value;
2358 NormalizeString(m_minVersion);
2359 m_data.minVersionRequired = m_minVersion;
2360 } else if (attribute.name == L"height") {
2361 DPL::OptionalString value = attribute.value;
2362 NormalizeString(value);
2363 std::string v = DPL::ToUTF8String(*value);
2366 unsigned char c = v.c_str()[0];
2367 if (c >= '0' && c <= '9') {
2369 for (size_t i = 0; i < v.size(); ++i) {
2371 if (c >= '0' && c <= '9') {
2378 m_data.height = val;
2381 } else if (attribute.name == L"width") {
2382 DPL::OptionalString value = attribute.value;
2383 NormalizeString(value);
2384 std::string v = DPL::ToUTF8String(*value);
2387 unsigned char c = v.c_str()[0];
2388 if (c >= '0' && c <= '9') {
2390 for (size_t i = 0; i < v.size(); ++i) {
2392 if (c >= '0' && c <= '9') {
2402 } else if (attribute.name == L"viewmodes") {
2403 DPL::Tokenize(attribute.value,
2405 std::inserter(m_windowModes,
2406 m_windowModes.end()),
2408 } else if (attribute.name == L"dir") {
2409 m_textDirection = Unicode::ParseDirAttribute(attribute);
2410 } else if (L"defaultlocale" == attribute.name) {
2411 if (!m_defaultlocale) {
2412 m_defaultlocale = attribute.value;
2413 NormalizeString(m_defaultlocale);
2414 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2415 DPL::ToUTF8String(*m_defaultlocale)))
2417 LogWarning("Language tag: " <<
2418 m_defaultlocale << " is not valid");
2419 m_defaultlocale = DPL::OptionalString::Null;
2421 LogDebug("Default Locale Found " << m_defaultlocale);
2424 LogWarning("Ignoring subsequent default locale");
2427 //Any other value consider as a namespace definition
2428 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2429 LogInfo("Namespace domain: " << attribute.name);
2430 LogInfo("Namespace value: " << attribute.value);
2431 m_nameSpaces[attribute.name] = attribute.value;
2433 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2434 ", name=" << attribute.name <<
2435 ", value=" << attribute.value);
2439 void WidgetParser::Verify()
2441 FOREACH(mode, m_windowModes) {
2442 if (L"windowed" == *mode || L"floating" == *mode ||
2443 L"fullscreen" == *mode || L"maximized" == *mode ||
2444 L"minimized" == *mode)
2446 m_data.windowModes.insert(*mode);
2449 if (!m_version.IsNull()) {
2450 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2451 m_data.version = m_version;
2453 m_data.defaultlocale = m_defaultlocale;
2454 FOREACH(ns, m_nameSpaces) {
2455 m_data.nameSpaces.insert(ns->second);