2
* Copyright (C) 2007 Johan MATHE - johan.mathe@tremplin-utc.net - Centre
3
* Pompidou - IRI This library is free software; you can redistribute it
4
* and/or modify it under the terms of the GNU Lesser General Public
5
* License as published by the Free Software Foundation; either version
6
* 2.1 of the License, or (at your option) any later version. This
7
* library is distributed in the hope that it will be useful, but WITHOUT
8
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10
* License for more details. You should have received a copy of the GNU
11
* Lesser General Public License along with this library; if not, write to
12
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
13
* Boston, MA 02110-1301 USA $Id: xml.cpp 139 2007-03-29 14:37:40Z
14
* johmathe $ $Date: 2007-12-12 16:22:16 +0000 (Wed, 12 Dec 2007) $
25
xml::ConvertInput (const char *in, const char *encoding)
32
xmlCharEncodingHandlerPtr handler;
37
handler = xmlFindCharEncodingHandler (encoding);
41
printf ("ConvertInput: no encoding handler found for '%s'\n", encoding ? encoding : "");
45
size = (int) strlen (in) + 1;
46
out_size = size * 2 - 1;
47
out = (unsigned char *) xmlMalloc ((size_t) out_size);
52
ret = handler->input (out, &out_size, (const xmlChar *) in, &temp);
53
if ((ret < 0) || (temp - size + 1))
57
printf ("ConvertInput: conversion wasn't successful.\n");
61
printf ("ConvertInput: conversion wasn't successful. converted: %i octets.\n", temp);
69
out = (unsigned char *) xmlRealloc (out, out_size + 1);
70
out[out_size] = 0; /* null terminating out */
75
printf ("ConvertInput: no mem\n");
84
xml::write_data (string & filename)
87
xmlTextWriterPtr writer;
92
/* Create a new XmlWriter for DOM, with no compression. */
93
list < shot >::iterator il;
94
writer = xmlNewTextWriterDoc (&doc, 0);
96
rc = xmlTextWriterStartDocument (writer, NULL, MY_ENCODING, NULL);
97
rc = xmlTextWriterStartElement (writer, BAD_CAST "shotdetect");
98
tmp = ConvertInput ("IRI ShotDetect ", MY_ENCODING);
99
rc = xmlTextWriterWriteComment (writer, tmp);
104
xmlTextWriterStartElement (writer, BAD_CAST "content");
106
xmlTextWriterStartElement (writer, BAD_CAST "head");
109
xmlTextWriterStartElement (writer, BAD_CAST "media");
110
xmlTextWriterWriteAttribute (writer, BAD_CAST "src", BAD_CAST f->get_ipath().c_str ());
113
xmlTextWriterWriteElement (writer, BAD_CAST "fps", BAD_CAST strflx.str ().c_str ());
116
xmlTextWriterWriteElement (writer, BAD_CAST "height", BAD_CAST strflx.str ().c_str ());
119
xmlTextWriterWriteElement (writer, BAD_CAST "width", BAD_CAST strflx.str ().c_str ());
122
strflx << int (f->duration.mstotal);
123
xmlTextWriterWriteElement (writer, BAD_CAST "duration", BAD_CAST strflx.str ().c_str ());
126
strflx << f->nchannel;
127
xmlTextWriterWriteElement (writer, BAD_CAST "nchannel", BAD_CAST strflx.str ().c_str ());
128
xmlTextWriterStartElement (writer, BAD_CAST "codec");
129
xmlTextWriterWriteElement (writer, BAD_CAST "video", BAD_CAST f->codec.video.c_str ());
130
xmlTextWriterWriteElement (writer, BAD_CAST "audio", BAD_CAST f->codec.audio.c_str ());
131
xmlTextWriterEndElement (writer);
132
xmlTextWriterEndElement (writer);
134
xmlTextWriterEndElement (writer);
136
xmlTextWriterStartElement (writer, BAD_CAST "body");
137
xmlTextWriterStartElement (writer, BAD_CAST "shots");
139
/* Mise en place des elements shots */
140
for (il = f->shots.begin (); il != f->shots.end (); il++)
143
strflx << (*il).myid;
144
rc = xmlTextWriterStartElement (writer, BAD_CAST "shot");
145
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "id", BAD_CAST strflx.str ().c_str ());
148
strflx << (*il).fduration;
149
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "fduration", BAD_CAST strflx.str ().c_str ());
152
strflx << int ((*il).msduration);
153
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "msduration", BAD_CAST strflx.str ().c_str ());
156
strflx << (*il).fbegin;
157
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "fbegin", BAD_CAST strflx.str ().c_str ());
160
strflx << int ((*il).msbegin);
161
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "msbegin", BAD_CAST strflx.str ().c_str ());
167
if ((*il).img_begin != NULL)
171
rc = xmlTextWriterStartElement (writer, BAD_CAST "img");
172
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "size", BAD_CAST "original");
173
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "type", BAD_CAST "in");
175
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "src", BAD_CAST (*il).img_begin->img.c_str ());
178
strflx << (*il).img_begin->width;
179
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "width", BAD_CAST strflx.str ().c_str ());
182
strflx << (*il).img_begin->height;
183
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "height", BAD_CAST strflx.str ().c_str ());
184
rc = xmlTextWriterEndElement (writer);
191
rc = xmlTextWriterStartElement (writer, BAD_CAST "img");
192
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "size", BAD_CAST "thumb");
193
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "type", BAD_CAST "in");
195
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "src", BAD_CAST (*il).img_begin->thumb.c_str ());
198
strflx << (*il).img_begin->width_thumb;
199
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "width", BAD_CAST strflx.str ().c_str ());
202
strflx << (*il).img_begin->height_thumb;
203
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "height", BAD_CAST strflx.str ().c_str ());
204
rc = xmlTextWriterEndElement (writer);
209
if ((*il).img_end != NULL)
216
rc = xmlTextWriterStartElement (writer, BAD_CAST "img");
217
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "size", BAD_CAST "original");
218
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "type", BAD_CAST "out");
220
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "src", BAD_CAST (*il).img_end->img.c_str ());
223
strflx << (*il).img_end->width;
224
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "width", BAD_CAST strflx.str ().c_str ());
227
strflx << (*il).img_end->height;
228
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "height", BAD_CAST strflx.str ().c_str ());
229
rc = xmlTextWriterEndElement (writer);
236
rc = xmlTextWriterStartElement (writer, BAD_CAST "img");
237
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "size", BAD_CAST "thumb");
238
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "type", BAD_CAST "out");
240
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "src", BAD_CAST (*il).img_end->thumb.c_str ());
243
strflx << (*il).img_end->width_thumb;
244
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "width", BAD_CAST strflx.str ().c_str ());
247
strflx << (*il).img_end->height_thumb;
248
rc = xmlTextWriterWriteAttribute (writer, BAD_CAST "height", BAD_CAST strflx.str ().c_str ());
249
rc = xmlTextWriterEndElement (writer);
253
xmlTextWriterEndElement (writer);
257
rc = xmlTextWriterEndDocument (writer);
260
printf ("testXmlwriterDoc: Error at xmlTextWriterEndDocument\n");
264
xmlFreeTextWriter (writer);
266
xml_path = f->get_opath();
267
xml_path += "/result.xml";
268
xmlSaveFileEnc (xml_path.c_str (), doc, MY_ENCODING);