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