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