1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26
27 /** this file implements an export of a selected EditEngine content into
28 a xml stream. See editeng/source/inc/xmledit.hxx for interface */
29 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
30 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/io/XActiveDataSource.hpp>
33 #include <tools/debug.hxx>
34 #include <svl/itemprop.hxx>
35 #include <svl/brdcst.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <sot/storage.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include <xmloff/xmlnmspe.hxx>
41 #include <xmloff/nmspmap.hxx>
42 #include <xmloff/xmlmetae.hxx>
43 #include <cppuhelper/implbase4.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <unotools/streamwrap.hxx>
46 #include <xmloff/xmlexp.hxx>
47 #include <editeng/unoedsrc.hxx>
48 #include <editeng/unofored.hxx>
49 #include <editeng/unotext.hxx>
50 #include <editeng/unoprnms.hxx>
51 #include <editeng/unofield.hxx>
52 #include <editeng/editeng.hxx>
53 #include "editsource.hxx"
54 #include <editeng/unonrule.hxx>
55 #include <editeng/unoipset.hxx>
56
57 using namespace com::sun::star;
58 using namespace com::sun::star::container;
59 using namespace com::sun::star::document;
60 using namespace com::sun::star::uno;
61 using namespace com::sun::star::awt;
62 using namespace com::sun::star::lang;
63 using namespace com::sun::star::xml::sax;
64 using namespace ::rtl;
65 using namespace cppu;
66
67 ///////////////////////////////////////////////////////////////////////
68
69 class SvxEditEngineSourceImpl;
70
71 ///////////////////////////////////////////////////////////////////////
72
73 class SvxEditEngineSourceImpl
74 {
75 private:
76 oslInterlockedCount maRefCount;
77
78 EditEngine* mpEditEngine;
79 SvxTextForwarder* mpTextForwarder;
80
81 ~SvxEditEngineSourceImpl();
82
83 public:
84 SvxEditEngineSourceImpl( EditEngine* pEditEngine );
85
86 void SAL_CALL acquire();
87 void SAL_CALL release();
88
89 SvxTextForwarder* GetTextForwarder();
90 };
91
92 ///////////////////////////////////////////////////////////////////////
93
94
95 //------------------------------------------------------------------------
96
SvxEditEngineSourceImpl(EditEngine * pEditEngine)97 SvxEditEngineSourceImpl::SvxEditEngineSourceImpl( EditEngine* pEditEngine )
98 : maRefCount(0),
99 mpEditEngine( pEditEngine ),
100 mpTextForwarder(NULL)
101 {
102 }
103
104 //------------------------------------------------------------------------
105
~SvxEditEngineSourceImpl()106 SvxEditEngineSourceImpl::~SvxEditEngineSourceImpl()
107 {
108 delete mpTextForwarder;
109 }
110
111 //------------------------------------------------------------------------
112
acquire()113 void SAL_CALL SvxEditEngineSourceImpl::acquire()
114 {
115 osl_incrementInterlockedCount( &maRefCount );
116 }
117
118 //------------------------------------------------------------------------
119
release()120 void SAL_CALL SvxEditEngineSourceImpl::release()
121 {
122 if( ! osl_decrementInterlockedCount( &maRefCount ) )
123 delete this;
124 }
125
126 //------------------------------------------------------------------------
127
GetTextForwarder()128 SvxTextForwarder* SvxEditEngineSourceImpl::GetTextForwarder()
129 {
130 if (!mpTextForwarder)
131 mpTextForwarder = new SvxEditEngineForwarder( *mpEditEngine );
132
133 return mpTextForwarder;
134 }
135
136 // --------------------------------------------------------------------
137 // SvxTextEditSource
138 // --------------------------------------------------------------------
139
SvxEditEngineSource(EditEngine * pEditEngine)140 SvxEditEngineSource::SvxEditEngineSource( EditEngine* pEditEngine )
141 {
142 mpImpl = new SvxEditEngineSourceImpl( pEditEngine );
143 mpImpl->acquire();
144 }
145
146 // --------------------------------------------------------------------
147
SvxEditEngineSource(SvxEditEngineSourceImpl * pImpl)148 SvxEditEngineSource::SvxEditEngineSource( SvxEditEngineSourceImpl* pImpl )
149 {
150 mpImpl = pImpl;
151 mpImpl->acquire();
152 }
153
154 //------------------------------------------------------------------------
155
~SvxEditEngineSource()156 SvxEditEngineSource::~SvxEditEngineSource()
157 {
158 mpImpl->release();
159 }
160
161 //------------------------------------------------------------------------
162
Clone() const163 SvxEditSource* SvxEditEngineSource::Clone() const
164 {
165 return new SvxEditEngineSource( mpImpl );
166 }
167
168 //------------------------------------------------------------------------
169
GetTextForwarder()170 SvxTextForwarder* SvxEditEngineSource::GetTextForwarder()
171 {
172 return mpImpl->GetTextForwarder();
173 }
174
175 //------------------------------------------------------------------------
176
UpdateData()177 void SvxEditEngineSource::UpdateData()
178 {
179 }
180
181 class SvxSimpleUnoModel : public cppu::WeakAggImplHelper4<
182 ::com::sun::star::frame::XModel,
183 ::com::sun::star::ucb::XAnyCompareFactory,
184 ::com::sun::star::style::XStyleFamiliesSupplier,
185 ::com::sun::star::lang::XMultiServiceFactory >
186 {
187 public:
188 SvxSimpleUnoModel();
189 virtual ~SvxSimpleUnoModel();
190
191
192 // XMultiServiceFactory
193 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
194 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
195 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
196
197 // XStyleFamiliesSupplier
198 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getStyleFamilies( ) throw(::com::sun::star::uno::RuntimeException);
199
200 // XAnyCompareFactory
201 virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XAnyCompare > SAL_CALL createAnyCompareByName( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException);
202
203 // XModel
204 virtual sal_Bool SAL_CALL attachResource( const ::rtl::OUString& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw (::com::sun::star::uno::RuntimeException);
205 virtual ::rtl::OUString SAL_CALL getURL( ) throw (::com::sun::star::uno::RuntimeException);
206 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getArgs( ) throw (::com::sun::star::uno::RuntimeException);
207 virtual void SAL_CALL connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::uno::RuntimeException);
208 virtual void SAL_CALL disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::uno::RuntimeException);
209 virtual void SAL_CALL lockControllers( ) throw (::com::sun::star::uno::RuntimeException);
210 virtual void SAL_CALL unlockControllers( ) throw (::com::sun::star::uno::RuntimeException);
211 virtual sal_Bool SAL_CALL hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException);
212 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL getCurrentController( ) throw (::com::sun::star::uno::RuntimeException);
213 virtual void SAL_CALL setCurrentController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
214 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException);
215
216 // XComponent
217 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
218 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
219 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
220
221 };
222
SvxSimpleUnoModel()223 SvxSimpleUnoModel::SvxSimpleUnoModel()
224 {
225 }
226
~SvxSimpleUnoModel()227 SvxSimpleUnoModel::~SvxSimpleUnoModel()
228 {
229 }
230
231 // XMultiServiceFactory ( SvxFmMSFactory )
createInstance(const OUString & aServiceSpecifier)232 uno::Reference< uno::XInterface > SAL_CALL SvxSimpleUnoModel::createInstance( const OUString& aServiceSpecifier )
233 throw(uno::Exception, uno::RuntimeException)
234 {
235 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.NumberingRules" ) ) )
236 {
237 return uno::Reference< uno::XInterface >(
238 SvxCreateNumRule(), uno::UNO_QUERY );
239 }
240 if ( (0 == aServiceSpecifier.reverseCompareToAsciiL(
241 RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.DateTime")))
242 || (0 == aServiceSpecifier.reverseCompareToAsciiL(
243 RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime")))
244 )
245 {
246 return (::cppu::OWeakObject * )new SvxUnoTextField( ID_EXT_DATEFIELD );
247 }
248
249 return SvxUnoTextCreateTextField( aServiceSpecifier );
250
251 }
252
createInstanceWithArguments(const::rtl::OUString & ServiceSpecifier,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> &)253 uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvxSimpleUnoModel::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
254 {
255 return createInstance( ServiceSpecifier );
256 }
257
getAvailableServiceNames()258 Sequence< ::rtl::OUString > SAL_CALL SvxSimpleUnoModel::getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
259 {
260 Sequence< OUString > aSeq;
261 return aSeq;
262 }
263
264 // XAnyCompareFactory
createAnyCompareByName(const OUString & PropertyName)265 uno::Reference< com::sun::star::ucb::XAnyCompare > SAL_CALL SvxSimpleUnoModel::createAnyCompareByName( const OUString& PropertyName )
266 throw(uno::RuntimeException)
267 {
268 (void)PropertyName;
269 return SvxCreateNumRuleCompare();
270 }
271
272 // XStyleFamiliesSupplier
getStyleFamilies()273 uno::Reference< container::XNameAccess > SAL_CALL SvxSimpleUnoModel::getStyleFamilies( )
274 throw(uno::RuntimeException)
275 {
276 uno::Reference< container::XNameAccess > xStyles;
277 return xStyles;
278 }
279
280 // XModel
attachResource(const::rtl::OUString & aURL,const::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & aArgs)281 sal_Bool SAL_CALL SvxSimpleUnoModel::attachResource( const ::rtl::OUString& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw (::com::sun::star::uno::RuntimeException)
282 {
283 (void)aURL;
284 (void)aArgs;
285 return sal_False;
286 }
287
getURL()288 ::rtl::OUString SAL_CALL SvxSimpleUnoModel::getURL( ) throw (::com::sun::star::uno::RuntimeException)
289 {
290 OUString aStr;
291 return aStr;
292 }
293
getArgs()294 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SvxSimpleUnoModel::getArgs( ) throw (::com::sun::star::uno::RuntimeException)
295 {
296 Sequence< beans::PropertyValue > aSeq;
297 return aSeq;
298 }
299
connectController(const::com::sun::star::uno::Reference<::com::sun::star::frame::XController> &)300 void SAL_CALL SvxSimpleUnoModel::connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::uno::RuntimeException)
301 {
302 }
303
disconnectController(const::com::sun::star::uno::Reference<::com::sun::star::frame::XController> &)304 void SAL_CALL SvxSimpleUnoModel::disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::uno::RuntimeException)
305 {
306 }
307
lockControllers()308 void SAL_CALL SvxSimpleUnoModel::lockControllers( ) throw (::com::sun::star::uno::RuntimeException)
309 {
310 }
311
unlockControllers()312 void SAL_CALL SvxSimpleUnoModel::unlockControllers( ) throw (::com::sun::star::uno::RuntimeException)
313 {
314 }
315
hasControllersLocked()316 sal_Bool SAL_CALL SvxSimpleUnoModel::hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException)
317 {
318 return sal_True;
319 }
320
getCurrentController()321 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL SvxSimpleUnoModel::getCurrentController( ) throw (::com::sun::star::uno::RuntimeException)
322 {
323 uno::Reference< frame::XController > xRet;
324 return xRet;
325 }
326
setCurrentController(const::com::sun::star::uno::Reference<::com::sun::star::frame::XController> &)327 void SAL_CALL SvxSimpleUnoModel::setCurrentController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
328 {
329 }
330
getCurrentSelection()331 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvxSimpleUnoModel::getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException)
332 {
333 uno::Reference< XInterface > xRet;
334 return xRet;
335 }
336
337
338 // XComponent
dispose()339 void SAL_CALL SvxSimpleUnoModel::dispose( ) throw (::com::sun::star::uno::RuntimeException)
340 {
341 }
342
addEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> &)343 void SAL_CALL SvxSimpleUnoModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) throw (::com::sun::star::uno::RuntimeException)
344 {
345 }
346
removeEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> &)347 void SAL_CALL SvxSimpleUnoModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) throw (::com::sun::star::uno::RuntimeException)
348 {
349 }
350
351 ///////////////////////////////////////////////////////////////////////
352
353 class SvxXMLTextExportComponent : public SvXMLExport
354 {
355 public:
356 // #110680#
357 SvxXMLTextExportComponent(
358 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
359 EditEngine* pEditEngine,
360 const ESelection& rSel,
361 const ::rtl::OUString& rFileName,
362 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > & xHandler );
363
364 ~SvxXMLTextExportComponent();
365
366 // methods without content:
367 virtual void _ExportAutoStyles();
368 virtual void _ExportMasterStyles();
369 virtual void _ExportContent();
370
371 private:
372 com::sun::star::uno::Reference< com::sun::star::text::XText > mxText;
373 EditEngine* mpEditEngine;
374 ESelection maSelection;
375 };
376
377 ///////////////////////////////////////////////////////////////////////
378
379 // #110680#
SvxXMLTextExportComponent(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> xServiceFactory,EditEngine * pEditEngine,const ESelection & rSel,const::rtl::OUString & rFileName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> & xHandler)380 SvxXMLTextExportComponent::SvxXMLTextExportComponent(
381 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
382 EditEngine* pEditEngine,
383 const ESelection& rSel,
384 const ::rtl::OUString& rFileName,
385 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > & xHandler)
386 : SvXMLExport( xServiceFactory, rFileName, xHandler, ((frame::XModel*)new SvxSimpleUnoModel()), MAP_CM ),
387 mpEditEngine( pEditEngine ),
388 maSelection( rSel )
389 {
390 SvxEditEngineSource aEditSource( pEditEngine );
391
392 static const SfxItemPropertyMapEntry SvxXMLTextExportComponentPropertyMap[] =
393 {
394 SVX_UNOEDIT_CHAR_PROPERTIES,
395 SVX_UNOEDIT_FONT_PROPERTIES,
396 // SVX_UNOEDIT_OUTLINER_PROPERTIES,
397 {MAP_CHAR_LEN(UNO_NAME_NUMBERING_RULES), EE_PARA_NUMBULLET, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace>*)0), 0, 0 },
398 {MAP_CHAR_LEN(UNO_NAME_NUMBERING), EE_PARA_BULLETSTATE,&::getBooleanCppuType(), 0, 0 },
399 {MAP_CHAR_LEN(UNO_NAME_NUMBERING_LEVEL), EE_PARA_OUTLLEVEL, &::getCppuType((const sal_Int16*)0), 0, 0 },
400 SVX_UNOEDIT_PARA_PROPERTIES,
401 {0,0,0,0,0,0}
402 };
403 static SvxItemPropertySet aSvxXMLTextExportComponentPropertySet( SvxXMLTextExportComponentPropertyMap, EditEngine::GetGlobalItemPool() );
404
405 SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, &aSvxXMLTextExportComponentPropertySet, mxText );
406 pUnoText->SetSelection( rSel );
407 mxText = pUnoText;
408
409 setExportFlags( EXPORT_AUTOSTYLES|EXPORT_CONTENT );
410 }
411
~SvxXMLTextExportComponent()412 SvxXMLTextExportComponent::~SvxXMLTextExportComponent()
413 {
414 }
415
SvxWriteXML(EditEngine & rEditEngine,SvStream & rStream,const ESelection & rSel)416 void SvxWriteXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
417 {
418 try
419 {
420 do
421 {
422 // create service factory
423
424 uno::Reference< lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
425
426 if( !xServiceFactory.is() )
427 {
428 DBG_ERROR( "got no service manager" );
429 break;
430 }
431
432 // create document handler
433
434 uno::Reference< uno::XInterface > xWriter( xServiceFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ) );
435
436 if( !xWriter.is() )
437 {
438 DBG_ERROR( "com.sun.star.xml.sax.Writer service missing" );
439 break;
440 }
441
442 uno::Reference<xml::sax::XDocumentHandler> xHandler( xWriter, uno::UNO_QUERY );
443
444 // create output stream and active data source
445 uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( rStream ) );
446
447 /* testcode
448 const OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
449 SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, sal_True );
450 aMedium.IsRemote();
451 uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
452 */
453
454
455 uno::Reference<io::XActiveDataSource> xMetaSrc( xWriter, uno::UNO_QUERY );
456 xMetaSrc->setOutputStream( xOut );
457
458 // export text
459 const OUString aName;
460
461 // #110680#
462 // SvxXMLTextExportComponent aExporter( &rEditEngine, rSel, aName, xHandler );
463 SvxXMLTextExportComponent aExporter( xServiceFactory, &rEditEngine, rSel, aName, xHandler );
464
465 aExporter.exportDoc();
466
467 /* testcode
468 aMedium.Commit();
469 */
470
471 }
472 while( 0 );
473 }
474 catch( uno::Exception& )
475 {
476 DBG_ERROR("exception during xml export");
477 }
478 }
479
480 // methods without content:
_ExportAutoStyles()481 void SvxXMLTextExportComponent::_ExportAutoStyles()
482 {
483 UniReference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() );
484
485 xTextExport->collectTextAutoStyles( mxText );
486 xTextExport->exportTextAutoStyles();
487 }
488
_ExportContent()489 void SvxXMLTextExportComponent::_ExportContent()
490 {
491 UniReference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() );
492
493 xTextExport->exportText( mxText );
494 }
495
_ExportMasterStyles()496 void SvxXMLTextExportComponent::_ExportMasterStyles() {}
497