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>
40 #include <dpl/scoped_ptr.h>
47 using namespace WrtDB;
50 static const DPL::String UTF_LRE = L"\x0202a";
51 static const DPL::String UTF_LRO = L"\x0202d";
52 static const DPL::String UTF_RLE = L"\x0202b";
53 static const DPL::String UTF_RLO = L"\x0202e";
54 static const DPL::String UTF_PDF = L"\x0202c";
56 Direction ParseDirAttribute(const XmlAttribute& attribute)
58 Assert(L"dir" == attribute.name);
59 if (L"ltr" == attribute.value) {
61 } else if (L"rtl" == attribute.value) {
63 } else if (L"lro" == attribute.value) {
65 } else if (L"rlo" == attribute.value) {
68 LogWarning("dir attribute has wrong value:" << attribute.value);
73 void UpdateTextWithDirectionMark(Direction direction,
79 *text = UTF_RLO + *text + UTF_PDF;
82 *text = UTF_RLE + *text + UTF_PDF;
85 *text = UTF_LRE + *text + UTF_PDF;
88 *text = UTF_LRO + *text + UTF_PDF;
97 } // namespace Unicode
99 class InnerElementsParser : public ElementParser
102 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
103 const DPL::String& /*name*/)
105 return DPL::MakeDelegate(this, &InnerElementsParser::Other);
108 virtual void Accept(const Element& /*element*/)
111 virtual void Accept(const Text& text)
113 if (m_text.IsNull()) {
116 m_text->value += text.value;
120 virtual void Accept(const XmlAttribute& attribute)
122 if (attribute.name == L"dir") {
123 m_textDirection = Unicode::ParseDirAttribute(attribute);
127 virtual void Verify()
129 if (!m_text.IsNull()) {
130 Unicode::UpdateTextWithDirectionMark(m_textDirection,
132 m_parentParser->Accept(*m_text);
136 InnerElementsParser(ElementParserPtr parent) :
137 m_parentParser(parent),
138 m_textDirection(Unicode::EMPTY)
141 ElementParserPtr Other()
143 return ElementParserPtr(new InnerElementsParser(
144 std::static_pointer_cast<ElementParser>(
145 shared_from_this())));
149 DPL::Optional<Text> m_text;
150 ElementParserPtr m_parentParser;
151 Unicode::Direction m_textDirection;
154 class NameParser : public ElementParser
157 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
158 const DPL::String& /*name*/)
160 return DPL::MakeDelegate(this, &NameParser::Other);
163 virtual void Accept(const Element& element)
165 m_lang = element.lang;
169 virtual void Accept(const Text& text)
171 if (m_name.IsNull()) {
174 *m_name += text.value;
178 virtual void Accept(const XmlAttribute& attribute)
180 if (attribute.name == L"short") {
181 if (m_shortName.IsNull()) {
182 m_shortName = attribute.value;
184 } else if (attribute.name == L"dir") {
185 m_textDirection = Unicode::ParseDirAttribute(attribute);
189 virtual void Verify()
191 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
192 if (data.name.IsNull()) {
193 NormalizeString(m_name);
194 NormalizeString(m_shortName);
195 if (!m_name.IsNull()) {
196 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
199 if (!m_shortName.IsNull()) {
200 Unicode::UpdateTextWithDirectionMark(m_textDirection,
203 data.shortName = m_shortName;
207 NameParser(Unicode::Direction direction,
208 ConfigParserData& data) :
210 m_textDirection(direction)
213 ElementParserPtr Other()
215 return ElementParserPtr(new InnerElementsParser(
216 std::static_pointer_cast<ElementParser>(
217 shared_from_this())));
221 ConfigParserData& m_data;
222 DPL::OptionalString m_name;
223 DPL::OptionalString m_shortName;
224 DPL::OptionalString m_dir;
226 Unicode::Direction m_textDirection;
229 class AccessParser : public ElementParser
238 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
239 const DPL::String& /*name*/)
241 return DPL::MakeDelegate(this, &AccessParser::Other);
244 virtual void Accept(const Element& element)
246 // for tizen web apps WARP should be used
247 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
248 element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
250 m_standardType = STANDARD_TYPE_WARP;
254 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.");
289 iri.set(m_strIRIOrigin, false);
291 if (!iri.isAccessDefinition()) {
292 LogWarning("Access list element: " <<
294 " is not acceptable by WARP" <<
295 "standard and will be ignored!");
299 if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains
301 m_bSubDomainAccess = true;
304 ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
306 //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
307 m_data.accessInfoSet.insert(accessInfo);
310 virtual void Verify()
312 switch (m_standardType) {
313 case STANDARD_TYPE_WARP:
317 LogError("Error in Access tag - unknown standard.");
322 AccessParser(ConfigParserData& data) :
324 m_bSubDomainAccess(false),
325 m_standardType(STANDARD_TYPE_NONE),
330 ElementParserPtr Other()
332 return ElementParserPtr(new InnerElementsParser(
333 ElementParserPtr(shared_from_this())));
337 DPL::String m_strIRIOrigin;
338 bool m_bSubDomainAccess;
339 StandardType m_standardType;
341 ConfigParserData& m_data;
344 class DescriptionParser : public ElementParser
347 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
348 const DPL::String& /*name*/)
350 return DPL::MakeDelegate(this, &DescriptionParser::Other);
353 virtual void Accept(const Element& element)
355 m_lang = element.lang;
359 ElementParserPtr Other()
361 return ElementParserPtr(new InnerElementsParser(
362 std::static_pointer_cast<ElementParser>(
363 shared_from_this())));
366 virtual void Accept(const Text& text)
368 if (m_description.IsNull()) {
369 m_description = text.value;
371 *m_description += text.value;
375 virtual void Accept(const XmlAttribute& attribute)
377 if (attribute.name == L"dir") {
378 m_textDirection = Unicode::ParseDirAttribute(attribute);
382 virtual void Verify()
384 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
385 if (data.description.IsNull()) {
386 if (!m_description.IsNull()) {
387 Unicode::UpdateTextWithDirectionMark(m_textDirection,
390 data.description = m_description;
394 DescriptionParser(Unicode::Direction direction,
395 ConfigParserData& data) :
399 m_textDirection(direction)
403 ConfigParserData& m_data;
405 DPL::OptionalString m_description;
406 Unicode::Direction m_textDirection;
409 class AuthorParser : public ElementParser
412 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
413 const DPL::String& /*name*/)
415 return DPL::MakeDelegate(this, &AuthorParser::Other);
418 AuthorParser(Unicode::Direction direction,
419 ConfigParserData& data) :
421 m_textDirection(direction)
424 virtual void Accept(const Element& /*element*/)
429 virtual void Accept(const Text& text)
431 *(m_authorName) += text.value;
434 virtual void Accept(const XmlAttribute& attribute)
436 if (attribute.name == L"href") {
437 //Validate href IRI and ignore it if invalid
438 //See also test: ta-argMozRiC-an
439 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
440 if (iri.Validate()) {
441 m_authorHref = attribute.value;
443 } else if (attribute.name == L"email") {
444 m_authorEmail = attribute.value;
445 } else if (attribute.name == L"dir") {
446 m_textDirection = Unicode::ParseDirAttribute(attribute);
450 virtual void Verify()
452 if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
453 NormalizeString(m_authorName);
454 NormalizeString(m_authorHref);
455 NormalizeString(m_authorEmail);
456 if (!!m_authorName) {
457 Unicode::UpdateTextWithDirectionMark(m_textDirection,
459 m_data.authorName = m_authorName;
461 if (!!m_authorHref) {
462 m_data.authorHref = m_authorHref;
464 if (!!m_authorEmail) {
465 m_data.authorEmail = m_authorEmail;
470 ElementParserPtr Other()
472 return ElementParserPtr(new InnerElementsParser(
473 std::static_pointer_cast<ElementParser>(
474 shared_from_this())));
478 ConfigParserData& m_data;
479 DPL::OptionalString m_authorEmail;
480 DPL::OptionalString m_authorHref;
481 DPL::OptionalString m_authorName;
482 Unicode::Direction m_textDirection;
485 class LicenseParser : public ElementParser
488 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
489 const DPL::String& /*name*/)
491 return DPL::MakeDelegate(this, &LicenseParser::Other);
494 LicenseParser(Unicode::Direction direction,
495 ConfigParserData& data) :
498 m_textDirection(direction)
501 virtual void Accept(const Element& element)
503 if (m_license.IsNull()) {
504 m_lang = element.lang;
510 virtual void Accept(const Text& text)
513 *m_license += text.value;
517 virtual void Accept(const XmlAttribute& attribute)
520 if (attribute.name == L"href" && m_licenseHref.IsNull()) {
521 m_licenseHref = attribute.value;
522 } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
523 m_licenseFile = attribute.value;
524 } else if (attribute.name == L"dir") {
525 m_textDirection = Unicode::ParseDirAttribute(attribute);
530 virtual void Verify()
532 ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
533 if (data.license.IsNull()) {
534 if (!m_license.IsNull()) {
535 Unicode::UpdateTextWithDirectionMark(m_textDirection,
538 data.license = m_license;
539 data.licenseHref = m_licenseHref;
540 data.licenseFile = m_licenseFile;
544 ElementParserPtr Other()
546 return ElementParserPtr(new InnerElementsParser(
547 ElementParserPtr(shared_from_this())));
551 ConfigParserData& m_data;
555 DPL::OptionalString m_license;
556 DPL::OptionalString m_licenseFile;
557 DPL::OptionalString m_licenseHref;
558 Unicode::Direction m_textDirection;
561 class IconParser : public ElementParser
563 DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
566 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
567 const DPL::String& /*name*/)
569 return &IgnoringParser::Create;
572 IconParser(ConfigParserData& data) : ElementParser(),
576 virtual void Accept(const Element& /*element*/)
579 virtual void Accept(const XmlAttribute& attribute)
581 if (attribute.name == L"src") {
582 if (attribute.value.size() > 0) {
583 m_src = attribute.value;
585 } else if (attribute.name == L"width") {
586 m_width = ParseSizeAttributeValue(attribute.value);
587 } else if (attribute.name == L"height") {
588 m_height = ParseSizeAttributeValue(attribute.value);
592 virtual void Accept(const Text& /*text*/)
594 ThrowMsg(Exception::ParseError, "Icon element must be empty");
597 virtual void Verify()
599 if (m_src.IsNull()) {
600 LogWarning("src attribute of icon element is mandatory - ignoring");
606 ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
607 icon.width = m_width;
608 icon.height = m_height;
610 ConfigParserData::IconsList::iterator it = std::find(
611 m_data.iconsList.begin(), m_data.iconsList.end(), icon);
612 if (it == m_data.iconsList.end()) {
613 m_data.iconsList.push_front(icon);
618 LogWarning("src attribute is invalid: " << m_src);
623 ConfigParserData& m_data;
624 DPL::OptionalString m_src;
625 DPL::OptionalInt m_width;
626 DPL::OptionalInt m_height;
628 static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
630 DPL::OptionalString normalizedValue = value;
631 NormalizeString(normalizedValue);
632 if (!(*normalizedValue).empty()) {
636 strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
638 std::string(reterr) == DPL::ToUTF8String(value) ||
641 return DPL::OptionalInt::Null;
646 return DPL::OptionalInt::Null;
650 * @brief delocalizePath removes locales folder from relative path if
652 * @param source source string
654 * @throw BadSrcError if string is bad value of src attribute
656 * @return corrected string
658 static DPL::String delocalizeSrcPath(const DPL::String & source)
660 static const DPL::String localeFolder(L"locales/");
661 static const int index = localeFolder.size();
663 DPL::String result = source;
665 if (source.substr(0, index) == localeFolder) {
666 size_t pos = result.find_first_of('/', index);
667 if (pos != std::string::npos && pos + 1 < source.size()) {
668 result = result.substr(pos + 1, source.size());
677 class ContentParser : public ElementParser
680 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
681 const DPL::String& /*name*/)
683 return &IgnoringParser::Create;
686 ContentParser(ConfigParserData& data) :
691 virtual void Accept(const Element& /*element*/)
694 virtual void Accept(const Text& /*text*/)
697 virtual void Accept(const XmlAttribute& attribute)
699 DPL::String value = attribute.value;
700 NormalizeString(value);
702 if (attribute.name == L"src") {
704 } else if (attribute.name == L"type") {
706 MimeTypeUtils::MimeAttributes mimeAttributes =
707 MimeTypeUtils::getMimeAttributes(value);
708 if ((mimeAttributes.count(L"charset") > 0) && m_encoding.IsNull())
710 m_encoding = mimeAttributes[L"charset"];
712 } else if (attribute.name == L"encoding") {
713 if (!value.empty()) {
719 virtual void Verify()
721 if (m_data.startFileEncountered) {
722 LogWarning("This is not the first encountered "
723 "'content' element - ignoring.");
727 m_data.startFileEncountered = true;
729 //we're consciously setting startFile even if m_src is null or invalid.
730 //WidgetConfigurationManager will deal with this.
731 m_data.startFile = m_src;
734 m_data.startFileContentType = m_type;
736 m_data.startFileEncoding = m_encoding;
738 m_data.startFileEncoding = L"UTF-8";
744 DPL::OptionalString m_src;
745 DPL::OptionalString m_type;
746 DPL::OptionalString m_encoding;
747 ConfigParserData& m_data;
750 class PreferenceParser : public ElementParser
753 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
754 const DPL::String& /*name*/)
756 return &IgnoringParser::Create;
759 virtual void Accept(const XmlAttribute& attribute)
761 if (attribute.name == L"name") {
762 m_name = attribute.value;
763 } else if (attribute.name == L"value") {
764 m_value = attribute.value;
765 } else if (attribute.name == L"readonly") {
766 if (attribute.value == L"true") {
774 virtual void Accept(const Element& /*element*/)
777 virtual void Accept(const Text& /*text*/)
779 ThrowMsg(Exception::ParseError, "param element must be empty");
782 virtual void Verify()
784 if (m_name.IsNull()) {
785 LogWarning("preference element must have name attribute");
788 NormalizeString(m_name);
789 NormalizeString(m_value);
790 ConfigParserData::Preference preference(*m_name, m_required);
791 preference.value = m_value;
792 if (m_data.preferencesList.find(preference) ==
793 m_data.preferencesList.end())
795 m_data.preferencesList.insert(preference);
799 PreferenceParser(ConfigParserData& data) :
806 DPL::OptionalString m_name;
807 DPL::OptionalString m_value;
809 ConfigParserData& m_data;
812 class LinkParser : public ElementParser
815 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
816 const DPL::String& /*name*/)
818 return &DenyAllParser::Create;
821 virtual void Accept(const XmlAttribute& attribute)
823 if (m_properNamespace) {
824 LogDebug("attribute");
825 if (attribute.name == L"rel") {
826 if (attribute.value != L"describedby") {
827 ThrowMsg(Exception::ParseError,
828 "rel attribute must have describedby value");
830 } else if (attribute.name == L"type") {} else if (attribute.name ==
833 LogDebug("here is href");
834 m_href = attribute.value;
836 ThrowMsg(Exception::ParseError,
837 "unknown attribute '" +
838 DPL::ToUTF8String(attribute.name) +
839 "' in link element");
844 virtual void Accept(const Element& element)
847 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement)
849 m_properNamespace = true;
854 virtual void Accept(const Text&)
856 if (m_properNamespace) {
858 ThrowMsg(Exception::ParseError, "link element must be empty");
862 virtual void Verify()
865 ThrowMsg(Exception::ParseError,
866 "link element must have href attribute");
869 LibIri::Wrapper iri(DPL::ToUTF8String(*m_href).c_str());
870 if (!iri.Validate()) { // TODO: Better uri validator ?
871 ThrowMsg(Exception::ParseError,
872 "href attribute must be a valid iri/uri/url");
876 LinkParser(ConfigParserData& data) :
878 m_properNamespace(false),
880 m_href(DPL::OptionalString::Null)
884 bool m_properNamespace;
885 ConfigParserData& m_data;
886 DPL::OptionalString m_href;
889 class SettingParser : public ElementParser
892 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
893 const DPL::String& /*name*/)
895 return &IgnoringParser::Create;
898 virtual void Accept(const Text& /*text*/)
901 virtual void Accept(const Element& /*element*/)
904 virtual void Accept(const XmlAttribute& attribute)
906 m_setting.m_name = attribute.name;
907 m_setting.m_value = attribute.value;
908 m_data.settingsList.insert(m_setting);
911 virtual void Verify()
914 SettingParser(ConfigParserData& data) :
921 ConfigParserData& m_data;
922 ConfigParserData::Setting m_setting;
925 class AppControlParser : public ElementParser
928 struct SourceParser : public ElementParser
931 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
932 const DPL::String& /*name*/)
934 return &IgnoringParser::Create;
937 virtual void Accept(const Text& /*text*/)
940 virtual void Accept(const Element& /*element*/)
943 virtual void Accept(const XmlAttribute& attribute)
945 if (attribute.name == L"name") {
946 if (attribute.value.size() > 0) {
947 m_value = attribute.value;
948 NormalizeString(m_value);
953 virtual void Verify()
955 if (m_value.IsNull() || *m_value == L"") {
959 m_data.m_src = *m_value;
962 SourceParser(ConfigParserData::AppControlInfo& data) :
964 m_properNamespace(false),
969 bool m_properNamespace;
970 DPL::OptionalString m_value;
971 ConfigParserData::AppControlInfo& m_data;
974 struct OperationParser : public ElementParser
977 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
978 const DPL::String& /*name*/)
980 return &IgnoringParser::Create;
983 virtual void Accept(const Text& /*text*/)
986 virtual void Accept(const Element& /*element*/)
989 virtual void Accept(const XmlAttribute& attribute)
991 if (attribute.name == L"name") {
992 if (attribute.value.size() > 0) {
993 m_value = attribute.value;
994 NormalizeString(m_value);
999 virtual void Verify()
1001 if (m_value.IsNull() || *m_value == L"") {
1005 m_data.m_operation = *m_value;
1008 OperationParser(ConfigParserData::AppControlInfo& data) :
1010 m_properNamespace(false),
1015 bool m_properNamespace;
1016 DPL::OptionalString m_value;
1017 ConfigParserData::AppControlInfo& m_data;
1020 struct UriParser : public ElementParser
1023 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1024 const DPL::String& /*name*/)
1026 return &IgnoringParser::Create;
1029 virtual void Accept(const Text& /*text*/)
1032 virtual void Accept(const Element& /*element*/)
1035 virtual void Accept(const XmlAttribute& attribute)
1037 if (attribute.name == L"name") {
1038 if (attribute.value.size() > 0) {
1039 m_value = attribute.value;
1040 NormalizeString(m_value);
1045 virtual void Verify()
1048 DPL::String ignoreUri(L"file");
1050 if (!m_value.IsNull() && *m_value == ignoreUri)
1052 LogInfo("exception : '" << *m_value << "' scheme will be ignored.");
1053 m_value = DPL::OptionalString::Null;
1056 if (m_value.IsNull() || *m_value == L"") {
1060 DPL::String wildString(L"*/*");
1061 if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
1062 && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
1064 m_data.m_uriList.insert(*m_value);
1066 LogDebug("Ignoring uri with name" <<
1067 DPL::ToUTF8String(*m_value));
1071 UriParser(ConfigParserData::AppControlInfo& data) :
1073 m_properNamespace(false),
1078 bool m_properNamespace;
1079 DPL::OptionalString m_value;
1080 ConfigParserData::AppControlInfo& m_data;
1083 struct MimeParser : public ElementParser
1086 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1087 const DPL::String& /*name*/)
1089 return &IgnoringParser::Create;
1092 virtual void Accept(const Text& /*text*/)
1095 virtual void Accept(const Element& /*element*/)
1098 virtual void Accept(const XmlAttribute& attribute)
1100 if (attribute.name == L"name") {
1101 if (attribute.value.size() > 0) {
1102 m_value = attribute.value;
1103 NormalizeString(m_value);
1108 virtual void Verify()
1110 if (m_value.IsNull() || *m_value == L"") {
1114 DPL::String wildString(L"*/*");
1115 if ((m_data.m_mimeList.find(wildString) ==
1116 m_data.m_mimeList.end())
1117 && (m_data.m_mimeList.find(*m_value) ==
1118 m_data.m_mimeList.end()))
1120 m_data.m_mimeList.insert(*m_value);
1122 LogDebug("Ignoring mime with name" <<
1123 DPL::ToUTF8String(*m_value));
1127 MimeParser(ConfigParserData::AppControlInfo& data) :
1129 m_properNamespace(false),
1134 bool m_properNamespace;
1135 DPL::OptionalString m_value;
1136 ConfigParserData::AppControlInfo& m_data;
1139 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1140 const DPL::String& name)
1142 if (name == L"src") {
1143 return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
1144 } else if (name == L"operation") {
1145 return DPL::MakeDelegate(this,
1146 &AppControlParser::OnOperationElement);
1147 } else if (name == L"uri") {
1148 return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
1149 } else if (name == L"mime") {
1150 return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
1152 return &IgnoringParser::Create;
1156 virtual void Accept(const XmlAttribute& /*attribute*/)
1159 virtual void Accept(const Element& element)
1161 LogWarning("namespace for app service = " << element.ns);
1162 if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
1163 ThrowMsg(Exception::ParseError,
1164 "Wrong xml namespace for widget element");
1168 virtual void Accept(const Text& /*text*/)
1170 ThrowMsg(Exception::ParseError, "param element must be empty");
1173 virtual void Verify()
1175 if (m_appControl.m_src == L"") {
1176 LogWarning("service element must have src element");
1180 if (m_appControl.m_operation == L"") {
1181 LogWarning("service element must have operation element");
1185 m_data.appControlList.push_back(m_appControl);
1188 ElementParserPtr OnSourceElement()
1190 return ElementParserPtr(new SourceParser(m_appControl));
1193 ElementParserPtr OnOperationElement()
1195 return ElementParserPtr(new OperationParser(m_appControl));
1198 ElementParserPtr OnUriElement()
1200 return ElementParserPtr(new UriParser(m_appControl));
1203 ElementParserPtr OnMimeElement()
1205 return ElementParserPtr(new MimeParser(m_appControl));
1208 AppControlParser(ConfigParserData& data) :
1215 ConfigParserData& m_data;
1216 ConfigParserData::AppControlInfo m_appControl;
1219 class ApplicationParser : 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*/)
1230 if (m_properNamespace) {
1232 ThrowMsg(Exception::ParseError, "application element must be empty");
1236 virtual void Accept(const Element& element)
1239 ConfigurationNamespace::TizenWebAppNamespaceName)
1241 m_properNamespace = true;
1243 LogDebug("element");
1246 virtual void Accept(const XmlAttribute& attribute)
1248 if (m_properNamespace) {
1249 LogDebug("attribute");
1250 if (attribute.name == L"id") {
1251 m_id = attribute.value;
1252 NormalizeAndTrimSpaceString(m_id);
1253 } else if (attribute.name == L"package") {
1254 m_package = attribute.value;
1255 } else if (attribute.name == L"required_version") {
1256 m_version = attribute.value;
1257 NormalizeString(m_version);
1259 ThrowMsg(Exception::ParseError,
1260 "unknown attribute '" +
1261 DPL::ToUTF8String(attribute.name) +
1262 "' in application element");
1267 virtual void Verify()
1269 VerifyIdAndPackage();
1273 ApplicationParser(ConfigParserData& data) :
1276 m_id(DPL::OptionalString::Null),
1277 m_version(DPL::OptionalString::Null),
1278 m_properNamespace(false)
1282 void VerifyIdAndPackage()
1286 ThrowMsg(Exception::ParseError,
1287 "application element must have package attribute");
1291 pcrecpp::RE re(REGEXP_PACKAGE);
1292 if (!re.FullMatch(DPL::ToUTF8String(*m_package)))
1294 ThrowMsg(Exception::ParseError,
1295 "invalid format of package attribute");
1300 ThrowMsg(Exception::ParseError,
1301 "application element must have id attribute");
1305 std::string package;
1306 pcrecpp::RE re(REGEXP_ID);
1307 if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
1309 ThrowMsg(Exception::ParseError,
1310 "invalid format of id attribute");
1312 if (package != DPL::ToUTF8String(*m_package))
1314 ThrowMsg(Exception::ParseError,
1315 "invalid package prefix in id attribute");
1319 m_data.tizenAppId = m_id;
1320 m_data.tizenPkgId = m_package;
1323 void VerifyVersion()
1327 ThrowMsg(Exception::ParseError,
1328 "application element must have required_version attribute");
1332 pcrecpp::RE re(REGEXP_VERSION);
1333 if (!re.FullMatch(DPL::ToUTF8String(*m_version)))
1335 ThrowMsg(Exception::ParseError,
1336 "invalid format of version attribute");
1340 m_data.tizenMinVersionRequired = m_version;
1343 static const char* const REGEXP_PACKAGE;
1344 static const char* const REGEXP_ID;
1345 static const char* const REGEXP_VERSION;
1347 ConfigParserData& m_data;
1348 DPL::OptionalString m_id;
1349 DPL::OptionalString m_package;
1350 DPL::OptionalString m_version;
1351 bool m_properNamespace;
1354 const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}";
1355 const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\.[0-9A-Za-z]{1,52}";
1356 const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?";
1358 class SplashParser : public ElementParser
1361 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1362 const DPL::String& /*name*/)
1364 return &IgnoringParser::Create;
1367 virtual void Accept(const XmlAttribute& attribute)
1369 if (attribute.name == L"src") {
1370 if (attribute.value.size() > 0) {
1371 m_src = attribute.value;
1376 virtual void Accept(const Element& /*element*/)
1379 virtual void Accept(const Text& /*text*/)
1382 virtual void Verify()
1384 if (m_src.IsNull()) {
1386 "src attribute of splash element is mandatory - ignoring");
1390 m_data.splashImgSrc = m_src;
1393 SplashParser(ConfigParserData& data) :
1399 DPL::OptionalString m_src;
1400 ConfigParserData& m_data;
1403 class BackgroundParser : public ElementParser
1406 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1407 const DPL::String& /*name*/)
1409 return &IgnoringParser::Create;
1412 virtual void Accept(const XmlAttribute& attribute)
1414 if (attribute.name == L"src") {
1415 if (attribute.value.size() > 0) {
1416 m_src = attribute.value;
1421 virtual void Accept(const Element& /*element*/)
1424 virtual void Accept(const Text& /*text*/)
1427 virtual void Verify()
1429 if (m_src.IsNull()) {
1431 "src attribute of background element is mandatory - ignoring");
1435 m_data.backgroundPage = m_src;
1438 explicit BackgroundParser(ConfigParserData& data) :
1443 DPL::OptionalString m_src;
1444 ConfigParserData& m_data;
1447 class PrivilegeParser : public ElementParser
1450 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1451 const DPL::String& /*name*/)
1453 return &IgnoringParser::Create;
1456 virtual void Accept(const Text& /*text*/)
1459 virtual void Accept(const Element& element)
1462 ConfigurationNamespace::TizenWebAppNamespaceName)
1464 m_properNamespace = true;
1466 LogDebug("element");
1469 virtual void Accept(const XmlAttribute& attribute)
1471 if (m_properNamespace) {
1472 if (attribute.name == L"name") {
1473 m_feature.name = attribute.value;
1474 m_privilege.name = attribute.value;
1479 virtual void Verify()
1481 LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
1483 if (m_feature.name != L"") {
1484 if (iri.Validate()) {
1485 if (m_data.featuresList.find(m_feature) ==
1486 m_data.featuresList.end())
1488 m_data.featuresList.insert(m_feature);
1490 LogDebug("Ignoring feature with name" <<
1491 DPL::ToUTF8String(m_feature.name));
1496 LibIri::Wrapper iriPrivilege(
1497 DPL::ToUTF8String(m_privilege.name).c_str());
1499 if (m_privilege.name != L"") {
1500 if (iriPrivilege.Validate()) {
1501 if (m_data.privilegeList.find(m_privilege) ==
1502 m_data.privilegeList.end())
1504 m_data.privilegeList.insert(m_privilege);
1506 LogDebug("Ignoring privilege with name" <<
1507 DPL::ToUTF8String(m_privilege.name));
1513 PrivilegeParser(ConfigParserData& data) :
1518 m_properNamespace(false)
1522 ConfigParserData& m_data;
1523 ConfigParserData::Feature m_feature;
1524 ConfigParserData::Privilege m_privilege;
1525 bool m_properNamespace;
1528 class CategoryParser : public ElementParser
1531 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1532 const DPL::String& /*name*/)
1534 return &IgnoringParser::Create;
1537 virtual void Accept(const XmlAttribute& attribute)
1539 if (attribute.name == L"name") {
1540 if (attribute.value.size() > 0) {
1541 m_name = attribute.value;
1546 virtual void Accept(const Element& /*element*/)
1549 virtual void Accept(const Text& /*text*/)
1552 virtual void Verify()
1554 if (m_name.IsNull()) {
1556 "name attribute of category element is mandatory - ignoring");
1560 if (m_data.categoryList.find(*m_name) ==
1561 m_data.categoryList.end())
1563 m_data.categoryList.insert(*m_name);
1567 explicit CategoryParser(ConfigParserData& data) :
1572 DPL::OptionalString m_name;
1573 ConfigParserData& m_data;
1576 class AppWidgetParser : public ElementParser
1580 struct BoxLabelParser : 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*/)
1591 virtual void Accept(const Element& element)
1594 ConfigurationNamespace::TizenWebAppNamespaceName)
1596 m_properNamespace = true;
1600 virtual void Accept(const Text& text)
1602 if (m_properNamespace) {
1603 m_label = text.value;
1607 virtual void Verify()
1609 m_data.m_label = m_label;
1612 BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
1614 m_properNamespace(false),
1619 DPL::String m_label;
1620 bool m_properNamespace;
1621 ConfigParserData::LiveboxInfo& m_data;
1624 struct BoxIconParser : public ElementParser
1626 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1627 const DPL::String& /*name*/)
1629 return &IgnoringParser::Create;
1632 virtual void Accept(const XmlAttribute& attribute)
1634 if (m_properNamespace) {
1635 if (attribute.name == L"src") {
1636 m_icon = attribute.value;
1641 virtual void Accept(const Element& element)
1644 ConfigurationNamespace::TizenWebAppNamespaceName)
1646 m_properNamespace = true;
1650 virtual void Accept(const Text& /*text*/)
1653 virtual void Verify()
1655 m_data.m_icon = m_icon;
1658 explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
1660 m_properNamespace(false),
1666 bool m_properNamespace;
1667 ConfigParserData::LiveboxInfo& m_data;
1670 struct BoxContentParser : public ElementParser
1672 struct BoxSizeParser : public ElementParser
1674 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1675 const DPL::String& /*name*/)
1677 return &IgnoringParser::Create;
1680 virtual void Accept(const XmlAttribute& attribute)
1682 if (m_properNamespace) {
1683 if (attribute.name == L"preview") {
1684 m_preview = attribute.value;
1689 virtual void Accept(const Element& element)
1692 ConfigurationNamespace::TizenWebAppNamespaceName)
1694 m_properNamespace = true;
1698 virtual void Accept(const Text& text)
1700 if (m_properNamespace) {
1701 m_size = text.value;
1705 virtual void Verify()
1707 std::pair<DPL::String, DPL::String> boxSize;
1708 boxSize.first = m_size;
1709 boxSize.second = m_preview;
1710 m_data.m_boxSize.push_back(boxSize);
1713 explicit BoxSizeParser(
1714 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1716 m_properNamespace(false),
1722 DPL::String m_preview;
1723 bool m_properNamespace;
1724 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1727 struct PdParser : public ElementParser
1729 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1730 const DPL::String& /*name*/)
1732 return &IgnoringParser::Create;
1735 virtual void Accept(const XmlAttribute& attribute)
1737 if (m_properNamespace) {
1738 if (attribute.name == L"src") {
1739 m_src = attribute.value;
1740 } else if (attribute.name == L"width") {
1741 m_width = attribute.value;
1742 } else if (attribute.name == L"height") {
1743 m_height = attribute.value;
1744 } else if (attribute.name == L"fast-open") {
1745 m_fastOpen= attribute.value;
1750 virtual void Accept(const Element& element)
1753 ConfigurationNamespace::TizenWebAppNamespaceName)
1755 m_properNamespace = true;
1759 virtual void Accept(const Text& /*text*/)
1762 virtual void Verify()
1764 m_data.m_pdSrc = m_src;
1765 m_data.m_pdWidth = m_width;
1766 m_data.m_pdHeight = m_height;
1767 m_data.m_pdFastOpen = m_fastOpen;
1771 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
1773 m_properNamespace(false),
1779 DPL::String m_width;
1780 DPL::String m_height;
1781 DPL::String m_fastOpen;
1783 bool m_properNamespace;
1784 ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
1787 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1788 const DPL::String& name)
1790 if (name == L"box-size") {
1791 return DPL::MakeDelegate(
1793 &AppWidgetParser::BoxContentParser::
1795 } else if (name == L"pd") {
1796 return DPL::MakeDelegate(
1798 &AppWidgetParser::BoxContentParser::
1801 ThrowMsg(Exception::ParseError,
1802 "No element parser for name: " << name);
1806 virtual void Accept(const XmlAttribute& attribute)
1808 if (m_properNamespace) {
1809 if (attribute.name == L"src") {
1810 m_box.m_boxSrc = attribute.value;
1812 if (attribute.name == L"mouse-event") {
1813 m_box.m_boxMouseEvent = attribute.value;
1815 if (attribute.name == L"touch-effect") {
1816 m_box.m_boxTouchEffect = attribute.value;
1821 virtual void Accept(const Element& element)
1824 ConfigurationNamespace::TizenWebAppNamespaceName)
1826 m_properNamespace = true;
1830 virtual void Accept(const Text& /*text*/)
1833 virtual void Verify()
1835 m_data.m_boxInfo = m_box;
1838 explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
1840 m_properNamespace(false),
1844 ElementParserPtr OnBoxSizeElement()
1846 return ElementParserPtr(new BoxSizeParser(m_box));
1849 ElementParserPtr OnPdElement()
1851 return ElementParserPtr(new PdParser(m_box));
1856 bool m_properNamespace;
1857 ConfigParserData::LiveboxInfo& m_data;
1858 ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
1861 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1862 const DPL::String& name)
1864 if (name == L"box-label") {
1865 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
1866 } else if (name == L"box-icon") {
1867 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
1868 } else if (name == L"box-content") {
1869 return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
1871 return &IgnoringParser::Create;
1875 virtual void Accept(const XmlAttribute& attribute)
1877 if (m_properNamespace) {
1878 if (attribute.name == L"id") {
1879 m_liveboxId = attribute.value;
1880 } else if (attribute.name == L"primary") {
1881 m_primary = attribute.value;
1882 } else if (attribute.name == L"auto-launch") {
1883 m_autoLaunch = attribute.value;
1884 } else if (attribute.name == L"update-period") {
1885 m_updatePeriod = attribute.value;
1886 } else if (attribute.name == L"type") {
1887 m_type = attribute.value;
1892 virtual void Accept(const Element& element)
1895 ConfigurationNamespace::TizenWebAppNamespaceName)
1897 m_properNamespace = true;
1901 virtual void Accept(const Text& /*text*/)
1904 virtual void Verify()
1906 m_livebox.m_liveboxId = m_liveboxId;
1907 m_livebox.m_primary = m_primary;
1908 m_livebox.m_autoLaunch = m_autoLaunch;
1909 m_livebox.m_updatePeriod = m_updatePeriod;
1910 m_livebox.m_type = m_type;
1912 m_data.m_livebox.push_back(m_livebox);
1915 explicit AppWidgetParser(ConfigParserData& data) :
1918 m_properNamespace(false)
1920 m_livebox = ConfigParserData::LiveboxInfo();
1923 ElementParserPtr OnBoxLabelElement()
1925 return ElementParserPtr(new BoxLabelParser(m_livebox));
1928 ElementParserPtr OnBoxIconElement()
1930 return ElementParserPtr(new BoxIconParser(m_livebox));
1933 ElementParserPtr OnBoxContentElement()
1935 return ElementParserPtr(new BoxContentParser(m_livebox));
1939 ConfigParserData& m_data;
1940 ConfigParserData::LiveboxInfo m_livebox;
1941 DPL::String m_liveboxId;
1942 DPL::String m_primary;
1943 DPL::String m_autoLaunch;
1944 DPL::String m_updatePeriod;
1946 bool m_properNamespace;
1949 class AllowNavigationParser : public ElementParser
1952 AllowNavigationParser(ConfigParserData& data) :
1955 m_properNamespace(false)
1958 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
1959 const DPL::String& /*name*/)
1961 return &IgnoringParser::Create;
1964 virtual void Accept(const Element& element)
1966 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
1967 m_properNamespace = true;
1971 virtual void Accept(const Text& text)
1973 if (m_properNamespace) {
1974 m_origin = text.value;
1978 virtual void Accept(const XmlAttribute& /*attribute*/)
1982 virtual void Verify()
1984 if (m_origin.IsNull()) {
1985 LogWarning("data is empty");
1989 char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
1990 char* ptr = strtok(data," ");
1991 while (ptr != NULL) {
1992 std::string origin = ptr;
1993 ptr = strtok(NULL," ");
1995 ConfigParserData::AllowNavigationInfo info(L"*", L"*");
1996 m_data.allowNavigationInfoList.push_back(info);
2000 DPL::ScopedPtr<iri_t> iri(iri_parse(origin.c_str()));
2001 if (!iri->host || strlen(iri->host) == 0) {
2002 // input origin should has schem and host
2003 // in case of file scheme path is filled
2005 LogWarning("input origin isn't verified");
2008 DPL::String scheme = L"*";
2009 if (iri->scheme && strlen(iri->scheme) != 0) {
2010 scheme = DPL::FromUTF8String(iri->scheme);
2012 ConfigParserData::AllowNavigationInfo info(
2014 DPL::FromUTF8String(iri->host));
2015 m_data.allowNavigationInfoList.push_back(info);
2021 DPL::OptionalString m_origin;
2022 ConfigParserData& m_data;
2023 bool m_properNamespace;
2026 class CspParser : public ElementParser
2029 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2030 const DPL::String& /*name*/)
2032 return &IgnoringParser::Create;
2035 CspParser(ConfigParserData& data) :
2038 m_properNamespace(false)
2041 virtual void Accept(const Element& element)
2043 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2044 m_properNamespace = true;
2048 virtual void Accept(const XmlAttribute& /*attribute*/)
2051 virtual void Accept(const Text& text)
2053 if (m_properNamespace) {
2054 m_policy = text.value;
2058 virtual void Verify()
2060 if (!m_policy.IsNull()) {
2061 m_data.cspPolicy = *m_policy;
2066 ConfigParserData& m_data;
2067 bool m_properNamespace;
2068 DPL::OptionalString m_policy;
2071 class CspReportOnlyParser : public ElementParser
2074 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2075 const DPL::String& /*name*/)
2077 return &IgnoringParser::Create;
2080 CspReportOnlyParser(ConfigParserData& data) :
2083 m_properNamespace(false)
2086 virtual void Accept(const Element& element)
2088 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2089 m_properNamespace = true;
2093 virtual void Accept(const XmlAttribute& /*attribute*/)
2096 virtual void Accept(const Text& text)
2098 if (m_properNamespace) {
2099 m_policy = text.value;
2103 virtual void Verify()
2105 if (!m_policy.IsNull()) {
2106 m_data.cspPolicyReportOnly = *m_policy;
2111 ConfigParserData& m_data;
2112 bool m_properNamespace;
2113 DPL::OptionalString m_policy;
2116 class AccountParser : public ElementParser
2119 struct AccountProviderParser : public ElementParser
2123 struct IconParser : public ElementParser
2126 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2127 const DPL::String& /*name*/)
2129 return &IgnoringParser::Create;
2132 virtual void Accept(const Text& text)
2134 if (text.value == L"") {
2137 m_value = text.value;
2140 virtual void Accept(const Element& /*element*/)
2143 virtual void Accept(const XmlAttribute& attribute)
2145 if (attribute.name == L"section") {
2146 if (attribute.value == L"account") {
2147 m_type = ConfigParserData::IconSectionType::DefaultIcon;
2148 } else if (attribute.value == L"account-small") {
2149 m_type = ConfigParserData::IconSectionType::SmallIcon;
2154 virtual void Verify()
2156 if (m_value.IsNull() || *m_value == L"") {
2160 std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
2161 icon.first = m_type;
2162 icon.second = *m_value;
2164 m_data.m_iconSet.insert(icon);
2167 IconParser(ConfigParserData::AccountProvider& data) :
2169 m_properNamespace(false),
2170 m_type(ConfigParserData::DefaultIcon),
2175 bool m_properNamespace;
2176 ConfigParserData::IconSectionType m_type;
2177 ConfigParserData::AccountProvider& m_data;
2178 DPL::OptionalString m_value;
2181 struct DisplayNameParser : public ElementParser
2184 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2185 const DPL::String& /*name*/)
2187 return &IgnoringParser::Create;
2190 virtual void Accept(const Text& text)
2192 if (text.value == L"") {
2195 m_value = text.value;
2198 virtual void Accept(const Element& element)
2200 m_lang = element.lang;
2204 virtual void Accept(const XmlAttribute& /*attribute*/)
2207 virtual void Verify()
2209 if (m_value.IsNull() || *m_value == L"") {
2213 std::pair<DPL::String, DPL::String> name;
2214 name.first = *m_lang;
2215 name.second = *m_value;
2217 m_data.m_displayNameSet.insert(name);
2220 DisplayNameParser(ConfigParserData::AccountProvider& data) :
2222 m_properNamespace(false),
2227 bool m_properNamespace;
2228 DPL::OptionalString m_lang;
2229 DPL::OptionalString m_value;
2230 ConfigParserData::AccountProvider& m_data;
2233 struct CapabilityParser : public ElementParser
2236 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2237 const DPL::String& /*name*/)
2239 return &IgnoringParser::Create;
2242 virtual void Accept(const Text& text)
2244 if (text.value == L"") {
2247 m_value = text.value;
2250 virtual void Accept(const Element& /*element*/)
2253 virtual void Accept(const XmlAttribute& /*attribute*/)
2256 virtual void Verify()
2258 if (m_value.IsNull() || *m_value == L"") {
2261 m_data.m_capabilityList.push_back(*m_value);
2264 CapabilityParser(ConfigParserData::AccountProvider& data) :
2266 m_properNamespace(false),
2271 bool m_properNamespace;
2272 DPL::OptionalString m_value;
2273 ConfigParserData::AccountProvider& m_data;
2275 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2276 const DPL::String& name)
2278 if (name == L"icon") {
2279 return DPL::MakeDelegate(this, &AccountProviderParser::OnIconElement);
2280 } else if (name == L"display-name") {
2281 return DPL::MakeDelegate(this,
2282 &AccountProviderParser::OnDisplayNameElement);
2283 } else if (name == L"capability") {
2284 return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement);
2286 return &IgnoringParser::Create;
2290 virtual void Accept(const Text& /*text*/)
2293 virtual void Accept(const Element& /*element*/)
2296 virtual void Accept(const XmlAttribute& attribute)
2298 if (attribute.name == L"multiple-accounts-support") {
2299 if (attribute.value == L"") {
2303 if (attribute.value == L"ture") {
2304 m_multiSupport = true;
2309 virtual void Verify()
2311 m_data.m_multiAccountSupport = m_multiSupport;
2314 ElementParserPtr OnIconElement()
2316 return ElementParserPtr(new IconParser(m_data));
2319 ElementParserPtr OnDisplayNameElement()
2321 return ElementParserPtr(new DisplayNameParser(m_data));
2324 ElementParserPtr OnCapabilityElement()
2326 return ElementParserPtr(new CapabilityParser(m_data));
2329 AccountProviderParser(ConfigParserData::AccountProvider& data) :
2331 m_properNamespace(false),
2332 m_multiSupport(false),
2337 bool m_properNamespace;
2338 bool m_multiSupport;
2339 ConfigParserData::AccountProvider& m_data;
2342 virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
2343 const DPL::String& name)
2345 if (name == L"account-provider") {
2346 return DPL::MakeDelegate(this, &AccountParser::OnProviderElement);
2348 return &IgnoringParser::Create;
2352 virtual void Accept(const Element& element)
2354 if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
2355 m_properNamespace = true;
2359 virtual void Accept(const XmlAttribute& /*attribute*/)
2362 virtual void Accept(const Text& /*text*/)
2365 virtual void Verify()
2368 ElementParserPtr OnProviderElement()
2370 return ElementParserPtr(new AccountProviderParser(m_account));
2373 AccountParser(ConfigParserData& data) :
2376 m_account(data.accountProvider),
2377 m_properNamespace(false),
2378 m_multiSupport(false)
2382 ConfigParserData& m_data;
2383 ConfigParserData::AccountProvider& m_account;
2384 bool m_properNamespace;
2385 bool m_multiSupport;
2388 ElementParser::ActionFunc WidgetParser::GetElementParser(
2389 const DPL::String& /*ns*/,
2393 FuncMap::const_iterator it = m_map.find(name);
2394 if (it != m_map.end()) {
2397 return &IgnoringParser::Create;
2401 WidgetParser::WidgetParser(ConfigParserData& data) :
2403 m_textDirection(Unicode::EMPTY)
2405 m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
2406 m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
2407 m_map[L"description"] =
2408 DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
2409 m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
2411 DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
2412 m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
2414 DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
2415 m_map[L"preference"] =
2416 DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
2417 m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement);
2419 DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
2420 m_map[L"application"] = DPL::MakeDelegate(
2423 OnApplicationElement);
2424 m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
2425 m_map[L"background"] = DPL::MakeDelegate(this,
2426 &WidgetParser::OnBackgroundElement);
2427 m_map[L"privilege"] = DPL::MakeDelegate(this,
2428 &WidgetParser::OnPrivilegeElement);
2429 m_map[L"app-control"] = DPL::MakeDelegate(
2432 OnAppControlElement);
2433 m_map[L"category"] = DPL::MakeDelegate(this,
2434 &WidgetParser::OnCategoryElement);
2435 m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
2437 m_map[L"content-security-policy"] = DPL::MakeDelegate(
2441 m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
2444 OnCspReportOnlyElement);
2446 #ifdef ALLOW_NAVIGATION_ENABLED
2447 m_map[L"allow-navigation"] =
2448 DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
2450 m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
2453 ElementParserPtr WidgetParser::OnNameElement()
2455 return ElementParserPtr(new NameParser(m_textDirection, m_data));
2458 ElementParserPtr WidgetParser::OnAccessElement()
2460 return ElementParserPtr(new AccessParser(m_data));
2463 ElementParserPtr WidgetParser::OnDescriptionElement()
2465 return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
2468 ElementParserPtr WidgetParser::OnAuthorElement()
2470 return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
2473 ElementParserPtr WidgetParser::OnLicenseElement()
2475 return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
2478 ElementParserPtr WidgetParser::OnIconElement()
2480 return ElementParserPtr(new IconParser(m_data));
2483 ElementParserPtr WidgetParser::OnContentElement()
2485 return ElementParserPtr(new ContentParser(m_data));
2488 ElementParserPtr WidgetParser::OnPreferenceElement()
2490 return ElementParserPtr(new PreferenceParser(m_data));
2493 ElementParserPtr WidgetParser::OnLinkElement()
2495 return ElementParserPtr(new LinkParser(m_data));
2498 ElementParserPtr WidgetParser::OnSettingElement()
2500 return ElementParserPtr(new SettingParser(m_data));
2503 ElementParserPtr WidgetParser::OnApplicationElement()
2505 return ElementParserPtr(new ApplicationParser(m_data));
2508 ElementParserPtr WidgetParser::OnSplashElement()
2510 return ElementParserPtr(new SplashParser(m_data));
2513 ElementParserPtr WidgetParser::OnBackgroundElement()
2515 return ElementParserPtr(new BackgroundParser(m_data));
2518 ElementParserPtr WidgetParser::OnPrivilegeElement()
2520 return ElementParserPtr(new PrivilegeParser(m_data));
2523 ElementParserPtr WidgetParser::OnAppControlElement()
2525 return ElementParserPtr(new AppControlParser(m_data));
2528 ElementParserPtr WidgetParser::OnCategoryElement()
2530 return ElementParserPtr(new CategoryParser(m_data));
2533 ElementParserPtr WidgetParser::OnAppWidgetElement()
2535 return ElementParserPtr(new AppWidgetParser(m_data));
2538 ElementParserPtr WidgetParser::OnCspElement()
2540 return ElementParserPtr(new CspParser(m_data));
2543 ElementParserPtr WidgetParser::OnCspReportOnlyElement()
2545 return ElementParserPtr(new CspReportOnlyParser(m_data));
2548 ElementParserPtr WidgetParser::OnAllowNavigationElement()
2550 return ElementParserPtr(new AllowNavigationParser(m_data));
2553 ElementParserPtr WidgetParser::OnAccountElement()
2555 return ElementParserPtr(new AccountParser(m_data));
2558 void WidgetParser::Accept(const Element& element)
2560 if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
2561 element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
2563 ThrowMsg(Exception::ParseError,
2564 "Wrong xml namespace for widget element");
2568 void WidgetParser::Accept(const Text& /*text*/)
2570 ThrowMsg(Exception::ParseError, "widged element must be empty");
2573 void WidgetParser::Accept(const XmlAttribute& attribute)
2575 if (attribute.name == L"id") {
2576 LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
2577 //If may important tests starts to fail this test we will have
2578 //to consider commenting this test out again.
2579 if (iri.Validate()) {
2580 m_data.widget_id = attribute.value;
2581 NormalizeString(m_data.widget_id);
2583 LogWarning("Widget id validation failed: " << attribute.value);
2585 } else if (attribute.name == L"version") {
2586 m_version = attribute.value;
2587 NormalizeString(m_version);
2588 } else if (attribute.name == L"min-version") {
2589 LogInfo("min-version attribute was found. Value: " << attribute.value);
2590 m_minVersion = attribute.value;
2591 NormalizeString(m_minVersion);
2592 m_data.minVersionRequired = m_minVersion;
2593 } else if (attribute.name == L"height") {
2594 DPL::OptionalString value = attribute.value;
2595 NormalizeString(value);
2596 std::string v = DPL::ToUTF8String(*value);
2599 unsigned char c = v.c_str()[0];
2600 if (c >= '0' && c <= '9') {
2602 for (size_t i = 0; i < v.size(); ++i) {
2604 if (c >= '0' && c <= '9') {
2611 m_data.height = val;
2614 } else if (attribute.name == L"width") {
2615 DPL::OptionalString value = attribute.value;
2616 NormalizeString(value);
2617 std::string v = DPL::ToUTF8String(*value);
2620 unsigned char c = v.c_str()[0];
2621 if (c >= '0' && c <= '9') {
2623 for (size_t i = 0; i < v.size(); ++i) {
2625 if (c >= '0' && c <= '9') {
2635 } else if (attribute.name == L"viewmodes") {
2636 DPL::Tokenize(attribute.value,
2638 std::inserter(m_windowModes,
2639 m_windowModes.end()),
2641 } else if (attribute.name == L"dir") {
2642 m_textDirection = Unicode::ParseDirAttribute(attribute);
2643 } else if (L"defaultlocale" == attribute.name) {
2644 if (!m_defaultlocale) {
2645 m_defaultlocale = attribute.value;
2646 NormalizeString(m_defaultlocale);
2647 if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag(
2648 DPL::ToUTF8String(*m_defaultlocale)))
2650 LogWarning("Language tag: " <<
2651 m_defaultlocale << " is not valid");
2652 m_defaultlocale = DPL::OptionalString::Null;
2654 LogDebug("Default Locale Found " << m_defaultlocale);
2657 LogWarning("Ignoring subsequent default locale");
2660 //Any other value consider as a namespace definition
2661 } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
2662 LogInfo("Namespace domain: " << attribute.name);
2663 LogInfo("Namespace value: " << attribute.value);
2664 m_nameSpaces[attribute.name] = attribute.value;
2666 LogError("Unknown attirbute: namespace=" << attribute.ns <<
2667 ", name=" << attribute.name <<
2668 ", value=" << attribute.value);
2672 void WidgetParser::Verify()
2674 FOREACH(mode, m_windowModes) {
2675 if (L"windowed" == *mode || L"floating" == *mode ||
2676 L"fullscreen" == *mode || L"maximized" == *mode ||
2677 L"minimized" == *mode)
2679 m_data.windowModes.insert(*mode);
2682 if (!m_version.IsNull()) {
2683 Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
2684 m_data.version = m_version;
2686 m_data.defaultlocale = m_defaultlocale;
2687 FOREACH(ns, m_nameSpaces) {
2688 m_data.nameSpaces.insert(ns->second);