xref: /AOO41X/main/sw/source/filter/xml/xmlexp.cxx (revision 8e8ee8fefdac26d905672cc573c35fd0ae1f9356)
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_sw.hxx"
26 
27 #include <com/sun/star/text/XTextDocument.hpp>
28 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <com/sun/star/container/XIndexContainer.hpp>
32 #include <com/sun/star/uno/RuntimeException.hpp>
33 #include <com/sun/star/xforms/XFormsSupplier.hpp>
34 #include <svx/svdmodel.hxx>
35 #include <svx/svdpage.hxx>
36 #include <svx/xmleohlp.hxx>
37 #include <svx/xmlgrhlp.hxx>
38 #include <editeng/eeitem.hxx>
39 #include <svx/svddef.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/xmlnmspe.hxx>
42 #include <editeng/xmlcnitm.hxx>
43 #include <xmloff/ProgressBarHelper.hxx>
44 #include <xmloff/xmluconv.hxx>
45 #include <xmloff/xformsexport.hxx>
46 #include <pam.hxx>
47 #include <doc.hxx>
48 #include <swmodule.hxx>
49 #include <docsh.hxx>
50 #include <viewsh.hxx>
51 #include <docstat.hxx>
52 #include <swerror.h>
53 #include <unotext.hxx>
54 #include <xmltexte.hxx>
55 #include <xmlexp.hxx>
56 #include <sfx2/viewsh.hxx>
57 #include <comphelper/processfactory.hxx>
58 #include <docary.hxx>
59 #include <editeng/unolingu.hxx>
60 #include <editeng/forbiddencharacterstable.hxx>
61 #include <ForbiddenCharactersEnum.hxx>
62 
63 // for locking SolarMutex: svapp + mutex
64 #include <vcl/svapp.hxx>
65 #include <vos/mutex.hxx>
66 
67 #include <pausethreadstarting.hxx>
68 
69 using ::rtl::OUString;
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::frame;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::xml::sax;
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::text;
76 using namespace ::com::sun::star::container;
77 using namespace ::com::sun::star::document;
78 using namespace ::com::sun::star::drawing;
79 using namespace ::com::sun::star::beans;
80 using namespace ::com::sun::star::i18n;
81 using namespace ::com::sun::star::xforms;
82 using namespace ::xmloff::token;
83 
84 #ifdef XML_CORE_API
SetCurPaM(SwPaM & rPaM,sal_Bool bWhole,sal_Bool bTabOnly)85 void SwXMLExport::SetCurPaM( SwPaM& rPaM, sal_Bool bWhole, sal_Bool bTabOnly )
86 {
87     if( !pCurPaM )
88     {
89         pCurPaM = new SwPaM( *rPaM.End(), *rPaM.Start() );
90     }
91     else
92     {
93         *pCurPaM->GetPoint() = *rPaM.Start();
94         *pCurPaM->GetMark() = *rPaM.End();
95     }
96 
97     // Set PaM to table/section start node if whole doc should be exported
98     if( bWhole )
99     {
100         SwTableNode *pTblNd = pCurPaM->GetNode()->FindTableNode();
101         if( pTblNd )
102         {
103             pCurPaM->GetPoint()->nNode = *pTblNd;
104 
105             if( bTabOnly )
106                 pCurPaM->GetMark()->nNode = *pTblNd->EndOfSectionNode();
107         }
108 
109         SwSectionNode * pSectNd = pCurPaM->GetNode()->FindSectionNode();
110         while( pSectNd )
111         {
112             pCurPaM->GetPoint()->nNode = *pSectNd;
113 
114             // SwSectionNode::FindSectionNode() returns the section node itself
115             pSectNd = pSectNd->StartOfSectionNode()->FindSectionNode();
116         }
117     }
118 }
119 #endif
120 
121 // #110680#
SwXMLExport(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,sal_uInt16 nExportFlags)122 SwXMLExport::SwXMLExport(
123     const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
124     sal_uInt16 nExportFlags)
125 :   SvXMLExport( xServiceFactory, MAP_INCH, XML_TEXT, nExportFlags ),
126 #ifdef XML_CORE_API
127     pCurPaM( 0 ),
128     pOrigPaM( &rPaM ),
129 #endif
130     pTableItemMapper( 0 ),
131     pTableLines( 0 ),
132 #ifdef XML_CORE_API
133     bExportWholeDoc( bExpWholeDoc ),
134     bExportFirstTableOnly( bExpFirstTableOnly ),
135 #endif
136     bBlock( sal_False ),
137     bShowProgress( sal_True ),
138     sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")),
139     sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")),
140     sCell(RTL_CONSTASCII_USTRINGPARAM("Cell"))
141 {
142     _InitItemExport();
143 }
144 
145 #ifdef XML_CORE_API
146 // #110680#
SwXMLExport(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,const Reference<XModel> & rModel,SwPaM & rPaM,const OUString & rFileName,const Reference<XDocumentHandler> & rHandler,const Reference<XGraphicObjectResolver> & rEmbeddedGrfObjs,sal_Bool bExpWholeDoc,sal_Bool bExpFirstTableOnly,sal_Bool bShowProg)147 SwXMLExport::SwXMLExport(
148     const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
149     const Reference< XModel >& rModel,
150     SwPaM& rPaM,
151     const OUString& rFileName,
152     const Reference< XDocumentHandler > & rHandler,
153     const Reference< XGraphicObjectResolver > & rEmbeddedGrfObjs,
154     sal_Bool bExpWholeDoc, sal_Bool bExpFirstTableOnly,
155     sal_Bool bShowProg )
156 :   SvXMLExport( xServiceFactory, rFileName, rHandler, rModel, rEmbeddedGrfObjs,
157                  SW_MOD()->GetMetric( rPaM.GetDoc()->get(IDocumentSettingAccess::HTML_MODE) ) ),
158     pCurPaM( 0 ),
159     pOrigPaM( &rPaM ),
160     pTableItemMapper( 0 ),
161     pTableLines( 0 ),
162     bExportWholeDoc( bExpWholeDoc ),
163     bExportFirstTableOnly( bExpFirstTableOnly ),
164     bShowProgress( bShowProg ),
165     sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")),
166     sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")),
167     sCell(RTL_CONSTASCII_USTRINGPARAM("Cell"))
168 {
169     _InitItemExport();
170 }
171 #endif
172 
setBlockMode()173 void SwXMLExport::setBlockMode()
174 {
175     bBlock = sal_True;
176 
177 }
178 
exportDoc(enum XMLTokenEnum eClass)179 sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
180 {
181     if( !GetModel().is() )
182         return ERR_SWG_WRITE_ERROR;
183 
184     // --> OD 2007-03-30 #i73788#
185     SwPauseThreadStarting aPauseThreadStarting;
186     // <--
187 
188     Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
189     Reference < XText > xText = xTextDoc->getText();
190     Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
191     ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
192     if( !xTextTunnel.is() )
193         return ERR_SWG_WRITE_ERROR;
194 
195     // from here, we use core interfaces -> lock Solar-Mutex (#91949#)
196     vos::OGuard aGuard(Application::GetSolarMutex());
197 
198     {
199         Reference<XPropertySet> rInfoSet = getExportInfo();
200         if( rInfoSet.is() )
201         {
202             OUString sAutoTextMode(
203                 RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
204             if( rInfoSet->getPropertySetInfo()->hasPropertyByName(
205                         sAutoTextMode ) )
206             {
207                 Any aAny = rInfoSet->getPropertyValue(sAutoTextMode);
208                 if( aAny.getValueType() == ::getBooleanCppuType() &&
209                     *static_cast<const sal_Bool*>(aAny.getValue()) )
210                     setBlockMode();
211             }
212         }
213     }
214 
215     SwXText *pText = reinterpret_cast< SwXText * >(
216             sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
217     ASSERT( pText, "SwXText missing" );
218     if( !pText )
219         return ERR_SWG_WRITE_ERROR;
220 
221     SwDoc *pDoc = pText->GetDoc();
222 
223     sal_Bool bExtended = sal_False;
224     if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
225                              EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
226     {
227         GetTextParagraphExport()->SetBlockMode( bBlock );
228 
229         const SfxPoolItem* pItem;
230         const SfxItemPool& rPool = pDoc->GetAttrPool();
231         sal_uInt16 aWhichIds[5] = { RES_UNKNOWNATR_CONTAINER,
232                                     RES_TXTATR_UNKNOWN_CONTAINER,
233                                     SDRATTR_XMLATTRIBUTES,
234                                     EE_PARA_XMLATTRIBS,
235                                     EE_CHAR_XMLATTRIBS };
236 
237         sal_uInt16 nWhichIds = rPool.GetSecondaryPool() ? 5 : 2;
238         for( sal_uInt16 j=0; j < nWhichIds; j++ )
239         {
240             sal_uInt16 nWhichId = aWhichIds[j];
241             sal_uInt32 i=0, nItems = rPool.GetItemCount2( nWhichId );
242             for( i = 0; i < nItems; ++i )
243             {
244                 if( 0 != (pItem = rPool.GetItem2( nWhichId , i ) ) )
245                 {
246                     const SvXMLAttrContainerItem *pUnknown =
247                                 PTR_CAST( SvXMLAttrContainerItem, pItem );
248                     ASSERT( pUnknown, "illegal attribute container item" );
249                     if( pUnknown && (pUnknown->GetAttrCount() > 0) )
250                     {
251                         sal_uInt16 nIdx = pUnknown->GetFirstNamespaceIndex();
252                         while( USHRT_MAX != nIdx )
253                         {
254                             const OUString& rPrefix =
255                                 pUnknown->GetPrefix( nIdx );
256                             _GetNamespaceMap().Add( rPrefix,
257                                                 pUnknown->GetNamespace( nIdx ),
258                                                 XML_NAMESPACE_UNKNOWN );
259                             nIdx = pUnknown->GetNextNamespaceIndex( nIdx );
260                         }
261                         bExtended = sal_True;
262                     }
263                 }
264             }
265         }
266     }
267 
268     MapUnit eUnit =
269         SvXMLUnitConverter::GetMapUnit( SW_MOD()->GetMetric(pDoc->get(IDocumentSettingAccess::HTML_MODE)) );
270     if( GetMM100UnitConverter().getXMLMeasureUnit() != eUnit )
271     {
272         GetMM100UnitConverter().setXMLMeasureUnit( eUnit );
273         pTwipUnitConv->setXMLMeasureUnit( eUnit );
274     }
275 
276     SetExtended( bExtended );
277 
278     SwDocStat aDocStat( pDoc->GetDocStat() );
279     if( (getExportFlags() & EXPORT_META) != 0 )
280     {
281         // Update doc stat, so that correct values are exported and
282         // the progress works correctly.
283         if( aDocStat.bModified )
284             pDoc->UpdateDocStat( aDocStat );
285 
286         SfxObjectShell* pObjSh = pDoc->GetDocShell();
287         if( pObjSh )
288             pObjSh->UpdateDocInfoForSave();     // update information
289     }
290     if( bShowProgress )
291     {
292         ProgressBarHelper *pProgress = GetProgressBarHelper();
293         if( -1 == pProgress->GetReference() )
294         {
295             // progress isn't initialized:
296             // We assume that the whole doc is exported, and the following
297             // durations:
298             // - meta information: 2
299             // - settings: 4 (TODO: not now!)
300             // - styles (except page styles): 2
301             // - page styles: 2 (TODO: not now!) + 2 for each paragraph
302             // - paragraph: 2 (1 for automatic styles and one for content)
303 
304             // If required, update doc stat, so that
305             // the progress works correctly.
306             if( aDocStat.bModified )
307                 pDoc->UpdateDocStat( aDocStat );
308 
309             // count each item once, and then multiply by two to reach the
310             // figures given above
311             // The styles in pDoc also count the default style that never
312             // gets exported -> subtract one.
313             sal_Int32 nRef = 1; // meta.xml
314             nRef += pDoc->GetCharFmts()->Count() - 1;
315             nRef += pDoc->GetFrmFmts()->Count() - 1;
316             nRef += pDoc->GetTxtFmtColls()->Count() - 1;
317 //          nRef += pDoc->GetPageDescCnt();
318             nRef *= 2; // for the above styles, xmloff will increment by 2!
319             // #i93174#: count all paragraphs for the progress bar
320             nRef += aDocStat.nAllPara; // 1: only content, no autostyle
321             pProgress->SetReference( nRef );
322             pProgress->SetValue( 0 );
323         }
324     }
325 
326     if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
327     {
328         //Auf die Korrektheit der OrdNums sind wir schon angewiesen.
329         SdrModel* pModel = pDoc->GetDrawModel();
330         if( pModel )
331             pModel->GetPage( 0 )->RecalcObjOrdNums();
332     }
333 
334     // adjust document class (eClass)
335     if (pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT))
336     {
337         eClass = XML_TEXT_GLOBAL;
338 
339         // additionally, we take care of the save-linked-sections-thingy
340         mbSaveLinkedSections = pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
341     }
342     // MIB: 03/26/04: The Label information is saved in the settings, so
343     // we don't need it here.
344     // else: keep default pClass that we received
345 
346     SvXMLGraphicHelper *pGraphicResolver = 0;
347     if( !GetGraphicResolver().is() )
348     {
349         pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_WRITE );
350         Reference< XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
351         SetGraphicResolver( xGraphicResolver );
352     }
353 
354     SvXMLEmbeddedObjectHelper *pEmbeddedResolver = 0;
355     if( !GetEmbeddedResolver().is() )
356     {
357         SfxObjectShell *pPersist = pDoc->GetPersist();
358         if( pPersist )
359         {
360             pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
361                                             *pPersist,
362                                             EMBEDDEDOBJECTHELPER_MODE_WRITE );
363             Reference< XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
364             SetEmbeddedResolver( xEmbeddedResolver );
365         }
366     }
367 
368     // set redline mode if we export STYLES or CONTENT, unless redline
369     // mode is taken care of outside (through info XPropertySet)
370     sal_Bool bSaveRedline =
371         ( (getExportFlags() & (EXPORT_CONTENT|EXPORT_STYLES)) != 0 );
372     if( bSaveRedline )
373     {
374         // if the info property set has a ShowChanges property,
375         // then change tracking is taken care of on the outside,
376         // so we don't have to!
377         Reference<XPropertySet> rInfoSet = getExportInfo();
378         if( rInfoSet.is() )
379         {
380             OUString sShowChanges( RTL_CONSTASCII_USTRINGPARAM("ShowChanges"));
381             bSaveRedline = ! rInfoSet->getPropertySetInfo()->hasPropertyByName(
382                                                                 sShowChanges );
383         }
384     }
385     sal_uInt16 nRedlineMode = 0;
386     bSavedShowChanges = IDocumentRedlineAccess::IsShowChanges( pDoc->GetRedlineMode() );
387     if( bSaveRedline )
388     {
389         // now save and switch redline mode
390         nRedlineMode = pDoc->GetRedlineMode();
391         pDoc->SetRedlineMode(
392                  (RedlineMode_t)(( nRedlineMode & nsRedlineMode_t::REDLINE_SHOW_MASK ) | nsRedlineType_t::REDLINE_INSERT ));
393     }
394 
395     sal_uInt32 nRet = SvXMLExport::exportDoc( eClass );
396 
397     // now we can restore the redline mode (if we changed it previously)
398     if( bSaveRedline )
399     {
400       pDoc->SetRedlineMode( (RedlineMode_t)(nRedlineMode ));
401     }
402 
403 
404     if( pGraphicResolver )
405         SvXMLGraphicHelper::Destroy( pGraphicResolver );
406     if( pEmbeddedResolver )
407         SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
408 
409     ASSERT( !pTableLines, "there are table columns infos left" );
410 
411     return nRet;
412 }
413 
CreateTextParagraphExport()414 XMLTextParagraphExport* SwXMLExport::CreateTextParagraphExport()
415 {
416     return new SwXMLTextParagraphExport( *this, *GetAutoStylePool().get() );
417 }
418 
CreateShapeExport()419 XMLShapeExport* SwXMLExport::CreateShapeExport()
420 {
421     XMLShapeExport* pShapeExport = new XMLShapeExport( *this, XMLTextParagraphExport::CreateShapeExtPropMapper( *this ) );
422     Reference < XDrawPageSupplier > xDPS( GetModel(), UNO_QUERY );
423     if( xDPS.is() )
424     {
425         Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY );
426         pShapeExport->seekShapes( xShapes );
427     }
428 
429     return pShapeExport;
430 }
431 
~SwXMLExport()432 __EXPORT SwXMLExport::~SwXMLExport()
433 {
434     _FinitItemExport();
435 }
436 
437 
_ExportFontDecls()438 void SwXMLExport::_ExportFontDecls()
439 {
440     GetFontAutoStylePool(); // make sure the pool is created
441     SvXMLExport::_ExportFontDecls();
442 }
443 
444 #define NUM_EXPORTED_VIEW_SETTINGS 11
GetViewSettings(Sequence<PropertyValue> & aProps)445 void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps)
446 {
447     Reference< XMultiServiceFactory > xServiceFactory =
448             comphelper::getProcessServiceFactory();
449     ASSERT( xServiceFactory.is(),
450             "XMLReader::Read: got no service manager" );
451     if( !xServiceFactory.is() )
452         return;
453 
454     aProps.realloc( NUM_EXPORTED_VIEW_SETTINGS );
455      // Currently exporting 9 properties
456     PropertyValue *pValue = aProps.getArray();
457     sal_Int32 nIndex = 0;
458 
459     Reference < XIndexContainer > xBox (xServiceFactory->createInstance
460             (OUString( RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.document.IndexedPropertyValues") ) ), UNO_QUERY);
461     if (xBox.is() )
462     {
463         pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "Views") );
464         pValue[nIndex++].Value <<= Reference < XIndexAccess > ( xBox, UNO_QUERY );
465     }
466 
467     Reference < XText > xText;
468     SwXText *pText = 0;
469 
470     if( GetModel().is() )
471     {
472         Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
473         xText = xTextDoc->getText();
474         Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
475         ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
476         if( xTextTunnel.is() )
477         {
478             pText = reinterpret_cast< SwXText * >(
479                     sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId()) ));
480             ASSERT( pText, "SwXText missing" );
481         }
482     }
483 
484     if( !pText )
485     {
486         aProps.realloc(nIndex);
487         return;
488     }
489 
490     SwDoc *pDoc = pText->GetDoc();
491     const Rectangle rRect =
492         pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
493     sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
494 
495     ASSERT ( bTwip, "Map unit for visible area is not in TWIPS!" );
496 
497     pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaTop") );
498     pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.Top() ) : rRect.Top();
499 
500     pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaLeft") );
501     pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.Left() ) : rRect.Left();
502 
503     pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaWidth") );
504     pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.GetWidth() ) : rRect.GetWidth();
505 
506     pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaHeight") );
507     pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.GetHeight() ) : rRect.GetHeight();
508 
509     // "show redline mode" cannot simply be read from the document
510     // since it gets changed during execution. If it's in the info
511     // XPropertySet, we take it from there.
512     sal_Bool bShowRedlineChanges = bSavedShowChanges;
513     Reference<XPropertySet> xInfoSet( getExportInfo() );
514     if ( xInfoSet.is() )
515     {
516         OUString sShowChanges( RTL_CONSTASCII_USTRINGPARAM( "ShowChanges" ));
517         if( xInfoSet->getPropertySetInfo()->hasPropertyByName( sShowChanges ) )
518         {
519             bShowRedlineChanges = *(sal_Bool*) xInfoSet->
520                                    getPropertyValue( sShowChanges ).getValue();
521         }
522     }
523 
524     pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ShowRedlineChanges") );
525     pValue[nIndex++].Value.setValue( &bShowRedlineChanges, ::getBooleanCppuType() );
526 
527     sal_Bool bInBrowse =  pDoc->get(IDocumentSettingAccess::BROWSE_MODE);
528     pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "InBrowseMode") );
529     pValue[nIndex++].Value.setValue( &bInBrowse, ::getBooleanCppuType() );
530 
531     if ( nIndex < NUM_EXPORTED_VIEW_SETTINGS )
532         aProps.realloc(nIndex);
533 }
534 #undef NUM_EXPORTED_VIEW_SETTINGS
535 
GetConfigurationSettings(Sequence<PropertyValue> & rProps)536 void SwXMLExport::GetConfigurationSettings( Sequence < PropertyValue >& rProps)
537 {
538     Reference< XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
539     if( xFac.is() )
540     {
541         Reference< XPropertySet > xProps( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), UNO_QUERY );
542         if( xProps.is() )
543         {
544             // property CurrentDatabaseDataSource needs to be exported before CurrentDatabaseCommand and CurrentDatabaseCommandType
545             // in order to assure that AOO/OOo versions (before AOO 4.0.1) are able to apply the current database settings correct
546             // Thus, put CurrentDatabaseDataSource as the first one into the Sequence
547 //            SvXMLUnitConverter::convertPropertySet( rProps, xProps );
548             uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = xProps->getPropertySetInfo();
549             if (xPropertySetInfo.is())
550             {
551                 uno::Sequence< beans::Property > aProps = xPropertySetInfo->getProperties();
552                 const sal_Int32 nCount(aProps.getLength());
553                 if (nCount)
554                 {
555                     rProps.realloc(nCount);
556                     beans::PropertyValue* pProps = rProps.getArray();
557 
558                     static ::rtl::OUString csCurrentDatabaseSource = ::rtl::OUString::createFromAscii("CurrentDatabaseDataSource");
559                     const sal_Bool bHasCurrentDatabaseSource = xPropertySetInfo->hasPropertyByName( csCurrentDatabaseSource );
560                     if ( bHasCurrentDatabaseSource )
561                     {
562                         beans::Property aProp = xPropertySetInfo->getPropertyByName( csCurrentDatabaseSource );
563                         pProps->Name = aProp.Name;
564                         pProps->Value = xProps->getPropertyValue(aProp.Name);
565                         ++pProps;
566                     }
567 
568                     for (sal_Int32 i = 0; i < nCount; i++ )
569                     {
570                         if ( bHasCurrentDatabaseSource
571                              && aProps[i].Name.compareTo( csCurrentDatabaseSource ) == 0 )
572                         {
573                             // nothing to do - already added as first item - see above
574                         }
575                         else
576                         {
577                             pProps->Name = aProps[i].Name;
578                             pProps->Value = xProps->getPropertyValue(aProps[i].Name);
579                             ++pProps;
580                         }
581                     }
582                 }
583             }
584         }
585     }
586 }
587 
GetDocumentSpecificSettings(::std::list<SettingsGroup> & _out_rSettings)588 sal_Int32 SwXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >& _out_rSettings )
589 {
590     // the only doc-specific settings group we know so far are the XForms settings
591     uno::Sequence<beans::PropertyValue> aXFormsSettings;
592     Reference< XFormsSupplier > xXFormsSupp( GetModel(), UNO_QUERY );
593     Reference< XNameAccess > xXForms;
594     if ( xXFormsSupp.is() )
595         xXForms = xXFormsSupp->getXForms().get();
596     if ( xXForms.is() )
597     {
598         getXFormsSettings( xXForms, aXFormsSettings );
599         _out_rSettings.push_back( SettingsGroup( XML_XFORM_MODEL_SETTINGS, aXFormsSettings ) );
600     }
601 
602     return aXFormsSettings.getLength() + SvXMLExport::GetDocumentSpecificSettings( _out_rSettings );
603 }
604 
SetBodyAttributes()605 void SwXMLExport::SetBodyAttributes()
606 {
607     Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
608     Reference < XText > xText = xTextDoc->getText();
609     // export use of soft page breaks
610     {
611         Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
612         ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
613         if( xTextTunnel.is() )
614         {
615             SwXText *pText = reinterpret_cast< SwXText * >(
616                     sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
617             ASSERT( pText, "SwXText missing" );
618             if( pText )
619             {
620                 SwDoc *pDoc = pText->GetDoc();
621                 if( pDoc && pDoc->GetCurrentViewShell() &&
622                     pDoc->GetCurrentViewShell()->GetPageCount() > 1 )
623                 {
624                     sal_Bool bValue = sal_True;
625                     rtl::OUStringBuffer sBuffer;
626                     GetMM100UnitConverter().convertBool(sBuffer, bValue);
627                     AddAttribute(XML_NAMESPACE_TEXT, XML_USE_SOFT_PAGE_BREAKS,
628                         sBuffer.makeStringAndClear());
629                 }
630             }
631         }
632     }
633 }
634 
635 
_ExportContent()636 void SwXMLExport::_ExportContent()
637 {
638     // export forms
639     Reference<XDrawPageSupplier> xDrawPageSupplier(GetModel(), UNO_QUERY);
640     if (xDrawPageSupplier.is())
641     {
642         // export only if we actually have elements
643         Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
644         if (xPage.is())
645         {
646             // #103597# prevent export of form controls which are embedded in
647             // mute sections
648             Reference<XIndexAccess> xIAPage( xPage, UNO_QUERY );
649             GetTextParagraphExport()->PreventExportOfControlsInMuteSections(
650                 xIAPage, GetFormExport() );
651 
652             // #i36597# / 2004-12-13 / fs@openoffice.org
653             if ( GetFormExport()->pageContainsForms( xPage ) || GetFormExport()->documentContainsXForms() )
654             {
655                 ::xmloff::OOfficeFormsExport aOfficeForms(*this);
656 
657                 GetFormExport()->exportXForms();
658 
659                 GetFormExport()->seekPage(xPage);
660                 GetFormExport()->exportForms(xPage);
661             }
662         }
663     }
664 
665     Reference<XPropertySet> xPropSet(GetModel(), UNO_QUERY);
666     if (xPropSet.is())
667     {
668         OUString sTwoDigitYear(RTL_CONSTASCII_USTRINGPARAM("TwoDigitYear"));
669 
670         Any aAny = xPropSet->getPropertyValue( sTwoDigitYear );
671         aAny <<= (sal_Int16)1930;
672 
673         sal_Int16 nYear = 0;
674         aAny >>= nYear;
675         if (nYear != 1930 )
676         {
677             rtl::OUStringBuffer sBuffer;
678             GetMM100UnitConverter().convertNumber(sBuffer, nYear);
679             AddAttribute(XML_NAMESPACE_TABLE, XML_NULL_YEAR, sBuffer.makeStringAndClear());
680             SvXMLElementExport aCalcSettings(*this, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, sal_True, sal_True);
681         }
682     }
683 
684     GetTextParagraphExport()->exportTrackedChanges( sal_False );
685     GetTextParagraphExport()->exportTextDeclarations();
686     Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
687     Reference < XText > xText = xTextDoc->getText();
688 
689     GetTextParagraphExport()->exportFramesBoundToPage( bShowProgress );
690     GetTextParagraphExport()->exportText( xText, bShowProgress );
691 }
692 
693 
694 
695 //
696 // uno component registration
697 // helper functions for export service(s)
698 //
699 
700 // OOo
SwXMLExportOOO_getImplementationName()701 OUString SAL_CALL SwXMLExportOOO_getImplementationName() throw()
702 {
703     return OUString( RTL_CONSTASCII_USTRINGPARAM(
704         "com.sun.star.comp.Writer.XMLExporter" ) );
705 }
706 
SwXMLExportOOO_getSupportedServiceNames()707 Sequence< OUString > SAL_CALL SwXMLExportOOO_getSupportedServiceNames()
708     throw()
709 {
710     const OUString aServiceName(SwXMLExportOOO_getImplementationName());
711     const Sequence< OUString > aSeq( &aServiceName, 1 );
712     return aSeq;
713 }
714 
SwXMLExportOOO_createInstance(const Reference<XMultiServiceFactory> & rSMgr)715 Reference< XInterface > SAL_CALL SwXMLExportOOO_createInstance(
716         const Reference< XMultiServiceFactory > & rSMgr)
717     throw( Exception )
718 {
719     return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_ALL);
720 }
721 
SwXMLExportStylesOOO_getImplementationName()722 OUString SAL_CALL SwXMLExportStylesOOO_getImplementationName() throw()
723 {
724     return OUString( RTL_CONSTASCII_USTRINGPARAM(
725         "com.sun.star.comp.Writer.XMLStylesExporter" ) );
726 }
727 
SwXMLExportStylesOOO_getSupportedServiceNames()728 Sequence< OUString > SAL_CALL SwXMLExportStylesOOO_getSupportedServiceNames()
729     throw()
730 {
731     const OUString aServiceName(SwXMLExportStylesOOO_getImplementationName());
732     const Sequence< OUString > aSeq( &aServiceName, 1 );
733     return aSeq;
734 }
735 
SwXMLExportStylesOOO_createInstance(const Reference<XMultiServiceFactory> & rSMgr)736 Reference< XInterface > SAL_CALL SwXMLExportStylesOOO_createInstance(
737         const Reference< XMultiServiceFactory > & rSMgr)
738     throw( Exception )
739 {
740     return (cppu::OWeakObject*)new SwXMLExport( rSMgr,
741         EXPORT_STYLES | EXPORT_MASTERSTYLES | EXPORT_AUTOSTYLES |
742         EXPORT_FONTDECLS );
743 }
744 
SwXMLExportContentOOO_getImplementationName()745 OUString SAL_CALL SwXMLExportContentOOO_getImplementationName() throw()
746 {
747     return OUString( RTL_CONSTASCII_USTRINGPARAM(
748         "com.sun.star.comp.Writer.XMLContentExporter" ) );
749 }
750 
SwXMLExportContentOOO_getSupportedServiceNames()751 Sequence< OUString > SAL_CALL SwXMLExportContentOOO_getSupportedServiceNames()
752     throw()
753 {
754     const OUString aServiceName(SwXMLExportContentOOO_getImplementationName());
755     const Sequence< OUString > aSeq( &aServiceName, 1 );
756     return aSeq;
757 }
758 
SwXMLExportContentOOO_createInstance(const Reference<XMultiServiceFactory> & rSMgr)759 Reference< XInterface > SAL_CALL SwXMLExportContentOOO_createInstance(
760         const Reference< XMultiServiceFactory > & rSMgr)
761     throw( Exception )
762 {
763     return (cppu::OWeakObject*)new SwXMLExport(rSMgr,
764         EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_SCRIPTS |
765         EXPORT_FONTDECLS );
766 }
767 
SwXMLExportMetaOOO_getImplementationName()768 OUString SAL_CALL SwXMLExportMetaOOO_getImplementationName() throw()
769 {
770     return OUString( RTL_CONSTASCII_USTRINGPARAM(
771         "com.sun.star.comp.Writer.XMLMetaExporter" ) );
772 }
773 
SwXMLExportMetaOOO_getSupportedServiceNames()774 Sequence< OUString > SAL_CALL SwXMLExportMetaOOO_getSupportedServiceNames()
775     throw()
776 {
777     const OUString aServiceName(SwXMLExportMetaOOO_getImplementationName());
778     const Sequence< OUString > aSeq( &aServiceName, 1 );
779     return aSeq;
780 }
781 
SwXMLExportMetaOOO_createInstance(const Reference<XMultiServiceFactory> & rSMgr)782 Reference< XInterface > SAL_CALL SwXMLExportMetaOOO_createInstance(
783         const Reference< XMultiServiceFactory > & rSMgr)
784     throw( Exception )
785 {
786     return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_META);
787 }
788 
SwXMLExportSettingsOOO_getImplementationName()789 OUString SAL_CALL SwXMLExportSettingsOOO_getImplementationName() throw()
790 {
791     return OUString( RTL_CONSTASCII_USTRINGPARAM(
792         "com.sun.star.comp.Writer.XMLSettingsExporter" ) );
793 }
794 
SwXMLExportSettingsOOO_getSupportedServiceNames()795 Sequence< OUString > SAL_CALL SwXMLExportSettingsOOO_getSupportedServiceNames()
796     throw()
797 {
798     const OUString aServiceName(SwXMLExportSettingsOOO_getImplementationName());
799     const Sequence< OUString > aSeq( &aServiceName, 1 );
800     return aSeq;
801 }
802 
SwXMLExportSettingsOOO_createInstance(const Reference<XMultiServiceFactory> & rSMgr)803 Reference< XInterface > SAL_CALL SwXMLExportSettingsOOO_createInstance(
804         const Reference< XMultiServiceFactory > & rSMgr)
805     throw( Exception )
806 {
807     return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_SETTINGS);
808 }
809 
810 // OASIS
SwXMLExport_getImplementationName()811 OUString SAL_CALL SwXMLExport_getImplementationName() throw()
812 {
813     return OUString( RTL_CONSTASCII_USTRINGPARAM(
814         "com.sun.star.comp.Writer.XMLOasisExporter" ) );
815 }
816 
SwXMLExport_getSupportedServiceNames()817 Sequence< OUString > SAL_CALL SwXMLExport_getSupportedServiceNames()
818     throw()
819 {
820     const OUString aServiceName(SwXMLExport_getImplementationName());
821     const Sequence< OUString > aSeq( &aServiceName, 1 );
822     return aSeq;
823 }
824 
SwXMLExport_createInstance(const Reference<XMultiServiceFactory> & rSMgr)825 Reference< XInterface > SAL_CALL SwXMLExport_createInstance(
826         const Reference< XMultiServiceFactory > & rSMgr)
827     throw( Exception )
828 {
829     return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_ALL|EXPORT_OASIS);
830 }
831 
SwXMLExportStyles_getImplementationName()832 OUString SAL_CALL SwXMLExportStyles_getImplementationName() throw()
833 {
834     return OUString( RTL_CONSTASCII_USTRINGPARAM(
835         "com.sun.star.comp.Writer.XMLOasisStylesExporter" ) );
836 }
837 
SwXMLExportStyles_getSupportedServiceNames()838 Sequence< OUString > SAL_CALL SwXMLExportStyles_getSupportedServiceNames()
839     throw()
840 {
841     const OUString aServiceName(SwXMLExportStyles_getImplementationName());
842     const Sequence< OUString > aSeq( &aServiceName, 1 );
843     return aSeq;
844 }
845 
SwXMLExportStyles_createInstance(const Reference<XMultiServiceFactory> & rSMgr)846 Reference< XInterface > SAL_CALL SwXMLExportStyles_createInstance(
847         const Reference< XMultiServiceFactory > & rSMgr)
848     throw( Exception )
849 {
850     // #110680#
851     //return (cppu::OWeakObject*)new SwXMLExport(
852     //  EXPORT_STYLES | EXPORT_MASTERSTYLES | EXPORT_AUTOSTYLES |
853     //  EXPORT_FONTDECLS );
854     return (cppu::OWeakObject*)new SwXMLExport( rSMgr,
855         EXPORT_STYLES | EXPORT_MASTERSTYLES | EXPORT_AUTOSTYLES |
856         EXPORT_FONTDECLS|EXPORT_OASIS );
857 }
858 
SwXMLExportContent_getImplementationName()859 OUString SAL_CALL SwXMLExportContent_getImplementationName() throw()
860 {
861     return OUString( RTL_CONSTASCII_USTRINGPARAM(
862         "com.sun.star.comp.Writer.XMLOasisContentExporter" ) );
863 }
864 
SwXMLExportContent_getSupportedServiceNames()865 Sequence< OUString > SAL_CALL SwXMLExportContent_getSupportedServiceNames()
866     throw()
867 {
868     const OUString aServiceName(SwXMLExportContent_getImplementationName());
869     const Sequence< OUString > aSeq( &aServiceName, 1 );
870     return aSeq;
871 }
872 
SwXMLExportContent_createInstance(const Reference<XMultiServiceFactory> & rSMgr)873 Reference< XInterface > SAL_CALL SwXMLExportContent_createInstance(
874         const Reference< XMultiServiceFactory > & rSMgr)
875     throw( Exception )
876 {
877     // #110680#
878     //return (cppu::OWeakObject*)new SwXMLExport(
879     //  EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_SCRIPTS |
880     //  EXPORT_FONTDECLS );
881     return (cppu::OWeakObject*)new SwXMLExport(
882         rSMgr,
883         EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_SCRIPTS |
884         EXPORT_FONTDECLS|EXPORT_OASIS );
885 }
886 
SwXMLExportMeta_getImplementationName()887 OUString SAL_CALL SwXMLExportMeta_getImplementationName() throw()
888 {
889     return OUString( RTL_CONSTASCII_USTRINGPARAM(
890         "com.sun.star.comp.Writer.XMLOasisMetaExporter" ) );
891 }
892 
SwXMLExportMeta_getSupportedServiceNames()893 Sequence< OUString > SAL_CALL SwXMLExportMeta_getSupportedServiceNames()
894     throw()
895 {
896     const OUString aServiceName(SwXMLExportMeta_getImplementationName());
897     const Sequence< OUString > aSeq( &aServiceName, 1 );
898     return aSeq;
899 }
900 
SwXMLExportMeta_createInstance(const Reference<XMultiServiceFactory> & rSMgr)901 Reference< XInterface > SAL_CALL SwXMLExportMeta_createInstance(
902         const Reference< XMultiServiceFactory > & rSMgr)
903     throw( Exception )
904 {
905     return (cppu::OWeakObject*)new SwXMLExport(rSMgr, EXPORT_META|EXPORT_OASIS);
906 }
907 
SwXMLExportSettings_getImplementationName()908 OUString SAL_CALL SwXMLExportSettings_getImplementationName() throw()
909 {
910     return OUString( RTL_CONSTASCII_USTRINGPARAM(
911         "com.sun.star.comp.Writer.XMLOasisSettingsExporter" ) );
912 }
913 
SwXMLExportSettings_getSupportedServiceNames()914 Sequence< OUString > SAL_CALL SwXMLExportSettings_getSupportedServiceNames()
915     throw()
916 {
917     const OUString aServiceName(SwXMLExportSettings_getImplementationName());
918     const Sequence< OUString > aSeq( &aServiceName, 1 );
919     return aSeq;
920 }
921 
SwXMLExportSettings_createInstance(const Reference<XMultiServiceFactory> & rSMgr)922 Reference< XInterface > SAL_CALL SwXMLExportSettings_createInstance(
923         const Reference< XMultiServiceFactory > & rSMgr)
924     throw( Exception )
925 {
926     return (cppu::OWeakObject*)new SwXMLExport(rSMgr, EXPORT_SETTINGS|EXPORT_OASIS);
927 }
928 
getUnoTunnelId()929 const Sequence< sal_Int8 > & SwXMLExport::getUnoTunnelId() throw()
930 {
931     static Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
932     return aSeq;
933 }
934 
getSomething(const Sequence<sal_Int8> & rId)935 sal_Int64 SAL_CALL SwXMLExport::getSomething( const Sequence< sal_Int8 >& rId )
936     throw(RuntimeException)
937 {
938     if( rId.getLength() == 16
939         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
940                                         rId.getConstArray(), 16 ) )
941     {
942         return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
943     }
944     return SvXMLExport::getSomething( rId );
945 }
946 
947 
948 // XServiceInfo
949 // override empty method from parent class
getImplementationName()950 OUString SAL_CALL SwXMLExport::getImplementationName()
951     throw(RuntimeException)
952 {
953     switch( getExportFlags() )
954     {
955         case EXPORT_ALL:
956             return SwXMLExport_getImplementationName();
957         case (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS):
958             return SwXMLExportStyles_getImplementationName();
959         case (EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS):
960             return SwXMLExportContent_getImplementationName();
961         case EXPORT_META:
962             return SwXMLExportMeta_getImplementationName();
963         case EXPORT_SETTINGS:
964             return SwXMLExportSettings_getImplementationName();
965         default:
966             // generic name for 'unknown' cases
967             return OUString( RTL_CONSTASCII_USTRINGPARAM(
968                 "com.sun.star.comp.Writer.SwXMLExport" ) );
969     }
970 }
971 
972 
973 #ifdef XML_CORE_API
ExportCurPaM(sal_Bool bExportWholePaM)974 void SwXMLExport::ExportCurPaM( sal_Bool bExportWholePaM )
975 {
976     sal_Bool bFirstNode = sal_True;
977     sal_Bool bExportWholeNode = bExportWholePaM;
978 
979     SwXMLNumRuleInfo aPrevNumInfo;
980     SwXMLNumRuleInfo aNextNumInfo;
981 
982     while( pCurPaM->GetPoint()->nNode.GetIndex() <
983                                 pCurPaM->GetMark()->nNode.GetIndex() ||
984            ( pCurPaM->GetPoint()->nNode.GetIndex() ==
985                                 pCurPaM->GetMark()->nNode.GetIndex() &&
986              pCurPaM->GetPoint()->nContent.GetIndex() <=
987                                 pCurPaM->GetMark()->nContent.GetIndex() ) )
988     {
989         SwNode *pNd = pCurPaM->GetNode();
990 
991         aNextNumInfo.Set( *pNd );
992         ExportListChange( aPrevNumInfo, aNextNumInfo );
993 
994         ASSERT( !(pNd->IsGrfNode() || pNd->IsOLENode()),
995                 "SwXMLExport::exportCurPaM: grf or OLE node unexpected" );
996         if( pNd->IsTxtNode() )
997         {
998             SwTxtNode* pTxtNd = pNd->GetTxtNode();
999 
1000             if( !bFirstNode )
1001                 pCurPaM->GetPoint()->nContent.Assign( pTxtNd, 0 );
1002 
1003             ExportTxtNode( *pTxtNd, 0, STRING_LEN, bExportWholeNode );
1004         }
1005         else if( pNd->IsTableNode() )
1006         {
1007             ExportTable( *pNd->GetTableNode() );
1008         }
1009         else if( pNd->IsSectionNode() )
1010         {
1011             ExportSection( *pNd->GetSectionNode() );
1012         }
1013         else if( pNd == &pDoc->GetNodes().GetEndOfContent() )
1014             break;
1015 
1016         pCurPaM->GetPoint()->nNode++;   // next node
1017 
1018         sal_uInt32 nPos = pCurPaM->GetPoint()->nNode.GetIndex();
1019 
1020         // if not everything should be exported, the WriteAll flag must be
1021         // set for all but the first and last node anyway.
1022         bExportWholeNode = bExportWholePaM ||
1023                            nPos != pCurPaM->GetMark()->nNode.GetIndex();
1024         bFirstNode = sal_False;
1025 
1026         aPrevNumInfo = aNextNumInfo;
1027     }
1028     aNextNumInfo.Reset();
1029     ExportListChange( aPrevNumInfo, aNextNumInfo );
1030 }
1031 #endif
1032