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