LibreOffice Module writerperfect (master) 1
XMLTextFrameContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11
13#include "txtparai.hxx"
14#include "xmlimp.hxx"
15#include "xmltext.hxx"
16
17#include <sal/log.hxx>
18
19using namespace com::sun::star;
20
21namespace writerperfect::exp
22{
23namespace
24{
26class XMLTextBoxContext : public XMLImportContext
27{
28public:
29 XMLTextBoxContext(XMLImport& rImport);
30
32 CreateChildContext(const OUString& rName,
33 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
34
35 void SAL_CALL
36 startElement(const OUString& rName,
37 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
38 void SAL_CALL endElement(const OUString& rName) override;
39};
40}
41
42XMLTextBoxContext::XMLTextBoxContext(XMLImport& rImport)
43 : XMLImportContext(rImport)
44{
45}
46
47rtl::Reference<XMLImportContext> XMLTextBoxContext::CreateChildContext(
48 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
49{
50 return CreateTextChildContext(GetImport(), rName);
51}
52
53void XMLTextBoxContext::startElement(
54 const OUString& /*rName*/,
55 const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
56{
57 GetImport().GetGenerator().openTextBox(librevenge::RVNGPropertyList());
58}
59
60void XMLTextBoxContext::endElement(const OUString& /*rName*/)
61{
62 GetImport().GetGenerator().closeTextBox();
63}
64
65namespace
66{
68class XMLTextImageContext : public XMLImportContext
69{
70public:
71 XMLTextImageContext(XMLImport& rImport);
72
74 CreateChildContext(const OUString& rName,
75 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
76
77 void SAL_CALL
78 startElement(const OUString& rName,
79 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
80 void SAL_CALL endElement(const OUString& rName) override;
81
82private:
83 OString m_aMimeType;
85};
86}
87
88XMLTextImageContext::XMLTextImageContext(XMLImport& rImport)
89 : XMLImportContext(rImport)
90{
91}
92
93rtl::Reference<XMLImportContext> XMLTextImageContext::CreateChildContext(
94 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
95{
96 if (rName == "office:binary-data")
97 {
98 m_xBinaryData = new XMLBase64ImportContext(GetImport());
99 return m_xBinaryData;
100 }
101 return nullptr;
102}
103
104void XMLTextImageContext::startElement(
105 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
106{
107 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
108 {
109 const OUString& rAttributeName = xAttribs->getNameByIndex(i);
110 if (rAttributeName == "loext:mime-type" || rAttributeName == "draw:mime-type")
111 m_aMimeType = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
112 }
113}
114
115void XMLTextImageContext::endElement(const OUString& /*rName*/)
116{
117 librevenge::RVNGPropertyList aPropertyList;
118
119 aPropertyList.insert("librevenge:mime-type", m_aMimeType.getStr());
120 if (m_xBinaryData.is())
121 aPropertyList.insert("office:binary-data", m_xBinaryData->getBinaryData());
122
123 GetImport().GetGenerator().insertBinaryObject(aPropertyList);
124}
125
127 : XMLImportContext(rImport)
128{
129}
130
132 const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
133{
134 if (rName == "draw:image")
135 return new XMLTextImageContext(GetImport());
136 if (rName == "draw:text-box")
137 return new XMLTextBoxContext(GetImport());
138 SAL_WARN("writerperfect", "XMLTextFrameContext::CreateChildContext: unhandled " << rName);
139 return nullptr;
140}
141
143 const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
144{
145 librevenge::RVNGPropertyList aPropertyList;
146 for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
147 {
148 const OUString& rAttributeName = xAttribs->getNameByIndex(i);
149 const OUString& rAttributeValue = xAttribs->getValueByIndex(i);
150
151 if (rAttributeName == "draw:style-name")
152 FillStyles(rAttributeValue, GetImport().GetAutomaticGraphicStyles(),
153 GetImport().GetGraphicStyles(), aPropertyList);
154 else
155 {
156 OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
157 OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8);
158 aPropertyList.insert(sName.getStr(), sValue.getStr());
159 }
160 }
161 GetImport().GetGenerator().openFrame(aPropertyList);
162}
163
164void XMLTextFrameContext::endElement(const OUString& /*rName*/)
165{
166 GetImport().GetGenerator().closeFrame();
167}
168
169} // namespace writerperfect::exp
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< XMLBase64ImportContext > m_xBinaryData
OString m_aMimeType
XMLTextFrameContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::text::TextContentAnchorType eDfltAnchorType)
Base class for a handler of a single XML element during ODF -> librevenge conversion.
Definition: xmlictxt.hxx:23
ODT export feeds this class to make librevenge calls.
Definition: xmlimp.hxx:69
librevenge::RVNGTextInterface & GetGenerator() const
Definition: xmlimp.cxx:462
void SAL_CALL endElement(const OUString &rName) override
void SAL_CALL startElement(const OUString &rName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
rtl::Reference< XMLImportContext > CreateChildContext(const OUString &rName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
OUString sName
#define SAL_WARN(area, stream)
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
void FillStyles(const OUString &rName, std::map< OUString, librevenge::RVNGPropertyList > &rAutomaticStyles, std::map< OUString, librevenge::RVNGPropertyList > &rNamedStyles, librevenge::RVNGPropertyList &rPropertyList)
Looks for rName in rAutomaticStyles (and failing that, in rNamedStyles) and fills rPropertyList based...
Definition: txtparai.cxx:623
rtl::Reference< XMLImportContext > CreateTextChildContext(XMLImport &rImport, std::u16string_view rName, bool bTopLevel)
Context factory for body text, section, table cell, etc.
Definition: xmltext.cxx:39