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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /** this file implements an export of a selected EditEngine content into
22 a xml stream. See editeng/source/inc/xmledit.hxx for interface */
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>
33 #include <comphelper/processfactory.hxx>
34 #include <comphelper/diagnose_ex.hxx>
35 #include <unotools/streamwrap.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>
49 using namespace com::sun::star
;
50 using namespace com::sun::star::container
;
51 using namespace com::sun::star::document
;
52 using namespace com::sun::star::uno
;
53 using namespace com::sun::star::awt
;
54 using namespace com::sun::star::lang
;
55 using namespace com::sun::star::xml::sax
;
58 class SvxEditEngineSourceImpl
;
60 class SvxEditEngineSourceImpl
: public salhelper::SimpleReferenceObject
63 EditEngine
* mpEditEngine
;
64 std::unique_ptr
<SvxTextForwarder
> mpTextForwarder
;
66 virtual ~SvxEditEngineSourceImpl() override
;
69 explicit SvxEditEngineSourceImpl( EditEngine
* pEditEngine
);
71 SvxTextForwarder
* GetTextForwarder();
74 SvxEditEngineSourceImpl::SvxEditEngineSourceImpl( EditEngine
* pEditEngine
)
75 : mpEditEngine( pEditEngine
)
79 SvxEditEngineSourceImpl::~SvxEditEngineSourceImpl()
83 SvxTextForwarder
* SvxEditEngineSourceImpl::GetTextForwarder()
86 mpTextForwarder
.reset( new SvxEditEngineForwarder( *mpEditEngine
) );
88 return mpTextForwarder
.get();
92 SvxEditEngineSource::SvxEditEngineSource( EditEngine
* pEditEngine
)
93 : mxImpl( new SvxEditEngineSourceImpl( pEditEngine
) )
97 SvxEditEngineSource::SvxEditEngineSource( SvxEditEngineSourceImpl
* pImpl
)
102 SvxEditEngineSource::~SvxEditEngineSource()
106 std::unique_ptr
<SvxEditSource
> SvxEditEngineSource::Clone() const
108 return std::unique_ptr
<SvxEditSource
>(new SvxEditEngineSource( mxImpl
.get() ));
111 SvxTextForwarder
* SvxEditEngineSource::GetTextForwarder()
113 return mxImpl
->GetTextForwarder();
117 void SvxEditEngineSource::UpdateData()
122 SvxSimpleUnoModel::SvxSimpleUnoModel()
126 // XMultiServiceFactory ( SvxFmMSFactory )
127 uno::Reference
< uno::XInterface
> SAL_CALL
SvxSimpleUnoModel::createInstance( const OUString
& aServiceSpecifier
)
129 if( aServiceSpecifier
== "com.sun.star.text.NumberingRules" )
131 return uno::Reference
< uno::XInterface
>(
132 SvxCreateNumRule(), uno::UNO_QUERY
);
134 if ( aServiceSpecifier
== "com.sun.star.text.textfield.DateTime"
135 || aServiceSpecifier
== "com.sun.star.text.TextField.DateTime"
138 return cppu::getXWeak(new SvxUnoTextField( text::textfield::Type::DATE
));
141 if( aServiceSpecifier
== "com.sun.star.text.TextField.URL" )
143 return cppu::getXWeak(new SvxUnoTextField(text::textfield::Type::URL
));
146 return SvxUnoTextCreateTextField( aServiceSpecifier
);
150 uno::Reference
< css::uno::XInterface
> SAL_CALL
SvxSimpleUnoModel::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const css::uno::Sequence
< css::uno::Any
>& )
152 return createInstance( ServiceSpecifier
);
155 Sequence
< OUString
> SAL_CALL
SvxSimpleUnoModel::getAvailableServiceNames( )
157 Sequence
< OUString
> aSeq
;
161 // XAnyCompareFactory
162 uno::Reference
< css::ucb::XAnyCompare
> SAL_CALL
SvxSimpleUnoModel::createAnyCompareByName( const OUString
& )
164 return SvxCreateNumRuleCompare();
167 // XStyleFamiliesSupplier
168 uno::Reference
< container::XNameAccess
> SAL_CALL
SvxSimpleUnoModel::getStyleFamilies( )
170 uno::Reference
< container::XNameAccess
> xStyles
;
175 sal_Bool SAL_CALL
SvxSimpleUnoModel::attachResource( const OUString
&, const css::uno::Sequence
< css::beans::PropertyValue
>& )
180 OUString SAL_CALL
SvxSimpleUnoModel::getURL( )
185 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
SvxSimpleUnoModel::getArgs( )
187 Sequence
< beans::PropertyValue
> aSeq
;
191 void SAL_CALL
SvxSimpleUnoModel::connectController( const css::uno::Reference
< css::frame::XController
>& )
195 void SAL_CALL
SvxSimpleUnoModel::disconnectController( const css::uno::Reference
< css::frame::XController
>& )
199 void SAL_CALL
SvxSimpleUnoModel::lockControllers( )
203 void SAL_CALL
SvxSimpleUnoModel::unlockControllers( )
207 sal_Bool SAL_CALL
SvxSimpleUnoModel::hasControllersLocked( )
212 css::uno::Reference
< css::frame::XController
> SAL_CALL
SvxSimpleUnoModel::getCurrentController( )
214 uno::Reference
< frame::XController
> xRet
;
218 void SAL_CALL
SvxSimpleUnoModel::setCurrentController( const css::uno::Reference
< css::frame::XController
>& )
222 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
SvxSimpleUnoModel::getCurrentSelection( )
224 uno::Reference
< XInterface
> xRet
;
230 void SAL_CALL
SvxSimpleUnoModel::dispose( )
234 void SAL_CALL
SvxSimpleUnoModel::addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& )
238 void SAL_CALL
SvxSimpleUnoModel::removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& )
244 class SvxXMLTextExportComponent
: public SvXMLExport
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
);
253 // methods without content:
254 virtual void ExportAutoStyles_() override
;
255 virtual void ExportMasterStyles_() override
;
256 virtual void ExportContent_() override
;
259 css::uno::Reference
< css::text::XText
> mxText
;
264 SvxXMLTextExportComponent::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
,
270 SvXMLExportFlags::OASIS
| SvXMLExportFlags::AUTOSTYLES
| SvXMLExportFlags::CONTENT
)
272 SvxEditEngineSource
aEditSource( pEditEngine
);
274 static const SfxItemPropertyMapEntry SvxXMLTextExportComponentPropertyMap
[] =
276 SVX_UNOEDIT_CHAR_PROPERTIES
,
277 SVX_UNOEDIT_FONT_PROPERTIES
,
278 { UNO_NAME_NUMBERING_RULES
, EE_PARA_NUMBULLET
, cppu::UnoType
<css::container::XIndexReplace
>::get(), 0, 0 },
279 { UNO_NAME_NUMBERING
, EE_PARA_BULLETSTATE
,cppu::UnoType
<bool>::get(), 0, 0 },
280 { UNO_NAME_NUMBERING_LEVEL
, EE_PARA_OUTLLEVEL
, ::cppu::UnoType
<sal_Int16
>::get(), 0, 0 },
281 SVX_UNOEDIT_PARA_PROPERTIES
,
283 static SvxItemPropertySet
aSvxXMLTextExportComponentPropertySet( SvxXMLTextExportComponentPropertyMap
, EditEngine::GetGlobalItemPool() );
285 rtl::Reference
<SvxUnoText
> pUnoText
= new SvxUnoText( &aEditSource
, &aSvxXMLTextExportComponentPropertySet
, mxText
);
286 pUnoText
->SetSelection( rSel
);
291 void SvxWriteXML( EditEngine
& rEditEngine
, SvStream
& rStream
, const ESelection
& rSel
)
297 // create service factory
298 uno::Reference
<uno::XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
300 // create document handler
301 uno::Reference
< xml::sax::XWriter
> xWriter
= xml::sax::Writer::create( xContext
);
303 // create output stream and active data source
304 uno::Reference
<io::XOutputStream
> xOut( new utl::OOutputStreamWrapper( rStream
) );
307 static constexpr OUStringLiteral aURL( u"file:///e:/test.xml" );
308 SvFileStream aStream(aURL, StreamMode::WRITE | StreamMode::TRUNC);
309 xOut = new utl::OOutputStreamWrapper(aStream);
313 xWriter
->setOutputStream( xOut
);
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
) );
321 xExporter
->exportDoc();
330 catch( const uno::Exception
& )
332 TOOLS_WARN_EXCEPTION("editeng", "exception during xml export");
336 // methods without content:
337 void SvxXMLTextExportComponent::ExportAutoStyles_()
339 rtl::Reference
< XMLTextParagraphExport
> xTextExport( GetTextParagraphExport() );
341 xTextExport
->collectTextAutoStyles( mxText
);
342 xTextExport
->exportTextAutoStyles();
345 void SvxXMLTextExportComponent::ExportContent_()
347 rtl::Reference
< XMLTextParagraphExport
> xTextExport( GetTextParagraphExport() );
349 xTextExport
->exportText( mxText
);
352 void SvxXMLTextExportComponent::ExportMasterStyles_() {}
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */