/src/libreoffice/editeng/source/xml/xmltxtexp.cxx
Line | Count | Source |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | /** this file implements an export of a selected EditEngine content into |
22 | | a xml stream. See editeng/source/inc/xmledit.hxx for interface */ |
23 | | #include <memory> |
24 | | #include <com/sun/star/lang/Locale.hpp> |
25 | | #include <com/sun/star/xml/sax/Writer.hpp> |
26 | | #include <com/sun/star/frame/XModel.hpp> |
27 | | #include <svl/itemprop.hxx> |
28 | | #include <com/sun/star/uno/Sequence.hxx> |
29 | | #include <comphelper/processfactory.hxx> |
30 | | #include <comphelper/diagnose_ex.hxx> |
31 | | #include <unotools/streamwrap.hxx> |
32 | | #include <xmloff/xmlexp.hxx> |
33 | | #include <editeng/unoedsrc.hxx> |
34 | | #include <editeng/unofored.hxx> |
35 | | #include <editeng/unotext.hxx> |
36 | | #include <editeng/unoprnms.hxx> |
37 | | #include <editeng/unofield.hxx> |
38 | | #include <editeng/editeng.hxx> |
39 | | #include "editsource.hxx" |
40 | | #include <editxml.hxx> |
41 | | #include <editeng/unonrule.hxx> |
42 | | #include <editeng/unoipset.hxx> |
43 | | #include <unomodel.hxx> |
44 | | |
45 | | using namespace com::sun::star; |
46 | | using namespace com::sun::star::container; |
47 | | using namespace com::sun::star::uno; |
48 | | using namespace com::sun::star::lang; |
49 | | using namespace com::sun::star::xml::sax; |
50 | | using namespace cppu; |
51 | | |
52 | | class SvxEditEngineSourceImpl : public salhelper::SimpleReferenceObject |
53 | | { |
54 | | private: |
55 | | EditEngine* mpEditEngine; |
56 | | std::unique_ptr<SvxTextForwarder> mpTextForwarder; |
57 | | |
58 | | virtual ~SvxEditEngineSourceImpl() override; |
59 | | |
60 | | public: |
61 | | explicit SvxEditEngineSourceImpl( EditEngine* pEditEngine ); |
62 | | |
63 | | SvxTextForwarder* GetTextForwarder(); |
64 | | }; |
65 | | |
66 | | SvxEditEngineSourceImpl::SvxEditEngineSourceImpl( EditEngine* pEditEngine ) |
67 | 0 | : mpEditEngine( pEditEngine ) |
68 | 0 | { |
69 | 0 | } |
70 | | |
71 | | SvxEditEngineSourceImpl::~SvxEditEngineSourceImpl() |
72 | 0 | { |
73 | 0 | } |
74 | | |
75 | | SvxTextForwarder* SvxEditEngineSourceImpl::GetTextForwarder() |
76 | 0 | { |
77 | 0 | if (!mpTextForwarder) |
78 | 0 | mpTextForwarder.reset( new SvxEditEngineForwarder( *mpEditEngine ) ); |
79 | |
|
80 | 0 | return mpTextForwarder.get(); |
81 | 0 | } |
82 | | |
83 | | // SvxTextEditSource |
84 | | SvxEditEngineSource::SvxEditEngineSource( EditEngine* pEditEngine ) |
85 | 0 | : mxImpl( new SvxEditEngineSourceImpl( pEditEngine ) ) |
86 | 0 | { |
87 | 0 | } |
88 | | |
89 | | SvxEditEngineSource::SvxEditEngineSource( SvxEditEngineSourceImpl* pImpl ) |
90 | 0 | : mxImpl(pImpl) |
91 | 0 | { |
92 | 0 | } |
93 | | |
94 | | SvxEditEngineSource::~SvxEditEngineSource() |
95 | 0 | { |
96 | 0 | } |
97 | | |
98 | | std::unique_ptr<SvxEditSource> SvxEditEngineSource::Clone() const |
99 | 0 | { |
100 | 0 | return std::unique_ptr<SvxEditSource>(new SvxEditEngineSource( mxImpl.get() )); |
101 | 0 | } |
102 | | |
103 | | SvxTextForwarder* SvxEditEngineSource::GetTextForwarder() |
104 | 0 | { |
105 | 0 | return mxImpl->GetTextForwarder(); |
106 | 0 | } |
107 | | |
108 | | |
109 | | void SvxEditEngineSource::UpdateData() |
110 | 0 | { |
111 | 0 | } |
112 | | |
113 | | |
114 | | SvxSimpleUnoModel::SvxSimpleUnoModel() |
115 | 0 | { |
116 | 0 | } |
117 | | |
118 | | // XMultiServiceFactory ( SvxFmMSFactory ) |
119 | | uno::Reference< uno::XInterface > SAL_CALL SvxSimpleUnoModel::createInstance( const OUString& aServiceSpecifier ) |
120 | 0 | { |
121 | 0 | if( aServiceSpecifier == "com.sun.star.text.NumberingRules" ) |
122 | 0 | { |
123 | 0 | return uno::Reference< uno::XInterface >( |
124 | 0 | SvxCreateNumRule(), uno::UNO_QUERY ); |
125 | 0 | } |
126 | 0 | if ( aServiceSpecifier == "com.sun.star.text.textfield.DateTime" |
127 | 0 | || aServiceSpecifier == "com.sun.star.text.TextField.DateTime" |
128 | 0 | ) |
129 | 0 | { |
130 | 0 | return cppu::getXWeak(new SvxUnoTextField( text::textfield::Type::DATE )); |
131 | 0 | } |
132 | | |
133 | 0 | if( aServiceSpecifier == "com.sun.star.text.TextField.URL" ) |
134 | 0 | { |
135 | 0 | return cppu::getXWeak(new SvxUnoTextField(text::textfield::Type::URL)); |
136 | 0 | } |
137 | | |
138 | 0 | return SvxUnoTextCreateTextField( aServiceSpecifier ); |
139 | |
|
140 | 0 | } |
141 | | |
142 | | uno::Reference< css::uno::XInterface > SAL_CALL SvxSimpleUnoModel::createInstanceWithArguments( const OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& ) |
143 | 0 | { |
144 | 0 | return createInstance( ServiceSpecifier ); |
145 | 0 | } |
146 | | |
147 | | Sequence< OUString > SAL_CALL SvxSimpleUnoModel::getAvailableServiceNames( ) |
148 | 0 | { |
149 | 0 | Sequence< OUString > aSeq; |
150 | 0 | return aSeq; |
151 | 0 | } |
152 | | |
153 | | // XAnyCompareFactory |
154 | | uno::Reference< css::ucb::XAnyCompare > SAL_CALL SvxSimpleUnoModel::createAnyCompareByName( const OUString& ) |
155 | 0 | { |
156 | 0 | return SvxCreateNumRuleCompare(); |
157 | 0 | } |
158 | | |
159 | | // XStyleFamiliesSupplier |
160 | | uno::Reference< container::XNameAccess > SAL_CALL SvxSimpleUnoModel::getStyleFamilies( ) |
161 | 0 | { |
162 | 0 | uno::Reference< container::XNameAccess > xStyles; |
163 | 0 | return xStyles; |
164 | 0 | } |
165 | | |
166 | | // XModel |
167 | | sal_Bool SAL_CALL SvxSimpleUnoModel::attachResource( const OUString&, const css::uno::Sequence< css::beans::PropertyValue >& ) |
168 | 0 | { |
169 | 0 | return false; |
170 | 0 | } |
171 | | |
172 | | OUString SAL_CALL SvxSimpleUnoModel::getURL( ) |
173 | 0 | { |
174 | 0 | return OUString(); |
175 | 0 | } |
176 | | |
177 | | css::uno::Sequence< css::beans::PropertyValue > SAL_CALL SvxSimpleUnoModel::getArgs( ) |
178 | 0 | { |
179 | 0 | Sequence< beans::PropertyValue > aSeq; |
180 | 0 | return aSeq; |
181 | 0 | } |
182 | | |
183 | | void SAL_CALL SvxSimpleUnoModel::connectController( const css::uno::Reference< css::frame::XController >& ) |
184 | 0 | { |
185 | 0 | } |
186 | | |
187 | | void SAL_CALL SvxSimpleUnoModel::disconnectController( const css::uno::Reference< css::frame::XController >& ) |
188 | 0 | { |
189 | 0 | } |
190 | | |
191 | | void SAL_CALL SvxSimpleUnoModel::lockControllers( ) |
192 | 0 | { |
193 | 0 | } |
194 | | |
195 | | void SAL_CALL SvxSimpleUnoModel::unlockControllers( ) |
196 | 0 | { |
197 | 0 | } |
198 | | |
199 | | sal_Bool SAL_CALL SvxSimpleUnoModel::hasControllersLocked( ) |
200 | 0 | { |
201 | 0 | return true; |
202 | 0 | } |
203 | | |
204 | | css::uno::Reference< css::frame::XController > SAL_CALL SvxSimpleUnoModel::getCurrentController( ) |
205 | 0 | { |
206 | 0 | uno::Reference< frame::XController > xRet; |
207 | 0 | return xRet; |
208 | 0 | } |
209 | | |
210 | | void SAL_CALL SvxSimpleUnoModel::setCurrentController( const css::uno::Reference< css::frame::XController >& ) |
211 | 0 | { |
212 | 0 | } |
213 | | |
214 | | css::uno::Reference< css::uno::XInterface > SAL_CALL SvxSimpleUnoModel::getCurrentSelection( ) |
215 | 0 | { |
216 | 0 | uno::Reference< XInterface > xRet; |
217 | 0 | return xRet; |
218 | 0 | } |
219 | | |
220 | | |
221 | | // XComponent |
222 | | void SAL_CALL SvxSimpleUnoModel::dispose( ) |
223 | 0 | { |
224 | 0 | } |
225 | | |
226 | | void SAL_CALL SvxSimpleUnoModel::addEventListener( const css::uno::Reference< css::lang::XEventListener >& ) |
227 | 0 | { |
228 | 0 | } |
229 | | |
230 | | void SAL_CALL SvxSimpleUnoModel::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& ) |
231 | 0 | { |
232 | 0 | } |
233 | | |
234 | | namespace { |
235 | | |
236 | | class SvxXMLTextExportComponent : public SvXMLExport |
237 | | { |
238 | | public: |
239 | | SvxXMLTextExportComponent( |
240 | | const css::uno::Reference< css::uno::XComponentContext >& rContext, |
241 | | EditEngine* pEditEngine, |
242 | | const ESelection& rSel, |
243 | | const css::uno::Reference< css::xml::sax::XDocumentHandler >& rHandler ); |
244 | | |
245 | | // methods without content: |
246 | | virtual void ExportAutoStyles_() override; |
247 | | virtual void ExportMasterStyles_() override; |
248 | | virtual void ExportContent_() override; |
249 | | |
250 | | private: |
251 | | rtl::Reference< SvxUnoText > mxText; |
252 | | }; |
253 | | |
254 | | } |
255 | | |
256 | | SvxXMLTextExportComponent::SvxXMLTextExportComponent( |
257 | | const css::uno::Reference< css::uno::XComponentContext >& xContext, |
258 | | EditEngine* pEditEngine, |
259 | | const ESelection& rSel, |
260 | | const css::uno::Reference< css::xml::sax::XDocumentHandler > & xHandler) |
261 | 0 | : SvXMLExport( xContext, u""_ustr, /*rFileName*/u""_ustr, xHandler, static_cast<frame::XModel*>(new SvxSimpleUnoModel()), FieldUnit::CM, |
262 | 0 | SvXMLExportFlags::OASIS | SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::CONTENT | SvXMLExportFlags::EMBEDDED ) |
263 | 0 | { |
264 | 0 | SvxEditEngineSource aEditSource( pEditEngine ); |
265 | |
|
266 | 0 | static const SfxItemPropertyMapEntry SvxXMLTextExportComponentPropertyMap[] = |
267 | 0 | { |
268 | 0 | SVX_UNOEDIT_CHAR_PROPERTIES, |
269 | 0 | SVX_UNOEDIT_FONT_PROPERTIES, |
270 | 0 | { UNO_NAME_NUMBERING_RULES, EE_PARA_NUMBULLET, cppu::UnoType<css::container::XIndexReplace>::get(), 0, 0 }, |
271 | 0 | { UNO_NAME_NUMBERING, EE_PARA_BULLETSTATE,cppu::UnoType<bool>::get(), 0, 0 }, |
272 | 0 | { UNO_NAME_NUMBERING_LEVEL, EE_PARA_OUTLLEVEL, ::cppu::UnoType<sal_Int16>::get(), 0, 0 }, |
273 | 0 | SVX_UNOEDIT_PARA_PROPERTIES, |
274 | 0 | }; |
275 | 0 | static SvxItemPropertySet aSvxXMLTextExportComponentPropertySet( SvxXMLTextExportComponentPropertyMap, EditEngine::GetGlobalItemPool() ); |
276 | |
|
277 | 0 | mxText = new SvxUnoText( &aEditSource, &aSvxXMLTextExportComponentPropertySet, mxText ); |
278 | 0 | mxText->SetSelection(rSel); |
279 | 0 | } |
280 | | |
281 | | void SvxWriteXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel ) |
282 | 0 | { |
283 | 0 | try |
284 | 0 | { |
285 | 0 | do |
286 | 0 | { |
287 | | // create service factory |
288 | 0 | const uno::Reference<uno::XComponentContext>& xContext( ::comphelper::getProcessComponentContext() ); |
289 | | |
290 | | // create document handler |
291 | 0 | uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext ); |
292 | | |
293 | | // create output stream and active data source |
294 | 0 | uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( rStream ) ); |
295 | | |
296 | | /* testcode |
297 | | static constexpr OUStringLiteral aURL( u"file:///e:/test.xml" ); |
298 | | SvFileStream aStream(aURL, StreamMode::WRITE | StreamMode::TRUNC); |
299 | | xOut = new utl::OOutputStreamWrapper(aStream); |
300 | | */ |
301 | | |
302 | |
|
303 | 0 | xWriter->setOutputStream( xOut ); |
304 | | |
305 | | // export text |
306 | | |
307 | | // SvxXMLTextExportComponent aExporter( &rEditEngine, rSel, aName, xHandler ); |
308 | 0 | uno::Reference< xml::sax::XDocumentHandler > xHandler(xWriter, UNO_QUERY_THROW); |
309 | 0 | rtl::Reference< SvxXMLTextExportComponent > xExporter( new SvxXMLTextExportComponent( xContext, &rEditEngine, rSel, xHandler ) ); |
310 | |
|
311 | 0 | xExporter->exportDoc(); |
312 | | |
313 | | /* testcode |
314 | | aStream.Close(); |
315 | | */ |
316 | |
|
317 | 0 | } |
318 | 0 | while( false ); |
319 | 0 | } |
320 | 0 | catch( const uno::Exception& ) |
321 | 0 | { |
322 | 0 | TOOLS_WARN_EXCEPTION("editeng", "exception during xml export"); |
323 | 0 | } |
324 | 0 | } |
325 | | |
326 | | // methods without content: |
327 | | void SvxXMLTextExportComponent::ExportAutoStyles_() |
328 | 0 | { |
329 | 0 | rtl::Reference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() ); |
330 | |
|
331 | 0 | xTextExport->collectTextAutoStyles( mxText ); |
332 | 0 | xTextExport->exportTextAutoStyles(); |
333 | 0 | } |
334 | | |
335 | | void SvxXMLTextExportComponent::ExportContent_() |
336 | 0 | { |
337 | 0 | rtl::Reference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() ); |
338 | |
|
339 | 0 | xTextExport->exportText( mxText ); |
340 | 0 | } |
341 | | |
342 | 0 | void SvxXMLTextExportComponent::ExportMasterStyles_() {} |
343 | | |
344 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |