libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
metaxml.cpp
Go to the documentation of this file.
1/*
2 libodsstream is a library to read and write ODS documents as streams
3 Copyright (C) 2013 Olivier Langella <Olivier.Langella@moulon.inra.fr>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20#include "../../config.h"
21#include "metaxml.h"
22#include <QDateTime>
23#include "../../odsexception.h"
24#include <quazipfile.h>
25
26#define LIBODS_GENERATOR_NAME LIBODSSTREAM_LIB_NAME "/" LIBODSSTREAM_VERSION
27
28
29std::map<const QString, const QString> MetaXml::_hash_namespace_uri;
30
31const QString &
32MetaXml::getNamespaceURI(const QString &xml_namespace)
33{
34 if(_hash_namespace_uri.size() == 0)
35 {
36 _hash_namespace_uri.insert(std::make_pair(
37 "anim", "urn:oasis:names:tc:opendocument:xmlns:animation:1.0"));
38 _hash_namespace_uri.insert(std::make_pair(
39 "chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"));
40 _hash_namespace_uri.insert(std::make_pair(
41 "config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0"));
42 _hash_namespace_uri.insert(std::make_pair(
43 "db", "urn:oasis:names:tc:opendocument:xmlns:database:1.0"));
45 std::make_pair("dc", "http://purl.org/dc/elements/1.1/"));
46 _hash_namespace_uri.insert(std::make_pair(
47 "dr3d", "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"));
48 _hash_namespace_uri.insert(std::make_pair(
49 "draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"));
50 _hash_namespace_uri.insert(std::make_pair(
51 "fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"));
52 _hash_namespace_uri.insert(std::make_pair(
53 "form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0"));
55 std::make_pair("grddl", "http://www.w3.org/2003/g/data-view#"));
57 std::make_pair("math", "http://www.w3.org/1998/Math/MathML"));
58 _hash_namespace_uri.insert(std::make_pair(
59 "meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"));
60 _hash_namespace_uri.insert(std::make_pair(
61 "number", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"));
63 std::make_pair("of", "urn:oasis:names:tc:opendocument:xmlns:of:1.2"));
64 _hash_namespace_uri.insert(std::make_pair(
65 "office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0"));
67 std::make_pair("ooo", "http://openoffice.org/2004/office"));
68 _hash_namespace_uri.insert(std::make_pair(
69 "presentation",
70 "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"));
71 _hash_namespace_uri.insert(std::make_pair(
72 "script", "urn:oasis:names:tc:opendocument:xmlns:script:1.0"));
73 _hash_namespace_uri.insert(std::make_pair(
74 "smil", "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"));
75 _hash_namespace_uri.insert(std::make_pair(
76 "style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0"));
77 _hash_namespace_uri.insert(std::make_pair(
78 "svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"));
79 _hash_namespace_uri.insert(std::make_pair(
80 "table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0"));
81 _hash_namespace_uri.insert(std::make_pair(
82 "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0"));
84 std::make_pair("xforms", "http://www.w3.org/2002/xforms"));
86 std::make_pair("calcext",
87 "urn:org:documentfoundation:names:experimental:calc:"
88 "xmlns:calcext:1.0"));
90 std::make_pair("xhtml", "http://www.w3.org/1999/xhtml"));
92 std::make_pair("xlink", "http://www.w3.org/1999/xlink"));
93 }
94 auto it = _hash_namespace_uri.find(xml_namespace);
95 if(it != _hash_namespace_uri.end())
96 {
97 return it->second;
98 }
99 else
100 {
101 throw OdsException(
102 QObject::tr("XML namespace %1 not defined in MetaXml object")
103 .arg(xml_namespace));
104 }
105}
106
107
108MetaXml::MetaXml(QuaZip *p_quaZip) : _p_quaZip(p_quaZip)
109{
110 QuaZipFile outFile(_p_quaZip);
111 QuaZipNewInfo info("meta.xml");
112 outFile.open(QIODevice::WriteOnly, info);
113 QXmlStreamWriter *p_writer = new QXmlStreamWriter(&outFile);
114 p_writer->setAutoFormatting(true);
115
116 this->WriteHeader(p_writer);
117
118 p_writer->writeStartElement(MetaXml::getNamespaceURI("office"), "meta");
119
120 /*
121 * see RFC2616, or 3.1.1 in the oasis doc : meta:generator
122 */
123 p_writer->writeStartElement(MetaXml::getNamespaceURI("meta"), "generator");
124 p_writer->writeCharacters(LIBODS_GENERATOR_NAME);
125 p_writer->writeEndElement();
126
127 QDateTime currentdate(QDateTime::currentDateTime());
128
129 p_writer->writeStartElement(MetaXml::getNamespaceURI("meta"),
130 "creation-date");
131 p_writer->writeCharacters(currentdate.toString("yyyy-MM-dd'T'HH:mm:ss"));
132 p_writer->writeEndElement();
133
134 p_writer->writeStartElement(MetaXml::getNamespaceURI("dc"), "date");
135 p_writer->writeCharacters(currentdate.toString("yyyy-MM-dd'T'HH:mm:ss"));
136 p_writer->writeEndElement();
137
138 p_writer->writeStartElement(MetaXml::getNamespaceURI("meta"),
139 "editing-cycles");
140 p_writer->writeCharacters("1");
141 p_writer->writeEndElement();
142
143 p_writer->writeStartElement(MetaXml::getNamespaceURI("meta"),
144 "editing-duration");
145 p_writer->writeCharacters("PT0.602S");
146 p_writer->writeEndElement();
147
148 p_writer->writeEndDocument();
149
150 delete p_writer;
151
152 outFile.close();
153}
154
155void
156MetaXml::WriteHeader(QXmlStreamWriter *p_writer)
157{
158 p_writer->writeStartDocument("1.0");
159 MetaXml::getNamespaceURI("office");
160
161 std::map<const QString, const QString>::const_iterator it =
163 while(it != MetaXml::_hash_namespace_uri.end())
164 {
165 p_writer->writeNamespace(QString(it->second), it->first);
166 it++;
167 }
168
169 // <manifest:manifest
170 // xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
171 // manifest:version="1.2" >
172 p_writer->writeStartElement(MetaXml::getNamespaceURI("office"),
173 "document-meta");
174 p_writer->writeAttribute(
175 MetaXml::getNamespaceURI("office"), "version", "1.2");
176 // writer.setPrefix("manifest", namespaceURI);
177 // writer.setDefaultNamespace(namespaceURI);
178 // writer.writeStartElement("mzXML");
179}
180
181
QuaZip * _p_quaZip
Definition metaxml.h:39
MetaXml(QuaZip *p_quaZip)
Definition metaxml.cpp:108
static std::map< const QString, const QString > _hash_namespace_uri
Definition metaxml.h:34
static const QString & getNamespaceURI(const QString &xml_namespace)
Definition metaxml.cpp:32
virtual ~MetaXml()
Definition metaxml.cpp:182
void WriteHeader(QXmlStreamWriter *p_writer)
Definition metaxml.cpp:156
#define LIBODS_GENERATOR_NAME
Definition metaxml.cpp:26