Update wrt-installer_0.0.51
[framework/web/wrt-installer.git] / src / jobs / widget_install / manifest.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    manifest.h
18  * @author  Mariusz Domanski (m.domanski@samsung.com)
19  */
20
21 #ifndef INSTALLER_JOBS_MANIFEST_H
22 #define INSTALLER_JOBS_MANIFEST_H
23
24 #include <list>
25
26 #include <libxml/encoding.h>
27 #include <libxml/xmlwriter.h>
28
29 #include <dpl/string.h>
30 #include <dpl/optional_typedefs.h>
31 #include <dpl/foreach.h>
32
33 namespace Jobs {
34 namespace WidgetInstall {
35
36 /**
37  * @brief string with optional language attribute
38  */
39 class StringWithLang
40 {
41 public:
42     StringWithLang() { }
43     StringWithLang(DPL::String s): string(s) { }
44     StringWithLang(DPL::String s, DPL::String l): string(s), lang(l) { }
45     DPL::String getString() { return this->string; }
46     DPL::String getLang() { return this->lang; }
47     bool hasLang() { return !this->lang.empty(); }
48 private:
49     DPL::String string;
50     DPL::String lang;
51 };
52
53 typedef StringWithLang LabelType, IconType, DescriptionType;
54
55 /**
56  * These types are basicaly strings but they should allow usage of different
57  * range of characters or words (details in XML spec.).
58  * For simplicity DPL::Strings are used, although this can lead to XML validation
59  * errors (related to usage of not allowed characters in given places).
60  */
61 typedef DPL::String NcnameType, NmtokenType, AnySimpleType, LangType;
62 typedef DPL::String OperationType, MimeType, UriType, TypeType, PackageType;
63 typedef DPL::OptionalString InstallLocationType, CategoriesType;
64
65 /**
66  * xmllib2 wrappers
67  */
68 void writeElement(xmlTextWriterPtr writer, const char * name, DPL::String body);
69 void writeText(xmlTextWriterPtr writer, DPL::String text);
70 void writeElement(xmlTextWriterPtr writer, const char * name, const char * body);
71 void writeElementWithOneAttribute(xmlTextWriterPtr writer, const char * name,
72         const char * body, const char * nameAttr, DPL::String bodyAttr,
73         bool condition = true);
74 void startElement(xmlTextWriterPtr writer, const char * name);
75 void endElement(xmlTextWriterPtr writer);
76 void writeAttribute(xmlTextWriterPtr writer, const char * name,
77         DPL::String body, bool condition);
78 void writeAttribute(xmlTextWriterPtr writer, const char * name,
79         const char * body, bool condition);
80
81 /**
82  * @brief author element
83  */
84 class Author
85 {
86 public:
87     Author() {}
88     Author(AnySimpleType e,
89             NcnameType h,
90             LangType l,
91             DPL::String b)
92         : email(e), href(h), lang(l), body(b) {}
93     void serialize(xmlTextWriterPtr writer);
94 private:
95     AnySimpleType email;
96     NcnameType href;
97     LangType lang;
98     DPL::String body;
99 };
100
101 typedef Author AuthorType;
102
103 /**
104  * @brief application-service element
105  */
106 class ApplicationService
107 {
108 public:
109     ApplicationService() {}
110     void addOperation(const OperationType &x) { this->operation.push_back(x); }
111     void addUri(const UriType &x) { this->uri.push_back(x); }
112     void addMime(const MimeType &x) { this->mime.push_back(x); }
113     void serialize(xmlTextWriterPtr writer);
114 private:
115     std::list<OperationType> operation; //attr name AnySimpleType
116     std::list<UriType> uri; //attr name AnySimpleType
117     std::list<MimeType> mime; //attr name AnySimpleType
118 };
119
120 typedef ApplicationService ApplicationServiceType;
121
122 /**
123  * @brief ime-application element
124  */
125 class ImeApplication
126 {
127 public:
128     ImeApplication() {}
129     void setAppid(const NcnameType &x) { this->appid = x; }
130     void setExec(const NcnameType &x) { this->exec = x; }
131     void setMultiple(bool x) { this->multiple = x; }
132     void setNodisplay(bool x) { this->nodisplay = x; }
133     void setType(const TypeType &x) { this->type = x; }
134     void addLabel(const LabelType &x) { this->label.push_back(x); }
135     void addIcon(const IconType &x) { this->icon.push_back(x); }
136     void serialize(xmlTextWriterPtr writer);
137 private:
138     NcnameType appid;
139     NcnameType exec;
140     DPL::OptionalBool multiple;
141     DPL::OptionalBool nodisplay;
142     TypeType type;
143     std::list<LabelType> label;
144     std::list<IconType> icon;
145 };
146
147 typedef ImeApplication ImeApplicationType;
148
149 /**
150  * @brief service-application element
151  */
152 class ServiceApplication
153 {
154 public:
155     ServiceApplication() {}
156     void setAppid(const NcnameType &x) { this->appid = x; }
157     void setAutoRestart(bool x) { this->autoRestart = x; }
158     void setExec(const AnySimpleType &x) { this->exec = x; }
159     void setOnBoot(bool x) { this->onBoot = x; }
160     void setType(const TypeType &x) { this->type = x; }
161     void addLabel(const LabelType &x) { this->label.push_back(x); }
162     void addIcon(const IconType &x) { this->icon.push_back(x); }
163     void addApplicationService(const ApplicationServiceType &x)
164     {
165         this->applicationService.push_back(x);
166     }
167     void serialize(xmlTextWriterPtr writer);
168 private:
169     NcnameType appid;
170     DPL::OptionalBool autoRestart;
171     AnySimpleType exec;
172     DPL::OptionalBool onBoot;
173     TypeType type;
174     std::list<LabelType> label; //attr name AnySimpleType
175     std::list<IconType> icon; //attr name AnySimpleType
176     std::list<ApplicationServiceType> applicationService; //attr name AnySimpleType
177 };
178
179 typedef ServiceApplication ServiceApplicationType;
180
181 /**
182  * @brief ui-application element
183  */
184 class UiApplication
185 {
186 public:
187     UiApplication() {}
188     void setAppid(const NcnameType &x) { this->appid = x; }
189     void setExtraid(const NcnameType &x) { this->extraid = x; }
190     void setExec(const AnySimpleType &x) { this->exec = x; }
191     void setMultiple(bool x) { this->multiple = x; }
192     void setNodisplay(bool x) { this->nodisplay = x; }
193     void setTaskmanage(bool x) { this->taskmanage = x; }
194     void setType(const TypeType &x) { this->type = x; }
195     void setCategories(const NcnameType &x) { this->categories = x; }
196     void addLabel(const LabelType &x) { this->label.push_back(x); }
197     void addIcon(const IconType &x) { this->icon.push_back(x); }
198     void addApplicationService(const ApplicationServiceType &x)
199     {
200         this->applicationService.push_back(x);
201     }
202     void serialize(xmlTextWriterPtr writer);
203 private:
204     NcnameType appid;
205     NcnameType extraid;
206     AnySimpleType exec;
207     DPL::OptionalBool multiple;
208     DPL::OptionalBool nodisplay;
209     DPL::OptionalBool taskmanage;
210     TypeType type;
211     CategoriesType categories;
212     std::list<LabelType> label;
213     std::list<IconType> icon;
214     std::list<ApplicationServiceType> applicationService;
215 };
216
217 typedef UiApplication UiApplicationType;
218
219 /**
220  * @brief manifest element
221  *
222  * Manifest xml file representation.
223  */
224 class Manifest
225 {
226 public:
227     Manifest() {}
228     void serialize(xmlTextWriterPtr writer);
229     void generate(DPL::String filename);
230
231     void addLabel(const LabelType &x) { this->label.push_back(x); }
232     void addIcon(const IconType &x) { this->icon.push_back(x); }
233     void addAuthor(const AuthorType &x) { this->author.push_back(x); };
234     void addDescription(const DescriptionType &x)
235     {
236         this->description.push_back(x);
237     }
238 //    void addCompatibility(const CompatibilityType &x)
239 //    {
240 //        this->compatibility.push_back(x);
241 //    }
242 //    void addDeviceProfile(const DeviceProfileType &x)
243 //    {
244 //        this->deviceProfile.push_back(x);
245 //    }
246     void addServiceApplication(const ServiceApplicationType &x)
247     {
248         this->serviceApplication.push_back(x);
249     }
250     void addUiApplication(const UiApplicationType &x)
251     {
252         this->uiApplication.push_back(x);
253     }
254     void addImeApplication(const ImeApplicationType &x)
255     {
256         this->imeApplication.push_back(x);
257     }
258 //    void addFont(const FontType &x) { this->font.push_back(x); }
259 //    void addLivebox(const LiveboxType &x) { this->livebox.push_back(x); }
260
261     void setInstallLocation(const InstallLocationType &x)
262     {
263         this->installLocation = x;
264     }
265     void setPackage(const NcnameType &x) { this->package = x; }
266     void setType(const PackageType &x) { this->type = x; }
267     void setVersion(const NmtokenType &x) { this->version = x; }
268 private:
269     std::list<LabelType> label;
270     std::list<IconType> icon;
271     std::list<AuthorType> author;
272     std::list<DescriptionType> description;
273 //    std::list<CompatibilityType> compatibility;
274 //    std::list<DeviceProfileType> deviceProfile;
275     std::list<ServiceApplicationType> serviceApplication;
276     std::list<UiApplicationType> uiApplication;
277     std::list<ImeApplicationType> imeApplication;
278 //    std::list<FontType> font;
279 //    std::list<LiveboxType> livebox;
280     InstallLocationType installLocation;
281     NcnameType package;
282     PackageType type;
283     NmtokenType version;
284 };
285
286 } //namespace Jobs
287 } //namespace WidgetInstall
288
289 #endif //INSTALLER_JOBS_MANIFEST_H