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

Generated by: LCOV version 1.10