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