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