LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmlimp.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 618 738 83.7 %
Date: 2014-11-03 Functions: 58 89 65.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10