LibreOffice Module sw (master)  1
xmlimp.cxx
Go to the documentation of this file.
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 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <cassert>
24 
25 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
26 #include <com/sun/star/drawing/XDrawPage.hpp>
27 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
28 #include <com/sun/star/text/XTextDocument.hpp>
29 #include <com/sun/star/text/XTextRange.hpp>
30 
31 #include <o3tl/any.hxx>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/xmltkmap.hxx>
34 #include <xmloff/xmlictxt.hxx>
35 #include <xmloff/txtimp.hxx>
39 #include <doc.hxx>
40 #include <drawdoc.hxx>
43 #include <IDocumentListsAccess.hxx>
46 #include <TextCursorHelper.hxx>
47 #include <unotext.hxx>
48 #include <unotextrange.hxx>
49 #include <poolfmt.hxx>
50 #include <ndtxt.hxx>
51 #include <editsh.hxx>
52 #include <strings.hrc>
53 #include <svl/stritem.hxx>
54 #include "xmlimp.hxx"
55 #include "xmlimpit.hxx"
56 #include "xmltexti.hxx"
57 #include <list.hxx>
58 #include <swdll.hxx>
60 #include <docsh.hxx>
61 #include <svx/xmlgrhlp.hxx>
62 #include <svx/xmleohlp.hxx>
63 #include <sfx2/printer.hxx>
64 #include <xmloff/xmluconv.hxx>
65 #include <unotools/saveopt.hxx>
66 #include <unotools/streamwrap.hxx>
67 #include <tools/helpers.hxx>
68 
69 #include <vcl/svapp.hxx>
70 #include <unotxdoc.hxx>
71 #include <numrule.hxx>
72 
73 #include <xmloff/xmlmetai.hxx>
74 #include <xmloff/xformsimport.hxx>
78 
79 #include <unordered_set>
80 
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::uno;
83 using namespace ::com::sun::star::text;
84 using namespace ::com::sun::star::lang;
85 using namespace ::com::sun::star::beans;
86 using namespace ::com::sun::star::container;
87 using namespace ::com::sun::star::i18n;
88 using namespace ::com::sun::star::drawing;
89 using namespace ::com::sun::star::xforms;
90 using namespace ::xmloff::token;
91 using namespace ::std;
92 
93 namespace {
94 
95 class SwXMLBodyContext_Impl : public SvXMLImportContext
96 {
97  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
98 
99 public:
100 
101  SwXMLBodyContext_Impl( SwXMLImport& rImport );
102 
103  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
104  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
105 };
106 
107 }
108 
109 SwXMLBodyContext_Impl::SwXMLBodyContext_Impl( SwXMLImport& rImport ) :
110  SvXMLImportContext( rImport )
111 {
112  // tdf#107211: if at this point we don't have a defined char style "Default"
113  // or "Default Style", add a mapping for it as it is not written
114  // into the file since it's not really a style but "no style"
115  // (hence referencing it actually makes no sense except for hyperlinks
116  // which default to something other than "Default")
117  OUString const sDefault(SwResId(STR_POOLCHR_STANDARD));
118  uno::Reference<container::XNameContainer> const& xStyles(
119  rImport.GetTextImport()->GetTextStyles());
120  if (!xStyles->hasByName("Default"))
121  { // this old name was used before LO 4.0
122  rImport.AddStyleDisplayName(XmlStyleFamily::TEXT_TEXT, "Default", sDefault);
123  }
124  if (!xStyles->hasByName("Default_20_Style"))
125  { // this new name contains a space which is converted to _20_ on export
126  rImport.AddStyleDisplayName(XmlStyleFamily::TEXT_TEXT, "Default_20_Style", sDefault);
127  }
128  bool isEncoded(false);
129  OUString const defaultEncoded(
130  rImport.GetMM100UnitConverter().encodeStyleName(sDefault, &isEncoded));
131  if (isEncoded && defaultEncoded != "Default_20_Style"
132  && !xStyles->hasByName(defaultEncoded))
133  { // new name may contain a space which is converted to _20_ on export
134  rImport.AddStyleDisplayName(XmlStyleFamily::TEXT_TEXT, defaultEncoded, sDefault);
135  }
136 }
137 
138 css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLBodyContext_Impl::createFastChildContext(
139  sal_Int32 /*nElement*/,
140  const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
141 {
142  return GetSwImport().CreateBodyContentContext();
143 }
144 
145 namespace {
146 
147 // #i69629#
148 // enhance class <SwXMLDocContext_Impl> in order to be able to create subclasses
149 // NB: virtually inherit so we can multiply inherit properly
150 // in SwXMLOfficeDocContext_Impl
151 class SwXMLDocContext_Impl : public virtual SvXMLImportContext
152 {
153 
154 protected: // #i69629#
155  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
156 
157 public:
158  SwXMLDocContext_Impl( SwXMLImport& rImport );
159 
160  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
161  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
162 };
163 
164 }
165 
166 SwXMLDocContext_Impl::SwXMLDocContext_Impl( SwXMLImport& rImport ) :
167  SvXMLImportContext( rImport )
168 {
169 }
170 
171 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SwXMLDocContext_Impl::createFastChildContext(
172  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
173 {
174  switch (nElement)
175  {
176  case XML_ELEMENT(OFFICE, XML_SCRIPTS):
177  return GetSwImport().CreateScriptContext();
178  break;
179  case XML_ELEMENT(OFFICE, XML_SETTINGS):
180  return new XMLDocumentSettingsContext( GetImport() );
181  break;
182  case XML_ELEMENT(OFFICE, XML_STYLES):
183  GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
184  return GetSwImport().CreateStylesContext( false );
185  break;
186  case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
187  // don't use the autostyles from the styles-document for the progress
188  if ( !IsPrefixFilledIn() || ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
189  GetSwImport().GetProgressBarHelper()->Increment
190  ( PROGRESS_BAR_STEP );
191  return GetSwImport().CreateStylesContext( true );
192  break;
193  case XML_ELEMENT(OFFICE, XML_MASTER_STYLES):
194  return GetSwImport().CreateMasterStylesContext();
195  break;
196  case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
197  return GetSwImport().CreateFontDeclsContext();
198  break;
199  case XML_ELEMENT(OFFICE, XML_META):
200  OSL_FAIL(" XML_ELEMENT(OFFICE, XML_META): should not have come here, maybe document is invalid?");
201  break;
202  case XML_ELEMENT(OFFICE, XML_BODY):
203  GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
204  return new SwXMLBodyContext_Impl( GetSwImport() );
205  break;
206  case XML_ELEMENT(XFORMS, XML_MODEL):
207  return createXFormsModelContext(GetImport());
208  break;
209  default:
210  XMLOFF_WARN_UNKNOWN_ELEMENT("sw", nElement);
211  }
212  return nullptr;
213 }
214 
215 namespace {
216 
217 // #i69629# - new subclass <SwXMLOfficeDocContext_Impl> of class <SwXMLDocContext_Impl>
218 class SwXMLOfficeDocContext_Impl :
219  public SwXMLDocContext_Impl, public SvXMLMetaDocumentContext
220 {
221 public:
222 
223  SwXMLOfficeDocContext_Impl( SwXMLImport& rImport,
225 
226  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
227  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs ) override;
228 };
229 
230 }
231 
232 SwXMLOfficeDocContext_Impl::SwXMLOfficeDocContext_Impl(
233  SwXMLImport& rImport,
235  SvXMLImportContext( rImport ),
236  SwXMLDocContext_Impl( rImport ),
237  SvXMLMetaDocumentContext( rImport, xDocProps )
238 {
239 }
240 
241 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SwXMLOfficeDocContext_Impl::createFastChildContext(
242  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
243 {
244  // assign paragraph styles to list levels of outline style after all styles
245  // are imported and finished. This is the case, when <office:body> starts
246  // in flat OpenDocument file format.
247  {
248  if( nElement == XML_ELEMENT( OFFICE, XML_BODY ) )
249  {
250  GetImport().GetTextImport()->SetOutlineStyles( true );
251  }
252  }
253 
254  // behave like meta base class iff we encounter office:meta
255  if ( nElement == XML_ELEMENT( OFFICE, XML_META ) ) {
257  nElement, xAttrList );
258  } else {
259  return SwXMLDocContext_Impl::createFastChildContext(
260  nElement, xAttrList );
261  }
262 }
263 
264 namespace {
265 
266 // #i69629# - new subclass <SwXMLDocStylesContext_Impl> of class <SwXMLDocContext_Impl>
267 class SwXMLDocStylesContext_Impl : public SwXMLDocContext_Impl
268 {
269 public:
270 
271  SwXMLDocStylesContext_Impl( SwXMLImport& rImport );
272 
273  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
274 };
275 
276 }
277 
278 SwXMLDocStylesContext_Impl::SwXMLDocStylesContext_Impl( SwXMLImport& rImport ) :
279  SvXMLImportContext( rImport ),
280  SwXMLDocContext_Impl( rImport )
281 {
282 }
283 
284 void SwXMLDocStylesContext_Impl::endFastElement(sal_Int32 )
285 {
286  // assign paragraph styles to list levels of outline style after all styles
287  // are imported and finished.
288  SwXMLImport& rSwImport = dynamic_cast<SwXMLImport&>( GetImport());
289  GetImport().GetTextImport()->SetOutlineStyles(
290  bool(rSwImport.GetStyleFamilyMask() & SfxStyleFamily::Para));
291 }
292 
294  const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
295 {
296  SvXMLImportContext *pContext = nullptr;
297 
298  switch (nElement)
299  {
301  pContext = CreateMetaContext(nElement);
302  break;
304  {
305  uno::Reference<document::XDocumentProperties> const xDocProps(
307  // flat OpenDocument file format
308  pContext = new SwXMLOfficeDocContext_Impl( *this, xDocProps );
309  }
310  break;
311  // #i69629# - own subclasses for <office:document> and <office:document-styles>
314  pContext = new SwXMLDocContext_Impl( *this );
315  break;
317  pContext = new SwXMLDocStylesContext_Impl( *this );
318  break;
319  }
320  return pContext;
321 }
322 
324  const uno::Reference< uno::XComponentContext >& rContext,
325  OUString const & implementationName, SvXMLImportFlags nImportFlags)
326 : SvXMLImport( rContext, implementationName, nImportFlags ),
327  m_nStyleFamilyMask( SfxStyleFamily::All ),
328  m_bLoadDoc( true ),
329  m_bInsert( false ),
330  m_bBlock( false ),
331  m_bOrganizerMode( false ),
332  m_bInititedXForms( false ),
333  m_pDoc( nullptr )
334 {
335  InitItemImport();
336 }
337 
339 {
340  if (HasShapeImport())
341  {
342  SAL_WARN("sw", "endDocument skipped, dropping shapes now to avoid dangling SvTextShapeImportHelper pointing to this");
344  }
345  m_pTableElemTokenMap.reset();
346  m_pTableCellAttrTokenMap.reset();
347  FinitItemImport();
348 }
349 
351  const Reference< XTextRange > & rInsertPos )
352 {
353  m_bInsert = true;
354 
355  Reference < XText > xText = rInsertPos->getText();
356  Reference < XTextCursor > xTextCursor =
357  xText->createTextCursorByRange( rInsertPos );
358  GetTextImport()->SetCursor( xTextCursor );
359 }
360 
362  bool bOverwrite )
363 {
364  m_bInsert = !bOverwrite;
365  m_nStyleFamilyMask = nFamilies;
366  m_bLoadDoc = false;
367 }
368 
369 namespace
370 {
371  class theSwXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXMLImportUnoTunnelId > {};
372 }
373 
374 const Sequence< sal_Int8 > & SwXMLImport::getUnoTunnelId() throw()
375 {
376  return theSwXMLImportUnoTunnelId::get().getSeq();
377 }
378 
379 sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId )
380 {
381  if( isUnoTunnelId<SwXMLImport>(rId) )
382  {
383  return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
384  }
385  return SvXMLImport::getSomething( rId );
386 }
387 
388 static OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
389 {
390  Reference<XUnoTunnel> xCursorTunnel( rTextCursor, UNO_QUERY );
391  OSL_ENSURE( xCursorTunnel.is(), "missing XUnoTunnel for Cursor" );
392  if( !xCursorTunnel.is() )
393  return nullptr;
394  OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper *>(
395  sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
396  OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
397  return pTextCursor;
398 }
399 
401 {
402  // delegate to parent
404 
405  OSL_ENSURE( GetModel().is(), "model is missing" );
406  if( !GetModel().is() )
407  return;
408 
409  // this method will modify the document directly -> lock SolarMutex
410  SolarMutexGuard aGuard;
411 
412  Reference< XPropertySet > xImportInfo( getImportInfo() );
413  Reference< XPropertySetInfo > xPropertySetInfo;
414  if( xImportInfo.is() )
415  xPropertySetInfo = xImportInfo->getPropertySetInfo();
416  if( xPropertySetInfo.is() )
417  {
418  Any aAny;
419  // insert style mode?
420  OUString sStyleInsertModeFamilies("StyleInsertModeFamilies");
421  if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeFamilies) )
422  {
423  aAny = xImportInfo->getPropertyValue(sStyleInsertModeFamilies);
424  Sequence< OUString> aFamiliesSeq;
425  if( aAny >>= aFamiliesSeq )
426  {
427  SfxStyleFamily nFamilyMask = SfxStyleFamily::None;
428  for( const OUString& rFamily : std::as_const(aFamiliesSeq) )
429  {
430  if( rFamily=="FrameStyles" )
431  nFamilyMask |= SfxStyleFamily::Frame;
432  else if( rFamily=="PageStyles" )
433  nFamilyMask |= SfxStyleFamily::Page;
434  else if( rFamily=="CharacterStyles" )
435  nFamilyMask |= SfxStyleFamily::Char;
436  else if( rFamily=="ParagraphStyles" )
437  nFamilyMask |= SfxStyleFamily::Para;
438  else if( rFamily=="NumberingStyles" )
439  nFamilyMask |= SfxStyleFamily::Pseudo;
440  }
441 
442  bool bOverwrite = false;
443  const OUString sStyleInsertModeOverwrite("StyleInsertModeOverwrite");
444  if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeOverwrite) )
445  {
446  aAny = xImportInfo->getPropertyValue(sStyleInsertModeOverwrite);
447  if( auto b = o3tl::tryAccess<bool>(aAny) )
448  {
449  if( *b )
450  bOverwrite = true;
451  }
452  }
453 
454  setStyleInsertMode( nFamilyMask, bOverwrite );
455  }
456  }
457 
458  // text insert mode?
459  const OUString sTextInsertModeRange("TextInsertModeRange");
460  if( xPropertySetInfo->hasPropertyByName(sTextInsertModeRange) )
461  {
462  aAny = xImportInfo->getPropertyValue(sTextInsertModeRange);
463  Reference<XTextRange> xInsertTextRange;
464  if( aAny >>= xInsertTextRange )
465  setTextInsertMode( xInsertTextRange );
466  }
467 
468  // auto text mode
469  const OUString sAutoTextMode("AutoTextMode");
470  if( xPropertySetInfo->hasPropertyByName(sAutoTextMode) )
471  {
472  aAny = xImportInfo->getPropertyValue(sAutoTextMode);
473  if( auto b = o3tl::tryAccess<bool>(aAny) )
474  {
475  if( *b )
476  m_bBlock = true;
477  }
478  }
479 
480  // organizer mode
481  const OUString sOrganizerMode("OrganizerMode");
482  if( xPropertySetInfo->hasPropertyByName(sOrganizerMode) )
483  {
484  aAny = xImportInfo->getPropertyValue(sOrganizerMode);
485  if( auto b = o3tl::tryAccess<bool>(aAny) )
486  {
487  if( *b )
488  m_bOrganizerMode = true;
489  }
490  }
491 
492  // default document properties
493  const OUString sDefSettings("DefaultDocumentSettings");
494  if (xPropertySetInfo->hasPropertyByName(sDefSettings))
495  {
496  aAny = xImportInfo->getPropertyValue(sDefSettings);
497  Sequence<PropertyValue> aProps;
498  if (aAny >>= aProps)
499  {
500  Reference<lang::XMultiServiceFactory> xFac(GetModel(), UNO_QUERY);
502  xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY);
503  Reference<XPropertySetInfo> xInfo(xProps->getPropertySetInfo());
504 
505  if (xProps.is() && xInfo.is())
506  {
507  for (const auto& rProp : std::as_const(aProps))
508  {
509  if (xInfo->hasPropertyByName(rProp.Name))
510  {
511  xProps->setPropertyValue(rProp.Name, rProp.Value);
512  }
513  }
514  }
515  }
516  }
517  }
518 
519  // There only is a text cursor by now if we are in insert mode. In any
520  // other case we have to create one at the start of the document.
521  // We also might change into the insert mode later, so we have to make
522  // sure to first set the insert mode and then create the text import
523  // helper. Otherwise it won't have the insert flag set!
524  OTextCursorHelper *pTextCursor = nullptr;
525  Reference < XTextCursor > xTextCursor;
526  if( HasTextImport() )
527  xTextCursor = GetTextImport()->GetCursor();
528  if( !xTextCursor.is() )
529  {
530  Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
531  Reference < XText > xText = xTextDoc->getText();
532  xTextCursor = xText->createTextCursor();
533  SwCursorShell *pCursorSh = nullptr;
534  SwDoc *pDoc = nullptr;
535  if( SvXMLImportFlags::ALL == getImportFlags() )
536  {
537  pTextCursor = lcl_xml_GetSwXTextCursor( xTextCursor );
538  OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
539  if( !pTextCursor )
540  return;
541 
542  pDoc = pTextCursor->GetDoc();
543  OSL_ENSURE( pDoc, "SwDoc missing" );
544  if( !pDoc )
545  return;
546 
547  // Is there an edit shell. If yes, then we are currently inserting
548  // a document. We then have to insert at the current edit shell's
549  // cursor position. That not quite clean code, but there is no other
550  // way currently.
551  pCursorSh = pDoc->GetEditShell();
552  }
553  if( pCursorSh )
554  {
555  const uno::Reference<text::XTextRange> xInsertTextRange(
557  *pDoc, *pCursorSh->GetCursor()->GetPoint(), nullptr ) );
558  setTextInsertMode( xInsertTextRange );
559  xTextCursor = GetTextImport()->GetCursor();
560  pTextCursor = nullptr;
561  }
562  else
563  GetTextImport()->SetCursor( xTextCursor );
564  }
565 
566  if( !(getImportFlags() & (SvXMLImportFlags::CONTENT|SvXMLImportFlags::MASTERSTYLES)) )
567  return;
568 
569  if( !pTextCursor )
570  pTextCursor = lcl_xml_GetSwXTextCursor( xTextCursor );
571  OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
572  if( !pTextCursor )
573  return;
574 
575  SwDoc *pDoc = pTextCursor->GetDoc();
576  OSL_ENSURE( pDoc, "SwDoc missing" );
577  if( !pDoc )
578  return;
579 
580  if (SvXMLImportFlags::ALL == getImportFlags())
581  {
582  // for flat ODF - this is done in SwReader::Read() for package ODF
583  pDoc->SetInReading(true);
584  pDoc->SetInXMLImport(true);
585  }
586 
587  if( (getImportFlags() & SvXMLImportFlags::CONTENT) && !IsStylesOnlyMode() )
588  {
589  m_pSttNdIdx.reset(new SwNodeIndex( pDoc->GetNodes() ));
590  if( IsInsertMode() )
591  {
592  SwPaM *pPaM = pTextCursor->GetPaM();
593  const SwPosition* pPos = pPaM->GetPoint();
594 
595  // Split once and remember the node that has been split.
596  pDoc->getIDocumentContentOperations().SplitNode( *pPos, false );
597  *m_pSttNdIdx = pPos->nNode.GetIndex()-1;
598 
599  // Split again.
600  pDoc->getIDocumentContentOperations().SplitNode( *pPos, false );
601 
602  // Insert all content into the new node
603  pPaM->Move( fnMoveBackward );
604  pDoc->SetTextFormatColl
606  }
607  }
608 
609  // We need a draw model to be able to set the z order
610  pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel(); // #i52858# - method name changed
611 
612  // SJ: #i49801# locking the model to disable repaints
613  SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
614  if ( pDrawModel )
615  pDrawModel->setLock(true);
616 
617  if (!GetGraphicStorageHandler().is())
618  {
619  m_xGraphicStorageHandler = SvXMLGraphicHelper::Create(SvXMLGraphicHelperMode::Read);
621  }
622 
623  if( !GetEmbeddedResolver().is() )
624  {
625  SfxObjectShell *pPersist = pDoc->GetPersist();
626  if( pPersist )
627  {
629  *pPersist,
630  SvXMLEmbeddedObjectHelperMode::Read );
631  Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( m_xEmbeddedResolver.get() );
632  SetEmbeddedResolver( xEmbeddedResolver );
633  }
634  }
635 }
636 
638 {
639  OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
640  if( !GetModel().is() )
641  return;
642 
643  // this method will modify the document directly -> lock SolarMutex
644  SolarMutexGuard aGuard;
645 
647  m_xGraphicStorageHandler->dispose();
648  m_xGraphicStorageHandler.clear();
649 
650  if( m_xEmbeddedResolver )
651  m_xEmbeddedResolver->dispose();
652  m_xEmbeddedResolver.clear();
653  // Clear the shape import to sort the shapes (and not in the
654  // destructor that might be called after the import has finished
655  // for Java filters.
656  if( HasShapeImport() )
658 
659  SwDoc *pDoc = nullptr;
660  if( (getImportFlags() & SvXMLImportFlags::CONTENT) && !IsStylesOnlyMode() )
661  {
662  Reference<XUnoTunnel> xCursorTunnel( GetTextImport()->GetCursor(),
663  UNO_QUERY);
664  assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
665  OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper *>(
666  sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
667  assert(pTextCursor && "SwXTextCursor missing");
668  SwPaM *pPaM = pTextCursor->GetPaM();
669  if( IsInsertMode() && m_pSttNdIdx->GetIndex() )
670  {
671  // If we are in insert mode, join the split node that is in front
672  // of the new content with the first new node. Or in other words:
673  // Revert the first split node.
674  SwTextNode* pTextNode = m_pSttNdIdx->GetNode().GetTextNode();
675  SwNodeIndex aNxtIdx( *m_pSttNdIdx );
676  if( pTextNode && pTextNode->CanJoinNext( &aNxtIdx ) &&
677  m_pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex() )
678  {
679  // If the PaM points to the first new node, move the PaM to the
680  // end of the previous node.
681  if( pPaM->GetPoint()->nNode == aNxtIdx )
682  {
683  pPaM->GetPoint()->nNode = *m_pSttNdIdx;
684  pPaM->GetPoint()->nContent.Assign( pTextNode,
685  pTextNode->GetText().getLength());
686  }
687 
688 #if OSL_DEBUG_LEVEL > 0
689  // !!! This should be impossible !!!!
690  OSL_ENSURE( m_pSttNdIdx->GetIndex()+1 !=
691  pPaM->GetBound().nNode.GetIndex(),
692  "PaM.Bound1 point to new node " );
693  OSL_ENSURE( m_pSttNdIdx->GetIndex()+1 !=
694  pPaM->GetBound( false ).nNode.GetIndex(),
695  "PaM.Bound2 points to new node" );
696 
697  if( m_pSttNdIdx->GetIndex()+1 ==
698  pPaM->GetBound().nNode.GetIndex() )
699  {
700  const sal_Int32 nCntPos =
701  pPaM->GetBound().nContent.GetIndex();
702  pPaM->GetBound().nContent.Assign( pTextNode,
703  pTextNode->GetText().getLength() + nCntPos );
704  }
705  if( m_pSttNdIdx->GetIndex()+1 ==
706  pPaM->GetBound( false ).nNode.GetIndex() )
707  {
708  const sal_Int32 nCntPos =
709  pPaM->GetBound( false ).nContent.GetIndex();
710  pPaM->GetBound( false ).nContent.Assign( pTextNode,
711  pTextNode->GetText().getLength() + nCntPos );
712  }
713 #endif
714  // If the first new node isn't empty, convert the node's text
715  // attributes into hints. Otherwise, set the new node's
716  // paragraph style at the previous (empty) node.
717  SwTextNode* pDelNd = aNxtIdx.GetNode().GetTextNode();
718  if (!pTextNode->GetText().isEmpty())
719  pDelNd->FormatToTextAttr( pTextNode );
720  else
721  {
723  pTextNode->ChgFormatColl( pDelNd->GetTextColl() );
724  if (!pDelNd->GetNoCondAttr(RES_PARATR_LIST_ID, /*bInParents=*/false))
725  {
726  // MergeListsAtDocumentInsertPosition() will deal with lists below, copy
727  // paragraph direct formatting otherwise.
728  pDelNd->CopyCollFormat(*pTextNode);
729  }
730  }
731  pTextNode->JoinNext();
732  }
733  }
734 
735  SwPosition* pPos = pPaM->GetPoint();
736  OSL_ENSURE( !pPos->nContent.GetIndex(), "last paragraph isn't empty" );
737  if( !pPos->nContent.GetIndex() )
738  {
739  SwTextNode* pCurrNd;
740  sal_uLong nNodeIdx = pPos->nNode.GetIndex();
741  pDoc = &pPaM->GetDoc();
742 
743  OSL_ENSURE( pPos->nNode.GetNode().IsContentNode(),
744  "insert position is not a content node" );
745  if( !IsInsertMode() )
746  {
747  // If we're not in insert mode, the last node is deleted.
748  const SwNode *pPrev = pDoc->GetNodes()[nNodeIdx -1];
749  if( pPrev->IsContentNode() ||
750  ( pPrev->IsEndNode() &&
751  pPrev->StartOfSectionNode()->IsSectionNode() ) )
752  {
753  SwContentNode* pCNd = pPaM->GetContentNode();
754  if( pCNd && pCNd->StartOfSectionIndex()+2 <
755  pCNd->EndOfSectionIndex() )
756  {
757  pPaM->GetBound().nContent.Assign( nullptr, 0 );
758  pPaM->GetBound(false).nContent.Assign( nullptr, 0 );
759  pDoc->GetNodes().Delete( pPaM->GetPoint()->nNode );
760  }
761  }
762  }
763  else if( nullptr != (pCurrNd = pDoc->GetNodes()[nNodeIdx]->GetTextNode()) )
764  {
765  // Id we're in insert mode, the empty node is joined with
766  // the next and the previous one.
767  if( pCurrNd->CanJoinNext( &pPos->nNode ))
768  {
769  SwTextNode* pNextNd = pPos->nNode.GetNode().GetTextNode();
770  pPos->nContent.Assign( pNextNd, 0 );
771  pPaM->SetMark(); pPaM->DeleteMark();
772  pNextNd->JoinPrev();
773 
774  // Remove line break that has been inserted by the import,
775  // but only if one has been inserted!
776  if( pNextNd->CanJoinPrev(/* &pPos->nNode*/ ) &&
777  *m_pSttNdIdx != pPos->nNode )
778  {
779  pNextNd->JoinPrev();
780  }
781  }
782  else if (pCurrNd->GetText().isEmpty())
783  {
784  pPos->nContent.Assign( nullptr, 0 );
785  pPaM->SetMark(); pPaM->DeleteMark();
786  pDoc->GetNodes().Delete( pPos->nNode );
787  pPaM->Move( fnMoveBackward );
788  }
789  }
790 
791  // tdf#113877
792  // when we insert one document with list inside into another one with list at the insert position,
793  // the resulting numbering in these lists is not consequent.
794  //
795  // Main document:
796  // 1. One
797  // 2. Two
798  // 3. Three
799  // 4. <-- insert position
800  //
801  // Inserted document:
802  // 1. One
803  // 2. Two
804  // 3. Three
805  // 4.
806  //
807  // Expected result
808  // 1. One
809  // 2. Two
810  // 3. Three
811  // 4. One
812  // 5. Two
813  // 6. Three
814  // 7.
815  //
817  }
818  }
819 
820  /* Was called too early. Moved from SwXMLBodyContext_Impl::EndElement */
821 
822  GetTextImport()->RedlineAdjustStartNodeCursor();
823 
824  if( (getImportFlags() & SvXMLImportFlags::CONTENT) ||
825  ((getImportFlags() & SvXMLImportFlags::MASTERSTYLES) && IsStylesOnlyMode()) )
826  {
827  // pDoc might be 0. In this case UpdateTextCollCondition is looking
828  // for it itself.
829  UpdateTextCollConditions( pDoc );
830  }
831 
832  GetTextImport()->ResetCursor();
833 
834  m_pSttNdIdx.reset();
835 
836  // SJ: #i49801# -> now permitting repaints
837  if ( pDoc )
838  {
839  if( getImportFlags() == SvXMLImportFlags::ALL )
840  {
841  // Notify math objects. If we are in the package filter this will
842  // be done by the filter object itself
843  if( IsInsertMode() )
844  pDoc->PrtOLENotify( false );
845  else if ( pDoc->IsOLEPrtNotifyPending() )
846  pDoc->PrtOLENotify( true );
847 
848  assert(pDoc->IsInReading());
849  assert(pDoc->IsInXMLImport());
850  pDoc->SetInReading(false);
851  pDoc->SetInXMLImport(false);
852  }
853 
854  SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
855  if ( pDrawModel )
856  pDrawModel->setLock(false);
857  }
858 
859  // #i90243#
860  if ( m_bInititedXForms )
861  {
862  Reference< xforms::XFormsSupplier > xFormsSupp( GetModel(), UNO_QUERY );
863  Reference< XNameAccess > xXForms;
864  if ( xFormsSupp.is() )
865  xXForms = xFormsSupp->getXForms().get();
866 
867  if ( xXForms.is() )
868  {
869  try
870  {
871  Sequence< beans::PropertyValue > aXFormsSettings;
872 
873  const OUString& sXFormsSettingsName( GetXMLToken( XML_XFORM_MODEL_SETTINGS ) );
874  if ( m_xLateInitSettings.is() && m_xLateInitSettings->hasByName( sXFormsSettingsName ) )
875  {
876  OSL_VERIFY( m_xLateInitSettings->getByName( sXFormsSettingsName ) >>= aXFormsSettings );
877  applyXFormsSettings( xXForms, aXFormsSettings );
878  }
879  }
880  catch( const Exception& )
881  {
882  }
883  }
884  }
885 
886 #if 1
887  if (!pDoc) { pDoc = SwImport::GetDocFromXMLImport(*this); }
888  for (sal_uLong i = 0; i < pDoc->GetNodes().Count(); ++i)
889  {
890  if (SwTableNode *const pTableNode = pDoc->GetNodes()[i]->GetTableNode())
891  {
892  if (!pTableNode->GetTable().IsNewModel()
893  && pTableNode->GetTable().CanConvertSubtables())
894  {
895  pTableNode->GetTable().ConvertSubtables();
896  }
897  }
898  // don't skip to the end; nested tables could have subtables too...
899  }
900 #endif
901 
902  // delegate to parent: takes care of error handling
904  ClearTextImport();
905 }
906 
907 // tdf#113877
908 // when we insert one document with list inside into another one with list at the insert position,
909 // the resulting numbering in these lists is not consequent.
910 //
911 // CASE-1: Main document:
912 // 1. One
913 // 2. Two
914 // 3. Three
915 // 4. <-- insert position
916 //
917 // Inserted document:
918 // 1. One
919 // 2. Two
920 // 3. Three
921 // 4.
922 //
923 // Expected result
924 // 1. One
925 // 2. Two
926 // 3. Three
927 // 4. One
928 // 5. Two
929 // 6. Three
930 // 7.
931 //
932 // CASE-2: Main document:
933 // 1. One
934 // 2. Two
935 // 3. Three
936 // 4. <-- insert position
937 //
938 // Inserted document:
939 // A) One
940 // B) Two
941 // C) Three
942 // D)
943 //
944 // Expected result
945 // 1. One
946 // 2. Two
947 // 3. Three
948 // 4. One
949 // A) Two
950 // B) Three
951 // 5.
952 //
954 {
955  // 1. check environment
956  if (! pDoc)
957  return;
958 
959  if (! IsInsertMode() || ! m_pSttNdIdx->GetIndex())
960  return;
961 
962  sal_uLong index = 1;
963 
964  // the last node of the main document where we have inserted a document
965  const SwNodePtr node1 = pDoc->GetNodes()[m_pSttNdIdx->GetIndex() + 0];
966 
967  // the first node of the inserted document
968  SwNodePtr node2 = pDoc->GetNodes()[m_pSttNdIdx->GetIndex() + index];
969 
970  if (! (node1 && node2
971  && (node1->GetNodeType() == node2->GetNodeType())
972  && (node1->IsTextNode() == node2->IsTextNode())
973  ))
974  {
975  // not a text node at insert position
976  return;
977  }
978 
979  // 2. get the first node of the inserted document,
980  // which will be used to detect if inside inserted document a new list was started after the first list
981  const SfxPoolItem* pListId2Initial = nullptr;
982  {
983  SwContentNode* contentNode1 = static_cast<SwContentNode *>(node1);
984  SwContentNode* contentNode2 = static_cast<SwContentNode *>(node2);
985 
986  // check if both lists have the same list properties
987  const SfxPoolItem* pListId1 = contentNode1->GetNoCondAttr( RES_PARATR_LIST_ID, false );
988  const SfxPoolItem* pListId2 = contentNode2->GetNoCondAttr( RES_PARATR_LIST_ID, false );
989 
990  if (! pListId1)
991  return;
992  if (! pListId2)
993  return;
994 
995  auto pStringListId1 = dynamic_cast<const SfxStringItem*>(pListId1);
996  assert(pStringListId1);
997  const OUString& sListId1 = pStringListId1->GetValue();
998  auto pStringListId2 = dynamic_cast<const SfxStringItem*>(pListId2);
999  assert(pStringListId2);
1000  const OUString& sListId2 = pStringListId2->GetValue();
1001 
1002  const SwList* pList1 = pDoc->getIDocumentListsAccess().getListByName( sListId1 );
1003  const SwList* pList2 = pDoc->getIDocumentListsAccess().getListByName( sListId2 );
1004 
1005  if (! pList1)
1006  return;
1007  if (! pList2)
1008  return;
1009 
1010  const OUString& sDefaultListStyleName1 = pList1->GetDefaultListStyleName();
1011  const OUString& sDefaultListStyleName2 = pList2->GetDefaultListStyleName();
1012 
1013  if (sDefaultListStyleName1 != sDefaultListStyleName2)
1014  {
1015  const SwNumRule* pNumRule1 = pDoc->FindNumRulePtr( sDefaultListStyleName1 );
1016  const SwNumRule* pNumRule2 = pDoc->FindNumRulePtr( sDefaultListStyleName2 );
1017 
1018  if (pNumRule1 && pNumRule2)
1019  {
1020  // check style of the each list level
1021  for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
1022  {
1023  if( pNumRule1->Get( n ) != pNumRule2->Get( n ) )
1024  {
1025  return;
1026  }
1027  }
1028 
1029  // our list should be merged
1030  pListId2Initial = pListId2;
1031  }
1032  }
1033  else
1034  {
1035  // our list should be merged
1036  pListId2Initial = pListId2;
1037  }
1038  }
1039 
1040  if (! pListId2Initial)
1041  {
1042  // two lists have different styles => they should not be merged
1043  return;
1044  }
1045 
1046  // 3. merge two lists
1047  while (
1048  node1 && node2
1049  && (node1->GetNodeType() == node2->GetNodeType())
1050  && (node1->IsTextNode() == node2->IsTextNode())
1051  )
1052  {
1053  SwContentNode* contentNode1 = static_cast<SwContentNode *>( node1 );
1054  SwContentNode* contentNode2 = static_cast<SwContentNode *>( node2 );
1055 
1056  const SfxPoolItem* pListId1 = contentNode1->GetNoCondAttr( RES_PARATR_LIST_ID, false );
1057  const SfxPoolItem* pListId2 = contentNode2->GetNoCondAttr( RES_PARATR_LIST_ID, false );
1058 
1059  if (! pListId1)
1060  return;
1061  if (! pListId2)
1062  return;
1063 
1064  if (*pListId2Initial != *pListId2)
1065  {
1066  // no more list items of the first list inside inserted document
1067  return;
1068  }
1069 
1070  // set list style to this list element
1071  contentNode2->SetAttr(*pListId1);
1072 
1073  // get next item
1074  index++;
1075  if (index >= pDoc->GetNodes().Count())
1076  {
1077  // no more items
1078  return;
1079  }
1080 
1081  node2 = pDoc->GetNodes()[m_pSttNdIdx->GetIndex() + index];
1082  }
1083 }
1084 
1085 namespace {
1086 
1087 // Locally derive XMLTextShapeImportHelper, so we can take care of the
1088 // form import This is Writer, but not text specific, so it should go
1089 // here!
1090 class SvTextShapeImportHelper : public XMLTextShapeImportHelper
1091 {
1092  // hold own reference form import helper, because the SvxImport
1093  // stored in the superclass, from whom we originally got the
1094  // reference, is already destroyed when we want to use it in the
1095  // destructor
1097 
1098  // hold reference to the one page (if it exists) for calling startPage()
1099  // and endPage. If !xPage.is(), then this document doesn't have a
1100  // XDrawPage.
1102 
1103 public:
1104  explicit SvTextShapeImportHelper(SvXMLImport& rImp);
1105  virtual ~SvTextShapeImportHelper() override;
1106 };
1107 
1108 }
1109 
1110 SvTextShapeImportHelper::SvTextShapeImportHelper(SvXMLImport& rImp) :
1112 {
1113  Reference<drawing::XDrawPageSupplier> xSupplier(rImp.GetModel(),UNO_QUERY);
1114  if (xSupplier.is())
1115  {
1116  if (rImp.GetFormImport().is())
1117  {
1118  rImp.GetFormImport()->startPage(xSupplier->getDrawPage());
1119  rFormImport = rImp.GetFormImport();
1120  }
1121 
1122  xPage = xSupplier->getDrawPage();
1124  }
1125 }
1126 
1127 SvTextShapeImportHelper::~SvTextShapeImportHelper()
1128 {
1129  rFormImport->endPage();
1130 
1131  if (xPage.is())
1132  {
1134  }
1135 }
1136 
1138 {
1139  return new SwXMLTextImportHelper( GetModel(), *this, getImportInfo(),
1140  IsInsertMode(),
1141  IsStylesOnlyMode(),
1143 }
1144 
1146 {
1147  return new SvTextShapeImportHelper( *this );
1148 }
1149 
1151 {
1152  XMLFontStylesContext *pFSContext =
1153  new XMLFontStylesContext( *this, osl_getThreadTextEncoding() );
1154  SetFontDecls( pFSContext );
1155  return pFSContext;
1156 }
1157 
1158 void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
1159 {
1160  if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || m_bOrganizerMode || !GetModel().is() )
1161  return;
1162 
1163  // this method will modify the document directly -> lock SolarMutex
1164  SolarMutexGuard aGuard;
1165 
1166  SwDoc *pDoc = getDoc();
1167  tools::Rectangle aRect;
1168  if( pDoc->GetDocShell() )
1169  aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
1170  //TODO/LATER: why that cast?!
1171  //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea();
1172 
1173  sal_Int64 nTmp = 0;
1174  bool bShowRedlineChanges = false, bBrowseMode = false;
1175  bool bChangeShowRedline = false, bChangeBrowseMode = false;
1176 
1177  //TODO/LATER: why that cast?!
1178  bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MapUnit::MapTwip;
1179  //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MapUnit::MapTwip;
1180 
1181  for (const PropertyValue& rValue : aViewProps)
1182  {
1183  if ( rValue.Name == "ViewAreaTop" )
1184  {
1185  rValue.Value >>= nTmp;
1186  aRect.setY( static_cast< tools::Long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) );
1187  }
1188  else if ( rValue.Name == "ViewAreaLeft" )
1189  {
1190  rValue.Value >>= nTmp;
1191  aRect.setX( static_cast< tools::Long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) );
1192  }
1193  else if ( rValue.Name == "ViewAreaWidth" )
1194  {
1195  rValue.Value >>= nTmp;
1196  Size aSize( aRect.GetSize() );
1197  aSize.setWidth( static_cast< tools::Long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) );
1198  aRect.SetSize( aSize );
1199  }
1200  else if ( rValue.Name == "ViewAreaHeight" )
1201  {
1202  rValue.Value >>= nTmp;
1203  Size aSize( aRect.GetSize() );
1204  aSize.setHeight( static_cast< tools::Long >(bTwip ? sanitiseMm100ToTwip(nTmp) : nTmp) );
1205  aRect.SetSize( aSize );
1206  }
1207  else if ( rValue.Name == "ShowRedlineChanges" )
1208  {
1209  bShowRedlineChanges = *o3tl::doAccess<bool>(rValue.Value);
1210  bChangeShowRedline = true;
1211  }
1212 // Headers and footers are not displayed in BrowseView anymore
1213  else if ( rValue.Name == "InBrowseMode" )
1214  {
1215  bBrowseMode = *o3tl::doAccess<bool>(rValue.Value);
1216  bChangeBrowseMode = true;
1217  }
1218  }
1219  if( pDoc->GetDocShell() )
1220  pDoc->GetDocShell()->SetVisArea ( aRect );
1221 
1222  if (bChangeBrowseMode)
1224 
1225  if (bChangeShowRedline)
1226  GetTextImport()->SetShowChanges( bShowRedlineChanges );
1227 }
1228 
1229 // Note: this will be called only if there are OOo elements in settings.xml.
1230 // So if a setting is missing there we can assume that it was written
1231 // by an OOo/LO version that is older than the introduction of the setting!
1232 void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aConfigProps)
1233 {
1234  // this method will modify the document directly -> lock SolarMutex
1235  SolarMutexGuard aGuard;
1236 
1237  Reference< lang::XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
1238  if( !xFac.is() )
1239  return;
1240 
1241  Reference< XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY );
1242  if( !xProps.is() )
1243  return;
1244 
1245  Reference< XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
1246  if( !xInfo.is() )
1247  return;
1248 
1249  std::unordered_set< OUString > aExcludeAlways;
1250  aExcludeAlways.insert("LinkUpdateMode");
1251  // this should contain things that are actually user-settable, via Tools->Options
1252  std::unordered_set< OUString > aExcludeWhenNotLoadingUserSettings {
1253  "ForbiddenCharacters",
1254  "IsKernAsianPunctuation",
1255  "CharacterCompressionType",
1256  "FieldAutoUpdate",
1257  "ChartAutoUpdate",
1258  "AddParaTableSpacing",
1259  "AddParaTableSpacingAtStart",
1260  "PrintAnnotationMode",
1261  "PrintBlackFonts",
1262  "PrintControls",
1263  "PrintDrawings",
1264  "PrintGraphics",
1265  "PrintHiddenText",
1266  "PrintLeftPages",
1267  "PrintPageBackground",
1268  "PrintProspect",
1269  "PrintReversed",
1270  "PrintRightPages",
1271  "PrintFaxName",
1272  "PrintPaperFromSetup",
1273  "PrintTables",
1274  "PrintTextPlaceholder",
1275  "PrintSingleJobs",
1276  "UpdateFromTemplate",
1277  "PrinterIndependentLayout",
1278  "PrintEmptyPages",
1279  "ConsiderTextWrapOnObjPos",
1280  "DoNotJustifyLinesWithManualBreak",
1281  "ProtectForm",
1282  "MsWordCompTrailingBlanks",
1283  "SubtractFlysAnchoredAtFlys",
1284  "EmptyDbFieldHidesPara"
1285  };
1286 
1287  SvtSaveOptions aSaveOpt;
1288  bool bIsUserSetting = aSaveOpt.IsLoadUserSettings();
1289 
1290  // for some properties we don't want to use the application
1291  // default if they're missing. So we watch for them in the loop
1292  // below, and set them if not found
1293  bool bPrinterIndependentLayout = false;
1294  bool bUseOldNumbering = false;
1295  bool bAddExternalLeading = false;
1296  bool bAddParaSpacingToTableCells = false;
1297  bool bAddParaLineSpacingToTableCells = false;
1298  bool bUseFormerLineSpacing = false;
1299  bool bUseFormerObjectPositioning = false;
1300  bool bUseFormerTextWrapping = false;
1301  bool bConsiderWrapOnObjPos = false;
1302  bool bIgnoreFirstLineIndentInNumbering = false;
1303  bool bDoNotJustifyLinesWithManualBreak = false;
1304  bool bDoNotResetParaAttrsForNumFont = false;
1305  bool bLoadReadonly = false;
1306  bool bDoNotCaptureDrawObjsOnPage( false );
1307  bool bClipAsCharacterAnchoredWriterFlyFrames( false );
1308  bool bUnixForceZeroExtLeading = false;
1309  bool bSmallCapsPercentage66 = false;
1310  bool bTabOverflow = false;
1311  bool bUnbreakableNumberings = false;
1312  bool bClippedPictures = false;
1313  bool bBackgroundParaOverDrawings = false;
1314  bool bTabOverMargin = false;
1315  bool bTabOverMarginValue = false;
1316  bool bPropLineSpacingShrinksFirstLine = false;
1317  bool bSubtractFlysAnchoredAtFlys = false;
1318  bool bCollapseEmptyCellPara = false;
1319 
1320  const PropertyValue* currentDatabaseDataSource = nullptr;
1321  const PropertyValue* currentDatabaseCommand = nullptr;
1322  const PropertyValue* currentDatabaseCommandType = nullptr;
1323  const PropertyValue* embeddedDatabaseName = nullptr;
1324 
1325  for( const PropertyValue& rValue : aConfigProps )
1326  {
1327  bool bSet = aExcludeAlways.find(rValue.Name) == aExcludeAlways.end();
1328  if( bSet && !bIsUserSetting
1329  && (aExcludeWhenNotLoadingUserSettings.find(rValue.Name)
1330  != aExcludeWhenNotLoadingUserSettings.end()) )
1331  {
1332  bSet = false;
1333  }
1334 
1335  if( bSet )
1336  {
1337  try
1338  {
1339  if( xInfo->hasPropertyByName( rValue.Name ) )
1340  {
1341  if( rValue.Name == "RedlineProtectionKey" )
1342  {
1343  Sequence<sal_Int8> aKey;
1344  rValue.Value >>= aKey;
1345  GetTextImport()->SetChangesProtectionKey( aKey );
1346  }
1347  else
1348  {
1349  // HACK: Setting these out of order does not work.
1350  if( rValue.Name == "CurrentDatabaseDataSource" )
1351  currentDatabaseDataSource = &rValue;
1352  else if( rValue.Name == "CurrentDatabaseCommand" )
1353  currentDatabaseCommand = &rValue;
1354  else if( rValue.Name == "CurrentDatabaseCommandType" )
1355  currentDatabaseCommandType = &rValue;
1356  else if (rValue.Name == "EmbeddedDatabaseName")
1357  embeddedDatabaseName = &rValue;
1358  else
1359  xProps->setPropertyValue( rValue.Name, rValue.Value );
1360  }
1361  }
1362 
1363  // did we find any of the non-default cases?
1364  if ( rValue.Name == "PrinterIndependentLayout" )
1365  bPrinterIndependentLayout = true;
1366  else if ( rValue.Name == "AddExternalLeading" )
1367  bAddExternalLeading = true;
1368  else if ( rValue.Name == "AddParaSpacingToTableCells" )
1369  bAddParaSpacingToTableCells = true;
1370  else if ( rValue.Name == "AddParaLineSpacingToTableCells" )
1371  bAddParaLineSpacingToTableCells = true;
1372  else if ( rValue.Name == "UseFormerLineSpacing" )
1373  bUseFormerLineSpacing = true;
1374  else if ( rValue.Name == "UseFormerObjectPositioning" )
1375  bUseFormerObjectPositioning = true;
1376  else if ( rValue.Name == "UseFormerTextWrapping" )
1377  bUseFormerTextWrapping = true;
1378  else if ( rValue.Name == "UseOldNumbering" )
1379  bUseOldNumbering = true;
1380  else if ( rValue.Name == "ConsiderTextWrapOnObjPos" )
1381  bConsiderWrapOnObjPos = true;
1382  else if ( rValue.Name == "IgnoreFirstLineIndentInNumbering" )
1383  bIgnoreFirstLineIndentInNumbering = true;
1384  else if ( rValue.Name == "DoNotJustifyLinesWithManualBreak" )
1385  bDoNotJustifyLinesWithManualBreak = true;
1386  else if ( rValue.Name == "DoNotResetParaAttrsForNumFont" )
1387  bDoNotResetParaAttrsForNumFont = true;
1388  else if ( rValue.Name == "LoadReadonly" )
1389  bLoadReadonly = true;
1390  else if ( rValue.Name == "DoNotCaptureDrawObjsOnPage" )
1391  bDoNotCaptureDrawObjsOnPage = true;
1392  else if ( rValue.Name == "ClipAsCharacterAnchoredWriterFlyFrames" )
1393  bClipAsCharacterAnchoredWriterFlyFrames = true;
1394  else if ( rValue.Name == "UnxForceZeroExtLeading" )
1395  bUnixForceZeroExtLeading = true;
1396  else if ( rValue.Name == "SmallCapsPercentage66" )
1397  bSmallCapsPercentage66 = true;
1398  else if ( rValue.Name == "TabOverflow" )
1399  bTabOverflow = true;
1400  else if ( rValue.Name == "UnbreakableNumberings" )
1401  bUnbreakableNumberings = true;
1402  else if ( rValue.Name == "ClippedPictures" )
1403  bClippedPictures = true;
1404  else if ( rValue.Name == "BackgroundParaOverDrawings" )
1405  bBackgroundParaOverDrawings = true;
1406  else if ( rValue.Name == "TabOverMargin" )
1407  {
1408  bTabOverMargin = true;
1409  rValue.Value >>= bTabOverMarginValue;
1410  }
1411  else if ( rValue.Name == "PropLineSpacingShrinksFirstLine" )
1412  bPropLineSpacingShrinksFirstLine = true;
1413  else if (rValue.Name == "SubtractFlysAnchoredAtFlys")
1414  bSubtractFlysAnchoredAtFlys = true;
1415  else if (rValue.Name == "CollapseEmptyCellPara")
1416  bCollapseEmptyCellPara = true;
1417  }
1418  catch( Exception& )
1419  {
1420  OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
1421  }
1422  }
1423  }
1424 
1425  try
1426  {
1427  if( currentDatabaseDataSource != nullptr )
1428  xProps->setPropertyValue( currentDatabaseDataSource->Name, currentDatabaseDataSource->Value );
1429  if( currentDatabaseCommand != nullptr )
1430  xProps->setPropertyValue( currentDatabaseCommand->Name, currentDatabaseCommand->Value );
1431  if( currentDatabaseCommandType != nullptr )
1432  xProps->setPropertyValue( currentDatabaseCommandType->Name, currentDatabaseCommandType->Value );
1433  if (embeddedDatabaseName)
1434  xProps->setPropertyValue(embeddedDatabaseName->Name, embeddedDatabaseName->Value);
1435  } catch( Exception& )
1436  {
1437  OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
1438  }
1439 
1440  // finally, treat the non-default cases
1441  // introduce boolean, that indicates a document, written by version prior SO8.
1442  const bool bDocumentPriorSO8 = !bConsiderWrapOnObjPos;
1443 
1444  if( ! bPrinterIndependentLayout )
1445  {
1446  xProps->setPropertyValue( "PrinterIndependentLayout", Any(sal_Int16(document::PrinterIndependentLayout::DISABLED)) );
1447  }
1448 
1449  if( ! bAddExternalLeading )
1450  {
1451  xProps->setPropertyValue( "AddExternalLeading", makeAny( false ) );
1452  }
1453 
1454  if( ! bUseFormerLineSpacing )
1455  {
1456  xProps->setPropertyValue( "UseFormerLineSpacing", makeAny( true ) );
1457  }
1458 
1459  if( !bUseFormerObjectPositioning )
1460  {
1461  xProps->setPropertyValue( "UseFormerObjectPositioning", makeAny( true ) );
1462  }
1463 
1464  if( !bUseOldNumbering )
1465  {
1466  xProps->setPropertyValue( "UseOldNumbering", makeAny(true) );
1467  }
1468 
1469  if( !bAddParaSpacingToTableCells )
1470  {
1471  xProps->setPropertyValue( "AddParaSpacingToTableCells",
1472  makeAny( false ) );
1473  }
1474  if (!bAddParaLineSpacingToTableCells)
1475  {
1476  xProps->setPropertyValue("AddParaLineSpacingToTableCells", makeAny(false));
1477  }
1478 
1479  if( !bUseFormerTextWrapping )
1480  {
1481  xProps->setPropertyValue( "UseFormerTextWrapping", makeAny( true ) );
1482  }
1483 
1484  if( !bConsiderWrapOnObjPos )
1485  {
1486  xProps->setPropertyValue( "ConsiderTextWrapOnObjPos", makeAny( false ) );
1487  }
1488 
1489  // #i47448#
1490  // For SO7pp4, part of the 'new numbering' stuff has been backported from
1491  // SO8. Unfortunately, only part of it and by using the same compatibility option
1492  // like in SO8. Therefore documents generated with SO7pp4, containing
1493  // numbered paragraphs with first line indent differ between SO7pp4 and
1494  // SO8. In order to fix this for SO8pp1, I introduce a new compatibility
1495  // flag 'bIgnoreFirstLineIndentInNumbering'. This flag has to be set for all
1496  // documents < SO8, but not for SO8. So if the property is not present, the
1497  // flag will be set to 'true'. SO8 documents surely have the
1498  // 'ConsiderWrapOnObjPos' property set (no matter if 'true' or 'false'),
1499  // therefore the correct condition to set this flag is this:
1500  if( !bIgnoreFirstLineIndentInNumbering && bDocumentPriorSO8 )
1501  {
1502  xProps->setPropertyValue( "IgnoreFirstLineIndentInNumbering",
1503  makeAny( true ) );
1504  }
1505 
1506  // This flag has to be set for all documents < SO8
1507  if ( !bDoNotJustifyLinesWithManualBreak && bDocumentPriorSO8 )
1508  {
1509  xProps->setPropertyValue( "DoNotJustifyLinesWithManualBreak",
1510  makeAny( true ) );
1511  }
1512 
1513  // This flag has to be set for all documents < SO8
1514  if ( !bDoNotResetParaAttrsForNumFont && bDocumentPriorSO8 )
1515  {
1516  xProps->setPropertyValue( "DoNotResetParaAttrsForNumFont",
1517  makeAny( true ) );
1518  }
1519 
1520  if ( !bLoadReadonly )
1521  {
1522  xProps->setPropertyValue( "LoadReadonly", makeAny( false ) );
1523  }
1524 
1525  // This flag has to be set for all documents < SO8
1526  if ( !bDoNotCaptureDrawObjsOnPage && bDocumentPriorSO8 )
1527  {
1528  xProps->setPropertyValue( "DoNotCaptureDrawObjsOnPage",
1529  makeAny( true ) );
1530  }
1531 
1532  // This flag has to be set for all documents < SO8
1533  if ( !bClipAsCharacterAnchoredWriterFlyFrames && bDocumentPriorSO8 )
1534  {
1535  xProps->setPropertyValue( "ClipAsCharacterAnchoredWriterFlyFrames",
1536  makeAny( true ) );
1537  }
1538 
1539  if ( !bUnixForceZeroExtLeading )
1540  {
1541  xProps->setPropertyValue( "UnxForceZeroExtLeading", makeAny( true ) );
1542  }
1543 
1544  // Old LO versions had 66 as the value for small caps percentage, later changed to 80.
1545  // In order to keep backwards compatibility, SmallCapsPercentage66 option is written to .odt
1546  // files, and the default for new documents is 'false'. Files without this option
1547  // are considered to be old files, so set the compatibility option too.
1548  if ( !bSmallCapsPercentage66 )
1549  {
1550  xProps->setPropertyValue( "SmallCapsPercentage66", makeAny( true ) );
1551  }
1552 
1553  if ( !bTabOverflow )
1554  {
1555  xProps->setPropertyValue( "TabOverflow", makeAny( false ) );
1556  }
1557 
1558  if ( !bUnbreakableNumberings )
1559  {
1560  xProps->setPropertyValue( "UnbreakableNumberings", makeAny( false ) );
1561  }
1562 
1563  if ( !bClippedPictures )
1564  {
1565  xProps->setPropertyValue( "ClippedPictures", makeAny( false ) );
1566  }
1567 
1568  if ( !bBackgroundParaOverDrawings )
1569  xProps->setPropertyValue("BackgroundParaOverDrawings", makeAny( false ) );
1570 
1571  if ( !bTabOverMargin )
1572  xProps->setPropertyValue("TabOverMargin", makeAny( false ) );
1573 
1574  if (bTabOverMarginValue)
1575  // Let TabOverMargin imply the new default for
1576  // PrinterIndependentLayout, knowing the first is set by Word import
1577  // filters and Word defaults to our new default as well.
1578  xProps->setPropertyValue(
1579  "PrinterIndependentLayout",
1580  uno::Any(document::PrinterIndependentLayout::HIGH_RESOLUTION));
1581 
1582  if (!bPropLineSpacingShrinksFirstLine)
1583  xProps->setPropertyValue("PropLineSpacingShrinksFirstLine", makeAny(false));
1584 
1585  if (!bSubtractFlysAnchoredAtFlys)
1586  xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true));
1587 
1588  if (!bCollapseEmptyCellPara)
1589  xProps->setPropertyValue("CollapseEmptyCellPara", makeAny(false));
1590 
1591  SwDoc *pDoc = getDoc();
1592  SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( false );
1593  if( pPrinter )
1594  {
1595  // If the printer is known, then the OLE objects will
1596  // already have correct sizes, and we don't have to call
1597  // PrtOLENotify again. Otherwise we have to call it.
1598  // The flag might be set from setting the printer, so it
1599  // it is required to clear it.
1600  pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
1601  }
1602 }
1603 
1605  const OUString& _rSettingsGroupName,
1606  const Sequence< PropertyValue>& _rSettings )
1607 {
1608  // the only doc-specific settings group we know so far are the XForms settings
1609  if ( !IsXMLToken( _rSettingsGroupName, XML_XFORM_MODEL_SETTINGS ) )
1610  return;
1611 
1612  // preserve the settings for a later iteration - we are currently reading the settings.xml,
1613  // the content.xml will be read later, by another instance of SwXMLImport
1614  OSL_ENSURE( m_xLateInitSettings.is(), "SwXMLImport::SetDocumentSpecificSettings: no storage for those settings!" );
1615  if ( !m_xLateInitSettings.is() )
1616  return;
1617 
1618  try
1619  {
1620  if ( m_xLateInitSettings->hasByName( _rSettingsGroupName ) )
1621  {
1622  m_xLateInitSettings->replaceByName( _rSettingsGroupName, makeAny( _rSettings ) );
1623  OSL_FAIL( "SwXMLImport::SetDocumentSpecificSettings: already have settings for this model!" );
1624  }
1625  else
1626  m_xLateInitSettings->insertByName( _rSettingsGroupName, makeAny( _rSettings ) );
1627  }
1628  catch( const Exception& )
1629  {
1630  }
1631 }
1632 
1634  const Sequence<Any>& aArguments )
1635 {
1636  // delegate to super class
1637  SvXMLImport::initialize(aArguments);
1638 
1639  // we are only looking for a NamedValue "LateInitSettings"
1640  for(const auto& rArgument : aArguments)
1641  {
1642  beans::NamedValue aNamedValue;
1643  if ( rArgument >>= aNamedValue )
1644  {
1645  if (aNamedValue.Name == "LateInitSettings")
1646  {
1647  OSL_VERIFY( aNamedValue.Value >>= m_xLateInitSettings );
1648  }
1649  }
1650  }
1651 }
1652 
1654 {
1655  auto pTextDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(rImport.GetModel());
1656  assert( pTextDoc );
1657  assert( pTextDoc->GetDocShell() );
1658  SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
1659  OSL_ENSURE( pDoc, "Where is my document?" );
1660  return pDoc;
1661 }
1662 
1664 {
1665  // obtain SwDoc
1666  auto pXTextDocument = comphelper::getUnoTunnelImplementation<SwXTextDocument>(GetModel());
1667  if( pXTextDocument == nullptr )
1668  return;
1669 
1670  SwDoc *pDoc = pXTextDocument->GetDocShell()->GetDoc();
1671 
1672  // init XForms (if not already done)
1673  // (no default model, since we'll load the models)
1674  if( ! pDoc->isXForms() )
1675  pDoc->initXForms( false );
1676 
1677  m_bInititedXForms = true;
1678 }
1679 
1681 {
1682  if( m_pDoc != nullptr )
1683  return m_pDoc;
1684  Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1685  Reference < XText > xText = xTextDoc->getText();
1686  Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1687  assert( xTextTunnel.is());
1688  SwXText *pText = reinterpret_cast< SwXText *>(
1689  sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1690  assert( pText != nullptr );
1691  m_pDoc = pText->GetDoc();
1692  assert( m_pDoc != nullptr );
1693  return m_pDoc;
1694 }
1695 
1697 {
1698  return const_cast< SwXMLImport* >( this )->getDoc();
1699 }
1700 
1701 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1703  css::uno::Sequence<css::uno::Any> const &)
1704 {
1705  return cppu::acquire(new SwXMLImport(context, "com.sun.star.comp.Writer.XMLOasisImporter",
1706  SvXMLImportFlags::ALL));
1707 }
1708 
1709 
1710 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1712  css::uno::Sequence<css::uno::Any> const &)
1713 {
1714  return cppu::acquire(new SwXMLImport(context, "com.sun.star.comp.Writer.XMLOasisStylesImporter",
1715  SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES |
1716  SvXMLImportFlags::FONTDECLS));
1717 }
1718 
1719 
1720 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1722  css::uno::Sequence<css::uno::Any> const &)
1723 {
1724  return cppu::acquire(new SwXMLImport(context, "com.sun.star.comp.Writer.XMLOasisContentImporter",
1725  SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS | SvXMLImportFlags::AUTOSTYLES |
1726  SvXMLImportFlags::FONTDECLS));
1727 }
1728 
1729 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1731  css::uno::Sequence<css::uno::Any> const &)
1732 {
1733  return cppu::acquire(new SwXMLImport(context, "com.sun.star.comp.Writer.XMLOasisMetaImporter",
1734  SvXMLImportFlags::META));
1735 }
1736 
1737 
1738 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1740  css::uno::Sequence<css::uno::Any> const &)
1741 {
1742  return cppu::acquire(new SwXMLImport(context, "com.sun.star.comp.Writer.XMLOasisSettingsImporter",
1743  SvXMLImportFlags::SETTINGS));
1744 }
1745 
1746 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportFODT(SvStream &rStream)
1747 {
1749 
1750  SfxObjectShellLock xDocSh(new SwDocShell(SfxObjectCreateMode::INTERNAL));
1751  xDocSh->DoInitNew();
1752  uno::Reference<frame::XModel> xModel(xDocSh->GetModel());
1753 
1754  uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1755  uno::Reference<io::XInputStream> xStream(new utl::OSeekableInputStreamWrapper(rStream));
1756  uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance("com.sun.star.comp.Writer.XmlFilterAdaptor"), uno::UNO_SET_THROW);
1757 
1758  css::uno::Sequence<OUString> aUserData(7);
1759  aUserData[0] = "com.sun.star.comp.filter.OdfFlatXml";
1760  aUserData[2] = "com.sun.star.comp.Writer.XMLOasisImporter";
1761  aUserData[3] = "com.sun.star.comp.Writer.XMLOasisExporter";
1762  aUserData[6] = "true";
1763  uno::Sequence<beans::PropertyValue> aAdaptorArgs(comphelper::InitPropertySequence(
1764  {
1765  { "UserData", uno::Any(aUserData) },
1766  }));
1767  css::uno::Sequence<uno::Any> aOuterArgs(1);
1768  aOuterArgs[0] <<= aAdaptorArgs;
1769 
1770  uno::Reference<lang::XInitialization> xInit(xInterface, uno::UNO_QUERY_THROW);
1771  xInit->initialize(aOuterArgs);
1772 
1773  uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW);
1774  uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
1775  {
1776  { "InputStream", uno::Any(xStream) },
1777  { "URL", uno::Any(OUString("private:stream")) },
1778  }));
1779  xImporter->setTargetDocument(xModel);
1780 
1781  uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW);
1782  //SetLoading hack because the document properties will be re-initted
1783  //by the xml filter and during the init, while it's considered uninitialized,
1784  //setting a property will inform the document it's modified, which attempts
1785  //to update the properties, which throws cause the properties are uninitialized
1786  xDocSh->SetLoading(SfxLoadedFlags::NONE);
1787  bool ret = xFilter->filter(aArgs);
1788  xDocSh->SetLoading(SfxLoadedFlags::ALL);
1789 
1790  xDocSh->DoClose();
1791 
1792  return ret;
1793 }
1794 
1795 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDOCX(SvStream &rStream)
1796 {
1798 
1799  SfxObjectShellLock xDocSh(new SwDocShell(SfxObjectCreateMode::INTERNAL));
1800  xDocSh->DoInitNew();
1801  uno::Reference<frame::XModel> xModel(xDocSh->GetModel());
1802 
1803  uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1804  uno::Reference<io::XInputStream> xStream(new utl::OSeekableInputStreamWrapper(rStream));
1805 
1806  uno::Reference<document::XFilter> xFilter(xMultiServiceFactory->createInstance("com.sun.star.comp.Writer.WriterFilter"), uno::UNO_QUERY_THROW);
1807 
1808  uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW);
1809  uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
1810  {
1811  { "InputStream", uno::makeAny(xStream) },
1812  { "InputMode", uno::makeAny(true) },
1813  }));
1814  xImporter->setTargetDocument(xModel);
1815 
1816  //SetLoading hack because the document properties will be re-initted
1817  //by the xml filter and during the init, while it's considered uninitialized,
1818  //setting a property will inform the document it's modified, which attempts
1819  //to update the properties, which throws cause the properties are uninitialized
1820  xDocSh->SetLoading(SfxLoadedFlags::NONE);
1821  bool ret = false;
1822  try
1823  {
1824  ret = xFilter->filter(aArgs);
1825  }
1826  catch (...)
1827  {
1828  }
1829  xDocSh->SetLoading(SfxLoadedFlags::ALL);
1830 
1831  xDocSh->DoClose();
1832 
1833  return ret;
1834 }
1835 
1836 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLOasisMetaImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimp.cxx:1730
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
rtl::Reference< SvXMLEmbeddedObjectHelper > m_xEmbeddedResolver
Definition: xmlimp.hxx:71
static OTextCursorHelper * lcl_xml_GetSwXTextCursor(const Reference< XTextCursor > &rTextCursor)
Definition: xmlimp.cxx:388
SAL_DLLPUBLIC_EXPORT bool TestImportDOCX(SvStream &rStream)
Definition: xmlimp.cxx:1795
std::unique_ptr< SwNodeIndex > m_pSttNdIdx
Definition: xmlimp.hxx:62
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
void DeleteMark()
Definition: pam.hxx:177
virtual const SwDoc * GetDoc() const =0
sal_uLong Count() const
Definition: ndarr.hxx:142
const css::uno::Reference< css::document::XEmbeddedObjectResolver > & GetEmbeddedResolver() const
Marks a position in the document model.
Definition: pam.hxx:35
const SwDoc * getDoc() const
Definition: xmlimp.cxx:1696
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps) override
Definition: xmlimp.cxx:1232
void applyXFormsSettings(const Reference< XNameAccess > &_rXForms, const Sequence< PropertyValue > &_rSettings)
void ClearShapeImport()
bool IsSectionNode() const
Definition: node.hxx:647
rtl::Reference< ::xmloff::OFormLayerXMLImport > const & GetFormImport()
SW_DLLPUBLIC const OUString & GetDefaultListStyleName() const
Definition: list.cxx:232
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:190
sal_uLong StartOfSectionIndex() const
Definition: node.hxx:676
void setWidth(tools::Long nWidth)
XML_DOCUMENT_META
std::unique_ptr< SvXMLTokenMap > m_pTableCellAttrTokenMap
Definition: xmlimp.hxx:67
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLOasisImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimp.cxx:1702
const OUString & GetText() const
Definition: ndtxt.hxx:213
XML_DOCUMENT_STYLES
SwDocShell * GetDocShell()
Definition: doc.hxx:1350
SvXMLImportContext * CreateFontDeclsContext()
Definition: xmlimp.cxx:1150
rtl::Reference< SvXMLGraphicHelper > m_xGraphicStorageHandler
Definition: xmlimp.hxx:69
bool m_bLoadDoc
Definition: xmlimp.hxx:81
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:238
SwNodeIndex nNode
Definition: pam.hxx:37
sal_uIntPtr sal_uLong
SvXMLImport & GetImport()
Definition: list.hxx:35
bool IsBlockMode() const
Definition: xmlimp.hxx:144
sal_Int64 n
Definition: doc.hxx:186
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlimp.cxx:1145
css::uno::Reference< css::container::XNameContainer > m_xLateInitSettings
Definition: xmlimp.hxx:78
void setStyleInsertMode(SfxStyleFamily nFamilies, bool bOverwrite)
Definition: xmlimp.cxx:361
SwNode & GetNode() const
Definition: ndindex.hxx:119
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLOasisContentImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimp.cxx:1721
SwPosition & GetBound(bool bOne=true)
Definition: pam.hxx:245
SwXMLImport(const css::uno::Reference< css::uno::XComponentContext > &rContext, OUString const &implementationName, SvXMLImportFlags nImportFlags)
Definition: xmlimp.cxx:323
std::unique_ptr< SvXMLTokenMap > m_pTableElemTokenMap
Definition: xmlimp.hxx:66
css::uno::Reference< css::frame::XModel > GetModel() const
bool IsKnown() const
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
bool CanJoinNext(SwNodeIndex *pIdx=nullptr) const
Is it possible to join two nodes? In pIdx the second position can be returned.
Definition: node.cxx:1844
virtual SwContentNode * JoinNext() override
Definition: ndtxt.cxx:915
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unotext.cxx:1202
bool IsLoadUserSettings() const
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:155
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
void SetFontDecls(XMLFontStylesContext *pFontDecls)
bool m_bInsert
Definition: xmlimp.hxx:82
bool m_bInititedXForms
Definition: xmlimp.hxx:88
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLOasisSettingsImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimp.cxx:1739
css::uno::Any const & rValue
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlimp.cxx:1633
void Delete(const SwNodeIndex &rPos, sal_uLong nNodes=1)
delete nodes
Definition: nodes.cxx:1072
virtual void set(DocumentSettingId id, bool value)=0
Set the specified document setting.
bool IsStylesOnlyMode() const
Definition: xmlimp.hxx:143
Reference< XInputStream > xStream
SwNodeType GetNodeType() const
Definition: node.hxx:144
SwIndex nContent
Definition: pam.hxx:38
SvXMLImportFlags
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
bool SetTextFormatColl(const SwPaM &rRg, SwTextFormatColl *pFormat, const bool bReset=true, const bool bResetListAttrs=false, SwRootFrame const *pLayout=nullptr)
Add 4th optional parameter .
Definition: docfmt.cxx:1074
virtual void SAL_CALL startDocument() override
Definition: xmlimp.cxx:400
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLOasisStylesImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimp.cxx:1711
void PrtOLENotify(bool bAll)
Definition: docdesc.cxx:688
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
void SetInXMLImport(bool bNew)
Definition: doc.hxx:970
XML_DOCUMENT_SETTINGS
SfxStyleFamily
bool m_bOrganizerMode
Definition: xmlimp.hxx:87
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
void setX(tools::Long x)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
bool m_bBlock
Definition: xmlimp.hxx:86
void SetGraphicStorageHandler(css::uno::Reference< css::document::XGraphicStorageHandler > const &rxGraphicStorageHandler)
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
bool IsContentNode() const
Definition: node.hxx:631
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool HasShapeImport() const
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:502
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlimp.cxx:293
virtual tools::Rectangle GetVisArea(sal_uInt16 nAspect) const override
Definition: docsh.cxx:915
void SetOLEPrtNotifyPending(bool bSet=true)
Definition: doc.hxx:1676
SwNumRule * FindNumRulePtr(const OUString &rName) const
Definition: docnum.cxx:2415
virtual SwList * getListByName(const OUString &rListId) const =0
void setY(tools::Long y)
bool IsOLEPrtNotifyPending() const
Definition: doc.hxx:558
const SfxPoolItem * GetNoCondAttr(sal_uInt16 nWhich, bool bInParents) const
Obtains attribute that is not delivered via conditional style!
Definition: node.cxx:1804
int i
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void initXForms(bool bCreateDefaultModel)
Definition: docxforms.cxx:49
bool CanJoinPrev(SwNodeIndex *pIdx=nullptr) const
Can we join two Nodes? We can return the 2nd position in pIdx.
Definition: node.cxx:1868
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:328
bool HasTextImport() const
void FinitItemImport()
Definition: xmlitemi.cxx:238
void ensure()
Definition: swdll.cxx:67
static rtl::Reference< SvXMLEmbeddedObjectHelper > Create(const css::uno::Reference< css::embed::XStorage > &,::comphelper::IEmbeddedHelper &rDocPersist, SvXMLEmbeddedObjectHelperMode eCreateMode)
void SetLoading(SfxLoadedFlags nFlags)
void SetSize(const Size &rSize)
void UpdateTextCollConditions(SwDoc *pDoc)
Definition: xmlfmt.cxx:1016
#define PROGRESS_BAR_STEP
Definition: xmlimp.hxx:48
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
void startPage(css::uno::Reference< css::drawing::XShapes > const &rShapes)
virtual SwFormatColl * ChgFormatColl(SwFormatColl *) override
Definition: ndtxt.cxx:3894
XML_XFORM_MODEL_SETTINGS
Marks a node in the document model.
Definition: ndindex.hxx:31
bool IsEndNode() const
Definition: node.hxx:635
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
void SetInReading(bool bNew)
Definition: doc.hxx:954
tuple index
void endPage(css::uno::Reference< css::drawing::XShapes > const &rShapes)
void SetEmbeddedResolver(css::uno::Reference< css::document::XEmbeddedObjectResolver > const &_xEmbeddedResolver)
#define ASPECT_CONTENT
bool isXForms() const
Definition: docxforms.cxx:44
virtual SfxPrinter * getPrinter(bool bCreate) const =0
Return the printer set at the document.
bool IsInReading() const
Definition: doc.hxx:953
Size GetSize() const
virtual const SwPaM * GetPaM() const =0
virtual void SAL_CALL startDocument() override
SfxStyleFamily GetStyleFamilyMask() const
Definition: xmlimp.hxx:141
const SwNumFormat & Get(sal_uInt16 i) const
Definition: number.cxx:79
void setLock(bool bLock)
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:680
void CopyCollFormat(SwTextNode &rDestNd)
Copy collection with all auto formats to dest-node.
Definition: ndcopy.cxx:333
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
Reference< XMultiServiceFactory > getProcessServiceFactory()
XML_DOCUMENT
SfxStyleFamily m_nStyleFamilyMask
Definition: xmlimp.hxx:80
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: xmlimp.cxx:379
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1558
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
void ClearTextImport()
XML_DOCUMENT_CONTENT
SvXMLImportFlags getImportFlags() const
css::uno::Reference< css::document::XDocumentProperties > GetDocumentProperties() const
Definition: xmlmeta.cxx:40
void MergeListsAtDocumentInsertPosition(SwDoc *pDoc)
Definition: xmlimp.cxx:953
unsigned char sal_uInt8
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
void InitItemImport()
Definition: xmlitemi.cxx:225
MapUnit GetMapUnit() const
sal_Int32 GetIndex() const
Definition: index.hxx:91
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
bool DoInitNew(SfxMedium *pMedium=nullptr)
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:176
virtual SwDrawModel * GetOrCreateDrawModel()=0
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
SwNodes & GetNodes()
Definition: doc.hxx:405
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
#define XML_ELEMENT(prefix, name)
SfxObjectShell * GetPersist() const
Definition: docnew.cxx:636
virtual void SetDocumentSpecificSettings(const OUString &_rSettingsGroupName, const css::uno::Sequence< css::beans::PropertyValue > &_rSettings) override
Definition: xmlimp.cxx:1604
const SvXMLUnitConverter & GetMM100UnitConverter() const
SAL_DLLPUBLIC_EXPORT bool TestImportFODT(SvStream &rStream)
Definition: xmlimp.cxx:1746
const css::uno::Reference< css::frame::XModel > & GetModel() const
virtual void SAL_CALL endDocument() override
Definition: xmlimp.cxx:637
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
virtual void SetVisArea(const tools::Rectangle &rRect) override
OLE-stuff.
Definition: docsh.cxx:891
constexpr sal_uInt16 RES_CHRATR_END(46)
OUString encodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
virtual ~SwXMLImport() override
Definition: xmlimp.cxx:338
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart)=0
Split a node at rPos (implemented only for TextNode).
void AddStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName, const OUString &rDisplayName)
void setHeight(tools::Long nHeight)
void setTextInsertMode(const css::uno::Reference< css::text::XTextRange > &rInsertPos)
Definition: xmlimp.cxx:350
SwDoc * m_pDoc
Definition: xmlimp.hxx:90
const css::uno::Reference< css::beans::XPropertySet > & getImportInfo() const
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Definition: xmlimp.cxx:1158
#define SAL_WARN(area, stream)
Reference< XModel > xModel
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: xmlimp.cxx:374
SwDoc & GetDoc() const
Definition: pam.hxx:243
detail::Optional< bool >::type tryAccess< bool >(css::uno::Any const &any)
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:476
SvXMLImportContext * CreateMetaContext(const sal_Int32 nElement)
Definition: xmlmeta.cxx:52
static css::uno::Reference< css::text::XTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1202
void JoinPrev()
Definition: ndtxt.cxx:1013
void FormatToTextAttr(SwTextNode *pNd)
Convey attributes of an AttrSet (AutoFormat) to SwpHintsArray.
Definition: thints.cxx:2510
SvXMLImportContext * createXFormsModelContext(SvXMLImport &rImport)
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0) override
Definition: ndtxt.cxx:5101
SwDoc * GetDocFromXMLImport(SvXMLImport const &)
Definition: xmlimp.cxx:1653
virtual XMLTextImportHelper * CreateTextImport() override
Definition: xmlimp.cxx:1137
IDocumentListsAccess const & getIDocumentListsAccess() const
Definition: doc.cxx:293
bool IsTextNode() const
Definition: node.hxx:639
sal_Int64 sanitiseMm100ToTwip(sal_Int64 n)
virtual void initXForms() override
Definition: xmlimp.cxx:1663
constexpr TypedWhichId< SfxStringItem > RES_PARATR_LIST_ID(RES_PARATR_LIST_BEGIN)
bool IsInXMLImport() const
Definition: doc.hxx:969
virtual void SAL_CALL endDocument() override
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:848
const css::uno::Reference< css::document::XGraphicStorageHandler > & GetGraphicStorageHandler() const
Base class of the Writer document model elements.
Definition: node.hxx:79
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:842
bool IsInsertMode() const
Definition: xmlimp.hxx:142
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)