1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "xmlmetai.hxx"
14 using namespace com::sun::star
;
16 namespace writerperfect::exp
20 /// Handler for <dc:title>.
21 class XMLDcTitleContext
: public XMLImportContext
24 XMLDcTitleContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
);
26 void SAL_CALL
characters(const OUString
& rChars
) override
;
29 XMLMetaDocumentContext
& mrMeta
;
33 XMLDcTitleContext::XMLDcTitleContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
)
34 : XMLImportContext(rImport
)
39 void XMLDcTitleContext::characters(const OUString
& rChars
)
41 OString sCharU8
= OUStringToOString(rChars
, RTL_TEXTENCODING_UTF8
);
42 if (!mrMeta
.GetPropertyList()["dc:title"])
43 mrMeta
.GetPropertyList().insert("dc:title", librevenge::RVNGString(sCharU8
.getStr()));
48 /// Handler for <dc:language>.
49 class XMLDcLanguageContext
: public XMLImportContext
52 XMLDcLanguageContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
);
54 void SAL_CALL
characters(const OUString
& rChars
) override
;
57 XMLMetaDocumentContext
& mrMeta
;
61 XMLDcLanguageContext::XMLDcLanguageContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
)
62 : XMLImportContext(rImport
)
67 void XMLDcLanguageContext::characters(const OUString
& rChars
)
69 OString sCharU8
= OUStringToOString(rChars
, RTL_TEXTENCODING_UTF8
);
70 if (!mrMeta
.GetPropertyList()["dc:language"])
71 mrMeta
.GetPropertyList().insert("dc:language", librevenge::RVNGString(sCharU8
.getStr()));
76 /// Handler for <dc:date>.
77 class XMLDcDateContext
: public XMLImportContext
80 XMLDcDateContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
);
82 void SAL_CALL
characters(const OUString
& rChars
) override
;
85 XMLMetaDocumentContext
& mrMeta
;
89 XMLDcDateContext::XMLDcDateContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
)
90 : XMLImportContext(rImport
)
95 void XMLDcDateContext::characters(const OUString
& rChars
)
97 OString sCharU8
= OUStringToOString(rChars
, RTL_TEXTENCODING_UTF8
);
98 if (!mrMeta
.GetPropertyList()["dc:date"])
99 mrMeta
.GetPropertyList().insert("dc:date", librevenge::RVNGString(sCharU8
.getStr()));
104 /// Handler for <meta:generator>.
105 class XMLMetaGeneratorContext
: public XMLImportContext
108 XMLMetaGeneratorContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
);
110 void SAL_CALL
characters(const OUString
& rChars
) override
;
113 XMLMetaDocumentContext
& mrMeta
;
117 XMLMetaGeneratorContext::XMLMetaGeneratorContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
)
118 : XMLImportContext(rImport
)
123 void XMLMetaGeneratorContext::characters(const OUString
& rChars
)
125 OString sCharU8
= OUStringToOString(rChars
, RTL_TEXTENCODING_UTF8
);
126 mrMeta
.GetPropertyList().insert("meta:generator", librevenge::RVNGString(sCharU8
.getStr()));
131 /// Handler for <meta:initial-creator>.
132 class XMLMetaInitialCreatorContext
: public XMLImportContext
135 XMLMetaInitialCreatorContext(XMLImport
& rImport
, XMLMetaDocumentContext
& rMeta
);
137 void SAL_CALL
characters(const OUString
& rChars
) override
;
140 XMLMetaDocumentContext
& mrMeta
;
144 XMLMetaInitialCreatorContext::XMLMetaInitialCreatorContext(XMLImport
& rImport
,
145 XMLMetaDocumentContext
& rMeta
)
146 : XMLImportContext(rImport
)
151 void XMLMetaInitialCreatorContext::characters(const OUString
& rChars
)
153 OString sCharU8
= OUStringToOString(rChars
, RTL_TEXTENCODING_UTF8
);
154 if (!mrMeta
.GetPropertyList()["meta:initial-creator"])
155 mrMeta
.GetPropertyList().insert("meta:initial-creator",
156 librevenge::RVNGString(sCharU8
.getStr()));
159 XMLMetaDocumentContext::XMLMetaDocumentContext(XMLImport
& rImport
)
160 : XMLImportContext(rImport
)
162 librevenge::RVNGPropertyList::Iter
it(GetImport().GetMetaData());
163 for (it
.rewind(); it
.next();)
164 m_aPropertyList
.insert(it
.key(), it()->clone());
165 m_aPropertyList
.insert("librevenge:cover-images", GetImport().GetCoverImages());
168 rtl::Reference
<XMLImportContext
> XMLMetaDocumentContext::CreateChildContext(
169 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
171 if (rName
== "dc:title")
172 return new XMLDcTitleContext(GetImport(), *this);
173 if (rName
== "dc:language")
174 return new XMLDcLanguageContext(GetImport(), *this);
175 if (rName
== "dc:date")
176 return new XMLDcDateContext(GetImport(), *this);
177 if (rName
== "meta:generator")
178 return new XMLMetaGeneratorContext(GetImport(), *this);
179 if (rName
== "meta:initial-creator")
180 return new XMLMetaInitialCreatorContext(GetImport(), *this);
184 void XMLMetaDocumentContext::endElement(const OUString
& /*rName*/)
186 GetImport().GetGenerator().setDocumentMetaData(m_aPropertyList
);
189 XMPParser::XMPParser(librevenge::RVNGPropertyList
& rMetaData
)
190 : mrMetaData(rMetaData
)
194 XMPParser::~XMPParser() = default;
196 void XMPParser::startDocument() {}
198 void XMPParser::endDocument()
200 if (!mrMetaData
["dc:identifier"] && !m_aIdentifier
.isEmpty())
201 mrMetaData
.insert("dc:identifier", m_aIdentifier
.toUtf8().getStr());
202 if (!mrMetaData
["dc:title"] && !m_aTitle
.isEmpty())
203 mrMetaData
.insert("dc:title", m_aTitle
.toUtf8().getStr());
204 if (!mrMetaData
["meta:initial-creator"] && !m_aCreator
.isEmpty())
205 mrMetaData
.insert("meta:initial-creator", m_aCreator
.toUtf8().getStr());
206 if (!mrMetaData
["dc:language"] && !m_aLanguage
.isEmpty())
207 mrMetaData
.insert("dc:language", m_aLanguage
.toUtf8().getStr());
208 if (!mrMetaData
["dc:date"] && !m_aDate
.isEmpty())
209 mrMetaData
.insert("dc:date", m_aDate
.toUtf8().getStr());
212 void XMPParser::startElement(const OUString
& rName
,
213 const uno::Reference
<xml::sax::XAttributeList
>& /*xAttribs*/)
215 if (rName
== "dc:identifier")
216 m_bInIdentifier
= true;
217 else if (rName
== "dc:title")
219 else if (rName
== "dc:creator")
221 else if (rName
== "dc:language")
222 m_bInLanguage
= true;
223 else if (rName
== "dc:date")
225 else if (rName
== "rdf:li")
228 m_bInTitleItem
= true;
229 else if (m_bInCreator
)
230 m_bInCreatorItem
= true;
231 else if (m_bInLanguage
)
232 m_bInLanguageItem
= true;
234 m_bInDateItem
= true;
238 void XMPParser::endElement(const OUString
& rName
)
240 if (rName
== "dc:identifier")
241 m_bInIdentifier
= false;
242 else if (rName
== "dc:title")
244 else if (rName
== "dc:creator")
245 m_bInCreator
= false;
246 else if (rName
== "dc:language")
247 m_bInLanguage
= false;
248 else if (rName
== "dc:date")
250 else if (rName
== "rdf:li")
253 m_bInTitleItem
= false;
254 else if (m_bInCreator
)
255 m_bInCreatorItem
= false;
256 else if (m_bInLanguage
)
257 m_bInLanguageItem
= false;
259 m_bInDateItem
= false;
263 void XMPParser::characters(const OUString
& rChars
)
266 m_aIdentifier
+= rChars
;
267 else if (m_bInTitleItem
)
269 else if (m_bInCreatorItem
)
270 m_aCreator
+= rChars
;
271 else if (m_bInLanguageItem
)
272 m_aLanguage
+= rChars
;
273 else if (m_bInDateItem
)
277 void XMPParser::ignorableWhitespace(const OUString
& /*rWhitespace*/) {}
279 void XMPParser::processingInstruction(const OUString
& /*rTarget*/, const OUString
& /*rData*/) {}
281 void XMPParser::setDocumentLocator(const uno::Reference
<xml::sax::XLocator
>& /*xLocator*/) {}
283 } // namespace writerperfect::exp
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */