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