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