update dev300-m58
[ooovba.git] / svx / source / xml / xmltxtexp.cxx
blobf8b01a727cabbc7ec15971d9f92a714910dbc834
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmltxtexp.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 /** this file implements an export of a selected EditEngine content into
35 a xml stream. See svx/source/inc/xmledit.hxx for interface */
36 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
37 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/io/XActiveDataSource.hpp>
40 #include <tools/debug.hxx>
41 #include <svtools/itemprop.hxx>
42 #include <svtools/brdcst.hxx>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <sfx2/docfile.hxx>
45 #ifndef _SVSTOR_HXX
46 #include <sot/storage.hxx>
47 #endif
48 #include <rtl/ustrbuf.hxx>
49 #include <xmloff/xmluconv.hxx>
50 #include "xmloff/xmlnmspe.hxx"
51 #include "xmloff/nmspmap.hxx"
52 #include "xmloff/xmlmetae.hxx"
53 #include <comphelper/processfactory.hxx>
54 #include <unotools/streamwrap.hxx>
55 #include <svx/editeng.hxx>
56 #include "xmloff/xmlexp.hxx"
57 #include <svx/unoedsrc.hxx>
58 #include <svx/unofored.hxx>
59 #include <svx/unotext.hxx>
60 #include "editsource.hxx"
62 #include <cppuhelper/implbase4.hxx>
63 #include <svx/unofield.hxx>
64 #include <svx/unomod.hxx>
65 #include "unonrule.hxx"
67 using namespace com::sun::star;
68 using namespace com::sun::star::container;
69 using namespace com::sun::star::document;
70 using namespace com::sun::star::uno;
71 using namespace com::sun::star::awt;
72 using namespace com::sun::star::lang;
73 using namespace com::sun::star::xml::sax;
74 using namespace ::rtl;
75 using namespace cppu;
77 ///////////////////////////////////////////////////////////////////////
79 class SvxEditEngineSourceImpl;
81 ///////////////////////////////////////////////////////////////////////
83 class SvxEditEngineSourceImpl
85 private:
86 oslInterlockedCount maRefCount;
88 EditEngine* mpEditEngine;
89 SvxTextForwarder* mpTextForwarder;
91 ~SvxEditEngineSourceImpl();
93 public:
94 SvxEditEngineSourceImpl( EditEngine* pEditEngine );
96 void SAL_CALL acquire();
97 void SAL_CALL release();
99 SvxTextForwarder* GetTextForwarder();
102 ///////////////////////////////////////////////////////////////////////
105 //------------------------------------------------------------------------
107 SvxEditEngineSourceImpl::SvxEditEngineSourceImpl( EditEngine* pEditEngine )
108 : maRefCount(0),
109 mpEditEngine( pEditEngine ),
110 mpTextForwarder(NULL)
114 //------------------------------------------------------------------------
116 SvxEditEngineSourceImpl::~SvxEditEngineSourceImpl()
118 delete mpTextForwarder;
121 //------------------------------------------------------------------------
123 void SAL_CALL SvxEditEngineSourceImpl::acquire()
125 osl_incrementInterlockedCount( &maRefCount );
128 //------------------------------------------------------------------------
130 void SAL_CALL SvxEditEngineSourceImpl::release()
132 if( ! osl_decrementInterlockedCount( &maRefCount ) )
133 delete this;
136 //------------------------------------------------------------------------
138 SvxTextForwarder* SvxEditEngineSourceImpl::GetTextForwarder()
140 if (!mpTextForwarder)
141 mpTextForwarder = new SvxEditEngineForwarder( *mpEditEngine );
143 return mpTextForwarder;
146 // --------------------------------------------------------------------
147 // SvxTextEditSource
148 // --------------------------------------------------------------------
150 SvxEditEngineSource::SvxEditEngineSource( EditEngine* pEditEngine )
152 mpImpl = new SvxEditEngineSourceImpl( pEditEngine );
153 mpImpl->acquire();
156 // --------------------------------------------------------------------
158 SvxEditEngineSource::SvxEditEngineSource( SvxEditEngineSourceImpl* pImpl )
160 mpImpl = pImpl;
161 mpImpl->acquire();
164 //------------------------------------------------------------------------
166 SvxEditEngineSource::~SvxEditEngineSource()
168 mpImpl->release();
171 //------------------------------------------------------------------------
173 SvxEditSource* SvxEditEngineSource::Clone() const
175 return new SvxEditEngineSource( mpImpl );
178 //------------------------------------------------------------------------
180 SvxTextForwarder* SvxEditEngineSource::GetTextForwarder()
182 return mpImpl->GetTextForwarder();
185 //------------------------------------------------------------------------
187 void SvxEditEngineSource::UpdateData()
191 class SvxSimpleUnoModel : public cppu::WeakAggImplHelper4<
192 ::com::sun::star::frame::XModel,
193 ::com::sun::star::ucb::XAnyCompareFactory,
194 ::com::sun::star::style::XStyleFamiliesSupplier,
195 ::com::sun::star::lang::XMultiServiceFactory >
197 public:
198 SvxSimpleUnoModel();
199 virtual ~SvxSimpleUnoModel();
202 // XMultiServiceFactory
203 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);
204 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);
205 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
207 // XStyleFamiliesSupplier
208 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getStyleFamilies( ) throw(::com::sun::star::uno::RuntimeException);
210 // XAnyCompareFactory
211 virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XAnyCompare > SAL_CALL createAnyCompareByName( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException);
213 // XModel
214 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);
215 virtual ::rtl::OUString SAL_CALL getURL( ) throw (::com::sun::star::uno::RuntimeException);
216 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getArgs( ) throw (::com::sun::star::uno::RuntimeException);
217 virtual void SAL_CALL connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::uno::RuntimeException);
218 virtual void SAL_CALL disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::uno::RuntimeException);
219 virtual void SAL_CALL lockControllers( ) throw (::com::sun::star::uno::RuntimeException);
220 virtual void SAL_CALL unlockControllers( ) throw (::com::sun::star::uno::RuntimeException);
221 virtual sal_Bool SAL_CALL hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException);
222 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL getCurrentController( ) throw (::com::sun::star::uno::RuntimeException);
223 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);
224 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException);
226 // XComponent
227 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
228 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
229 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
233 SvxSimpleUnoModel::SvxSimpleUnoModel()
237 SvxSimpleUnoModel::~SvxSimpleUnoModel()
241 // XMultiServiceFactory ( SvxFmMSFactory )
242 uno::Reference< uno::XInterface > SAL_CALL SvxSimpleUnoModel::createInstance( const OUString& aServiceSpecifier )
243 throw(uno::Exception, uno::RuntimeException)
245 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.NumberingRules" ) ) )
247 return uno::Reference< uno::XInterface >(
248 SvxCreateNumRule( (SdrModel*)NULL ), uno::UNO_QUERY );
250 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime") ) )
252 return (::cppu::OWeakObject * )new SvxUnoTextField( ID_EXT_DATEFIELD );
255 return SvxUnoDrawMSFactory::createTextField( aServiceSpecifier );
259 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)
261 return createInstance( ServiceSpecifier );
264 Sequence< ::rtl::OUString > SAL_CALL SvxSimpleUnoModel::getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
266 Sequence< OUString > aSeq;
267 return aSeq;
270 // XAnyCompareFactory
271 uno::Reference< com::sun::star::ucb::XAnyCompare > SAL_CALL SvxSimpleUnoModel::createAnyCompareByName( const OUString& PropertyName )
272 throw(uno::RuntimeException)
274 (void)PropertyName;
275 return SvxCreateNumRuleCompare();
278 // XStyleFamiliesSupplier
279 uno::Reference< container::XNameAccess > SAL_CALL SvxSimpleUnoModel::getStyleFamilies( )
280 throw(uno::RuntimeException)
282 uno::Reference< container::XNameAccess > xStyles;
283 return xStyles;
286 // XModel
287 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)
289 (void)aURL;
290 (void)aArgs;
291 return sal_False;
294 ::rtl::OUString SAL_CALL SvxSimpleUnoModel::getURL( ) throw (::com::sun::star::uno::RuntimeException)
296 OUString aStr;
297 return aStr;
300 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SvxSimpleUnoModel::getArgs( ) throw (::com::sun::star::uno::RuntimeException)
302 Sequence< beans::PropertyValue > aSeq;
303 return aSeq;
306 void SAL_CALL SvxSimpleUnoModel::connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::uno::RuntimeException)
310 void SAL_CALL SvxSimpleUnoModel::disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::uno::RuntimeException)
314 void SAL_CALL SvxSimpleUnoModel::lockControllers( ) throw (::com::sun::star::uno::RuntimeException)
318 void SAL_CALL SvxSimpleUnoModel::unlockControllers( ) throw (::com::sun::star::uno::RuntimeException)
322 sal_Bool SAL_CALL SvxSimpleUnoModel::hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException)
324 return sal_True;
327 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL SvxSimpleUnoModel::getCurrentController( ) throw (::com::sun::star::uno::RuntimeException)
329 uno::Reference< frame::XController > xRet;
330 return xRet;
333 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)
337 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvxSimpleUnoModel::getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException)
339 uno::Reference< XInterface > xRet;
340 return xRet;
344 // XComponent
345 void SAL_CALL SvxSimpleUnoModel::dispose( ) throw (::com::sun::star::uno::RuntimeException)
349 void SAL_CALL SvxSimpleUnoModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) throw (::com::sun::star::uno::RuntimeException)
353 void SAL_CALL SvxSimpleUnoModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) throw (::com::sun::star::uno::RuntimeException)
357 ///////////////////////////////////////////////////////////////////////
359 class SvxXMLTextExportComponent : public SvXMLExport
361 public:
362 // #110680#
363 SvxXMLTextExportComponent(
364 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
365 EditEngine* pEditEngine,
366 const ESelection& rSel,
367 const ::rtl::OUString& rFileName,
368 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > & xHandler );
370 ~SvxXMLTextExportComponent();
372 // methods without content:
373 virtual void _ExportAutoStyles();
374 virtual void _ExportMasterStyles();
375 virtual void _ExportContent();
377 private:
378 com::sun::star::uno::Reference< com::sun::star::text::XText > mxText;
379 EditEngine* mpEditEngine;
380 ESelection maSelection;
383 ///////////////////////////////////////////////////////////////////////
385 // #110680#
386 SvxXMLTextExportComponent::SvxXMLTextExportComponent(
387 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
388 EditEngine* pEditEngine,
389 const ESelection& rSel,
390 const ::rtl::OUString& rFileName,
391 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > & xHandler)
392 : SvXMLExport( xServiceFactory, rFileName, xHandler, ((frame::XModel*)new SvxSimpleUnoModel()), MAP_CM ),
393 mpEditEngine( pEditEngine ),
394 maSelection( rSel )
396 SvxEditEngineSource aEditSource( pEditEngine );
398 static const SfxItemPropertyMapEntry SvxXMLTextExportComponentPropertyMap[] =
400 SVX_UNOEDIT_CHAR_PROPERTIES,
401 SVX_UNOEDIT_FONT_PROPERTIES,
402 // SVX_UNOEDIT_OUTLINER_PROPERTIES,
403 {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 },
404 {MAP_CHAR_LEN(UNO_NAME_NUMBERING), EE_PARA_BULLETSTATE,&::getBooleanCppuType(), 0, 0 },
405 {MAP_CHAR_LEN(UNO_NAME_NUMBERING_LEVEL), EE_PARA_OUTLLEVEL, &::getCppuType((const sal_Int16*)0), 0, 0 },
406 SVX_UNOEDIT_PARA_PROPERTIES,
407 {0,0,0,0,0,0}
409 static SvxItemPropertySet aSvxXMLTextExportComponentPropertySet( SvxXMLTextExportComponentPropertyMap );
411 SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, &aSvxXMLTextExportComponentPropertySet, mxText );
412 pUnoText->SetSelection( rSel );
413 mxText = pUnoText;
415 setExportFlags( EXPORT_AUTOSTYLES|EXPORT_CONTENT );
418 SvxXMLTextExportComponent::~SvxXMLTextExportComponent()
422 void SvxWriteXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
428 // create service factory
430 uno::Reference< lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
432 if( !xServiceFactory.is() )
434 DBG_ERROR( "got no service manager" );
435 break;
438 // create document handler
440 uno::Reference< uno::XInterface > xWriter( xServiceFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ) );
442 if( !xWriter.is() )
444 DBG_ERROR( "com.sun.star.xml.sax.Writer service missing" );
445 break;
448 uno::Reference<xml::sax::XDocumentHandler> xHandler( xWriter, uno::UNO_QUERY );
450 // create output stream and active data source
451 uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( rStream ) );
453 /* testcode
454 const OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
455 SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, TRUE );
456 aMedium.IsRemote();
457 uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
461 uno::Reference<io::XActiveDataSource> xMetaSrc( xWriter, uno::UNO_QUERY );
462 xMetaSrc->setOutputStream( xOut );
464 // export text
465 const OUString aName;
467 // #110680#
468 // SvxXMLTextExportComponent aExporter( &rEditEngine, rSel, aName, xHandler );
469 SvxXMLTextExportComponent aExporter( xServiceFactory, &rEditEngine, rSel, aName, xHandler );
471 aExporter.exportDoc();
473 /* testcode
474 aMedium.Commit();
478 while( 0 );
480 catch( uno::Exception& )
482 DBG_ERROR("exception during xml export");
486 // methods without content:
487 void SvxXMLTextExportComponent::_ExportAutoStyles()
489 UniReference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() );
491 xTextExport->collectTextAutoStyles( mxText );
492 xTextExport->exportTextAutoStyles();
495 void SvxXMLTextExportComponent::_ExportContent()
497 UniReference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() );
499 xTextExport->exportText( mxText );
502 void SvxXMLTextExportComponent::_ExportMasterStyles() {}