Prevent generating invalid manifest.
[platform/core/appfw/wgt-backend.git] / src / wgt / step / pkgmgr / step_generate_xml.cc
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
5
6 #include "wgt/step/pkgmgr/step_generate_xml.h"
7
8 #include <boost/filesystem/path.hpp>
9 #include <boost/system/error_code.hpp>
10
11 #include <common/utils/file_util.h>
12 #include <common/utils/glist_range.h>
13 #include <common/privileges.h>
14
15 #include <libxml/parser.h>
16 #include <libxml/xmlreader.h>
17 #include <pkgmgr-info.h>
18 #include <pkgmgr_parser.h>
19 #include <tzplatform_config.h>
20 #include <unistd.h>
21
22 #include <cassert>
23 #include <cstring>
24 #include <string>
25
26 #include "wgt/wgt_backend_data.h"
27
28 namespace bs = boost::system;
29 namespace bf = boost::filesystem;
30
31 namespace {
32
33 const char kResWgt[] = "res/wgt";
34 const char kSharedRes[] = "shared/res";
35
36 void WriteUIApplicationAttributes(
37     xmlTextWriterPtr writer, application_x *app) {
38   if (app->taskmanage)
39     xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage",
40         BAD_CAST app->taskmanage);
41   if (app->nodisplay)
42     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
43         BAD_CAST app->nodisplay);
44   if (app->multiple)
45     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
46         BAD_CAST app->multiple);
47   if (app->launch_mode && strlen(app->launch_mode))
48     xmlTextWriterWriteAttribute(writer, BAD_CAST "launch_mode",
49         BAD_CAST app->launch_mode);
50   if (app->ui_gadget && strlen(app->ui_gadget))
51     xmlTextWriterWriteAttribute(writer, BAD_CAST "ui-gadget",
52         BAD_CAST app->ui_gadget);
53   if (app->submode && strlen(app->submode))
54     xmlTextWriterWriteAttribute(writer, BAD_CAST "submode",
55         BAD_CAST app->submode);
56   if (app->submode_mainid && strlen(app->submode_mainid))
57     xmlTextWriterWriteAttribute(writer, BAD_CAST "submode-mainid",
58         BAD_CAST app->submode_mainid);
59   if (app->indicatordisplay && strlen(app->indicatordisplay))
60     xmlTextWriterWriteAttribute(writer, BAD_CAST "indicatordisplay",
61         BAD_CAST app->indicatordisplay);
62   if (app->portraitimg && strlen(app->portraitimg))
63     xmlTextWriterWriteAttribute(writer, BAD_CAST "portrait-effectimage",
64         BAD_CAST app->portraitimg);
65   if (app->landscapeimg && strlen(app->landscapeimg))
66     xmlTextWriterWriteAttribute(writer, BAD_CAST "landscape-effectimage",
67         BAD_CAST app->landscapeimg);
68   if (app->effectimage_type && strlen(app->effectimage_type))
69     xmlTextWriterWriteAttribute(writer, BAD_CAST "effectimage-type",
70         BAD_CAST app->effectimage_type);
71   if (app->hwacceleration && strlen(app->hwacceleration))
72     xmlTextWriterWriteAttribute(writer, BAD_CAST "hwacceleration",
73         BAD_CAST app->hwacceleration);
74 }
75
76 void WriteServiceApplicationAttributes(
77     xmlTextWriterPtr writer, application_x *app) {
78   xmlTextWriterWriteAttribute(writer, BAD_CAST "auto-restart",
79       BAD_CAST(app->autorestart ? app->autorestart : "false"));
80   xmlTextWriterWriteAttribute(writer, BAD_CAST "on-boot",
81       BAD_CAST(app->onboot ? app->onboot : "false"));
82   if (app->taskmanage)
83       xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage",
84          BAD_CAST app->taskmanage);
85 }
86
87 bool WriteWidgetApplicationAttributesAndElements(
88     xmlTextWriterPtr writer, application_x *app,
89     const wgt::parse::AppWidgetInfo& widget_info,
90     const bf::path& shared_path) {
91   if (app->nodisplay)
92     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
93         BAD_CAST app->nodisplay);
94   if (app->multiple)
95     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
96         BAD_CAST app->multiple);
97
98   // Generate attributes and elements not covered in manifest.xsd
99   auto& appwidgets = widget_info.app_widgets();
100   const auto& appwidget = std::find_if(appwidgets.begin(), appwidgets.end(),
101                                  [app](const wgt::parse::AppWidget& widget) {
102                                     return widget.id == app->appid;
103                                  });
104   if (appwidget == appwidgets.end()) {
105     LOG(ERROR) << "Failed to generate appwidget extra elements";
106     return false;
107   }
108
109   xmlTextWriterWriteAttribute(writer, BAD_CAST "main",
110       BAD_CAST (appwidget->primary ? "true" : "false"));  // NOLINT
111   if (!appwidget->update_period.empty()) {
112         xmlTextWriterWriteAttribute(writer, BAD_CAST "update-period", BAD_CAST
113             std::to_string(static_cast<int>(
114                     appwidget->update_period.front())).c_str());
115   }
116
117   xmlTextWriterWriteAttribute(writer, BAD_CAST "max-instance",
118       BAD_CAST std::to_string(appwidget->max_instance).c_str());
119
120   for (auto& size : appwidget->content_size) {
121     xmlTextWriterStartElement(writer, BAD_CAST "support-size");
122
123     std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
124     if (!size.preview.empty()) {
125       std::string icon_name = shared_path.string() + "/"
126           + appwidget->id + "." + type + "." + "preview" +
127           bf::path(size.preview).extension().string();
128       xmlTextWriterWriteAttribute(writer, BAD_CAST "preview",
129           BAD_CAST icon_name.c_str());  // NOLINT
130     }
131
132     xmlTextWriterWriteAttribute(writer, BAD_CAST "frame",
133                                 BAD_CAST "true");
134     xmlTextWriterWriteString(writer,
135         BAD_CAST type.c_str());
136     xmlTextWriterEndElement(writer);
137   }
138
139   for (auto& pair : appwidget->metadata) {
140     xmlTextWriterStartElement(writer, BAD_CAST "metadata");
141     xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
142                                 BAD_CAST pair.first.c_str());
143     if (!pair.second.empty())
144       xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
145                                   BAD_CAST pair.second.c_str());
146     xmlTextWriterEndElement(writer);
147   }
148   return true;
149 }
150
151 void WriteWatchApplicationAttributes(
152     xmlTextWriterPtr writer, application_x* app) {
153   if (app->ambient_support)
154     xmlTextWriterWriteAttribute(writer, BAD_CAST "ambient-support",
155         BAD_CAST app->ambient_support);
156 }
157
158 }  // namespace
159
160 namespace wgt {
161 namespace pkgmgr {
162
163 common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml(
164     application_x* app, xmlTextWriterPtr writer, AppCompType type) {
165   xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST app->appid);
166
167   // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
168   bf::path exec_path = context_->pkg_path.get()
169       / bf::path("bin") / bf::path(app->appid);
170   xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
171                               BAD_CAST exec_path.string().c_str());
172   if (app->type)
173     xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST app->type);
174   else
175     xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "capp");
176
177   if (app->process_pool && strlen(app->process_pool))
178     xmlTextWriterWriteAttribute(writer, BAD_CAST "process-pool",
179                                 BAD_CAST app->process_pool);
180   // app-specific attributes
181   switch (type) {
182   case AppCompType::UIAPP:
183     WriteUIApplicationAttributes(writer, app);
184     break;
185   case AppCompType::SVCAPP:
186     WriteServiceApplicationAttributes(writer, app);
187     break;
188   case AppCompType::WIDGETAPP:
189     if (!WriteWidgetApplicationAttributesAndElements(writer, app,
190         static_cast<WgtBackendData*>(
191             context_->backend_data.get())->appwidgets.get(),
192         context_->pkg_path.get() / "shared" / "res"))
193       return Status::MANIFEST_ERROR;
194     break;
195   case AppCompType::WATCHAPP:
196     WriteWatchApplicationAttributes(writer, app);
197     break;
198   }
199
200   for (label_x* label : GListRange<label_x*>(app->label)) {
201     if (label->name && strcmp(label->name, "") != 0) {
202       xmlTextWriterStartElement(writer, BAD_CAST "label");
203       if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) {
204         xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
205                                     BAD_CAST label->lang);
206       }
207       xmlTextWriterWriteString(writer, BAD_CAST label->name);
208       xmlTextWriterEndElement(writer);
209     }
210   }
211
212   if (app->icon) {
213     icon_x* iconx = reinterpret_cast<icon_x*>(app->icon->data);
214     xmlTextWriterWriteFormatElement(
215         writer, BAD_CAST "icon", "%s", BAD_CAST iconx->text);
216   } else {
217     // Default icon setting is role of the platform
218     LOG(DEBUG) << "Icon was not found in application";
219   }
220
221   for (image_x* image : GListRange<image_x*>(app->image)) {
222     xmlTextWriterStartElement(writer, BAD_CAST "image");
223     if (image->lang && strcmp(DEFAULT_LOCALE, image->lang) != 0) {
224       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
225
226                                   BAD_CAST image->lang);
227     }
228     if (image->section)
229       xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
230                                   BAD_CAST image->section);
231     xmlTextWriterEndElement(writer);
232   }
233
234   for (appcontrol_x* appc : GListRange<appcontrol_x*>(app->appcontrol)) {
235     xmlTextWriterStartElement(writer, BAD_CAST "app-control");
236
237     if (appc->operation) {
238       xmlTextWriterStartElement(writer, BAD_CAST "operation");
239       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
240           BAD_CAST appc->operation);
241       xmlTextWriterEndElement(writer);
242     }
243
244     if (appc->uri) {
245       xmlTextWriterStartElement(writer, BAD_CAST "uri");
246       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
247           BAD_CAST appc->uri);
248       xmlTextWriterEndElement(writer);
249     }
250
251     if (appc->mime) {
252       xmlTextWriterStartElement(writer, BAD_CAST "mime");
253       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
254           BAD_CAST appc->mime);
255       xmlTextWriterEndElement(writer);
256     }
257
258     xmlTextWriterEndElement(writer);
259   }
260
261   for (datacontrol_x* datacontrol :
262        GListRange<datacontrol_x*>(app->datacontrol)) {
263     xmlTextWriterStartElement(writer, BAD_CAST "datacontrol");
264     if (datacontrol->access) {
265       xmlTextWriterWriteAttribute(writer, BAD_CAST "access",
266           BAD_CAST datacontrol->access);
267     }
268     if (datacontrol->providerid) {
269       xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid",
270           BAD_CAST datacontrol->providerid);
271     }
272     if (datacontrol->type) {
273       xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
274           BAD_CAST datacontrol->type);
275     }
276     xmlTextWriterEndElement(writer);
277   }
278
279   for (metadata_x* meta : GListRange<metadata_x*>(app->metadata)) {
280     xmlTextWriterStartElement(writer, BAD_CAST "metadata");
281     xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
282         BAD_CAST meta->key);
283     if (meta->value)
284       xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
285           BAD_CAST meta->value);
286     xmlTextWriterEndElement(writer);
287   }
288
289   for (const char* category : GListRange<char*>(app->category)) {
290     xmlTextWriterStartElement(writer, BAD_CAST "category");
291     xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST category);
292     xmlTextWriterEndElement(writer);
293   }
294
295   for (const char* background_category : GListRange<char*>(
296       app->background_category)) {
297     xmlTextWriterStartElement(writer, BAD_CAST "background-category");
298     xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
299         BAD_CAST background_category);
300     xmlTextWriterEndElement(writer);
301   }
302
303   return Step::Status::OK;
304 }
305
306 common_installer::Step::Status StepGenerateXml::undo() {
307   bs::error_code error;
308   if (bf::exists(context_->xml_path.get()))
309     bf::remove_all(context_->xml_path.get(), error);
310   return Status::OK;
311 }
312
313 common_installer::Step::Status StepGenerateXml::precheck() {
314   if (!context_->manifest_data.get()) {
315     LOG(ERROR) << "manifest_data attribute is empty";
316     return Step::Status::INVALID_VALUE;
317   }
318   if (context_->pkgid.get().empty()) {
319     LOG(ERROR) << "pkgid attribute is empty";
320     return Step::Status::PACKAGE_NOT_FOUND;
321   }
322
323   if (!context_->manifest_data.get()->application) {
324     LOG(ERROR) << "No application in package";
325     return Step::Status::INVALID_VALUE;
326   }
327   // TODO(p.sikorski) check context_->uid.get()
328
329   return Step::Status::OK;
330 }
331
332 common_installer::Step::Status StepGenerateXml::process() {
333   bf::path xml_path =
334       bf::path(getUserManifestPath(context_->uid.get(), false))
335       / bf::path(context_->pkgid.get());
336   xml_path += ".xml";
337   context_->xml_path.set(xml_path.string());
338
339   bs::error_code error;
340   if (!bf::exists(xml_path.parent_path(), error)) {
341     if (!common_installer::CreateDir(xml_path.parent_path())) {
342       LOG(ERROR) <<
343           "Directory for manifest xml is missing and cannot be created";
344       return Status::MANIFEST_ERROR;
345     }
346   }
347
348   xmlTextWriterPtr writer;
349   writer = xmlNewTextWriterFilename(context_->xml_path.get().c_str(), 0);
350   if (!writer) {
351     LOG(ERROR) << "Failed to create new file";
352     return Step::Status::MANIFEST_ERROR;
353   }
354
355   xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
356   xmlTextWriterSetIndent(writer, 1);
357
358   Status status = GenerateManifestElement(writer);
359   if (status != Status::OK) {
360     return status;
361   }
362
363   xmlTextWriterEndDocument(writer);
364   xmlFreeTextWriter(writer);
365
366   if (pkgmgr_parser_check_manifest_validation(
367       context_->xml_path.get().c_str()) != 0) {
368     LOG(ERROR) << "Manifest is not valid";
369     return Step::Status::MANIFEST_ERROR;
370   }
371
372   LOG(DEBUG) << "Successfully create manifest xml "
373       << context_->xml_path.get();
374   return Status::OK;
375 }
376
377 common_installer::Step::Status StepGenerateXml::GenerateManifestElement(
378         xmlTextWriterPtr writer) {
379   xmlTextWriterStartElement(writer, BAD_CAST "manifest");
380
381   GenerateManifestElementAttributes(writer);
382   GenerateLangLabels(writer);
383   GenerateAuthor(writer);
384   GenerateDescription(writer);
385   Status status = GenerateApplications(writer);
386   if (status != Status::OK) {
387     return status;
388   }
389   GeneratePrivilege(writer);
390   GenerateAccount(writer);
391   GenerateIme(writer);
392   GenerateProfiles(writer);
393   GenerateShortcuts(writer);
394
395   xmlTextWriterEndElement(writer);
396   return Status::OK;
397 }
398
399 void StepGenerateXml::GenerateManifestElementAttributes(
400         xmlTextWriterPtr writer) {
401   xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
402       BAD_CAST "http://tizen.org/ns/packages");
403   xmlTextWriterWriteAttribute(writer, BAD_CAST "package",
404       BAD_CAST context_->manifest_data.get()->package);
405   xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
406       BAD_CAST context_->manifest_data.get()->type);
407   xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
408       BAD_CAST context_->manifest_data.get()->version);
409   xmlTextWriterWriteAttribute(writer, BAD_CAST "api-version",
410       BAD_CAST context_->manifest_data.get()->api_version);
411   xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay-setting",
412       BAD_CAST context_->manifest_data.get()->nodisplay_setting);
413 }
414
415 void StepGenerateXml::GenerateLangLabels(xmlTextWriterPtr writer) {
416   for (label_x* label :
417        GListRange<label_x*>(context_->manifest_data.get()->label)) {
418     if (label->name && strcmp(label->name, "") != 0) {
419       xmlTextWriterStartElement(writer, BAD_CAST "label");
420       if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) {
421       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
422                                     BAD_CAST label->lang);
423       }
424       xmlTextWriterWriteString(writer, BAD_CAST label->name);
425       xmlTextWriterEndElement(writer);
426     }
427   }
428 }
429
430 void StepGenerateXml::GenerateAuthor(xmlTextWriterPtr writer) {
431   for (author_x* author :
432        GListRange<author_x*>(context_->manifest_data.get()->author)) {
433     xmlTextWriterStartElement(writer, BAD_CAST "author");
434     if (author->email && strlen(author->email)) {
435       xmlTextWriterWriteAttribute(writer, BAD_CAST "email",
436                                   BAD_CAST author->email);
437     }
438     if (author->href && strlen(author->href)) {
439       xmlTextWriterWriteAttribute(writer, BAD_CAST "href",
440                                   BAD_CAST author->href);
441     }
442     xmlTextWriterWriteString(writer, BAD_CAST author->text);
443     xmlTextWriterEndElement(writer);
444   }
445 }
446
447 void StepGenerateXml::GenerateDescription(xmlTextWriterPtr writer) {
448   for (description_x* description :
449        GListRange<description_x*>(context_->manifest_data.get()->description)) {
450     xmlTextWriterStartElement(writer, BAD_CAST "description");
451     if (description->lang && strcmp(DEFAULT_LOCALE, description->lang) != 0) {
452       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
453                                   BAD_CAST description->lang);
454     }
455     xmlTextWriterWriteString(writer, BAD_CAST description->text);
456     xmlTextWriterEndElement(writer);
457   }
458 }
459
460 common_installer::Step::Status StepGenerateXml::GenerateApplications(
461         xmlTextWriterPtr writer) {
462   for (application_x* app :
463        GListRange<application_x*>(context_->manifest_data.get()->application)) {
464     AppCompType type;
465     if (strcmp(app->component_type, "uiapp") == 0) {
466       type = AppCompType::UIAPP;
467       xmlTextWriterStartElement(writer, BAD_CAST "ui-application");
468     } else if (strcmp(app->component_type, "svcapp") == 0) {
469       type = AppCompType::SVCAPP;
470       xmlTextWriterStartElement(writer, BAD_CAST "service-application");
471     } else if (strcmp(app->component_type, "widgetapp") == 0) {
472       type = AppCompType::WIDGETAPP;
473       xmlTextWriterStartElement(writer, BAD_CAST "widget-application");
474     } else if (strcmp(app->component_type, "watchapp") == 0) {
475       type = AppCompType::WATCHAPP;
476       xmlTextWriterStartElement(writer, BAD_CAST "watch-application");
477     } else {
478       LOG(ERROR) << "Unknown application component_type";
479       xmlFreeTextWriter(writer);
480       return Status::ERROR;
481     }
482     Status status = GenerateApplicationCommonXml(app, writer, type);
483     if (status != Status::OK) {
484       xmlFreeTextWriter(writer);
485       return status;
486     }
487     xmlTextWriterEndElement(writer);
488   }
489   return Status::OK;
490 }
491
492 void StepGenerateXml::GeneratePrivilege(xmlTextWriterPtr writer) {
493     if (context_->manifest_data.get()->privileges) {
494     xmlTextWriterStartElement(writer, BAD_CAST "privileges");
495     for (const char* priv :
496          GListRange<char*>(context_->manifest_data.get()->privileges)) {
497       xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege",
498         "%s", BAD_CAST priv);
499     }
500
501     xmlTextWriterEndElement(writer);
502   }
503 }
504
505 void StepGenerateXml::GenerateAccount(xmlTextWriterPtr writer) {
506   const auto& accounts =
507       context_->manifest_plugins_data.get().account_info.get().accounts();
508   if (!accounts.empty()) {
509     xmlTextWriterStartElement(writer, BAD_CAST "account");
510     // add account info
511     for (auto& account : accounts) {
512       xmlTextWriterStartElement(writer, BAD_CAST "account-provider");
513
514       xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
515                                   BAD_CAST account.appid.c_str());
516
517       if (!account.providerid.empty())
518         xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid",
519                                     BAD_CAST account.providerid.c_str());
520
521       if (account.multiple_account_support)
522         xmlTextWriterWriteAttribute(writer,
523                                     BAD_CAST "multiple-accounts-support",
524                                     BAD_CAST "true");
525       else
526         xmlTextWriterWriteAttribute(writer,
527                                     BAD_CAST "multiple-accounts-support",
528                                     BAD_CAST "false");
529       for (auto& icon_pair : account.icon_paths) {
530         xmlTextWriterStartElement(writer, BAD_CAST "icon");
531         if (icon_pair.first == "AccountSmall")
532           xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
533                                       BAD_CAST "account-small");
534         else
535           xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
536                                       BAD_CAST "account");
537         xmlTextWriterWriteString(writer, BAD_CAST icon_pair.second.c_str());
538         xmlTextWriterEndElement(writer);
539       }
540
541       for (auto& name_pair : account.names) {
542         xmlTextWriterStartElement(writer, BAD_CAST "label");
543         if (!name_pair.second.empty())
544           xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
545                                       BAD_CAST name_pair.second.c_str());
546         xmlTextWriterWriteString(writer, BAD_CAST name_pair.first.c_str());
547         xmlTextWriterEndElement(writer);
548       }
549
550       for (auto& capability : account.capabilities) {
551         xmlTextWriterWriteFormatElement(writer, BAD_CAST "capability",
552           "%s", BAD_CAST capability.c_str());
553       }
554
555       xmlTextWriterEndElement(writer);
556     }
557     xmlTextWriterEndElement(writer);
558   }
559 }
560
561 void StepGenerateXml::GenerateIme(xmlTextWriterPtr writer) {
562   const auto &ime = context_->manifest_plugins_data.get().ime_info.get();
563   const auto ime_uuid = ime.uuid();
564   if (!ime_uuid.empty()) {
565     xmlTextWriterStartElement(writer, BAD_CAST "ime");
566
567     GListRange<application_x*> app_range(
568         context_->manifest_data.get()->application);
569     if (!app_range.Empty()) {
570       // wgt app have ui-application as first application element.
571       // there may be service-applications but not as first element.
572       application_x* app = *app_range.begin();
573       xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
574                                   BAD_CAST app->appid);
575     }
576
577     xmlTextWriterStartElement(writer, BAD_CAST "uuid");
578     xmlTextWriterWriteString(writer, BAD_CAST ime_uuid.c_str());
579     xmlTextWriterEndElement(writer);
580
581     xmlTextWriterStartElement(writer, BAD_CAST "languages");
582
583     for (auto it = ime.LanguagesBegin(); it != ime.LanguagesEnd(); ++it) {
584       xmlTextWriterStartElement(writer, BAD_CAST "language");
585       xmlTextWriterWriteString(writer, BAD_CAST it->c_str());
586       xmlTextWriterEndElement(writer);
587     }
588
589     xmlTextWriterEndElement(writer);
590
591     xmlTextWriterEndElement(writer);
592   }
593 }
594
595 void StepGenerateXml::GenerateProfiles(xmlTextWriterPtr writer) {
596   for (const char* profile :
597        GListRange<char*>(context_->manifest_data.get()->deviceprofile)) {
598     xmlTextWriterStartElement(writer, BAD_CAST "profile");
599     xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
600                                 BAD_CAST profile);
601     xmlTextWriterEndElement(writer);
602   }
603 }
604
605 void StepGenerateXml::GenerateShortcuts(xmlTextWriterPtr writer) {
606   const auto& shortcuts =
607       context_->manifest_plugins_data.get().shortcut_info.get();
608   if (!shortcuts.empty()) {
609     xmlTextWriterStartElement(writer, BAD_CAST "shortcut-list");
610     for (auto& shortcut : shortcuts) {
611       xmlTextWriterStartElement(writer, BAD_CAST "shortcut");
612       if (!shortcut.app_id.empty())
613         xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
614                                     BAD_CAST shortcut.app_id.c_str());
615       if (!shortcut.app_id.empty())
616         xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_data",
617                                     BAD_CAST shortcut.extra_data.c_str());
618       if (!shortcut.app_id.empty())
619         xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_key",
620                                     BAD_CAST shortcut.extra_key.c_str());
621       if (!shortcut.icon.empty()) {
622         xmlTextWriterStartElement(writer, BAD_CAST "icon");
623         xmlTextWriterWriteString(writer, BAD_CAST shortcut.icon.c_str());
624         xmlTextWriterEndElement(writer);
625       }
626       for (auto& label : shortcut.labels) {
627         xmlTextWriterStartElement(writer, BAD_CAST "label");
628         if (!label.first.empty())
629           xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
630                                       BAD_CAST label.first.c_str());
631         xmlTextWriterWriteString(writer, BAD_CAST label.second.c_str());
632         xmlTextWriterEndElement(writer);
633       }
634       xmlTextWriterEndElement(writer);
635     }
636     xmlTextWriterEndElement(writer);
637   }
638 }
639
640 }  // namespace pkgmgr
641 }  // namespace wgt