LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmlimp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 600 715 83.9 %
Date: 2015-06-13 12:38:46 Functions: 49 79 62.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      22             : #include <cassert>
      23             : 
      24             : #include <com/sun/star/container/XIndexAccess.hpp>
      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/i18n/XForbiddenCharacters.hpp>
      29             : #include <com/sun/star/text/XTextDocument.hpp>
      30             : #include <com/sun/star/text/XTextRange.hpp>
      31             : 
      32             : #include <xmloff/xmlnmspe.hxx>
      33             : #include <xmloff/xmltkmap.hxx>
      34             : #include <xmloff/xmlictxt.hxx>
      35             : #include <xmloff/txtimp.hxx>
      36             : #include <xmloff/nmspmap.hxx>
      37             : #include <xmloff/XMLTextShapeImportHelper.hxx>
      38             : #include <xmloff/XMLFontStylesContext.hxx>
      39             : #include <xmloff/ProgressBarHelper.hxx>
      40             : #include <doc.hxx>
      41             : #include <drawdoc.hxx>
      42             : #include <IDocumentSettingAccess.hxx>
      43             : #include <IDocumentDeviceAccess.hxx>
      44             : #include <IDocumentStylePoolAccess.hxx>
      45             : #include <IDocumentDrawModelAccess.hxx>
      46             : #include <unofreg.hxx>
      47             : #include <TextCursorHelper.hxx>
      48             : #include <unotext.hxx>
      49             : #include <unotextrange.hxx>
      50             : #include "unocrsr.hxx"
      51             : #include <poolfmt.hxx>
      52             : #include <ndtxt.hxx>
      53             : #include <editsh.hxx>
      54             : #include "xmlimp.hxx"
      55             : #include "xmltexti.hxx"
      56             : #include <xmloff/DocumentSettingsContext.hxx>
      57             : #include <docsh.hxx>
      58             : #include <editeng/unolingu.hxx>
      59             : #include <svx/svdmodel.hxx>
      60             : #include <svx/xmlgrhlp.hxx>
      61             : #include <svx/xmleohlp.hxx>
      62             : #include <sfx2/printer.hxx>
      63             : #include <xmloff/xmluconv.hxx>
      64             : #include <unotools/saveopt.hxx>
      65             : #include <tools/diagnose_ex.h>
      66             : 
      67             : #include <vcl/svapp.hxx>
      68             : #include <osl/mutex.hxx>
      69             : #include <unotxdoc.hxx>
      70             : 
      71             : #include <xmloff/xmlmetai.hxx>
      72             : #include <xmloff/xformsimport.hxx>
      73             : #include <comphelper/servicehelper.hxx>
      74             : #include <comphelper/processfactory.hxx>
      75             : 
      76             : #include <unordered_set>
      77             : 
      78             : using namespace ::com::sun::star;
      79             : using namespace ::com::sun::star::uno;
      80             : using namespace ::com::sun::star::text;
      81             : using namespace ::com::sun::star::lang;
      82             : using namespace ::com::sun::star::beans;
      83             : using namespace ::com::sun::star::container;
      84             : using namespace ::com::sun::star::i18n;
      85             : using namespace ::com::sun::star::drawing;
      86             : using namespace ::com::sun::star::xforms;
      87             : using namespace ::xmloff::token;
      88             : using namespace ::std;
      89             : 
      90             : enum SwXMLDocTokens
      91             : {
      92             :     XML_TOK_DOC_FONTDECLS,
      93             :     XML_TOK_DOC_STYLES,
      94             :     XML_TOK_DOC_AUTOSTYLES,
      95             :     XML_TOK_DOC_MASTERSTYLES,
      96             :     XML_TOK_DOC_META,
      97             :     XML_TOK_DOC_BODY,
      98             :     XML_TOK_DOC_SCRIPT,
      99             :     XML_TOK_DOC_SETTINGS,
     100             :     XML_TOK_DOC_XFORMS,
     101             :     XML_TOK_OFFICE_END=XML_TOK_UNKNOWN
     102             : };
     103             : 
     104             : static SvXMLTokenMapEntry aDocTokenMap[] =
     105             : {
     106             :     { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS,     XML_TOK_DOC_FONTDECLS  },
     107             :     { XML_NAMESPACE_OFFICE, XML_STYLES,         XML_TOK_DOC_STYLES      },
     108             :     { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES    },
     109             :     { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES,   XML_TOK_DOC_MASTERSTYLES   },
     110             :     { XML_NAMESPACE_OFFICE, XML_META,           XML_TOK_DOC_META        },
     111             :     { XML_NAMESPACE_OFFICE, XML_BODY,           XML_TOK_DOC_BODY        },
     112             :     { XML_NAMESPACE_OFFICE, XML_SCRIPTS,        XML_TOK_DOC_SCRIPT      },
     113             :     { XML_NAMESPACE_OFFICE, XML_SETTINGS,       XML_TOK_DOC_SETTINGS    },
     114             :     { XML_NAMESPACE_XFORMS, XML_MODEL,          XML_TOK_DOC_XFORMS      },
     115             :     XML_TOKEN_MAP_END
     116             : };
     117             : 
     118             : class SwXMLBodyContext_Impl : public SvXMLImportContext
     119             : {
     120         353 :     SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
     121             : 
     122             : public:
     123             : 
     124             :     SwXMLBodyContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
     125             :                 const OUString& rLName,
     126             :                 const Reference< xml::sax::XAttributeList > & xAttrList );
     127             :     virtual ~SwXMLBodyContext_Impl();
     128             : 
     129             :     TYPEINFO_OVERRIDE();
     130             : 
     131             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
     132             :                 const OUString& rLocalName,
     133             :                 const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     134             : };
     135             : 
     136         353 : SwXMLBodyContext_Impl::SwXMLBodyContext_Impl( SwXMLImport& rImport,
     137             :                 sal_uInt16 nPrfx, const OUString& rLName,
     138             :                 const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
     139         353 :     SvXMLImportContext( rImport, nPrfx, rLName )
     140             : {
     141         353 : }
     142             : 
     143         706 : SwXMLBodyContext_Impl::~SwXMLBodyContext_Impl()
     144             : {
     145         706 : }
     146             : 
     147           0 : TYPEINIT1( SwXMLBodyContext_Impl, SvXMLImportContext );
     148             : 
     149         353 : SvXMLImportContext *SwXMLBodyContext_Impl::CreateChildContext(
     150             :         sal_uInt16 /*nPrefix*/,
     151             :         const OUString& rLocalName,
     152             :         const Reference< xml::sax::XAttributeList > & /*xAttrList*/ )
     153             : {
     154         353 :     return GetSwImport().CreateBodyContentContext( rLocalName );
     155             : }
     156             : 
     157             : // #i69629#
     158             : // enhance class <SwXMLDocContext_Impl> in order to be able to create subclasses
     159             : // NB: virtually inherit so we can multiply inherit properly
     160             : //     in SwXMLOfficeDocContext_Impl
     161             : class SwXMLDocContext_Impl : public virtual SvXMLImportContext
     162             : {
     163             : 
     164             : protected: // #i69629#
     165        6845 :     SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
     166             : 
     167             : public:
     168             : 
     169             :     SwXMLDocContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
     170             :                 const OUString& rLName,
     171             :                 const Reference< xml::sax::XAttributeList > & xAttrList );
     172             :     virtual ~SwXMLDocContext_Impl();
     173             : 
     174             :     TYPEINFO_OVERRIDE();
     175             : 
     176             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
     177             :                 const OUString& rLocalName,
     178             :                 const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     179             : };
     180             : 
     181         927 : SwXMLDocContext_Impl::SwXMLDocContext_Impl( SwXMLImport& rImport,
     182             :                 sal_uInt16 nPrfx, const OUString& rLName,
     183             :                 const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
     184         927 :     SvXMLImportContext( rImport, nPrfx, rLName )
     185             : {
     186         927 : }
     187             : 
     188        2071 : SwXMLDocContext_Impl::~SwXMLDocContext_Impl()
     189             : {
     190        2071 : }
     191             : 
     192           0 : TYPEINIT1( SwXMLDocContext_Impl, SvXMLImportContext );
     193             : 
     194        2874 : SvXMLImportContext *SwXMLDocContext_Impl::CreateChildContext(
     195             :         sal_uInt16 nPrefix,
     196             :         const OUString& rLocalName,
     197             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     198             : {
     199        2874 :     SvXMLImportContext *pContext = 0;
     200             : 
     201        2874 :     const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
     202        2874 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     203             :     {
     204             :     case XML_TOK_DOC_FONTDECLS:
     205         631 :         pContext = GetSwImport().CreateFontDeclsContext( rLocalName,
     206         631 :                                                              xAttrList );
     207         631 :         break;
     208             :     case XML_TOK_DOC_STYLES:
     209         345 :         GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     210         345 :         pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
     211         345 :                                                       false );
     212         345 :         break;
     213             :     case XML_TOK_DOC_AUTOSTYLES:
     214             :         // don't use the autostyles from the styles-document for the progress
     215         632 :         if ( ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
     216         343 :             GetSwImport().GetProgressBarHelper()->Increment
     217         343 :                 ( PROGRESS_BAR_STEP );
     218         632 :         pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
     219         632 :                                                       true );
     220         632 :         break;
     221             : 
     222             :     case XML_TOK_DOC_MASTERSTYLES:
     223         344 :         pContext = GetSwImport().CreateMasterStylesContext( rLocalName,
     224         344 :                                                             xAttrList );
     225         344 :         break;
     226             :     case XML_TOK_DOC_META:
     227             :         OSL_FAIL("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
     228           0 :         break;
     229             :     case XML_TOK_DOC_SCRIPT:
     230         284 :         pContext = GetSwImport().CreateScriptContext( rLocalName );
     231         284 :         break;
     232             :     case XML_TOK_DOC_BODY:
     233         353 :         GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     234             :         pContext = new SwXMLBodyContext_Impl( GetSwImport(), nPrefix,
     235         353 :                                               rLocalName, xAttrList );
     236         353 :         break;
     237             :     case XML_TOK_DOC_SETTINGS:
     238         285 :         pContext = new XMLDocumentSettingsContext( GetImport(), nPrefix, rLocalName, xAttrList );
     239         285 :         break;
     240             :     case XML_TOK_DOC_XFORMS:
     241           0 :         pContext = createXFormsModelContext(GetImport(), nPrefix, rLocalName);
     242           0 :         break;
     243             :     }
     244             : 
     245        2874 :     if( !pContext )
     246           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     247             : 
     248        2874 :     return pContext;
     249             : }
     250             : 
     251             : // #i69629# - new subclass <SwXMLOfficeDocContext_Impl> of class <SwXMLDocContext_Impl>
     252             : class SwXMLOfficeDocContext_Impl :
     253             :          public SwXMLDocContext_Impl, public SvXMLMetaDocumentContext
     254             : {
     255             : public:
     256             : 
     257             :     SwXMLOfficeDocContext_Impl( SwXMLImport& rImport,
     258             :                 sal_uInt16 nPrfx,
     259             :                 const OUString& rLName,
     260             :                 const Reference< xml::sax::XAttributeList > & xAttrList,
     261             :                 const Reference< document::XDocumentProperties >& xDocProps);
     262             :     virtual ~SwXMLOfficeDocContext_Impl();
     263             : 
     264             :     TYPEINFO_OVERRIDE();
     265             : 
     266             :     virtual SvXMLImportContext *CreateChildContext(
     267             :                 sal_uInt16 nPrefix,
     268             :                 const OUString& rLocalName,
     269             :                 const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     270             : };
     271             : 
     272          66 : SwXMLOfficeDocContext_Impl::SwXMLOfficeDocContext_Impl(
     273             :                 SwXMLImport& rImport,
     274             :                 sal_uInt16 nPrfx,
     275             :                 const OUString& rLName,
     276             :                 const Reference< xml::sax::XAttributeList > & xAttrList,
     277             :                 const Reference< document::XDocumentProperties >& xDocProps) :
     278             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     279             :     SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList ),
     280          66 :     SvXMLMetaDocumentContext( rImport, nPrfx, rLName, xDocProps)
     281             : {
     282          66 : }
     283             : 
     284         198 : SwXMLOfficeDocContext_Impl::~SwXMLOfficeDocContext_Impl()
     285             : {
     286         198 : }
     287             : 
     288           0 : TYPEINIT1( SwXMLOfficeDocContext_Impl, SwXMLDocContext_Impl );
     289             : 
     290         341 : SvXMLImportContext* SwXMLOfficeDocContext_Impl::CreateChildContext(
     291             :                 sal_uInt16 nPrefix,
     292             :                 const OUString& rLocalName,
     293             :                 const Reference< xml::sax::XAttributeList > & xAttrList )
     294             : {
     295         341 :     const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
     296             : 
     297             :     // assign paragraph styles to list levels of outline style after all styles
     298             :     // are imported and finished. This is the case, when <office:body> starts
     299             :     // in flat OpenDocument file format.
     300             :     {
     301         341 :         if ( rTokenMap.Get( nPrefix, rLocalName ) == XML_TOK_DOC_BODY )
     302             :         {
     303          66 :             GetImport().GetTextImport()->SetOutlineStyles( true );
     304             :         }
     305             :     }
     306             : 
     307             :     // behave like meta base class iff we encounter office:meta
     308         341 :     if ( XML_TOK_DOC_META == rTokenMap.Get( nPrefix, rLocalName ) ) {
     309             :         return SvXMLMetaDocumentContext::CreateChildContext(
     310          54 :                     nPrefix, rLocalName, xAttrList );
     311             :     } else {
     312             :         return SwXMLDocContext_Impl::CreateChildContext(
     313         287 :                     nPrefix, rLocalName, xAttrList );
     314             :     }
     315             : }
     316             : 
     317             : // #i69629# - new subclass <SwXMLDocStylesContext_Impl> of class <SwXMLDocContext_Impl>
     318             : class SwXMLDocStylesContext_Impl : public SwXMLDocContext_Impl
     319             : {
     320             : public:
     321             : 
     322             :     SwXMLDocStylesContext_Impl( SwXMLImport& rImport,
     323             :                                 sal_uInt16 nPrfx,
     324             :                                 const OUString& rLName,
     325             :                                 const Reference< xml::sax::XAttributeList > & xAttrList );
     326             :     virtual ~SwXMLDocStylesContext_Impl();
     327             : 
     328             :     TYPEINFO_OVERRIDE();
     329             : 
     330             :     virtual void EndElement() SAL_OVERRIDE;
     331             : };
     332             : 
     333         289 : SwXMLDocStylesContext_Impl::SwXMLDocStylesContext_Impl(
     334             :                     SwXMLImport& rImport,
     335             :                     sal_uInt16 nPrfx,
     336             :                     const OUString& rLName,
     337             :                     const Reference< xml::sax::XAttributeList > & xAttrList ) :
     338             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     339         289 :     SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList )
     340             : {
     341         289 : }
     342             : 
     343         867 : SwXMLDocStylesContext_Impl::~SwXMLDocStylesContext_Impl()
     344             : {
     345         867 : }
     346             : 
     347           0 : TYPEINIT1( SwXMLDocStylesContext_Impl, SwXMLDocContext_Impl );
     348             : 
     349         289 : void SwXMLDocStylesContext_Impl::EndElement()
     350             : {
     351             :     // assign paragraph styles to list levels of outline style after all styles
     352             :     // are imported and finished.
     353         289 :     SwXMLImport& rSwImport = dynamic_cast<SwXMLImport&>( GetImport());
     354         289 :     GetImport().GetTextImport()->SetOutlineStyles(
     355         578 :             (rSwImport.GetStyleFamilyMask() & SFX_STYLE_FAMILY_PARA ) != 0);
     356         289 : }
     357             : 
     358        3215 : const SvXMLTokenMap& SwXMLImport::GetDocElemTokenMap()
     359             : {
     360        3215 :     if( !pDocElemTokenMap )
     361         927 :         pDocElemTokenMap = new SvXMLTokenMap( aDocTokenMap );
     362             : 
     363        3215 :     return *pDocElemTokenMap;
     364             : }
     365             : 
     366        1409 : SvXMLImportContext *SwXMLImport::CreateContext(
     367             :         sal_uInt16 nPrefix,
     368             :         const OUString& rLocalName,
     369             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     370             : {
     371        1409 :     SvXMLImportContext *pContext = 0;
     372             : 
     373             :     // #i69629# - own subclasses for <office:document> and <office:document-styles>
     374        3194 :     if( XML_NAMESPACE_OFFICE==nPrefix &&
     375        2141 :         ( IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) ||
     376         928 :           IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ))
     377        1144 :         pContext = new SwXMLDocContext_Impl( *this, nPrefix, rLocalName,
     378        1144 :                                              xAttrList );
     379        1478 :     else if ( XML_NAMESPACE_OFFICE==nPrefix &&
     380         641 :               IsXMLToken( rLocalName, XML_DOCUMENT_META ) )
     381             :     {
     382         286 :         pContext = CreateMetaContext(rLocalName);
     383             :     }
     384         906 :     else if ( XML_NAMESPACE_OFFICE==nPrefix &&
     385         355 :               IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) )
     386             :     {
     387         578 :         pContext = new SwXMLDocStylesContext_Impl( *this, nPrefix, rLocalName,
     388         578 :                                                    xAttrList );
     389             :     }
     390         328 :     else if ( XML_NAMESPACE_OFFICE==nPrefix &&
     391          66 :               IsXMLToken( rLocalName, XML_DOCUMENT ) )
     392             :     {
     393             :         uno::Reference<document::XDocumentProperties> const xDocProps(
     394          66 :             GetDocumentProperties());
     395             :         // flat OpenDocument file format
     396         132 :         pContext = new SwXMLOfficeDocContext_Impl( *this, nPrefix, rLocalName,
     397         132 :                         xAttrList, xDocProps);
     398             :     }
     399             :     else
     400         196 :         pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
     401             : 
     402        1409 :     return pContext;
     403             : }
     404             : 
     405        1220 : SwXMLImport::SwXMLImport(
     406             :     const uno::Reference< uno::XComponentContext >& rContext,
     407             :     OUString const & implementationName, SvXMLImportFlags nImportFlags)
     408             : :   SvXMLImport( rContext, implementationName, nImportFlags ),
     409             :     pSttNdIdx( 0 ),
     410             :     pTableItemMapper( 0 ),
     411             :     pDocElemTokenMap( 0 ),
     412             :     pTableElemTokenMap( 0 ),
     413             :     pTableCellAttrTokenMap( 0 ),
     414             :     pGraphicResolver( 0 ),
     415             :     pEmbeddedResolver( 0 ),
     416             :     nStyleFamilyMask( SFX_STYLE_FAMILY_ALL ),
     417             :     bLoadDoc( true ),
     418             :     bInsert( false ),
     419             :     bBlock( false ),
     420             :     bShowProgress( true ),
     421             :     bOrganizerMode( false ),
     422             :     bInititedXForms( false ),
     423             :     bPreserveRedlineMode( true ),
     424        1220 :     doc( NULL )
     425             : {
     426        1220 :     _InitItemImport();
     427             : 
     428        1220 : }
     429             : 
     430        3660 : SwXMLImport::~SwXMLImport() throw ()
     431             : {
     432        1220 :     delete pDocElemTokenMap;
     433        1220 :     delete pTableElemTokenMap;
     434        1220 :     delete pTableCellAttrTokenMap;
     435        1220 :     _FinitItemImport();
     436        2440 : }
     437             : 
     438          54 : void SwXMLImport::setTextInsertMode(
     439             :          const Reference< XTextRange > & rInsertPos )
     440             : {
     441          54 :     bInsert = true;
     442             : 
     443          54 :     Reference < XText > xText = rInsertPos->getText();
     444             :     Reference < XTextCursor > xTextCursor =
     445         108 :         xText->createTextCursorByRange( rInsertPos );
     446         108 :     GetTextImport()->SetCursor( xTextCursor );
     447          54 : }
     448             : 
     449           0 : void SwXMLImport::setStyleInsertMode( sal_uInt16 nFamilies,
     450             :                                       bool bOverwrite )
     451             : {
     452           0 :     bInsert = !bOverwrite;
     453           0 :     nStyleFamilyMask = nFamilies;
     454           0 :     bLoadDoc = false;
     455           0 : }
     456             : 
     457           4 : void SwXMLImport::setBlockMode( )
     458             : {
     459           4 :     bBlock = true;
     460           4 : }
     461             : 
     462           6 : void SwXMLImport::setOrganizerMode( )
     463             : {
     464           6 :     bOrganizerMode = true;
     465           6 : }
     466             : 
     467             : namespace
     468             : {
     469             :     class theSwXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXMLImportUnoTunnelId > {};
     470             : }
     471             : 
     472           0 : const Sequence< sal_Int8 > & SwXMLImport::getUnoTunnelId() throw()
     473             : {
     474           0 :     return theSwXMLImportUnoTunnelId::get().getSeq();
     475             : }
     476             : 
     477           0 : sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId )
     478             :     throw(RuntimeException, std::exception)
     479             : {
     480           0 :     if( rId.getLength() == 16
     481           0 :         && 0 == memcmp( getUnoTunnelId().getConstArray(),
     482           0 :                                         rId.getConstArray(), 16 ) )
     483             :     {
     484           0 :         return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
     485             :     }
     486           0 :     return SvXMLImport::getSomething( rId );
     487             : }
     488             : 
     489         697 : static OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
     490             : {
     491         697 :     Reference<XUnoTunnel> xCrsrTunnel( rTextCursor, UNO_QUERY );
     492             :     OSL_ENSURE( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
     493         697 :     if( !xCrsrTunnel.is() )
     494           0 :         return 0;
     495             :     OTextCursorHelper *pTextCrsr = reinterpret_cast< OTextCursorHelper *>(
     496         697 :             sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething(  OTextCursorHelper::getUnoTunnelId() )));
     497             :     OSL_ENSURE( pTextCrsr, "SwXTextCursor missing" );
     498         697 :     return pTextCrsr;
     499             : }
     500             : 
     501        1214 : void SwXMLImport::startDocument()
     502             :     throw (xml::sax::SAXException,
     503             :            uno::RuntimeException,
     504             :            std::exception)
     505             : {
     506             :     // delegate to parent
     507        1214 :     SvXMLImport::startDocument();
     508             : 
     509             :     OSL_ENSURE( GetModel().is(), "model is missing" );
     510        1214 :     if( !GetModel().is() )
     511         571 :         return;
     512             : 
     513             :     // this method will modify the document directly -> lock SolarMutex
     514        1214 :     SolarMutexGuard aGuard;
     515             : 
     516        1857 :     Reference< XPropertySet > xImportInfo( getImportInfo() );
     517        1857 :     Reference< XPropertySetInfo > xPropertySetInfo;
     518        1214 :        if( xImportInfo.is() )
     519        1159 :         xPropertySetInfo = xImportInfo->getPropertySetInfo();
     520        1214 :     if( xPropertySetInfo.is() )
     521             :     {
     522        1159 :         Any aAny;
     523             :         // insert style mode?
     524        2318 :         OUString sStyleInsertModeFamilies("StyleInsertModeFamilies");
     525        1159 :         if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeFamilies) )
     526             :         {
     527        1147 :             aAny = xImportInfo->getPropertyValue(sStyleInsertModeFamilies);
     528        1147 :             Sequence< OUString> aFamiliesSeq;
     529        1147 :             if( aAny >>= aFamiliesSeq )
     530             :             {
     531           0 :                 sal_uInt16 nFamilyMask = 0U;
     532           0 :                 sal_Int32 nCount = aFamiliesSeq.getLength();
     533           0 :                 const OUString *pSeq = aFamiliesSeq.getConstArray();
     534           0 :                 for( sal_Int32 i=0; i < nCount; i++ )
     535             :                 {
     536           0 :                     const OUString& rFamily = pSeq[i];
     537           0 :                     if( rFamily=="FrameStyles" )
     538           0 :                         nFamilyMask |= SFX_STYLE_FAMILY_FRAME;
     539           0 :                     else if( rFamily=="PageStyles" )
     540           0 :                         nFamilyMask |= SFX_STYLE_FAMILY_PAGE;
     541           0 :                     else if( rFamily=="CharacterStyles" )
     542           0 :                         nFamilyMask |= SFX_STYLE_FAMILY_CHAR;
     543           0 :                     else if( rFamily=="ParagraphStyles" )
     544           0 :                         nFamilyMask |= SFX_STYLE_FAMILY_PARA;
     545           0 :                     else if( rFamily=="NumberingStyles" )
     546           0 :                         nFamilyMask |= SFX_STYLE_FAMILY_PSEUDO;
     547             :                 }
     548             : 
     549           0 :                 bool bOverwrite = false;
     550           0 :                 const OUString sStyleInsertModeOverwrite("StyleInsertModeOverwrite");
     551           0 :                 if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeOverwrite) )
     552             :                 {
     553           0 :                     aAny = xImportInfo->getPropertyValue(sStyleInsertModeOverwrite);
     554           0 :                     if( aAny.getValueType() == cppu::UnoType<bool>::get() &&
     555           0 :                         *static_cast<const sal_Bool*>(aAny.getValue()) )
     556           0 :                         bOverwrite = true;
     557             :                 }
     558             : 
     559           0 :                 setStyleInsertMode( nFamilyMask, bOverwrite );
     560        1147 :             }
     561             :         }
     562             : 
     563             :         // text insert mode?
     564        2318 :         const OUString sTextInsertModeRange("TextInsertModeRange");
     565        1159 :         if( xPropertySetInfo->hasPropertyByName(sTextInsertModeRange) )
     566             :         {
     567        1147 :             aAny = xImportInfo->getPropertyValue(sTextInsertModeRange);
     568        1147 :             Reference<XTextRange> xInsertTextRange;
     569        1147 :             if( aAny >>= xInsertTextRange )
     570           0 :                 setTextInsertMode( xInsertTextRange );
     571             :         }
     572             : 
     573             :         // auto text mode
     574        2318 :         const OUString sAutoTextMode("AutoTextMode");
     575        1159 :         if( xPropertySetInfo->hasPropertyByName(sAutoTextMode) )
     576             :         {
     577        1147 :             aAny = xImportInfo->getPropertyValue(sAutoTextMode);
     578        1151 :             if( aAny.getValueType() == cppu::UnoType<bool>::get() &&
     579           4 :                 *static_cast<const sal_Bool*>(aAny.getValue()) )
     580           4 :                     setBlockMode();
     581             :         }
     582             : 
     583             :         // organizer mode
     584        2318 :         const OUString sOrganizerMode("OrganizerMode");
     585        1159 :         if( xPropertySetInfo->hasPropertyByName(sOrganizerMode) )
     586             :         {
     587        1147 :             aAny = xImportInfo->getPropertyValue(sOrganizerMode);
     588        1153 :             if( aAny.getValueType() == cppu::UnoType<bool>::get() &&
     589           6 :                 *static_cast<const sal_Bool*>(aAny.getValue()) )
     590           6 :                     setOrganizerMode();
     591        1159 :         }
     592             :     }
     593             : 
     594             :     // There only is a text cursor by now if we are in insert mode. In any
     595             :     // other case we have to create one at the start of the document.
     596             :     // We also might change into the insert mode later, so we have to make
     597             :     // sure to first set the insert mode and then create the text import
     598             :     // helper. Otherwise it won't have the insert flag set!
     599        1214 :     OTextCursorHelper *pTextCrsr = 0;
     600        1857 :     Reference < XTextCursor > xTextCursor;
     601        1214 :     if( HasTextImport() )
     602           0 :            xTextCursor = GetTextImport()->GetCursor();
     603        1214 :     if( !xTextCursor.is() )
     604             :     {
     605        1214 :         Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
     606        2428 :         Reference < XText > xText = xTextDoc->getText();
     607        1214 :         xTextCursor = xText->createTextCursor();
     608        1214 :         SwCrsrShell *pCrsrSh = 0;
     609        1214 :         SwDoc *pDoc = 0;
     610        1214 :         if( SvXMLImportFlags::ALL == getImportFlags() )
     611             :         {
     612          67 :             pTextCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
     613             :             OSL_ENSURE( pTextCrsr, "SwXTextCursor missing" );
     614          67 :             if( !pTextCrsr )
     615           0 :                 return;
     616             : 
     617          67 :             pDoc = pTextCrsr->GetDoc();
     618             :             OSL_ENSURE( pDoc, "SwDoc missing" );
     619          67 :             if( !pDoc )
     620           0 :                 return;
     621             : 
     622             :             // Is there a edit shell. If yes, then we are currently inserting
     623             :             // a document. We then have to insert at the current edit shell's
     624             :             // cursor position. That not quite clean code, but there is no other
     625             :             // way currently.
     626          67 :             pCrsrSh = pDoc->GetEditShell();
     627             :         }
     628        1214 :         if( pCrsrSh )
     629             :         {
     630             :             const uno::Reference<text::XTextRange> xInsertTextRange(
     631             :                 SwXTextRange::CreateXTextRange(
     632          54 :                     *pDoc, *pCrsrSh->GetCrsr()->GetPoint(), 0 ) );
     633          54 :             setTextInsertMode( xInsertTextRange );
     634          54 :             xTextCursor = GetTextImport()->GetCursor();
     635          54 :             pTextCrsr = 0;
     636             :         }
     637             :         else
     638        2374 :             GetTextImport()->SetCursor( xTextCursor );
     639             :     }
     640             : 
     641        1214 :     if( (!(getImportFlags() & (SvXMLImportFlags::CONTENT|SvXMLImportFlags::MASTERSTYLES))))
     642         571 :         return;
     643             : 
     644         643 :     if( !pTextCrsr  )
     645         630 :         pTextCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
     646             :     OSL_ENSURE( pTextCrsr, "SwXTextCursor missing" );
     647         643 :     if( !pTextCrsr )
     648           0 :         return;
     649             : 
     650         643 :     SwDoc *pDoc = pTextCrsr->GetDoc();
     651             :     OSL_ENSURE( pDoc, "SwDoc missing" );
     652         643 :     if( !pDoc )
     653           0 :         return;
     654             : 
     655         643 :     if( (getImportFlags() & SvXMLImportFlags::CONTENT) && !IsStylesOnlyMode() )
     656             :     {
     657         353 :         pSttNdIdx = new SwNodeIndex( pDoc->GetNodes() );
     658         353 :         if( IsInsertMode() )
     659             :         {
     660          54 :             SwPaM *pPaM = pTextCrsr->GetPaM();
     661          54 :             const SwPosition* pPos = pPaM->GetPoint();
     662             : 
     663             :             // Split once and remember the node that has been splitted.
     664          54 :             pDoc->getIDocumentContentOperations().SplitNode( *pPos, false );
     665          54 :             *pSttNdIdx = pPos->nNode.GetIndex()-1;
     666             : 
     667             :             // Split again.
     668          54 :             pDoc->getIDocumentContentOperations().SplitNode( *pPos, false );
     669             : 
     670             :             // Insert all content into the new node
     671          54 :             pPaM->Move( fnMoveBackward );
     672             :             pDoc->SetTextFormatColl
     673          54 :                 ( *pPaM, pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, false ) );
     674             :         }
     675             :     }
     676             : 
     677             :     // We need a draw model to be able to set the z order
     678         643 :     pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel(); // #i52858# - method name changed
     679             : 
     680             :     // SJ: #i49801# locking the modell to disable repaints
     681         643 :     SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
     682         643 :     if ( pDrawModel )
     683         643 :         pDrawModel->setLock(true);
     684             : 
     685         643 :     if( !GetGraphicResolver().is() )
     686             :     {
     687           0 :         pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_READ );
     688           0 :         Reference< document::XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
     689           0 :         SetGraphicResolver( xGraphicResolver );
     690             :     }
     691             : 
     692         643 :     if( !GetEmbeddedResolver().is() )
     693             :     {
     694           0 :         SfxObjectShell *pPersist = pDoc->GetPersist();
     695           0 :         if( pPersist )
     696             :         {
     697             :             pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
     698             :                                             *pPersist,
     699           0 :                                             EMBEDDEDOBJECTHELPER_MODE_READ );
     700           0 :             Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
     701           0 :             SetEmbeddedResolver( xEmbeddedResolver );
     702             :         }
     703         643 :     }
     704             : }
     705             : 
     706        1213 : void SwXMLImport::endDocument()
     707             :     throw( xml::sax::SAXException, uno::RuntimeException, std::exception )
     708             : {
     709             :     OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
     710        1213 :     if( !GetModel().is() )
     711        1213 :         return;
     712             : 
     713             :     // this method will modify the document directly -> lock SolarMutex
     714        1213 :     SolarMutexGuard aGuard;
     715             : 
     716        1213 :     if( pGraphicResolver )
     717           0 :         SvXMLGraphicHelper::Destroy( pGraphicResolver );
     718        1213 :     if( pEmbeddedResolver )
     719           0 :         SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
     720             :     // Clear the shape import to sort the shapes  (and not in the
     721             :     // destructor that might be called after the import has finished
     722             :     // for Java filters.
     723        1213 :     if( HasShapeImport() )
     724         634 :         ClearShapeImport();
     725             : 
     726        1213 :     SwDoc *pDoc = 0;
     727        1213 :     if( (getImportFlags() & SvXMLImportFlags::CONTENT) && !IsStylesOnlyMode() )
     728             :     {
     729         706 :         Reference<XUnoTunnel> xCrsrTunnel( GetTextImport()->GetCursor(),
     730         353 :                                               UNO_QUERY);
     731             :         assert(xCrsrTunnel.is() && "missing XUnoTunnel for Cursor");
     732             :         OTextCursorHelper *pTextCrsr = reinterpret_cast< OTextCursorHelper *>(
     733         353 :                 sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
     734             :         assert(pTextCrsr && "SwXTextCursor missing");
     735         353 :         SwPaM *pPaM = pTextCrsr->GetPaM();
     736         353 :         if( IsInsertMode() && pSttNdIdx->GetIndex() )
     737             :         {
     738             :             // If we are in insert mode, join the splitted node that is in front
     739             :             // of the new content with the first new node. Or in other words:
     740             :             // Revert the first split node.
     741          54 :             SwTextNode* pTextNode = pSttNdIdx->GetNode().GetTextNode();
     742          54 :             SwNodeIndex aNxtIdx( *pSttNdIdx );
     743         108 :             if( pTextNode && pTextNode->CanJoinNext( &aNxtIdx ) &&
     744          54 :                 pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex() )
     745             :             {
     746             :                 // If the PaM points to the first new node, move the PaM to the
     747             :                 // end of the previous node.
     748          52 :                 if( pPaM->GetPoint()->nNode == aNxtIdx )
     749             :                 {
     750           0 :                     pPaM->GetPoint()->nNode = *pSttNdIdx;
     751           0 :                     pPaM->GetPoint()->nContent.Assign( pTextNode,
     752           0 :                                             pTextNode->GetText().getLength());
     753             :                 }
     754             : 
     755             : #if OSL_DEBUG_LEVEL > 0
     756             :                 // !!! This should be impossible !!!!
     757             :                 OSL_ENSURE( pSttNdIdx->GetIndex()+1 !=
     758             :                                         pPaM->GetBound( true ).nNode.GetIndex(),
     759             :                         "PaM.Bound1 point to new node " );
     760             :                 OSL_ENSURE( pSttNdIdx->GetIndex()+1 !=
     761             :                                         pPaM->GetBound( false ).nNode.GetIndex(),
     762             :                         "PaM.Bound2 points to new node" );
     763             : 
     764             :                 if( pSttNdIdx->GetIndex()+1 ==
     765             :                                         pPaM->GetBound( true ).nNode.GetIndex() )
     766             :                 {
     767             :                     const sal_Int32 nCntPos =
     768             :                             pPaM->GetBound( true ).nContent.GetIndex();
     769             :                     pPaM->GetBound( true ).nContent.Assign( pTextNode,
     770             :                             pTextNode->GetText().getLength() + nCntPos );
     771             :                 }
     772             :                 if( pSttNdIdx->GetIndex()+1 ==
     773             :                                 pPaM->GetBound( false ).nNode.GetIndex() )
     774             :                 {
     775             :                     const sal_Int32 nCntPos =
     776             :                             pPaM->GetBound( false ).nContent.GetIndex();
     777             :                     pPaM->GetBound( false ).nContent.Assign( pTextNode,
     778             :                             pTextNode->GetText().getLength() + nCntPos );
     779             :                 }
     780             : #endif
     781             :                 // If the first new node isn't empty, convert  the node's text
     782             :                 // attributes into hints. Otherwise, set the new node's
     783             :                 // paragraph style at the previous (empty) node.
     784          52 :                 SwTextNode* pDelNd = aNxtIdx.GetNode().GetTextNode();
     785          52 :                 if (!pTextNode->GetText().isEmpty())
     786           0 :                     pDelNd->FormatToTextAttr( pTextNode );
     787             :                 else
     788          52 :                     pTextNode->ChgFormatColl( pDelNd->GetTextColl() );
     789          52 :                 pTextNode->JoinNext();
     790          54 :             }
     791             :         }
     792             : 
     793         353 :         SwPosition* pPos = pPaM->GetPoint();
     794             :         OSL_ENSURE( !pPos->nContent.GetIndex(), "last paragraph isn't empty" );
     795         353 :         if( !pPos->nContent.GetIndex() )
     796             :         {
     797             :             SwTextNode* pCurrNd;
     798         353 :             sal_uLong nNodeIdx = pPos->nNode.GetIndex();
     799         353 :             pDoc = pPaM->GetDoc();
     800             : 
     801             :             OSL_ENSURE( pPos->nNode.GetNode().IsContentNode(),
     802             :                         "insert position is not a content node" );
     803         353 :             if( !IsInsertMode() )
     804             :             {
     805             :                 // If we're not in insert mode, the last node is deleted.
     806         299 :                 const SwNode *pPrev = pDoc->GetNodes()[nNodeIdx -1];
     807         599 :                 if( pPrev->IsContentNode() ||
     808           4 :                      ( pPrev->IsEndNode() &&
     809           2 :                       pPrev->StartOfSectionNode()->IsSectionNode() ) )
     810             :                 {
     811         298 :                     SwContentNode* pCNd = pPaM->GetContentNode();
     812         596 :                     if( pCNd && pCNd->StartOfSectionIndex()+2 <
     813         298 :                         pCNd->EndOfSectionIndex() )
     814             :                     {
     815         298 :                         pPaM->GetBound(true).nContent.Assign( 0, 0 );
     816         298 :                         pPaM->GetBound(false).nContent.Assign( 0, 0 );
     817         298 :                         pDoc->GetNodes().Delete( pPaM->GetPoint()->nNode );
     818             :                     }
     819             :                 }
     820             :             }
     821          54 :             else if( 0 != (pCurrNd = pDoc->GetNodes()[nNodeIdx]->GetTextNode()) )
     822             :             {
     823             :                 // Id we're in insert mode, the empty node is joined with
     824             :                 // the next and the previous one.
     825          54 :                 if( pCurrNd->CanJoinNext( &pPos->nNode ))
     826             :                 {
     827          54 :                     SwTextNode* pNextNd = pPos->nNode.GetNode().GetTextNode();
     828          54 :                     pPos->nContent.Assign( pNextNd, 0 );
     829          54 :                     pPaM->SetMark(); pPaM->DeleteMark();
     830          54 :                     pNextNd->JoinPrev();
     831             : 
     832             :                     // Remove line break that has been inserted by the import,
     833             :                     // but only if one has been inserted!
     834         108 :                     if( pNextNd->CanJoinPrev(/* &pPos->nNode*/ ) &&
     835          54 :                          *pSttNdIdx != pPos->nNode )
     836             :                     {
     837          54 :                         pNextNd->JoinPrev();
     838             :                     }
     839             :                 }
     840           0 :                 else if (pCurrNd->GetText().isEmpty())
     841             :                 {
     842           0 :                     pPos->nContent.Assign( 0, 0 );
     843           0 :                     pPaM->SetMark(); pPaM->DeleteMark();
     844           0 :                     pDoc->GetNodes().Delete( pPos->nNode, 1 );
     845           0 :                     pPaM->Move( fnMoveBackward );
     846             :                 }
     847             :             }
     848         353 :         }
     849             :     }
     850             : 
     851             :     /* Was called too early. Moved from SwXMLBodyContext_Impl::EndElement */
     852             : 
     853        1213 :     GetTextImport()->RedlineAdjustStartNodeCursor( false );
     854             : 
     855        5712 :     if( (getImportFlags() & SvXMLImportFlags::CONTENT) ||
     856        4435 :         ((getImportFlags() & SvXMLImportFlags::MASTERSTYLES) && IsStylesOnlyMode()) )
     857             :     {
     858             :         // pDoc might be 0. In this case UpdateTextCollCondition is looking
     859             :         // for it itself.
     860         353 :         UpdateTextCollConditions( pDoc );
     861             :     }
     862             : 
     863        1213 :     GetTextImport()->ResetCursor();
     864             : 
     865        1213 :     delete pSttNdIdx;
     866        1213 :     pSttNdIdx = 0;
     867             : 
     868             :     // SJ: #i49801# -> now permitting repaints
     869        1213 :     if ( pDoc )
     870             :     {
     871         353 :         if( (getImportFlags() == SvXMLImportFlags::ALL ) )
     872             :         {
     873             :             // Notify math objects. If we are in the package filter this will
     874             :             // be done by the filter object itself
     875          67 :             if( IsInsertMode() )
     876          54 :                 pDoc->PrtOLENotify( false );
     877          13 :             else if ( pDoc->IsOLEPrtNotifyPending() )
     878           0 :                 pDoc->PrtOLENotify( true );
     879             :         }
     880             : 
     881         353 :         SwDrawModel* pDrawModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
     882         353 :         if ( pDrawModel )
     883         353 :             pDrawModel->setLock(false);
     884             :     }
     885             : 
     886             :     // #i90243#
     887        1213 :     if ( bInititedXForms )
     888             :     {
     889           0 :         Reference< xforms::XFormsSupplier > xFormsSupp( GetModel(), UNO_QUERY );
     890           0 :         Reference< XNameAccess > xXForms;
     891           0 :         if ( xFormsSupp.is() )
     892           0 :             xXForms = xFormsSupp->getXForms().get();
     893             : 
     894           0 :         if ( xXForms.is() )
     895             :         {
     896             :             try
     897             :             {
     898           0 :                 Sequence< beans::PropertyValue > aXFormsSettings;
     899             : 
     900           0 :                 const OUString sXFormsSettingsName( GetXMLToken( XML_XFORM_MODEL_SETTINGS ) );
     901           0 :                 if ( xLateInitSettings.is() && xLateInitSettings->hasByName( sXFormsSettingsName ) )
     902             :                 {
     903           0 :                     OSL_VERIFY( xLateInitSettings->getByName( sXFormsSettingsName ) >>= aXFormsSettings );
     904           0 :                     applyXFormsSettings( xXForms, aXFormsSettings );
     905           0 :                 }
     906             :             }
     907           0 :             catch( const Exception& )
     908             :             {
     909             :             }
     910           0 :         }
     911             :     }
     912             : 
     913             :     // delegate to parent: takes care of error handling
     914        1213 :     SvXMLImport::endDocument();
     915        1213 :     ClearTextImport();
     916             : }
     917             : 
     918             : // Locally derive XMLTextShapeImportHelper, so we can take care of the
     919             : // form import This is Writer, but not text specific, so it should go
     920             : // here!
     921             : class SvTextShapeImportHelper : public XMLTextShapeImportHelper
     922             : {
     923             :     // hold own reference form import helper, because the SvxImport
     924             :     // stored in the superclass, from whom we originally got the
     925             :     // reference, is already destroyed when we want to use it in the
     926             :     // destructor
     927             :     rtl::Reference< ::xmloff::OFormLayerXMLImport > rFormImport;
     928             : 
     929             :     // hold reference to the one page (if it exists) for calling startPage()
     930             :     // and endPage. If !xPage.is(), then this document doesn't have a
     931             :     // XDrawPage.
     932             :     Reference<drawing::XDrawPage> xPage;
     933             : 
     934             : public:
     935             :     explicit SvTextShapeImportHelper(SvXMLImport& rImp);
     936             :     virtual ~SvTextShapeImportHelper();
     937             : };
     938             : 
     939         634 : SvTextShapeImportHelper::SvTextShapeImportHelper(SvXMLImport& rImp) :
     940         634 :     XMLTextShapeImportHelper(rImp)
     941             : {
     942         634 :     Reference<drawing::XDrawPageSupplier> xSupplier(rImp.GetModel(),UNO_QUERY);
     943         634 :     if (xSupplier.is())
     944             :     {
     945         634 :         if (rImp.GetFormImport().is())
     946             :         {
     947         634 :             rImp.GetFormImport()->startPage(xSupplier->getDrawPage());
     948         634 :             rFormImport = rImp.GetFormImport();
     949             :         }
     950             : 
     951         634 :         xPage  = xSupplier->getDrawPage();
     952         634 :         Reference<XShapes> xShapes( xPage, UNO_QUERY );
     953         634 :         XMLShapeImportHelper::startPage( xShapes );
     954         634 :     }
     955         634 : }
     956             : 
     957        1902 : SvTextShapeImportHelper::~SvTextShapeImportHelper()
     958             : {
     959         634 :     rFormImport->endPage();
     960             : 
     961         634 :     if (xPage.is())
     962             :     {
     963         634 :         Reference<XShapes> xShapes( xPage, UNO_QUERY );
     964         634 :         XMLShapeImportHelper::endPage(xShapes);
     965             :     }
     966        1268 : }
     967             : 
     968        1214 : XMLTextImportHelper* SwXMLImport::CreateTextImport()
     969             : {
     970        1214 :     return new SwXMLTextImportHelper( GetModel(), *this, getImportInfo(),
     971        1214 :                                       IsInsertMode(),
     972        1214 :                                       IsStylesOnlyMode(), bShowProgress,
     973        2428 :                                       IsBlockMode(), IsOrganizerMode(),
     974        6070 :                                       bPreserveRedlineMode );
     975             : }
     976             : 
     977         634 : XMLShapeImportHelper* SwXMLImport::CreateShapeImport()
     978             : {
     979         634 :     return new SvTextShapeImportHelper( *this );
     980             : }
     981             : 
     982         631 : SvXMLImportContext *SwXMLImport::CreateFontDeclsContext(
     983             :         const OUString& rLocalName,
     984             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     985             : {
     986             :     XMLFontStylesContext *pFSContext =
     987             :             new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
     988             :                                       rLocalName, xAttrList,
     989         631 :                                       osl_getThreadTextEncoding() );
     990         631 :     SetFontDecls( pFSContext );
     991         631 :     return pFSContext;
     992             : }
     993         284 : void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
     994             : {
     995         284 :     if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || IsOrganizerMode() || !GetModel().is() )
     996         284 :         return;
     997             : 
     998             :     // this method will modify the document directly -> lock SolarMutex
     999         284 :     SolarMutexGuard aGuard;
    1000             : 
    1001         284 :     SwDoc *pDoc = getDoc();
    1002         284 :     Rectangle aRect;
    1003         284 :     if( pDoc->GetDocShell() )
    1004         284 :         aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
    1005             :         //TODO/LATER: why that cast?!
    1006             :         //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea();
    1007             : 
    1008         284 :     sal_Int32 nCount = aViewProps.getLength();
    1009         284 :     const PropertyValue *pValue = aViewProps.getConstArray();
    1010             : 
    1011         284 :     sal_Int64 nTmp = 0;
    1012         284 :     bool bShowRedlineChanges = false, bBrowseMode = false;
    1013         284 :     bool bChangeShowRedline = false, bChangeBrowseMode = false;
    1014             : 
    1015             :     //TODO/LATER: why that cast?!
    1016         284 :     bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
    1017             :     //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MAP_TWIP;
    1018             : 
    1019        2245 :     for (sal_Int32 i = 0; i < nCount ; i++)
    1020             :     {
    1021        1961 :         if ( pValue->Name == "ViewAreaTop" )
    1022             :         {
    1023         284 :             pValue->Value >>= nTmp;
    1024         284 :             aRect.setY( static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp) );
    1025             :         }
    1026        1677 :         else if ( pValue->Name == "ViewAreaLeft" )
    1027             :         {
    1028         284 :             pValue->Value >>= nTmp;
    1029         284 :             aRect.setX( static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp) );
    1030             :         }
    1031        1393 :         else if ( pValue->Name == "ViewAreaWidth" )
    1032             :         {
    1033         284 :             pValue->Value >>= nTmp;
    1034         284 :             Size aSize( aRect.GetSize() );
    1035         284 :             aSize.Width() = static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp);
    1036         284 :             aRect.SetSize( aSize );
    1037             :         }
    1038        1109 :         else if ( pValue->Name == "ViewAreaHeight" )
    1039             :         {
    1040         284 :             pValue->Value >>= nTmp;
    1041         284 :             Size aSize( aRect.GetSize() );
    1042         284 :             aSize.Height() = static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp);
    1043         284 :             aRect.SetSize( aSize );
    1044             :         }
    1045         825 :         else if ( pValue->Name == "ShowRedlineChanges" )
    1046             :         {
    1047         284 :             bShowRedlineChanges = *static_cast<sal_Bool const *>(pValue->Value.getValue());
    1048         284 :             bChangeShowRedline = true;
    1049             :         }
    1050             : // Headers and footers are not displayed in BrowseView anymore
    1051         541 :         else if ( pValue->Name == "InBrowseMode" )
    1052             :         {
    1053         284 :             bBrowseMode = *static_cast<sal_Bool const *>(pValue->Value.getValue());
    1054         284 :             bChangeBrowseMode = true;
    1055             :         }
    1056        1961 :         pValue++;
    1057             :     }
    1058         284 :     if( pDoc->GetDocShell() )
    1059         284 :         pDoc->GetDocShell()->SetVisArea ( aRect );
    1060             : 
    1061         284 :     if (bChangeBrowseMode)
    1062         284 :         pDoc->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, bBrowseMode );
    1063             : 
    1064         284 :     if (bChangeShowRedline)
    1065         284 :         GetTextImport()->SetShowChanges( bShowRedlineChanges );
    1066             : }
    1067             : 
    1068             : // Note: this will be called only if there are OOo elements in settings.xml.
    1069             : // So if a setting is missing there we can assume that it was written
    1070             : // by an OOo/LO version that is older than the introduction of the setting!
    1071         285 : void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aConfigProps)
    1072             : {
    1073             :     // this method will modify the document directly -> lock SolarMutex
    1074         285 :     SolarMutexGuard aGuard;
    1075             : 
    1076         570 :     Reference< lang::XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
    1077         285 :     if( !xFac.is() )
    1078           0 :         return;
    1079             : 
    1080         570 :     Reference< XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY );
    1081         285 :     if( !xProps.is() )
    1082           0 :         return;
    1083             : 
    1084         570 :     Reference< XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
    1085         285 :     if( !xInfo.is() )
    1086           0 :         return;
    1087             : 
    1088         570 :     std::unordered_set< OUString, OUStringHash > aSet;
    1089         285 :     aSet.insert("ForbiddenCharacters");
    1090         285 :     aSet.insert("IsKernAsianPunctuation");
    1091         285 :     aSet.insert("CharacterCompressionType");
    1092         285 :     aSet.insert("LinkUpdateMode");
    1093         285 :     aSet.insert("FieldAutoUpdate");
    1094         285 :     aSet.insert("ChartAutoUpdate");
    1095         285 :     aSet.insert("AddParaTableSpacing");
    1096         285 :     aSet.insert("AddParaTableSpacingAtStart");
    1097         285 :     aSet.insert("PrintAnnotationMode");
    1098         285 :     aSet.insert("PrintBlackFonts");
    1099         285 :     aSet.insert("PrintControls");
    1100         285 :     aSet.insert("PrintDrawings");
    1101         285 :     aSet.insert("PrintGraphics");
    1102         285 :     aSet.insert("PrintLeftPages");
    1103         285 :     aSet.insert("PrintPageBackground");
    1104         285 :     aSet.insert("PrintProspect");
    1105         285 :     aSet.insert("PrintReversed");
    1106         285 :     aSet.insert("PrintRightPages");
    1107         285 :     aSet.insert("PrintFaxName");
    1108         285 :     aSet.insert("PrintPaperFromSetup");
    1109         285 :     aSet.insert("PrintTables");
    1110         285 :     aSet.insert("PrintSingleJobs");
    1111         285 :     aSet.insert("UpdateFromTemplate");
    1112         285 :     aSet.insert("PrinterIndependentLayout");
    1113         285 :     aSet.insert("PrintEmptyPages");
    1114         285 :     aSet.insert("SmallCapsPercentage66");
    1115         285 :     aSet.insert("TabOverflow");
    1116         285 :     aSet.insert("UnbreakableNumberings");
    1117         285 :     aSet.insert("ClippedPictures");
    1118         285 :     aSet.insert("BackgroundParaOverDrawings");
    1119         285 :     aSet.insert("TabOverMargin");
    1120         285 :     aSet.insert("PropLineSpacingShrinksFirstLine");
    1121         285 :     aSet.insert("SubtractFlysAnchoredAtFlys");
    1122             : 
    1123         285 :     sal_Int32 nCount = aConfigProps.getLength();
    1124         285 :     const PropertyValue* pValues = aConfigProps.getConstArray();
    1125             : 
    1126         570 :     SvtSaveOptions aSaveOpt;
    1127         285 :     bool bIsUserSetting = aSaveOpt.IsLoadUserSettings(),
    1128         285 :          bSet = bIsUserSetting;
    1129             : 
    1130             :     // for some properties we don't want to use the application
    1131             :     // default if they're missing. So we watch for them in the loop
    1132             :     // below, and set them if not found
    1133         285 :     bool bPrinterIndependentLayout = false;
    1134         285 :     bool bUseOldNumbering = false;
    1135         285 :     bool bOutlineLevelYieldsOutlineRule = false;
    1136         285 :     bool bAddExternalLeading = false;
    1137         285 :     bool bAddParaSpacingToTableCells = false;
    1138         285 :     bool bUseFormerLineSpacing = false;
    1139         285 :     bool bUseFormerObjectPositioning = false;
    1140         285 :     bool bUseFormerTextWrapping = false;
    1141         285 :     bool bConsiderWrapOnObjPos = false;
    1142         285 :     bool bIgnoreFirstLineIndentInNumbering = false;
    1143         285 :     bool bDoNotJustifyLinesWithManualBreak = false;
    1144         285 :     bool bDoNotResetParaAttrsForNumFont    = false;
    1145         285 :     bool bLoadReadonly = false;
    1146         285 :     bool bDoNotCaptureDrawObjsOnPage( false );
    1147         285 :     bool bClipAsCharacterAnchoredWriterFlyFrames( false );
    1148         285 :     bool bUnixForceZeroExtLeading = false;
    1149         285 :     bool bUseOldPrinterMetrics = false;
    1150         285 :     bool bSmallCapsPercentage66 = false;
    1151         285 :     bool bTabOverflow = false;
    1152         285 :     bool bUnbreakableNumberings = false;
    1153         285 :     bool bClippedPictures = false;
    1154         285 :     bool bBackgroundParaOverDrawings = false;
    1155         285 :     bool bTabOverMargin = false;
    1156         285 :     bool bPropLineSpacingShrinksFirstLine = false;
    1157         285 :     bool bSubtractFlysAnchoredAtFlys = false;
    1158             : 
    1159         285 :     const PropertyValue* currentDatabaseDataSource = NULL;
    1160         285 :     const PropertyValue* currentDatabaseCommand = NULL;
    1161         285 :     const PropertyValue* currentDatabaseCommandType = NULL;
    1162         285 :     const PropertyValue* embeddedDatabaseName = 0;
    1163             : 
    1164       22270 :     while( nCount-- )
    1165             :     {
    1166       21700 :         if( !bIsUserSetting )
    1167             :         {
    1168             :             // test over the hash value if the entry is in the table.
    1169           0 :             bSet = aSet.find(pValues->Name) == aSet.end();
    1170             :         }
    1171             : 
    1172       21700 :         if( bSet )
    1173             :         {
    1174             :             try
    1175             :             {
    1176       21700 :                 if( xInfo->hasPropertyByName( pValues->Name ) )
    1177             :                 {
    1178       21699 :                     if( pValues->Name == "RedlineProtectionKey" )
    1179             :                     {
    1180         282 :                         Sequence<sal_Int8> aKey;
    1181         282 :                         pValues->Value >>= aKey;
    1182         282 :                         GetTextImport()->SetChangesProtectionKey( aKey );
    1183             :                     }
    1184             :                     else
    1185             :                     {
    1186             :                         // HACK: Setting these out of order does not work.
    1187       21417 :                         if( pValues->Name == "CurrentDatabaseDataSource" )
    1188         284 :                             currentDatabaseDataSource = pValues;
    1189       21133 :                         else if( pValues->Name == "CurrentDatabaseCommand" )
    1190         284 :                             currentDatabaseCommand = pValues;
    1191       20849 :                         else if( pValues->Name == "CurrentDatabaseCommandType" )
    1192         284 :                             currentDatabaseCommandType = pValues;
    1193       20565 :                         else if (pValues->Name == "EmbeddedDatabaseName")
    1194          67 :                             embeddedDatabaseName = pValues;
    1195             :                         else
    1196       20498 :                             xProps->setPropertyValue( pValues->Name,
    1197       20498 :                                                   pValues->Value );
    1198             :                     }
    1199             :                 }
    1200             : 
    1201             :                 // did we find any of the non-default cases?
    1202       21700 :                 if ( pValues->Name == "PrinterIndependentLayout" )
    1203         284 :                     bPrinterIndependentLayout = true;
    1204       21416 :                 else if ( pValues->Name == "AddExternalLeading" )
    1205         282 :                     bAddExternalLeading = true;
    1206       21134 :                 else if ( pValues->Name == "AddParaSpacingToTableCells" )
    1207         282 :                     bAddParaSpacingToTableCells = true;
    1208       20852 :                 else if ( pValues->Name == "UseFormerLineSpacing" )
    1209         282 :                     bUseFormerLineSpacing = true;
    1210       20570 :                 else if ( pValues->Name == "UseFormerObjectPositioning" )
    1211         282 :                     bUseFormerObjectPositioning = true;
    1212       20288 :                 else if ( pValues->Name == "UseFormerTextWrapping" )
    1213         282 :                     bUseFormerTextWrapping = true;
    1214       20006 :                 else if ( pValues->Name == "UseOldNumbering" )
    1215         284 :                     bUseOldNumbering = true;
    1216       19722 :                 else if ( pValues->Name == "OutlineLevelYieldsNumbering" )
    1217         282 :                     bOutlineLevelYieldsOutlineRule = true;
    1218       19440 :                 else if ( pValues->Name == "ConsiderTextWrapOnObjPos" )
    1219         282 :                     bConsiderWrapOnObjPos = true;
    1220       19158 :                 else if ( pValues->Name == "IgnoreFirstLineIndentInNumbering" )
    1221         282 :                     bIgnoreFirstLineIndentInNumbering = true;
    1222       18876 :                 else if ( pValues->Name == "DoNotJustifyLinesWithManualBreak" )
    1223         282 :                     bDoNotJustifyLinesWithManualBreak = true;
    1224       18594 :                 else if ( pValues->Name == "DoNotResetParaAttrsForNumFont" )
    1225         282 :                     bDoNotResetParaAttrsForNumFont = true;
    1226       18312 :                 else if ( pValues->Name == "LoadReadonly" )
    1227         282 :                     bLoadReadonly = true;
    1228       18030 :                 else if ( pValues->Name == "DoNotCaptureDrawObjsOnPage" )
    1229         282 :                     bDoNotCaptureDrawObjsOnPage = true;
    1230       17748 :                 else if ( pValues->Name == "ClipAsCharacterAnchoredWriterFlyFrames" )
    1231         282 :                     bClipAsCharacterAnchoredWriterFlyFrames = true;
    1232       17466 :                 else if ( pValues->Name == "UnxForceZeroExtLeading" )
    1233         281 :                     bUnixForceZeroExtLeading = true;
    1234       17185 :                 else if ( pValues->Name == "UseOldPrinterMetrics" )
    1235         280 :                     bUseOldPrinterMetrics = true;
    1236       16905 :                 else if ( pValues->Name == "SmallCapsPercentage66" )
    1237         262 :                     bSmallCapsPercentage66 = true;
    1238       16643 :                 else if ( pValues->Name == "TabOverflow" )
    1239         261 :                     bTabOverflow = true;
    1240       16382 :                 else if ( pValues->Name == "UnbreakableNumberings" )
    1241         261 :                     bUnbreakableNumberings = true;
    1242       16121 :                 else if ( pValues->Name == "ClippedPictures" )
    1243         246 :                     bClippedPictures = true;
    1244       15875 :                 else if ( pValues->Name == "BackgroundParaOverDrawings" )
    1245         246 :                     bBackgroundParaOverDrawings = true;
    1246       15629 :                 else if ( pValues->Name == "TabOverMargin" )
    1247         238 :                     bTabOverMargin = true;
    1248       15391 :                 else if ( pValues->Name == "PropLineSpacingShrinksFirstLine" )
    1249         118 :                     bPropLineSpacingShrinksFirstLine = true;
    1250       15273 :                 else if (pValues->Name == "SubtractFlysAnchoredAtFlys")
    1251          82 :                     bSubtractFlysAnchoredAtFlys = true;
    1252             :             }
    1253           0 :             catch( Exception& )
    1254             :             {
    1255             :                 OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
    1256             :             }
    1257             :         }
    1258       21700 :         pValues++;
    1259             :     }
    1260             : 
    1261             :     try
    1262             :     {
    1263         285 :         if( currentDatabaseDataSource != NULL )
    1264         284 :             xProps->setPropertyValue( currentDatabaseDataSource->Name, currentDatabaseDataSource->Value );
    1265         285 :         if( currentDatabaseCommand != NULL )
    1266         284 :             xProps->setPropertyValue( currentDatabaseCommand->Name, currentDatabaseCommand->Value );
    1267         285 :         if( currentDatabaseCommandType != NULL )
    1268         284 :             xProps->setPropertyValue( currentDatabaseCommandType->Name, currentDatabaseCommandType->Value );
    1269         285 :         if (embeddedDatabaseName)
    1270          67 :             xProps->setPropertyValue(embeddedDatabaseName->Name, embeddedDatabaseName->Value);
    1271           0 :     } catch( Exception& )
    1272             :     {
    1273             :         OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
    1274             :     }
    1275             : 
    1276             :     // finally, treat the non-default cases
    1277             :     // introduce boolean, that indicates a document, written by version prior SO8.
    1278         285 :     const bool bDocumentPriorSO8 = !bConsiderWrapOnObjPos;
    1279             : 
    1280         285 :     if( ! bPrinterIndependentLayout )
    1281             :     {
    1282           1 :         Any aAny;
    1283           1 :         sal_Int16 nTmp = document::PrinterIndependentLayout::DISABLED;
    1284           1 :         aAny <<= nTmp;
    1285           1 :         xProps->setPropertyValue( "PrinterIndependentLayout", aAny );
    1286             :     }
    1287             : 
    1288         285 :     if( ! bAddExternalLeading )
    1289             :     {
    1290           3 :         xProps->setPropertyValue( "AddExternalLeading", makeAny( false ) );
    1291             :     }
    1292             : 
    1293         285 :     if( ! bUseFormerLineSpacing )
    1294             :     {
    1295           3 :         xProps->setPropertyValue( "UseFormerLineSpacing", makeAny( true ) );
    1296             :     }
    1297             : 
    1298         285 :     if( !bUseFormerObjectPositioning )
    1299             :     {
    1300           3 :         xProps->setPropertyValue( "UseFormerObjectPositioning", makeAny( true ) );
    1301             :     }
    1302             : 
    1303         285 :     if( !bUseOldNumbering )
    1304             :     {
    1305           1 :         xProps->setPropertyValue( "UseOldNumbering", makeAny(true) );
    1306             :     }
    1307             : 
    1308         285 :     if( !bOutlineLevelYieldsOutlineRule )
    1309             :     {
    1310           3 :         xProps->setPropertyValue( "OutlineLevelYieldsNumbering", makeAny(true) );
    1311             :     }
    1312             : 
    1313         285 :     if( !bAddParaSpacingToTableCells )
    1314             :     {
    1315           3 :         xProps->setPropertyValue( "AddParaSpacingToTableCells",
    1316           3 :             makeAny( false ) );
    1317             :     }
    1318             : 
    1319         285 :     if( !bUseFormerTextWrapping )
    1320             :     {
    1321           3 :         xProps->setPropertyValue( "UseFormerTextWrapping", makeAny( true ) );
    1322             :     }
    1323             : 
    1324         285 :     if( !bConsiderWrapOnObjPos )
    1325             :     {
    1326           3 :         xProps->setPropertyValue( "ConsiderTextWrapOnObjPos", makeAny( false ) );
    1327             :     }
    1328             : 
    1329             :     // #i47448#
    1330             :     // For SO7pp4, part of the 'new numbering' stuff has been backported from
    1331             :     // SO8. Unfortunately, only part of it and by using the same compatibility option
    1332             :     // like in SO8. Therefore documents generated with SO7pp4, containing
    1333             :     // numbered paragraphs with first line indent differ between SO7pp4 and
    1334             :     // SO8. In order to fix this for SO8pp1, I introduce a new compatibility
    1335             :     // flag 'bIgnoreFirstLineIndentInNumbering'. This flag has to be set for all
    1336             :     // documents < SO8, but not for SO8. So if the property is not present, the
    1337             :     // flag will be set to 'true'. SO8 documents surely have the
    1338             :     // 'ConsiderWrapOnObjPos' property set (no matter if 'true' or 'false'),
    1339             :     // therefore the correct condition to set this flag is this:
    1340         285 :     if( !bIgnoreFirstLineIndentInNumbering && bDocumentPriorSO8 )
    1341             :     {
    1342           3 :         xProps->setPropertyValue( "IgnoreFirstLineIndentInNumbering",
    1343           3 :             makeAny( true ) );
    1344             :     }
    1345             : 
    1346             :     // This flag has to be set for all documents < SO8
    1347         285 :     if ( !bDoNotJustifyLinesWithManualBreak && bDocumentPriorSO8 )
    1348             :     {
    1349           3 :         xProps->setPropertyValue( "DoNotJustifyLinesWithManualBreak",
    1350           3 :             makeAny( true ) );
    1351             :     }
    1352             : 
    1353             :     // This flag has to be set for all documents < SO8
    1354         285 :     if ( !bDoNotResetParaAttrsForNumFont && bDocumentPriorSO8 )
    1355             :     {
    1356           3 :         xProps->setPropertyValue( "DoNotResetParaAttrsForNumFont",
    1357           3 :             makeAny( true ) );
    1358             :     }
    1359             : 
    1360         285 :     if ( !bLoadReadonly )
    1361             :     {
    1362           3 :         xProps->setPropertyValue( "LoadReadonly", makeAny( false ) );
    1363             :     }
    1364             : 
    1365             :     // This flag has to be set for all documents < SO8
    1366         285 :     if ( !bDoNotCaptureDrawObjsOnPage && bDocumentPriorSO8 )
    1367             :     {
    1368           3 :         xProps->setPropertyValue( "DoNotCaptureDrawObjsOnPage",
    1369           3 :             makeAny( true ) );
    1370             :     }
    1371             : 
    1372             :     // This flag has to be set for all documents < SO8
    1373         285 :     if ( !bClipAsCharacterAnchoredWriterFlyFrames && bDocumentPriorSO8 )
    1374             :     {
    1375           3 :         xProps->setPropertyValue( "ClipAsCharacterAnchoredWriterFlyFrames",
    1376           3 :             makeAny( true ) );
    1377             :     }
    1378             : 
    1379         285 :     if ( !bUnixForceZeroExtLeading )
    1380             :     {
    1381           4 :         xProps->setPropertyValue(
    1382           4 :             OUString("UnxForceZeroExtLeading"), makeAny( true ) );
    1383             :     }
    1384             : 
    1385         285 :     if ( !bUseOldPrinterMetrics )
    1386             :     {
    1387           5 :         xProps->setPropertyValue(
    1388           5 :             OUString("UseOldPrinterMetrics"), makeAny( true ) );
    1389             :     }
    1390             : 
    1391             :     // Old LO versions had 66 as the value for small caps percentage, later changed to 80.
    1392             :     // In order to keep backwards compatibility, SmallCapsPercentage66 option is written to .odt
    1393             :     // files, and the default for new documents is 'false'. Files without this option
    1394             :     // are considered to be old files, so set the compatibility option too.
    1395         285 :     if ( !bSmallCapsPercentage66 )
    1396             :     {
    1397          23 :         xProps->setPropertyValue(
    1398          23 :             OUString("SmallCapsPercentage66"), makeAny( true ) );
    1399             :     }
    1400             : 
    1401         285 :     if ( !bTabOverflow )
    1402             :     {
    1403          24 :         xProps->setPropertyValue(
    1404          24 :             OUString("TabOverflow"), makeAny( false ) );
    1405             :     }
    1406             : 
    1407         285 :     if ( !bUnbreakableNumberings )
    1408             :     {
    1409          24 :         xProps->setPropertyValue( "UnbreakableNumberings", makeAny( false ) );
    1410             :     }
    1411             : 
    1412         285 :     if ( !bClippedPictures )
    1413             :     {
    1414          39 :         xProps->setPropertyValue( "ClippedPictures", makeAny( false ) );
    1415             :     }
    1416             : 
    1417         285 :     if ( !bBackgroundParaOverDrawings )
    1418          39 :         xProps->setPropertyValue("BackgroundParaOverDrawings", makeAny( false ) );
    1419             : 
    1420         285 :     if ( !bTabOverMargin )
    1421          47 :         xProps->setPropertyValue("TabOverMargin", makeAny( false ) );
    1422             : 
    1423         285 :     if (!bPropLineSpacingShrinksFirstLine)
    1424         167 :         xProps->setPropertyValue("PropLineSpacingShrinksFirstLine", makeAny(false));
    1425             : 
    1426         285 :     if (!bSubtractFlysAnchoredAtFlys)
    1427         203 :         xProps->setPropertyValue("SubtractFlysAnchoredAtFlys", makeAny(true));
    1428             : 
    1429         285 :     SwDoc *pDoc = getDoc();
    1430         285 :     SfxPrinter *pPrinter = pDoc->getIDocumentDeviceAccess().getPrinter( false );
    1431         285 :     if( pPrinter )
    1432             :     {
    1433             :         // If the printer is known, then the OLE objects will
    1434             :         // already have correct sizes, and we don't have to call
    1435             :         // PrtOLENotify again. Otherwise we have to call it.
    1436             :         // The flag might be set from setting the printer, so it
    1437             :         // it is required to clear it.
    1438          23 :         pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
    1439         285 :     }
    1440             : }
    1441             : 
    1442           0 : void SwXMLImport::SetDocumentSpecificSettings(
    1443             :     const OUString& _rSettingsGroupName,
    1444             :     const Sequence< PropertyValue>& _rSettings )
    1445             : {
    1446             :     // the only doc-specific settings group we know so far are the XForms settings
    1447           0 :     if ( !IsXMLToken( _rSettingsGroupName, XML_XFORM_MODEL_SETTINGS ) )
    1448           0 :         return;
    1449             : 
    1450             :     // preserve the settings for a later iteration - we are currently reading the settings.xml,
    1451             :     // the content.xml will be read later, by another instance of SwXMLImport
    1452             :     OSL_ENSURE( xLateInitSettings.is(), "SwXMLImport::SetDocumentSpecificSettings: no storage for those settings!" );
    1453           0 :     if ( !xLateInitSettings.is() )
    1454           0 :         return;
    1455             : 
    1456             :     try
    1457             :     {
    1458           0 :         if ( xLateInitSettings->hasByName( _rSettingsGroupName ) )
    1459             :         {
    1460           0 :             xLateInitSettings->replaceByName( _rSettingsGroupName, makeAny( _rSettings ) );
    1461             :             OSL_FAIL( "SwXMLImport::SetDocumentSpecificSettings: already have settings for this model!" );
    1462             :         }
    1463             :         else
    1464           0 :             xLateInitSettings->insertByName( _rSettingsGroupName, makeAny( _rSettings ) );
    1465             :     }
    1466           0 :     catch( const Exception& )
    1467             :     {
    1468             :     }
    1469             : }
    1470             : 
    1471        1167 : void SwXMLImport::initialize(
    1472             :     const Sequence<Any>& aArguments )
    1473             :     throw( uno::Exception, uno::RuntimeException, std::exception)
    1474             : {
    1475             :     // delegate to super class
    1476        1167 :     SvXMLImport::initialize(aArguments);
    1477             : 
    1478             :     // we are only looking for a PropertyValue "PreserveRedlineMode"
    1479        1167 :     sal_Int32 nLength = aArguments.getLength();
    1480        6342 :     for(sal_Int32 i = 0; i < nLength; i++)
    1481             :     {
    1482        5175 :         beans::PropertyValue aValue;
    1483        5175 :         if ( aArguments[i] >>= aValue )
    1484             :         {
    1485           0 :             if (aValue.Name == "PreserveRedlineMode")
    1486             :             {
    1487           0 :                 OSL_VERIFY( aValue.Value >>= bPreserveRedlineMode );
    1488             :             }
    1489           0 :             continue;
    1490             :         }
    1491             : 
    1492       10350 :         beans::NamedValue aNamedValue;
    1493        5175 :         if ( aArguments[i] >>= aNamedValue )
    1494             :         {
    1495         861 :             if (aNamedValue.Name == "LateInitSettings")
    1496             :             {
    1497         861 :                 OSL_VERIFY( aNamedValue.Value >>= xLateInitSettings );
    1498             :             }
    1499             :         }
    1500        5175 :     }
    1501        1167 : }
    1502             : 
    1503        2166 : SwDoc* SwImport::GetDocFromXMLImport( SvXMLImport& rImport )
    1504             : {
    1505        2166 :     uno::Reference<lang::XUnoTunnel> xModelTunnel( rImport.GetModel(), uno::UNO_QUERY );
    1506             :     SwXTextDocument *pTextDoc = reinterpret_cast< SwXTextDocument *>(
    1507        2166 :             sal::static_int_cast< sal_IntPtr >(  xModelTunnel->getSomething(SwXTextDocument::getUnoTunnelId() )));
    1508             :     assert( pTextDoc );
    1509             :     assert( pTextDoc->GetDocShell() );
    1510        2166 :     SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
    1511             :     OSL_ENSURE( pDoc, "Where is my document?" );
    1512        2166 :     return pDoc;
    1513             : }
    1514             : 
    1515           0 : void SwXMLImport::initXForms()
    1516             : {
    1517             :     // obtain SwDoc
    1518           0 :     Reference<XUnoTunnel> xDocTunnel( GetModel(), UNO_QUERY );
    1519           0 :     if( ! xDocTunnel.is() )
    1520           0 :         return;
    1521             :     SwXTextDocument* pXTextDocument = reinterpret_cast<SwXTextDocument*>(
    1522           0 :         xDocTunnel->getSomething( SwXTextDocument::getUnoTunnelId() ) );
    1523           0 :     if( pXTextDocument == NULL )
    1524           0 :         return;
    1525             : 
    1526           0 :     SwDoc *pDoc = pXTextDocument->GetDocShell()->GetDoc();
    1527             : 
    1528             :     // init XForms (if not already done)
    1529             :     // (no default model, since we'll load the models)
    1530           0 :     if( ! pDoc->isXForms() )
    1531           0 :         pDoc->initXForms( false );
    1532             : 
    1533           0 :     bInititedXForms = true;
    1534             : }
    1535             : 
    1536         569 : SwDoc* SwXMLImport::getDoc()
    1537             : {
    1538         569 :     if( doc != NULL )
    1539         284 :         return doc;
    1540         285 :     Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
    1541         570 :     Reference < XText > xText = xTextDoc->getText();
    1542         570 :     Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
    1543             :     assert( xTextTunnel.is());
    1544             :     SwXText *pText = reinterpret_cast< SwXText *>(
    1545         285 :             sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
    1546             :     assert( pText != NULL );
    1547         285 :     doc = pText->GetDoc();
    1548             :     assert( doc != NULL );
    1549         570 :     return doc;
    1550             : }
    1551             : 
    1552           0 : const SwDoc* SwXMLImport::getDoc() const
    1553             : {
    1554           0 :     return const_cast< SwXMLImport* >( this )->getDoc();
    1555             : }
    1556             : 
    1557             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
    1558          69 : com_sun_star_comp_Writer_XMLOasisImporter_get_implementation(::com::sun::star::uno::XComponentContext* context,
    1559             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
    1560             : {
    1561             :     return cppu::acquire(new SwXMLImport(context, OUString("com.sun.star.comp.Writer.XMLOasisImporter"),
    1562          69 :                 SvXMLImportFlags::ALL));
    1563             : }
    1564             : 
    1565             : 
    1566             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
    1567         290 : com_sun_star_comp_Writer_XMLOasisStylesImporter_get_implementation(::com::sun::star::uno::XComponentContext* context,
    1568             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
    1569             : {
    1570             :     return cppu::acquire(new SwXMLImport(context, OUString("com.sun.star.comp.Writer.XMLOasisStylesImporter"),
    1571         580 :                 SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES |
    1572         870 :                 SvXMLImportFlags::FONTDECLS));
    1573             : }
    1574             : 
    1575             : 
    1576             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
    1577         286 : com_sun_star_comp_Writer_XMLOasisContentImporter_get_implementation(::com::sun::star::uno::XComponentContext* context,
    1578             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
    1579             : {
    1580             :     return cppu::acquire(new SwXMLImport(context, OUString("com.sun.star.comp.Writer.XMLOasisContentImporter"),
    1581         572 :                 SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS | SvXMLImportFlags::AUTOSTYLES |
    1582         858 :                 SvXMLImportFlags::FONTDECLS));
    1583             : }
    1584             : 
    1585             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
    1586         288 : com_sun_star_comp_Writer_XMLOasisMetaImporter_get_implementation(::com::sun::star::uno::XComponentContext* context,
    1587             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
    1588             : {
    1589             :     return cppu::acquire(new SwXMLImport(context, OUString("com.sun.star.comp.Writer.XMLOasisMetaImporter"),
    1590         288 :                 SvXMLImportFlags::META));
    1591             : }
    1592             : 
    1593             : 
    1594             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
    1595         287 : com_sun_star_comp_Writer_XMLOasisSettingsImporter_get_implementation(::com::sun::star::uno::XComponentContext* context,
    1596             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
    1597             : {
    1598             :     return cppu::acquire(new SwXMLImport(context, OUString("com.sun.star.comp.Writer.XMLOasisSettingsImporter"),
    1599         287 :                 SvXMLImportFlags::SETTINGS));
    1600         177 : }
    1601             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11