Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <com/sun/star/text/XTextDocument.hpp>
22 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
23 : #include <com/sun/star/beans/XPropertySet.hpp>
24 : #include <com/sun/star/container/XNameContainer.hpp>
25 : #include <com/sun/star/container/XIndexContainer.hpp>
26 : #include <com/sun/star/uno/RuntimeException.hpp>
27 : #include <com/sun/star/xforms/XFormsSupplier.hpp>
28 :
29 : #include <sax/tools/converter.hxx>
30 : #include <svx/svdmodel.hxx>
31 : #include <svx/svdpage.hxx>
32 : #include <svx/xmleohlp.hxx>
33 : #include <svx/xmlgrhlp.hxx>
34 : #include <editeng/eeitem.hxx>
35 : #include <svx/svddef.hxx>
36 : #include <xmloff/nmspmap.hxx>
37 : #include <xmloff/xmlnmspe.hxx>
38 : #include <editeng/xmlcnitm.hxx>
39 : #include <xmloff/ProgressBarHelper.hxx>
40 : #include <xmloff/xmluconv.hxx>
41 : #include <xmloff/xformsexport.hxx>
42 : #include <pam.hxx>
43 : #include <doc.hxx>
44 : #include <swmodule.hxx>
45 : #include <docsh.hxx>
46 : #include <viewsh.hxx>
47 : #include <docstat.hxx>
48 : #include <swerror.h>
49 : #include <unotext.hxx>
50 : #include <xmltexte.hxx>
51 : #include <xmlexp.hxx>
52 : #include <sfx2/viewsh.hxx>
53 : #include <comphelper/processfactory.hxx>
54 : #include <docary.hxx>
55 : #include <editeng/unolingu.hxx>
56 : #include <editeng/forbiddencharacterstable.hxx>
57 : #include <comphelper/servicehelper.hxx>
58 :
59 : // for locking SolarMutex: svapp + mutex
60 : #include <vcl/svapp.hxx>
61 : #include <osl/mutex.hxx>
62 :
63 : #include <pausethreadstarting.hxx> // #i73788#
64 :
65 :
66 : using ::rtl::OUString;
67 : using namespace ::com::sun::star;
68 : using namespace ::com::sun::star::frame;
69 : using namespace ::com::sun::star::lang;
70 : using namespace ::com::sun::star::xml::sax;
71 : using namespace ::com::sun::star::uno;
72 : using namespace ::com::sun::star::text;
73 : using namespace ::com::sun::star::container;
74 : using namespace ::com::sun::star::document;
75 : using namespace ::com::sun::star::drawing;
76 : using namespace ::com::sun::star::beans;
77 : using namespace ::com::sun::star::i18n;
78 : using namespace ::com::sun::star::xforms;
79 : using namespace ::xmloff::token;
80 :
81 8 : SwXMLExport::SwXMLExport(
82 : const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
83 : sal_uInt16 nExportFlags)
84 : : SvXMLExport( util::MeasureUnit::INCH, xServiceFactory, XML_TEXT,
85 : nExportFlags ),
86 : pTableItemMapper( 0 ),
87 : pTableLines( 0 ),
88 : bBlock( sal_False ),
89 : bShowProgress( sal_True ),
90 : sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")),
91 : sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")),
92 8 : sCell(RTL_CONSTASCII_USTRINGPARAM("Cell"))
93 : {
94 8 : _InitItemExport();
95 8 : }
96 :
97 0 : void SwXMLExport::setBlockMode()
98 : {
99 0 : bBlock = sal_True;
100 :
101 0 : }
102 :
103 8 : sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
104 : {
105 8 : if( !GetModel().is() )
106 0 : return ERR_SWG_WRITE_ERROR;
107 :
108 8 : SwPauseThreadStarting aPauseThreadStarting; // #i73788#
109 :
110 8 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
111 8 : Reference < XText > xText = xTextDoc->getText();
112 8 : Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
113 : OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
114 8 : if( !xTextTunnel.is() )
115 0 : return ERR_SWG_WRITE_ERROR;
116 :
117 : // from here, we use core interfaces -> lock Solar-Mutex
118 8 : SolarMutexGuard aGuard;
119 :
120 : {
121 8 : Reference<XPropertySet> rInfoSet = getExportInfo();
122 8 : if( rInfoSet.is() )
123 : {
124 : OUString sAutoTextMode(
125 8 : RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
126 16 : if( rInfoSet->getPropertySetInfo()->hasPropertyByName(
127 8 : sAutoTextMode ) )
128 : {
129 8 : Any aAny = rInfoSet->getPropertyValue(sAutoTextMode);
130 8 : if( aAny.getValueType() == ::getBooleanCppuType() &&
131 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
132 0 : setBlockMode();
133 8 : }
134 8 : }
135 : }
136 :
137 : SwXText *pText = reinterpret_cast< SwXText * >(
138 8 : sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
139 : OSL_ENSURE( pText, "SwXText missing" );
140 8 : if( !pText )
141 0 : return ERR_SWG_WRITE_ERROR;
142 :
143 8 : SwDoc *pDoc = pText->GetDoc();
144 :
145 8 : sal_Bool bExtended = sal_False;
146 8 : if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
147 : EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
148 : {
149 4 : if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
150 : {
151 4 : _GetNamespaceMap().Add(
152 4 : GetXMLToken(XML_NP_OFFICE_EXT),
153 4 : GetXMLToken(XML_N_OFFICE_EXT),
154 4 : XML_NAMESPACE_OFFICE_EXT);
155 : }
156 :
157 4 : GetTextParagraphExport()->SetBlockMode( bBlock );
158 :
159 : const SfxPoolItem* pItem;
160 4 : const SfxItemPool& rPool = pDoc->GetAttrPool();
161 : sal_uInt16 aWhichIds[5] = { RES_UNKNOWNATR_CONTAINER,
162 : RES_TXTATR_UNKNOWN_CONTAINER,
163 : SDRATTR_XMLATTRIBUTES,
164 : EE_PARA_XMLATTRIBS,
165 4 : EE_CHAR_XMLATTRIBS };
166 :
167 4 : sal_uInt16 nWhichIds = rPool.GetSecondaryPool() ? 5 : 2;
168 24 : for( sal_uInt16 j=0; j < nWhichIds; j++ )
169 : {
170 20 : sal_uInt16 nWhichId = aWhichIds[j];
171 20 : sal_uInt32 i=0, nItems = rPool.GetItemCount2( nWhichId );
172 24 : for( i = 0; i < nItems; ++i )
173 : {
174 4 : if( 0 != (pItem = rPool.GetItem2( nWhichId , i ) ) )
175 : {
176 : const SvXMLAttrContainerItem *pUnknown =
177 4 : PTR_CAST( SvXMLAttrContainerItem, pItem );
178 : OSL_ENSURE( pUnknown, "illegal attribute container item" );
179 4 : if( pUnknown && (pUnknown->GetAttrCount() > 0) )
180 : {
181 0 : sal_uInt16 nIdx = pUnknown->GetFirstNamespaceIndex();
182 0 : while( USHRT_MAX != nIdx )
183 : {
184 : const OUString& rPrefix =
185 0 : pUnknown->GetPrefix( nIdx );
186 0 : _GetNamespaceMap().Add( rPrefix,
187 0 : pUnknown->GetNamespace( nIdx ),
188 0 : XML_NAMESPACE_UNKNOWN );
189 0 : nIdx = pUnknown->GetNextNamespaceIndex( nIdx );
190 : }
191 0 : bExtended = sal_True;
192 : }
193 : }
194 : }
195 : }
196 : }
197 :
198 : sal_uInt16 const eUnit = SvXMLUnitConverter::GetMeasureUnit(
199 8 : SW_MOD()->GetMetric(pDoc->get(IDocumentSettingAccess::HTML_MODE)));
200 8 : if (GetMM100UnitConverter().GetXMLMeasureUnit() != eUnit )
201 : {
202 0 : GetMM100UnitConverter().SetXMLMeasureUnit( eUnit );
203 0 : pTwipUnitConv->SetXMLMeasureUnit( eUnit );
204 : }
205 :
206 8 : SetExtended( bExtended );
207 :
208 8 : if( (getExportFlags() & EXPORT_META) != 0 )
209 : {
210 : // Update doc stat, so that correct values are exported and
211 : // the progress works correctly.
212 2 : pDoc->UpdateDocStat();
213 :
214 2 : SfxObjectShell* pObjSh = pDoc->GetDocShell();
215 2 : if( pObjSh )
216 2 : pObjSh->UpdateDocInfoForSave(); // update information
217 : }
218 8 : if( bShowProgress )
219 : {
220 8 : ProgressBarHelper *pProgress = GetProgressBarHelper();
221 8 : if( -1 == pProgress->GetReference() )
222 : {
223 : // progress isn't initialized:
224 : // We assume that the whole doc is exported, and the following
225 : // durations:
226 : // - meta information: 2
227 : // - settings: 4 (TODO: not now!)
228 : // - styles (except page styles): 2
229 : // - page styles: 2 (TODO: not now!) + 2 for each paragraph
230 : // - paragraph: 2 (1 for automatic styles and one for content)
231 :
232 : // count each item once, and then multiply by two to reach the
233 : // figures given above
234 : // The styles in pDoc also count the default style that never
235 : // gets exported -> subtract one.
236 2 : sal_Int32 nRef = 1; // meta.xml
237 2 : nRef += pDoc->GetCharFmts()->size() - 1;
238 2 : nRef += pDoc->GetFrmFmts()->size() - 1;
239 2 : nRef += pDoc->GetTxtFmtColls()->size() - 1;
240 2 : nRef *= 2; // for the above styles, xmloff will increment by 2!
241 : // #i93174#: count all paragraphs for the progress bar
242 2 : nRef += pDoc->GetUpdatedDocStat().nAllPara; // 1: only content, no autostyle
243 2 : pProgress->SetReference( nRef );
244 2 : pProgress->SetValue( 0 );
245 : }
246 : }
247 :
248 8 : if( (getExportFlags() & (EXPORT_MASTERSTYLES|EXPORT_CONTENT)) != 0 )
249 : {
250 : //Auf die Korrektheit der OrdNums sind wir schon angewiesen.
251 4 : SdrModel* pModel = pDoc->GetDrawModel();
252 4 : if( pModel )
253 4 : pModel->GetPage( 0 )->RecalcObjOrdNums();
254 : }
255 :
256 : // adjust document class (eClass)
257 8 : if (pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT))
258 : {
259 0 : eClass = XML_TEXT_GLOBAL;
260 :
261 : // additionally, we take care of the save-linked-sections-thingy
262 0 : mbSaveLinkedSections = pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
263 : }
264 : // MIB: 03/26/04: The Label information is saved in the settings, so
265 : // we don't need it here.
266 : // else: keep default pClass that we received
267 :
268 8 : SvXMLGraphicHelper *pGraphicResolver = 0;
269 8 : if( !GetGraphicResolver().is() )
270 : {
271 4 : pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_WRITE );
272 4 : Reference< XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
273 4 : SetGraphicResolver( xGraphicResolver );
274 : }
275 :
276 8 : SvXMLEmbeddedObjectHelper *pEmbeddedResolver = 0;
277 8 : if( !GetEmbeddedResolver().is() )
278 : {
279 4 : SfxObjectShell *pPersist = pDoc->GetPersist();
280 4 : if( pPersist )
281 : {
282 : pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
283 : *pPersist,
284 4 : EMBEDDEDOBJECTHELPER_MODE_WRITE );
285 4 : Reference< XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
286 4 : SetEmbeddedResolver( xEmbeddedResolver );
287 : }
288 : }
289 :
290 : // set redline mode if we export STYLES or CONTENT, unless redline
291 : // mode is taken care of outside (through info XPropertySet)
292 : sal_Bool bSaveRedline =
293 8 : ( (getExportFlags() & (EXPORT_CONTENT|EXPORT_STYLES)) != 0 );
294 8 : if( bSaveRedline )
295 : {
296 : // if the info property set has a ShowChanges property,
297 : // then change tracking is taken care of on the outside,
298 : // so we don't have to!
299 4 : Reference<XPropertySet> rInfoSet = getExportInfo();
300 4 : if( rInfoSet.is() )
301 : {
302 4 : OUString sShowChanges( RTL_CONSTASCII_USTRINGPARAM("ShowChanges"));
303 8 : bSaveRedline = ! rInfoSet->getPropertySetInfo()->hasPropertyByName(
304 8 : sShowChanges );
305 4 : }
306 : }
307 8 : sal_uInt16 nRedlineMode = 0;
308 8 : bSavedShowChanges = IDocumentRedlineAccess::IsShowChanges( pDoc->GetRedlineMode() );
309 8 : if( bSaveRedline )
310 : {
311 : // now save and switch redline mode
312 0 : nRedlineMode = pDoc->GetRedlineMode();
313 : pDoc->SetRedlineMode(
314 0 : (RedlineMode_t)(( nRedlineMode & nsRedlineMode_t::REDLINE_SHOW_MASK ) | nsRedlineType_t::REDLINE_INSERT ));
315 : }
316 :
317 8 : sal_uInt32 nRet = SvXMLExport::exportDoc( eClass );
318 :
319 : // now we can restore the redline mode (if we changed it previously)
320 8 : if( bSaveRedline )
321 : {
322 0 : pDoc->SetRedlineMode( (RedlineMode_t)(nRedlineMode ));
323 : }
324 :
325 :
326 8 : if( pGraphicResolver )
327 4 : SvXMLGraphicHelper::Destroy( pGraphicResolver );
328 8 : if( pEmbeddedResolver )
329 4 : SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
330 :
331 : OSL_ENSURE( !pTableLines, "there are table columns infos left" );
332 :
333 8 : return nRet;
334 : }
335 :
336 4 : XMLTextParagraphExport* SwXMLExport::CreateTextParagraphExport()
337 : {
338 4 : return new SwXMLTextParagraphExport( *this, *GetAutoStylePool().get() );
339 : }
340 :
341 4 : XMLShapeExport* SwXMLExport::CreateShapeExport()
342 : {
343 4 : XMLShapeExport* pShapeExport = new XMLShapeExport( *this, XMLTextParagraphExport::CreateShapeExtPropMapper( *this ) );
344 4 : Reference < XDrawPageSupplier > xDPS( GetModel(), UNO_QUERY );
345 4 : if( xDPS.is() )
346 : {
347 4 : Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY );
348 4 : pShapeExport->seekShapes( xShapes );
349 : }
350 :
351 4 : return pShapeExport;
352 : }
353 :
354 24 : SwXMLExport::~SwXMLExport()
355 : {
356 8 : DeleteTableLines();
357 8 : _FinitItemExport();
358 16 : }
359 :
360 :
361 4 : void SwXMLExport::_ExportFontDecls()
362 : {
363 4 : GetFontAutoStylePool(); // make sure the pool is created
364 4 : SvXMLExport::_ExportFontDecls();
365 4 : }
366 :
367 : #define NUM_EXPORTED_VIEW_SETTINGS 11
368 2 : void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps)
369 : {
370 : Reference< XMultiServiceFactory > xServiceFactory =
371 2 : comphelper::getProcessServiceFactory();
372 : OSL_ENSURE( xServiceFactory.is(),
373 : "XMLReader::Read: got no service manager" );
374 2 : if( !xServiceFactory.is() )
375 : return;
376 :
377 2 : aProps.realloc( NUM_EXPORTED_VIEW_SETTINGS );
378 : // Currently exporting 9 properties
379 2 : PropertyValue *pValue = aProps.getArray();
380 2 : sal_Int32 nIndex = 0;
381 :
382 2 : Reference < XIndexContainer > xBox (xServiceFactory->createInstance
383 2 : (OUString( RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.document.IndexedPropertyValues") ) ), UNO_QUERY);
384 2 : if (xBox.is() )
385 : {
386 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "Views") );
387 2 : pValue[nIndex++].Value <<= Reference < XIndexAccess > ( xBox, UNO_QUERY );
388 : }
389 :
390 2 : Reference < XText > xText;
391 2 : SwXText *pText = 0;
392 :
393 2 : if( GetModel().is() )
394 : {
395 2 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
396 2 : xText = xTextDoc->getText();
397 2 : Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
398 : OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
399 2 : if( xTextTunnel.is() )
400 : {
401 : pText = reinterpret_cast< SwXText * >(
402 2 : sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId()) ));
403 : OSL_ENSURE( pText, "SwXText missing" );
404 2 : }
405 : }
406 :
407 2 : if( !pText )
408 : {
409 0 : aProps.realloc(nIndex);
410 : return;
411 : }
412 :
413 2 : SwDoc *pDoc = pText->GetDoc();
414 : const Rectangle rRect =
415 2 : pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
416 2 : sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
417 :
418 : OSL_ENSURE( bTwip, "Map unit for visible area is not in TWIPS!" );
419 :
420 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaTop") );
421 2 : pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.Top() ) : rRect.Top();
422 :
423 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaLeft") );
424 2 : pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.Left() ) : rRect.Left();
425 :
426 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaWidth") );
427 2 : pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.GetWidth() ) : rRect.GetWidth();
428 :
429 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ViewAreaHeight") );
430 2 : pValue[nIndex++].Value <<= bTwip ? TWIP_TO_MM100 ( rRect.GetHeight() ) : rRect.GetHeight();
431 :
432 : // "show redline mode" cannot simply be read from the document
433 : // since it gets changed during execution. If it's in the info
434 : // XPropertySet, we take it from there.
435 2 : sal_Bool bShowRedlineChanges = bSavedShowChanges;
436 2 : Reference<XPropertySet> xInfoSet( getExportInfo() );
437 2 : if ( xInfoSet.is() )
438 : {
439 2 : OUString sShowChanges( RTL_CONSTASCII_USTRINGPARAM( "ShowChanges" ));
440 2 : if( xInfoSet->getPropertySetInfo()->hasPropertyByName( sShowChanges ) )
441 : {
442 2 : bShowRedlineChanges = *(sal_Bool*) xInfoSet->
443 2 : getPropertyValue( sShowChanges ).getValue();
444 2 : }
445 : }
446 :
447 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "ShowRedlineChanges") );
448 2 : pValue[nIndex++].Value.setValue( &bShowRedlineChanges, ::getBooleanCppuType() );
449 :
450 2 : sal_Bool bInBrowse = pDoc->get(IDocumentSettingAccess::BROWSE_MODE);
451 2 : pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "InBrowseMode") );
452 2 : pValue[nIndex++].Value.setValue( &bInBrowse, ::getBooleanCppuType() );
453 :
454 2 : if ( nIndex < NUM_EXPORTED_VIEW_SETTINGS )
455 2 : aProps.realloc(nIndex);
456 : }
457 : #undef NUM_EXPORTED_VIEW_SETTINGS
458 :
459 2 : void SwXMLExport::GetConfigurationSettings( Sequence < PropertyValue >& rProps)
460 : {
461 2 : Reference< XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
462 2 : if( xFac.is() )
463 : {
464 2 : Reference< XPropertySet > xProps( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), UNO_QUERY );
465 2 : if( xProps.is() )
466 2 : SvXMLUnitConverter::convertPropertySet( rProps, xProps );
467 2 : }
468 2 : }
469 :
470 2 : sal_Int32 SwXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >& _out_rSettings )
471 : {
472 : // the only doc-specific settings group we know so far are the XForms settings
473 2 : uno::Sequence<beans::PropertyValue> aXFormsSettings;
474 2 : Reference< XFormsSupplier > xXFormsSupp( GetModel(), UNO_QUERY );
475 2 : Reference< XNameAccess > xXForms;
476 2 : if ( xXFormsSupp.is() )
477 2 : xXForms = xXFormsSupp->getXForms().get();
478 2 : if ( xXForms.is() )
479 : {
480 0 : getXFormsSettings( xXForms, aXFormsSettings );
481 0 : _out_rSettings.push_back( SettingsGroup( XML_XFORM_MODEL_SETTINGS, aXFormsSettings ) );
482 : }
483 :
484 2 : return aXFormsSettings.getLength() + SvXMLExport::GetDocumentSpecificSettings( _out_rSettings );
485 : }
486 :
487 2 : void SwXMLExport::SetBodyAttributes()
488 : {
489 2 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
490 2 : Reference < XText > xText = xTextDoc->getText();
491 : // export use of soft page breaks
492 : {
493 2 : Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
494 : OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
495 2 : if( xTextTunnel.is() )
496 : {
497 : SwXText *pText = reinterpret_cast< SwXText * >(
498 2 : sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
499 : OSL_ENSURE( pText, "SwXText missing" );
500 2 : if( pText )
501 : {
502 2 : SwDoc *pDoc = pText->GetDoc();
503 4 : if( pDoc && pDoc->GetCurrentViewShell() &&
504 2 : pDoc->GetCurrentViewShell()->GetPageCount() > 1 )
505 : {
506 1 : sal_Bool bValue = sal_True;
507 1 : rtl::OUStringBuffer sBuffer;
508 1 : ::sax::Converter::convertBool(sBuffer, bValue);
509 : AddAttribute(XML_NAMESPACE_TEXT, XML_USE_SOFT_PAGE_BREAKS,
510 1 : sBuffer.makeStringAndClear());
511 : }
512 : }
513 2 : }
514 2 : }
515 2 : }
516 :
517 :
518 2 : void SwXMLExport::_ExportContent()
519 : {
520 : // export forms
521 2 : Reference<XDrawPageSupplier> xDrawPageSupplier(GetModel(), UNO_QUERY);
522 2 : if (xDrawPageSupplier.is())
523 : {
524 : // export only if we actually have elements
525 2 : Reference<XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
526 2 : if (xPage.is())
527 : {
528 : // prevent export of form controls which are embedded in mute sections
529 2 : Reference<XIndexAccess> xIAPage( xPage, UNO_QUERY );
530 : GetTextParagraphExport()->PreventExportOfControlsInMuteSections(
531 2 : xIAPage, GetFormExport() );
532 :
533 : // #i36597#
534 2 : if ( GetFormExport()->pageContainsForms( xPage ) || GetFormExport()->documentContainsXForms() )
535 : {
536 0 : ::xmloff::OOfficeFormsExport aOfficeForms(*this);
537 :
538 0 : GetFormExport()->exportXForms();
539 :
540 0 : GetFormExport()->seekPage(xPage);
541 0 : GetFormExport()->exportForms(xPage);
542 2 : }
543 2 : }
544 : }
545 :
546 2 : Reference<XPropertySet> xPropSet(GetModel(), UNO_QUERY);
547 2 : if (xPropSet.is())
548 : {
549 2 : OUString sTwoDigitYear(RTL_CONSTASCII_USTRINGPARAM("TwoDigitYear"));
550 :
551 2 : Any aAny = xPropSet->getPropertyValue( sTwoDigitYear );
552 2 : aAny <<= (sal_Int16)1930;
553 :
554 2 : sal_Int16 nYear = 0;
555 2 : aAny >>= nYear;
556 2 : if (nYear != 1930 )
557 : {
558 0 : rtl::OUStringBuffer sBuffer;
559 0 : ::sax::Converter::convertNumber(sBuffer, nYear);
560 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_NULL_YEAR, sBuffer.makeStringAndClear());
561 0 : SvXMLElementExport aCalcSettings(*this, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, sal_True, sal_True);
562 2 : }
563 : }
564 :
565 2 : GetTextParagraphExport()->exportTrackedChanges( sal_False );
566 2 : GetTextParagraphExport()->exportTextDeclarations();
567 2 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
568 2 : Reference < XText > xText = xTextDoc->getText();
569 :
570 2 : GetTextParagraphExport()->exportFramesBoundToPage( bShowProgress );
571 2 : GetTextParagraphExport()->exportText( xText, bShowProgress );
572 2 : }
573 :
574 :
575 :
576 : //
577 : // uno component registration
578 : // helper functions for export service(s)
579 : //
580 :
581 : // OOo
582 13 : OUString SAL_CALL SwXMLExportOOO_getImplementationName() throw()
583 : {
584 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
585 13 : "com.sun.star.comp.Writer.XMLExporter" ) );
586 : }
587 :
588 0 : Sequence< OUString > SAL_CALL SwXMLExportOOO_getSupportedServiceNames()
589 : throw()
590 : {
591 0 : const OUString aServiceName(SwXMLExportOOO_getImplementationName());
592 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
593 0 : return aSeq;
594 : }
595 :
596 0 : Reference< XInterface > SAL_CALL SwXMLExportOOO_createInstance(
597 : const Reference< XMultiServiceFactory > & rSMgr)
598 : throw( Exception )
599 : {
600 0 : return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_ALL);
601 : }
602 :
603 13 : OUString SAL_CALL SwXMLExportStylesOOO_getImplementationName() throw()
604 : {
605 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
606 13 : "com.sun.star.comp.Writer.XMLStylesExporter" ) );
607 : }
608 :
609 0 : Sequence< OUString > SAL_CALL SwXMLExportStylesOOO_getSupportedServiceNames()
610 : throw()
611 : {
612 0 : const OUString aServiceName(SwXMLExportStylesOOO_getImplementationName());
613 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
614 0 : return aSeq;
615 : }
616 :
617 0 : Reference< XInterface > SAL_CALL SwXMLExportStylesOOO_createInstance(
618 : const Reference< XMultiServiceFactory > & rSMgr)
619 : throw( Exception )
620 : {
621 : return (cppu::OWeakObject*)new SwXMLExport( rSMgr,
622 : EXPORT_STYLES | EXPORT_MASTERSTYLES | EXPORT_AUTOSTYLES |
623 0 : EXPORT_FONTDECLS );
624 : }
625 :
626 13 : OUString SAL_CALL SwXMLExportContentOOO_getImplementationName() throw()
627 : {
628 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
629 13 : "com.sun.star.comp.Writer.XMLContentExporter" ) );
630 : }
631 :
632 0 : Sequence< OUString > SAL_CALL SwXMLExportContentOOO_getSupportedServiceNames()
633 : throw()
634 : {
635 0 : const OUString aServiceName(SwXMLExportContentOOO_getImplementationName());
636 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
637 0 : return aSeq;
638 : }
639 :
640 0 : Reference< XInterface > SAL_CALL SwXMLExportContentOOO_createInstance(
641 : const Reference< XMultiServiceFactory > & rSMgr)
642 : throw( Exception )
643 : {
644 : return (cppu::OWeakObject*)new SwXMLExport(rSMgr,
645 : EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_SCRIPTS |
646 0 : EXPORT_FONTDECLS );
647 : }
648 :
649 13 : OUString SAL_CALL SwXMLExportMetaOOO_getImplementationName() throw()
650 : {
651 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
652 13 : "com.sun.star.comp.Writer.XMLMetaExporter" ) );
653 : }
654 :
655 0 : Sequence< OUString > SAL_CALL SwXMLExportMetaOOO_getSupportedServiceNames()
656 : throw()
657 : {
658 0 : const OUString aServiceName(SwXMLExportMetaOOO_getImplementationName());
659 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
660 0 : return aSeq;
661 : }
662 :
663 0 : Reference< XInterface > SAL_CALL SwXMLExportMetaOOO_createInstance(
664 : const Reference< XMultiServiceFactory > & rSMgr)
665 : throw( Exception )
666 : {
667 0 : return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_META);
668 : }
669 :
670 13 : OUString SAL_CALL SwXMLExportSettingsOOO_getImplementationName() throw()
671 : {
672 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
673 13 : "com.sun.star.comp.Writer.XMLSettingsExporter" ) );
674 : }
675 :
676 0 : Sequence< OUString > SAL_CALL SwXMLExportSettingsOOO_getSupportedServiceNames()
677 : throw()
678 : {
679 0 : const OUString aServiceName(SwXMLExportSettingsOOO_getImplementationName());
680 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
681 0 : return aSeq;
682 : }
683 :
684 0 : Reference< XInterface > SAL_CALL SwXMLExportSettingsOOO_createInstance(
685 : const Reference< XMultiServiceFactory > & rSMgr)
686 : throw( Exception )
687 : {
688 0 : return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_SETTINGS);
689 : }
690 :
691 : // OASIS
692 13 : OUString SAL_CALL SwXMLExport_getImplementationName() throw()
693 : {
694 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
695 13 : "com.sun.star.comp.Writer.XMLOasisExporter" ) );
696 : }
697 :
698 0 : Sequence< OUString > SAL_CALL SwXMLExport_getSupportedServiceNames()
699 : throw()
700 : {
701 0 : const OUString aServiceName(SwXMLExport_getImplementationName());
702 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
703 0 : return aSeq;
704 : }
705 :
706 0 : Reference< XInterface > SAL_CALL SwXMLExport_createInstance(
707 : const Reference< XMultiServiceFactory > & rSMgr)
708 : throw( Exception )
709 : {
710 0 : return (cppu::OWeakObject*)new SwXMLExport( rSMgr, EXPORT_ALL|EXPORT_OASIS);
711 : }
712 :
713 15 : OUString SAL_CALL SwXMLExportStyles_getImplementationName() throw()
714 : {
715 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
716 15 : "com.sun.star.comp.Writer.XMLOasisStylesExporter" ) );
717 : }
718 :
719 1 : Sequence< OUString > SAL_CALL SwXMLExportStyles_getSupportedServiceNames()
720 : throw()
721 : {
722 1 : const OUString aServiceName(SwXMLExportStyles_getImplementationName());
723 1 : const Sequence< OUString > aSeq( &aServiceName, 1 );
724 1 : return aSeq;
725 : }
726 :
727 2 : Reference< XInterface > SAL_CALL SwXMLExportStyles_createInstance(
728 : const Reference< XMultiServiceFactory > & rSMgr)
729 : throw( Exception )
730 : {
731 : return (cppu::OWeakObject*)new SwXMLExport( rSMgr,
732 : EXPORT_STYLES | EXPORT_MASTERSTYLES | EXPORT_AUTOSTYLES |
733 2 : EXPORT_FONTDECLS|EXPORT_OASIS );
734 : }
735 :
736 14 : OUString SAL_CALL SwXMLExportContent_getImplementationName() throw()
737 : {
738 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
739 14 : "com.sun.star.comp.Writer.XMLOasisContentExporter" ) );
740 : }
741 :
742 1 : Sequence< OUString > SAL_CALL SwXMLExportContent_getSupportedServiceNames()
743 : throw()
744 : {
745 1 : const OUString aServiceName(SwXMLExportContent_getImplementationName());
746 1 : const Sequence< OUString > aSeq( &aServiceName, 1 );
747 1 : return aSeq;
748 : }
749 :
750 2 : Reference< XInterface > SAL_CALL SwXMLExportContent_createInstance(
751 : const Reference< XMultiServiceFactory > & rSMgr)
752 : throw( Exception )
753 : {
754 : return (cppu::OWeakObject*)new SwXMLExport(
755 : rSMgr,
756 : EXPORT_AUTOSTYLES | EXPORT_CONTENT | EXPORT_SCRIPTS |
757 2 : EXPORT_FONTDECLS|EXPORT_OASIS );
758 : }
759 :
760 13 : OUString SAL_CALL SwXMLExportMeta_getImplementationName() throw()
761 : {
762 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
763 13 : "com.sun.star.comp.Writer.XMLOasisMetaExporter" ) );
764 : }
765 :
766 1 : Sequence< OUString > SAL_CALL SwXMLExportMeta_getSupportedServiceNames()
767 : throw()
768 : {
769 1 : const OUString aServiceName(SwXMLExportMeta_getImplementationName());
770 1 : const Sequence< OUString > aSeq( &aServiceName, 1 );
771 1 : return aSeq;
772 : }
773 :
774 2 : Reference< XInterface > SAL_CALL SwXMLExportMeta_createInstance(
775 : const Reference< XMultiServiceFactory > & rSMgr)
776 : throw( Exception )
777 : {
778 2 : return (cppu::OWeakObject*)new SwXMLExport(rSMgr, EXPORT_META|EXPORT_OASIS);
779 : }
780 :
781 12 : OUString SAL_CALL SwXMLExportSettings_getImplementationName() throw()
782 : {
783 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
784 12 : "com.sun.star.comp.Writer.XMLOasisSettingsExporter" ) );
785 : }
786 :
787 1 : Sequence< OUString > SAL_CALL SwXMLExportSettings_getSupportedServiceNames()
788 : throw()
789 : {
790 1 : const OUString aServiceName(SwXMLExportSettings_getImplementationName());
791 1 : const Sequence< OUString > aSeq( &aServiceName, 1 );
792 1 : return aSeq;
793 : }
794 :
795 2 : Reference< XInterface > SAL_CALL SwXMLExportSettings_createInstance(
796 : const Reference< XMultiServiceFactory > & rSMgr)
797 : throw( Exception )
798 : {
799 2 : return (cppu::OWeakObject*)new SwXMLExport(rSMgr, EXPORT_SETTINGS|EXPORT_OASIS);
800 : }
801 :
802 : namespace
803 : {
804 : class theSwXMLExportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXMLExportUnoTunnelId > {};
805 : }
806 :
807 0 : const Sequence< sal_Int8 > & SwXMLExport::getUnoTunnelId() throw()
808 : {
809 0 : return theSwXMLExportUnoTunnelId::get().getSeq();
810 : }
811 :
812 0 : sal_Int64 SAL_CALL SwXMLExport::getSomething( const Sequence< sal_Int8 >& rId )
813 : throw(RuntimeException)
814 : {
815 0 : if( rId.getLength() == 16
816 0 : && 0 == memcmp( getUnoTunnelId().getConstArray(),
817 0 : rId.getConstArray(), 16 ) )
818 : {
819 0 : return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
820 : }
821 0 : return SvXMLExport::getSomething( rId );
822 : }
823 :
824 :
825 : // XServiceInfo
826 : // override empty method from parent class
827 0 : OUString SAL_CALL SwXMLExport::getImplementationName()
828 : throw(RuntimeException)
829 : {
830 0 : switch( getExportFlags() )
831 : {
832 : case EXPORT_ALL:
833 0 : return SwXMLExport_getImplementationName();
834 : case (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS):
835 0 : return SwXMLExportStyles_getImplementationName();
836 : case (EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_FONTDECLS):
837 0 : return SwXMLExportContent_getImplementationName();
838 : case EXPORT_META:
839 0 : return SwXMLExportMeta_getImplementationName();
840 : case EXPORT_SETTINGS:
841 0 : return SwXMLExportSettings_getImplementationName();
842 : default:
843 : // generic name for 'unknown' cases
844 : return OUString( RTL_CONSTASCII_USTRINGPARAM(
845 0 : "com.sun.star.comp.Writer.SwXMLExport" ) );
846 : }
847 : }
848 :
849 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|