Bump for 3.6-28
[LibreOffice.git] / editeng / source / xml / xmltxtexp.cxx
bloba0455ff299dfd28e6dbace3e4dcfea06ae1f073b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /** this file implements an export of a selected EditEngine content into
31 a xml stream. See editeng/source/inc/xmledit.hxx for interface */
32 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
33 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/io/XActiveDataSource.hpp>
36 #include <svl/itemprop.hxx>
37 #include <svl/brdcst.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <sot/storage.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <xmloff/xmluconv.hxx>
42 #include <xmloff/xmlnmspe.hxx>
43 #include <xmloff/nmspmap.hxx>
44 #include <xmloff/xmlmetae.hxx>
45 #include <cppuhelper/implbase4.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include <unotools/streamwrap.hxx>
48 #include <xmloff/xmlexp.hxx>
49 #include <editeng/unoedsrc.hxx>
50 #include <editeng/unofored.hxx>
51 #include <editeng/unotext.hxx>
52 #include <editeng/unoprnms.hxx>
53 #include <editeng/unofield.hxx>
54 #include <editeng/editeng.hxx>
55 #include "editsource.hxx"
56 #include <editeng/unonrule.hxx>
57 #include <editeng/unoipset.hxx>
59 using namespace com::sun::star;
60 using namespace com::sun::star::container;
61 using namespace com::sun::star::document;
62 using namespace com::sun::star::uno;
63 using namespace com::sun::star::awt;
64 using namespace com::sun::star::lang;
65 using namespace com::sun::star::xml::sax;
66 using namespace ::rtl;
67 using namespace cppu;
69 ///////////////////////////////////////////////////////////////////////
71 class SvxEditEngineSourceImpl;
73 ///////////////////////////////////////////////////////////////////////
75 class SvxEditEngineSourceImpl
77 private:
78 oslInterlockedCount maRefCount;
80 EditEngine* mpEditEngine;
81 SvxTextForwarder* mpTextForwarder;
83 ~SvxEditEngineSourceImpl();
85 public:
86 SvxEditEngineSourceImpl( EditEngine* pEditEngine );
88 void SAL_CALL acquire();
89 void SAL_CALL release();
91 SvxTextForwarder* GetTextForwarder();
94 ///////////////////////////////////////////////////////////////////////
97 //------------------------------------------------------------------------
99 SvxEditEngineSourceImpl::SvxEditEngineSourceImpl( EditEngine* pEditEngine )
100 : maRefCount(0),
101 mpEditEngine( pEditEngine ),
102 mpTextForwarder(NULL)
106 //------------------------------------------------------------------------
108 SvxEditEngineSourceImpl::~SvxEditEngineSourceImpl()
110 delete mpTextForwarder;
113 //------------------------------------------------------------------------
115 void SAL_CALL SvxEditEngineSourceImpl::acquire()
117 osl_incrementInterlockedCount( &maRefCount );
120 //------------------------------------------------------------------------
122 void SAL_CALL SvxEditEngineSourceImpl::release()
124 if( ! osl_decrementInterlockedCount( &maRefCount ) )
125 delete this;
128 //------------------------------------------------------------------------
130 SvxTextForwarder* SvxEditEngineSourceImpl::GetTextForwarder()
132 if (!mpTextForwarder)
133 mpTextForwarder = new SvxEditEngineForwarder( *mpEditEngine );
135 return mpTextForwarder;
138 // --------------------------------------------------------------------
139 // SvxTextEditSource
140 // --------------------------------------------------------------------
142 SvxEditEngineSource::SvxEditEngineSource( EditEngine* pEditEngine )
144 mpImpl = new SvxEditEngineSourceImpl( pEditEngine );
145 mpImpl->acquire();
148 // --------------------------------------------------------------------
150 SvxEditEngineSource::SvxEditEngineSource( SvxEditEngineSourceImpl* pImpl )
152 mpImpl = pImpl;
153 mpImpl->acquire();
156 //------------------------------------------------------------------------
158 SvxEditEngineSource::~SvxEditEngineSource()
160 mpImpl->release();
163 //------------------------------------------------------------------------
165 SvxEditSource* SvxEditEngineSource::Clone() const
167 return new SvxEditEngineSource( mpImpl );
170 //------------------------------------------------------------------------
172 SvxTextForwarder* SvxEditEngineSource::GetTextForwarder()
174 return mpImpl->GetTextForwarder();
177 //------------------------------------------------------------------------
179 void SvxEditEngineSource::UpdateData()
183 class SvxSimpleUnoModel : public cppu::WeakAggImplHelper4<
184 ::com::sun::star::frame::XModel,
185 ::com::sun::star::ucb::XAnyCompareFactory,
186 ::com::sun::star::style::XStyleFamiliesSupplier,
187 ::com::sun::star::lang::XMultiServiceFactory >
189 public:
190 SvxSimpleUnoModel();
191 virtual ~SvxSimpleUnoModel();
194 // XMultiServiceFactory
195 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);
196 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);
197 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
199 // XStyleFamiliesSupplier
200 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getStyleFamilies( ) throw(::com::sun::star::uno::RuntimeException);
202 // XAnyCompareFactory
203 virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XAnyCompare > SAL_CALL createAnyCompareByName( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException);
205 // XModel
206 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);
207 virtual ::rtl::OUString SAL_CALL getURL( ) throw (::com::sun::star::uno::RuntimeException);
208 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getArgs( ) throw (::com::sun::star::uno::RuntimeException);
209 virtual void SAL_CALL connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::uno::RuntimeException);
210 virtual void SAL_CALL disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& xController ) throw (::com::sun::star::uno::RuntimeException);
211 virtual void SAL_CALL lockControllers( ) throw (::com::sun::star::uno::RuntimeException);
212 virtual void SAL_CALL unlockControllers( ) throw (::com::sun::star::uno::RuntimeException);
213 virtual sal_Bool SAL_CALL hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException);
214 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL getCurrentController( ) throw (::com::sun::star::uno::RuntimeException);
215 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);
216 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException);
218 // XComponent
219 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
220 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
221 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
225 SvxSimpleUnoModel::SvxSimpleUnoModel()
229 SvxSimpleUnoModel::~SvxSimpleUnoModel()
233 // XMultiServiceFactory ( SvxFmMSFactory )
234 uno::Reference< uno::XInterface > SAL_CALL SvxSimpleUnoModel::createInstance( const OUString& aServiceSpecifier )
235 throw(uno::Exception, uno::RuntimeException)
237 if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.NumberingRules" ) ) )
239 return uno::Reference< uno::XInterface >(
240 SvxCreateNumRule(), uno::UNO_QUERY );
242 if ( (0 == aServiceSpecifier.reverseCompareToAsciiL(
243 RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.DateTime")))
244 || (0 == aServiceSpecifier.reverseCompareToAsciiL(
245 RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime")))
248 return (::cppu::OWeakObject * )new SvxUnoTextField( text::textfield::Type::DATE );
251 return SvxUnoTextCreateTextField( aServiceSpecifier );
255 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)
257 return createInstance( ServiceSpecifier );
260 Sequence< ::rtl::OUString > SAL_CALL SvxSimpleUnoModel::getAvailableServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
262 Sequence< OUString > aSeq;
263 return aSeq;
266 // XAnyCompareFactory
267 uno::Reference< com::sun::star::ucb::XAnyCompare > SAL_CALL SvxSimpleUnoModel::createAnyCompareByName( const OUString& PropertyName )
268 throw(uno::RuntimeException)
270 (void)PropertyName;
271 return SvxCreateNumRuleCompare();
274 // XStyleFamiliesSupplier
275 uno::Reference< container::XNameAccess > SAL_CALL SvxSimpleUnoModel::getStyleFamilies( )
276 throw(uno::RuntimeException)
278 uno::Reference< container::XNameAccess > xStyles;
279 return xStyles;
282 // XModel
283 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)
285 (void)aURL;
286 (void)aArgs;
287 return sal_False;
290 ::rtl::OUString SAL_CALL SvxSimpleUnoModel::getURL( ) throw (::com::sun::star::uno::RuntimeException)
292 OUString aStr;
293 return aStr;
296 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL SvxSimpleUnoModel::getArgs( ) throw (::com::sun::star::uno::RuntimeException)
298 Sequence< beans::PropertyValue > aSeq;
299 return aSeq;
302 void SAL_CALL SvxSimpleUnoModel::connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::uno::RuntimeException)
306 void SAL_CALL SvxSimpleUnoModel::disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& ) throw (::com::sun::star::uno::RuntimeException)
310 void SAL_CALL SvxSimpleUnoModel::lockControllers( ) throw (::com::sun::star::uno::RuntimeException)
314 void SAL_CALL SvxSimpleUnoModel::unlockControllers( ) throw (::com::sun::star::uno::RuntimeException)
318 sal_Bool SAL_CALL SvxSimpleUnoModel::hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException)
320 return sal_True;
323 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL SvxSimpleUnoModel::getCurrentController( ) throw (::com::sun::star::uno::RuntimeException)
325 uno::Reference< frame::XController > xRet;
326 return xRet;
329 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)
333 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvxSimpleUnoModel::getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException)
335 uno::Reference< XInterface > xRet;
336 return xRet;
340 // XComponent
341 void SAL_CALL SvxSimpleUnoModel::dispose( ) throw (::com::sun::star::uno::RuntimeException)
345 void SAL_CALL SvxSimpleUnoModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) throw (::com::sun::star::uno::RuntimeException)
349 void SAL_CALL SvxSimpleUnoModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& ) throw (::com::sun::star::uno::RuntimeException)
353 ///////////////////////////////////////////////////////////////////////
355 class SvxXMLTextExportComponent : public SvXMLExport
357 public:
358 SvxXMLTextExportComponent(
359 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
360 EditEngine* pEditEngine,
361 const ESelection& rSel,
362 const ::rtl::OUString& rFileName,
363 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > & xHandler );
365 ~SvxXMLTextExportComponent();
367 // methods without content:
368 virtual void _ExportAutoStyles();
369 virtual void _ExportMasterStyles();
370 virtual void _ExportContent();
372 private:
373 com::sun::star::uno::Reference< com::sun::star::text::XText > mxText;
374 EditEngine* mpEditEngine;
375 ESelection maSelection;
378 ///////////////////////////////////////////////////////////////////////
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 )
390 SvxEditEngineSource aEditSource( pEditEngine );
392 static const SfxItemPropertyMapEntry SvxXMLTextExportComponentPropertyMap[] =
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}
403 static SvxItemPropertySet aSvxXMLTextExportComponentPropertySet( SvxXMLTextExportComponentPropertyMap, EditEngine::GetGlobalItemPool() );
405 SvxUnoText* pUnoText = new SvxUnoText( &aEditSource, &aSvxXMLTextExportComponentPropertySet, mxText );
406 pUnoText->SetSelection( rSel );
407 mxText = pUnoText;
409 setExportFlags( EXPORT_AUTOSTYLES|EXPORT_CONTENT );
412 SvxXMLTextExportComponent::~SvxXMLTextExportComponent()
416 void SvxWriteXML( EditEngine& rEditEngine, SvStream& rStream, const ESelection& rSel )
422 // create service factory
424 uno::Reference< lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
426 if( !xServiceFactory.is() )
428 OSL_FAIL( "got no service manager" );
429 break;
432 // create document handler
434 uno::Reference< uno::XInterface > xWriter( xServiceFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ) );
436 if( !xWriter.is() )
438 OSL_FAIL( "com.sun.star.xml.sax.Writer service missing" );
439 break;
442 uno::Reference<xml::sax::XDocumentHandler> xHandler( xWriter, uno::UNO_QUERY );
444 // create output stream and active data source
445 uno::Reference<io::XOutputStream> xOut( new utl::OOutputStreamWrapper( rStream ) );
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() ) );
455 uno::Reference<io::XActiveDataSource> xMetaSrc( xWriter, uno::UNO_QUERY );
456 xMetaSrc->setOutputStream( xOut );
458 // export text
459 const OUString aName;
461 // SvxXMLTextExportComponent aExporter( &rEditEngine, rSel, aName, xHandler );
462 SvxXMLTextExportComponent aExporter( xServiceFactory, &rEditEngine, rSel, aName, xHandler );
464 aExporter.exportDoc();
466 /* testcode
467 aMedium.Commit();
471 while( 0 );
473 catch( const uno::Exception& )
475 OSL_FAIL("exception during xml export");
479 // methods without content:
480 void SvxXMLTextExportComponent::_ExportAutoStyles()
482 UniReference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() );
484 xTextExport->collectTextAutoStyles( mxText );
485 xTextExport->exportTextAutoStyles();
488 void SvxXMLTextExportComponent::_ExportContent()
490 UniReference< XMLTextParagraphExport > xTextExport( GetTextParagraphExport() );
492 xTextExport->exportText( mxText );
495 void SvxXMLTextExportComponent::_ExportMasterStyles() {}
497 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */