1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "dbmm_global.hrc" 32*cdf0e10cSrcweir #include "dbmm_module.hxx" 33*cdf0e10cSrcweir #include "dbmm_types.hxx" 34*cdf0e10cSrcweir #include "docinteraction.hxx" 35*cdf0e10cSrcweir #include "migrationengine.hxx" 36*cdf0e10cSrcweir #include "migrationerror.hxx" 37*cdf0e10cSrcweir #include "migrationprogress.hxx" 38*cdf0e10cSrcweir #include "migrationlog.hxx" 39*cdf0e10cSrcweir #include "progresscapture.hxx" 40*cdf0e10cSrcweir #include "progressmixer.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /** === begin UNO includes === **/ 43*cdf0e10cSrcweir #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/embed/XComponentSupplier.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/document/XStorageBasedDocument.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/uri/UriReferenceFactory.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/form/XFormsSupplier.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/script/XEventAttacherManager.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainerPassword.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/io/WrongFormatException.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/script/XScriptEventsSupplier.hpp> 69*cdf0e10cSrcweir #include <com/sun/star/io/XInputStreamProvider.hpp> 70*cdf0e10cSrcweir /** === end UNO includes === **/ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #include <comphelper/documentinfo.hxx> 73*cdf0e10cSrcweir #include <comphelper/interaction.hxx> 74*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 75*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 76*cdf0e10cSrcweir #include <comphelper/string.hxx> 77*cdf0e10cSrcweir #include <comphelper/types.hxx> 78*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 79*cdf0e10cSrcweir #include <tools/string.hxx> 80*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 81*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 82*cdf0e10cSrcweir #include <rtl/ref.hxx> 83*cdf0e10cSrcweir #include <unotools/sharedunocomponent.hxx> 84*cdf0e10cSrcweir #include <xmlscript/xmldlg_imexp.hxx> 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir #include <vector> 87*cdf0e10cSrcweir #include <set> 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir #define DEFAULT_DOC_PROGRESS_RANGE 100000 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //........................................................................ 92*cdf0e10cSrcweir namespace dbmm 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir //........................................................................ 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /** === begin UNO using === **/ 97*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 98*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 99*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 100*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 101*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 102*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 103*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 104*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 105*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 106*cdf0e10cSrcweir using ::com::sun::star::sdb::XOfficeDatabaseDocument; 107*cdf0e10cSrcweir using ::com::sun::star::sdb::XFormDocumentsSupplier; 108*cdf0e10cSrcweir using ::com::sun::star::sdb::XReportDocumentsSupplier; 109*cdf0e10cSrcweir using ::com::sun::star::container::XNameAccess; 110*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 111*cdf0e10cSrcweir using ::com::sun::star::util::XCloseable; 112*cdf0e10cSrcweir using ::com::sun::star::util::CloseVetoException; 113*cdf0e10cSrcweir using ::com::sun::star::lang::XComponent; 114*cdf0e10cSrcweir using ::com::sun::star::frame::XModel; 115*cdf0e10cSrcweir using ::com::sun::star::frame::XComponentLoader; 116*cdf0e10cSrcweir using ::com::sun::star::ucb::XCommandProcessor; 117*cdf0e10cSrcweir using ::com::sun::star::ucb::XContent; 118*cdf0e10cSrcweir using ::com::sun::star::ucb::Command; 119*cdf0e10cSrcweir using ::com::sun::star::embed::XComponentSupplier; 120*cdf0e10cSrcweir using ::com::sun::star::task::XStatusIndicator; 121*cdf0e10cSrcweir using ::com::sun::star::embed::XStorage; 122*cdf0e10cSrcweir using ::com::sun::star::document::XStorageBasedDocument; 123*cdf0e10cSrcweir using ::com::sun::star::embed::XTransactedObject; 124*cdf0e10cSrcweir using ::com::sun::star::frame::XStorable; 125*cdf0e10cSrcweir using ::com::sun::star::embed::XEmbedPersist; 126*cdf0e10cSrcweir using ::com::sun::star::script::DocumentDialogLibraryContainer; 127*cdf0e10cSrcweir using ::com::sun::star::script::DocumentScriptLibraryContainer; 128*cdf0e10cSrcweir using ::com::sun::star::script::XStorageBasedLibraryContainer; 129*cdf0e10cSrcweir using ::com::sun::star::document::XEmbeddedScripts; 130*cdf0e10cSrcweir using ::com::sun::star::container::XNameContainer; 131*cdf0e10cSrcweir using ::com::sun::star::document::XEventsSupplier; 132*cdf0e10cSrcweir using ::com::sun::star::container::XNameReplace; 133*cdf0e10cSrcweir using com::sun::star::uri::UriReferenceFactory; 134*cdf0e10cSrcweir using com::sun::star::uri::XUriReferenceFactory; 135*cdf0e10cSrcweir using com::sun::star::uri::XVndSunStarScriptUrlReference; 136*cdf0e10cSrcweir using ::com::sun::star::form::XFormsSupplier; 137*cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPageSupplier; 138*cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPagesSupplier; 139*cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPage; 140*cdf0e10cSrcweir using ::com::sun::star::drawing::XDrawPages; 141*cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess; 142*cdf0e10cSrcweir using ::com::sun::star::script::XEventAttacherManager; 143*cdf0e10cSrcweir using ::com::sun::star::script::ScriptEventDescriptor; 144*cdf0e10cSrcweir using ::com::sun::star::script::XLibraryContainerPassword; 145*cdf0e10cSrcweir using ::com::sun::star::io::WrongFormatException; 146*cdf0e10cSrcweir using ::com::sun::star::script::XScriptEventsSupplier; 147*cdf0e10cSrcweir using ::com::sun::star::io::XInputStreamProvider; 148*cdf0e10cSrcweir using ::com::sun::star::io::XInputStream; 149*cdf0e10cSrcweir /** === end UNO using === **/ 150*cdf0e10cSrcweir namespace ElementModes = ::com::sun::star::embed::ElementModes; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // migration phases whose progresses are to be mixed into one progress 153*cdf0e10cSrcweir #define PHASE_JAVASCRIPT 1 154*cdf0e10cSrcweir #define PHASE_BEANSHELL 2 155*cdf0e10cSrcweir #define PHASE_PYTHON 3 156*cdf0e10cSrcweir #define PHASE_JAVA 4 157*cdf0e10cSrcweir #define PHASE_BASIC 5 158*cdf0e10cSrcweir #define PHASE_DIALOGS 6 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //==================================================================== 161*cdf0e10cSrcweir //= SubDocument 162*cdf0e10cSrcweir //==================================================================== 163*cdf0e10cSrcweir struct SubDocument 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir Reference< XCommandProcessor > xCommandProcessor; 166*cdf0e10cSrcweir Reference< XModel > xDocument; // valid only temporarily 167*cdf0e10cSrcweir ::rtl::OUString sHierarchicalName; 168*cdf0e10cSrcweir SubDocumentType eType; 169*cdf0e10cSrcweir size_t nNumber; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir SubDocument( const Reference< XCommandProcessor >& _rxCommandProcessor, const ::rtl::OUString& _rName, 172*cdf0e10cSrcweir const SubDocumentType _eType, const size_t _nNumber ) 173*cdf0e10cSrcweir :xCommandProcessor( _rxCommandProcessor ) 174*cdf0e10cSrcweir ,xDocument() 175*cdf0e10cSrcweir ,sHierarchicalName( _rName ) 176*cdf0e10cSrcweir ,eType( _eType ) 177*cdf0e10cSrcweir ,nNumber( _nNumber ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir }; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir typedef ::std::vector< SubDocument > SubDocuments; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //==================================================================== 185*cdf0e10cSrcweir //= helper 186*cdf0e10cSrcweir //==================================================================== 187*cdf0e10cSrcweir //-------------------------------------------------------------------- 188*cdf0e10cSrcweir typedef ::utl::SharedUNOComponent< XStorage > SharedStorage; 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir namespace 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir //---------------------------------------------------------------- 193*cdf0e10cSrcweir static const ::rtl::OUString& lcl_getScriptsStorageName() 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir static const ::rtl::OUString s_sScriptsStorageName( RTL_CONSTASCII_USTRINGPARAM( "Scripts" ) ); 196*cdf0e10cSrcweir return s_sScriptsStorageName; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir //---------------------------------------------------------------- 200*cdf0e10cSrcweir static const ::rtl::OUString& lcl_getScriptsSubStorageName( const ScriptType _eType ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir static const ::rtl::OUString s_sBeanShell ( RTL_CONSTASCII_USTRINGPARAM( "beanshell" ) ); 203*cdf0e10cSrcweir static const ::rtl::OUString s_sJavaScript( RTL_CONSTASCII_USTRINGPARAM( "javascript" ) ); 204*cdf0e10cSrcweir static const ::rtl::OUString s_sPython ( RTL_CONSTASCII_USTRINGPARAM( "python" ) ); // TODO: is this correct? 205*cdf0e10cSrcweir static const ::rtl::OUString s_sJava ( RTL_CONSTASCII_USTRINGPARAM( "java" ) ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir switch ( _eType ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir case eBeanShell: return s_sBeanShell; 210*cdf0e10cSrcweir case eJavaScript: return s_sJavaScript; 211*cdf0e10cSrcweir case ePython: return s_sPython; 212*cdf0e10cSrcweir case eJava: return s_sJava; 213*cdf0e10cSrcweir default: 214*cdf0e10cSrcweir break; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir OSL_ENSURE( false, "lcl_getScriptsSubStorageName: illegal type!" ); 218*cdf0e10cSrcweir static ::rtl::OUString s_sEmpty; 219*cdf0e10cSrcweir return s_sEmpty; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir //---------------------------------------------------------------- 223*cdf0e10cSrcweir static bool lcl_getScriptTypeFromLanguage( const ::rtl::OUString& _rLanguage, ScriptType& _out_rScriptType ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir struct LanguageMapping 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir const sal_Char* pAsciiLanguage; 228*cdf0e10cSrcweir const ScriptType eScriptType; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir LanguageMapping( const sal_Char* _pAsciiLanguage, const ScriptType _eScriptType ) 231*cdf0e10cSrcweir :pAsciiLanguage( _pAsciiLanguage ) 232*cdf0e10cSrcweir ,eScriptType( _eScriptType ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir aLanguageMapping[] = 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir LanguageMapping( "JavaScript", eJavaScript ), 239*cdf0e10cSrcweir LanguageMapping( "BeanShell", eBeanShell ), 240*cdf0e10cSrcweir LanguageMapping( "Java", eJava ), 241*cdf0e10cSrcweir LanguageMapping( "Python", ePython ), // TODO: is this correct? 242*cdf0e10cSrcweir LanguageMapping( "Basic", eBasic ) 243*cdf0e10cSrcweir }; 244*cdf0e10cSrcweir for ( size_t i=0; i < sizeof( aLanguageMapping ) / sizeof( aLanguageMapping[0] ); ++i ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir if ( _rLanguage.equalsAscii( aLanguageMapping[i].pAsciiLanguage ) ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir _out_rScriptType = aLanguageMapping[i].eScriptType; 249*cdf0e10cSrcweir return true; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir OSL_ENSURE( false, "lcl_getScriptTypeFromLanguage: unknown language!" ); 253*cdf0e10cSrcweir return false; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir //---------------------------------------------------------------- 257*cdf0e10cSrcweir ::rtl::OUString lcl_getSubDocumentDescription( const SubDocument& _rDocument ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir ::rtl::OUString sObjectName = String( MacroMigrationResId( _rDocument.eType == eForm ? STR_FORM : STR_REPORT ) ); 260*cdf0e10cSrcweir ::comphelper::string::searchAndReplaceAsciiI( sObjectName, "$name$", _rDocument.sHierarchicalName ); 261*cdf0e10cSrcweir return sObjectName; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir //---------------------------------------------------------------- 265*cdf0e10cSrcweir static Any lcl_executeCommand_throw( const Reference< XCommandProcessor >& _rxCommandProc, 266*cdf0e10cSrcweir const sal_Char* _pAsciiCommand ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir OSL_PRECOND( _rxCommandProc.is(), "lcl_executeCommand_throw: illegal object!" ); 269*cdf0e10cSrcweir if ( !_rxCommandProc.is() ) 270*cdf0e10cSrcweir return Any(); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir Command aCommand; 273*cdf0e10cSrcweir aCommand.Name = ::rtl::OUString::createFromAscii( _pAsciiCommand ); 274*cdf0e10cSrcweir return _rxCommandProc->execute( 275*cdf0e10cSrcweir aCommand, _rxCommandProc->createCommandIdentifier(), NULL ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir //---------------------------------------------------------------- 279*cdf0e10cSrcweir ::rtl::OUString lcl_getMimeType_nothrow( const Reference< XCommandProcessor >& _rxContent ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir ::rtl::OUString sMimeType; 282*cdf0e10cSrcweir try 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir Reference< XContent > xContent( _rxContent, UNO_QUERY_THROW ); 285*cdf0e10cSrcweir sMimeType = xContent->getContentType(); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir catch( const Exception& ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir return sMimeType; 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir //---------------------------------------------------------------- 295*cdf0e10cSrcweir enum OpenDocResult 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir eOpenedDoc, 298*cdf0e10cSrcweir eIgnoreDoc, 299*cdf0e10cSrcweir eFailure 300*cdf0e10cSrcweir }; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir //---------------------------------------------------------------- 303*cdf0e10cSrcweir static OpenDocResult lcl_loadSubDocument_nothrow( SubDocument& _rDocument, 304*cdf0e10cSrcweir const Reference< XStatusIndicator >& _rxProgress, MigrationLog& _rLogger ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir OSL_PRECOND( !_rDocument.xDocument.is(), "lcl_loadSubDocument_nothrow: already loaded!" ); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir try 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir ::comphelper::NamedValueCollection aLoadArgs; 311*cdf0e10cSrcweir aLoadArgs.put( "Hidden", (sal_Bool)sal_True ); 312*cdf0e10cSrcweir aLoadArgs.put( "StatusIndicator", _rxProgress ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir Reference< XCommandProcessor > xCommandProcessor( _rDocument.xCommandProcessor, UNO_SET_THROW ); 315*cdf0e10cSrcweir Command aCommand; 316*cdf0e10cSrcweir aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) ); 317*cdf0e10cSrcweir aCommand.Argument <<= aLoadArgs.getPropertyValues(); 318*cdf0e10cSrcweir Reference< XComponent > xDocComponent( 319*cdf0e10cSrcweir xCommandProcessor->execute( 320*cdf0e10cSrcweir aCommand, xCommandProcessor->createCommandIdentifier(), NULL 321*cdf0e10cSrcweir ), 322*cdf0e10cSrcweir UNO_QUERY 323*cdf0e10cSrcweir ); 324*cdf0e10cSrcweir OSL_ENSURE( xDocComponent.is(), "lcl_loadSubDocument_nothrow: no component loaded!" ); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir _rDocument.xDocument.set( xDocComponent, UNO_QUERY_THROW ); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir catch( const Exception& ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir Any aError( ::cppu::getCaughtException() ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir bool bCausedByNewStyleReport = 333*cdf0e10cSrcweir ( _rDocument.eType == eReport ) 334*cdf0e10cSrcweir && ( aError.isExtractableTo( ::cppu::UnoType< WrongFormatException >::get() ) ) 335*cdf0e10cSrcweir && ( lcl_getMimeType_nothrow( _rDocument.xCommandProcessor ).equalsAscii( "application/vnd.sun.xml.report" ) ); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir if ( bCausedByNewStyleReport ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir _rLogger.logRecoverable( MigrationError( 340*cdf0e10cSrcweir ERR_NEW_STYLE_REPORT, 341*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ) 342*cdf0e10cSrcweir ) ); 343*cdf0e10cSrcweir return eIgnoreDoc; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir else 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir _rLogger.logFailure( MigrationError( 348*cdf0e10cSrcweir ERR_OPENING_SUB_DOCUMENT_FAILED, 349*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 350*cdf0e10cSrcweir aError 351*cdf0e10cSrcweir ) ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir return _rDocument.xDocument.is() ? eOpenedDoc : eFailure; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //---------------------------------------------------------------- 358*cdf0e10cSrcweir static bool lcl_unloadSubDocument_nothrow( SubDocument& _rDocument, MigrationLog& _rLogger ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir bool bSuccess = false; 361*cdf0e10cSrcweir Any aException; 362*cdf0e10cSrcweir try 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir OSL_VERIFY( lcl_executeCommand_throw( _rDocument.xCommandProcessor, "close" ) >>= bSuccess ); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir catch( const Exception& ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir // log the failure, if any 372*cdf0e10cSrcweir if ( !bSuccess ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir _rLogger.logFailure( MigrationError( 375*cdf0e10cSrcweir ERR_CLOSING_SUB_DOCUMENT_FAILED, 376*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 377*cdf0e10cSrcweir aException 378*cdf0e10cSrcweir ) ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir _rDocument.xDocument.clear(); 382*cdf0e10cSrcweir return bSuccess; 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir //---------------------------------------------------------------- 386*cdf0e10cSrcweir bool lcl_commitStorage_nothrow( const Reference< XStorage >& _rxStorage ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir try 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY_THROW ); 391*cdf0e10cSrcweir xTrans->commit(); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir catch( const Exception& ) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir return false; 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir return true; 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir //---------------------------------------------------------------- 401*cdf0e10cSrcweir bool lcl_commitDocumentStorage_nothrow( const Reference< XModel >& _rxDocument, MigrationLog& _rLogger ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir bool bSuccess = false; 404*cdf0e10cSrcweir Any aException; 405*cdf0e10cSrcweir try 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY_THROW ); 408*cdf0e10cSrcweir Reference< XStorage > xDocStorage( xStorageDoc->getDocumentStorage(), UNO_QUERY_THROW ); 409*cdf0e10cSrcweir bSuccess = lcl_commitStorage_nothrow( xDocStorage ); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir catch( const Exception& ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir // log the failure, if any 417*cdf0e10cSrcweir if ( !bSuccess ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir _rLogger.logFailure( MigrationError( 420*cdf0e10cSrcweir ERR_STORAGE_COMMIT_FAILED, 421*cdf0e10cSrcweir ::comphelper::DocumentInfo::getDocumentTitle( _rxDocument ), 422*cdf0e10cSrcweir aException 423*cdf0e10cSrcweir ) ); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir return bSuccess; 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir //---------------------------------------------------------------- 429*cdf0e10cSrcweir bool lcl_storeDocument_nothrow( const Reference< XModel >& _rxDocument, MigrationLog& _rLogger ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir bool bSuccess = false; 432*cdf0e10cSrcweir Any aException; 433*cdf0e10cSrcweir try 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir Reference< XStorable > xStorable( _rxDocument, UNO_QUERY_THROW ); 436*cdf0e10cSrcweir xStorable->store(); 437*cdf0e10cSrcweir bSuccess = true; 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir catch( const Exception& ) 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir // log the failure, if any 445*cdf0e10cSrcweir if ( !bSuccess ) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir _rLogger.logFailure( MigrationError( 448*cdf0e10cSrcweir ERR_STORING_DATABASEDOC_FAILED, 449*cdf0e10cSrcweir aException 450*cdf0e10cSrcweir ) ); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir return bSuccess; 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir //---------------------------------------------------------------- 456*cdf0e10cSrcweir bool lcl_storeEmbeddedDocument_nothrow( const SubDocument& _rDocument ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir try 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir lcl_executeCommand_throw( _rDocument.xCommandProcessor, "store" ); 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir catch( const Exception& ) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 465*cdf0e10cSrcweir return false; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir return true; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir //==================================================================== 472*cdf0e10cSrcweir //= DrawPageIterator 473*cdf0e10cSrcweir //==================================================================== 474*cdf0e10cSrcweir class DrawPageIterator 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir public: 477*cdf0e10cSrcweir DrawPageIterator( const Reference< XModel >& _rxDocument ) 478*cdf0e10cSrcweir :m_xDocument( _rxDocument ) 479*cdf0e10cSrcweir ,m_nPageCount( 0 ) 480*cdf0e10cSrcweir ,m_nCurrentPage( 0 ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir Reference< XDrawPageSupplier > xSingle( _rxDocument, UNO_QUERY ); 483*cdf0e10cSrcweir Reference< XDrawPagesSupplier > xMulti( _rxDocument, UNO_QUERY ); 484*cdf0e10cSrcweir if ( xSingle.is() ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir m_xSinglePage.set( xSingle->getDrawPage(), UNO_SET_THROW ); 487*cdf0e10cSrcweir m_nPageCount = 1; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir else if ( xMulti.is() ) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir m_xMultiPages.set( xMulti->getDrawPages(), UNO_SET_THROW ); 492*cdf0e10cSrcweir m_nPageCount = m_xMultiPages->getCount(); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir bool hasMore() const 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir return m_nCurrentPage < m_nPageCount; 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir Reference< XDrawPage > next() 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir Reference< XDrawPage > xNextPage; 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir if ( m_xSinglePage.is() ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir xNextPage = m_xSinglePage; 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir else if ( m_xMultiPages.is() ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir xNextPage.set( m_xMultiPages->getByIndex( m_nCurrentPage ), UNO_QUERY_THROW ); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir ++m_nCurrentPage; 514*cdf0e10cSrcweir return xNextPage; 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir private: 518*cdf0e10cSrcweir const Reference< XModel > m_xDocument; 519*cdf0e10cSrcweir Reference< XDrawPage > m_xSinglePage; 520*cdf0e10cSrcweir Reference< XDrawPages > m_xMultiPages; 521*cdf0e10cSrcweir sal_Int32 m_nPageCount; 522*cdf0e10cSrcweir sal_Int32 m_nCurrentPage; 523*cdf0e10cSrcweir }; 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir //==================================================================== 526*cdf0e10cSrcweir //= FormComponentScripts 527*cdf0e10cSrcweir //==================================================================== 528*cdf0e10cSrcweir class FormComponentScripts 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir public: 531*cdf0e10cSrcweir FormComponentScripts( 532*cdf0e10cSrcweir const Reference< XInterface >& _rxComponent, 533*cdf0e10cSrcweir const Reference< XEventAttacherManager >& _rxManager, 534*cdf0e10cSrcweir const sal_Int32 _nIndex 535*cdf0e10cSrcweir ) 536*cdf0e10cSrcweir :m_xComponent( _rxComponent, UNO_SET_THROW ) 537*cdf0e10cSrcweir ,m_xManager( _rxManager, UNO_SET_THROW ) 538*cdf0e10cSrcweir ,m_nIndex( _nIndex ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir Sequence< ScriptEventDescriptor > getEvents() const 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir return m_xManager->getScriptEvents( m_nIndex ); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir void setEvents( const Sequence< ScriptEventDescriptor >& _rEvents ) const 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir m_xManager->registerScriptEvents( m_nIndex, _rEvents ); 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir const Reference< XInterface >& getComponent() const 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir return m_xComponent; 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir private: 558*cdf0e10cSrcweir const Reference< XInterface > m_xComponent; 559*cdf0e10cSrcweir const Reference< XEventAttacherManager > m_xManager; 560*cdf0e10cSrcweir const sal_Int32 m_nIndex; 561*cdf0e10cSrcweir }; 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir //==================================================================== 564*cdf0e10cSrcweir //= FormComponentIterator 565*cdf0e10cSrcweir //==================================================================== 566*cdf0e10cSrcweir class FormComponentIterator 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir public: 569*cdf0e10cSrcweir FormComponentIterator( const Reference< XIndexAccess >& _rxContainer ) 570*cdf0e10cSrcweir :m_xContainer( _rxContainer, UNO_SET_THROW ) 571*cdf0e10cSrcweir ,m_xEventManager( _rxContainer, UNO_QUERY_THROW ) 572*cdf0e10cSrcweir ,m_nElementCount( _rxContainer->getCount() ) 573*cdf0e10cSrcweir ,m_nCurrentElement( 0 ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir bool hasMore() const 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir return m_nCurrentElement < m_nElementCount; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir FormComponentScripts next() 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir FormComponentScripts aComponent( 585*cdf0e10cSrcweir Reference< XInterface >( m_xContainer->getByIndex( m_nCurrentElement ), UNO_QUERY_THROW ), 586*cdf0e10cSrcweir m_xEventManager, 587*cdf0e10cSrcweir m_nCurrentElement 588*cdf0e10cSrcweir ); 589*cdf0e10cSrcweir ++m_nCurrentElement; 590*cdf0e10cSrcweir return aComponent; 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir private: 594*cdf0e10cSrcweir const Reference< XIndexAccess > m_xContainer; 595*cdf0e10cSrcweir const Reference< XEventAttacherManager > m_xEventManager; 596*cdf0e10cSrcweir const sal_Int32 m_nElementCount; 597*cdf0e10cSrcweir sal_Int32 m_nCurrentElement; 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir }; 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir //==================================================================== 602*cdf0e10cSrcweir //= ScriptsStorage - declaration 603*cdf0e10cSrcweir //==================================================================== 604*cdf0e10cSrcweir /** a helper class which encapsulates access to the storages for Java/Script, BeanShell, and Python scripts, 605*cdf0e10cSrcweir i.e. all script types which can be manipulated on storage level. 606*cdf0e10cSrcweir */ 607*cdf0e10cSrcweir class ScriptsStorage 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir public: 610*cdf0e10cSrcweir ScriptsStorage( MigrationLog& _rLogger ); 611*cdf0e10cSrcweir ScriptsStorage( const Reference< XModel >& _rxDocument, MigrationLog& _rLogger ); 612*cdf0e10cSrcweir ~ScriptsStorage(); 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir /** determines whether the instance is valid, i.e. refers to a valid root storage 615*cdf0e10cSrcweir for reading/storing scripts 616*cdf0e10cSrcweir */ 617*cdf0e10cSrcweir inline bool isValid() const { return m_xScriptsStorage.is(); } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir /** binds the instance to a new document. Only to be called when the instance is not yet 620*cdf0e10cSrcweir bound (i.e. isValid returns <FALSE/>). 621*cdf0e10cSrcweir */ 622*cdf0e10cSrcweir void bind( const Reference< XModel >& _rxDocument ); 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir /// determines whether scripts of the given type are present 625*cdf0e10cSrcweir bool hasScripts( const ScriptType _eType ) const; 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir /// returns the root storage for the scripts of the given type 628*cdf0e10cSrcweir SharedStorage 629*cdf0e10cSrcweir getScriptsRoot( const ScriptType _eType ) const; 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir /** returns the names of the elements in the "Scripts" storage 632*cdf0e10cSrcweir */ 633*cdf0e10cSrcweir ::std::set< ::rtl::OUString > 634*cdf0e10cSrcweir getElementNames() const; 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir /** removes the sub storage for a given script type 637*cdf0e10cSrcweir @precond 638*cdf0e10cSrcweir the respective storage is empty 639*cdf0e10cSrcweir @precond 640*cdf0e10cSrcweir the ScriptsStorage instance was opened for writing 641*cdf0e10cSrcweir */ 642*cdf0e10cSrcweir void removeScriptTypeStorage( const ScriptType _eType ) const; 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir /** commits the changes at our XStorage object 645*cdf0e10cSrcweir */ 646*cdf0e10cSrcweir bool commit(); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir /** removes the "Scripts" sub storage from the given document's root storage 649*cdf0e10cSrcweir @precond 650*cdf0e10cSrcweir the "Scripts" storage is empty 651*cdf0e10cSrcweir */ 652*cdf0e10cSrcweir static bool 653*cdf0e10cSrcweir removeFromDocument( const Reference< XModel >& _rxDocument, MigrationLog& _rLogger ); 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir private: 656*cdf0e10cSrcweir MigrationLog& m_rLogger; 657*cdf0e10cSrcweir SharedStorage m_xScriptsStorage; 658*cdf0e10cSrcweir }; 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir //==================================================================== 661*cdf0e10cSrcweir //= ScriptsStorage - implementation 662*cdf0e10cSrcweir //==================================================================== 663*cdf0e10cSrcweir //-------------------------------------------------------------------- 664*cdf0e10cSrcweir ScriptsStorage::ScriptsStorage( MigrationLog& _rLogger ) 665*cdf0e10cSrcweir :m_rLogger( _rLogger ) 666*cdf0e10cSrcweir ,m_xScriptsStorage() 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir //-------------------------------------------------------------------- 671*cdf0e10cSrcweir ScriptsStorage::ScriptsStorage( const Reference< XModel >& _rxDocument, MigrationLog& _rLogger ) 672*cdf0e10cSrcweir :m_rLogger( _rLogger ) 673*cdf0e10cSrcweir ,m_xScriptsStorage() 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir bind( _rxDocument ); 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir //-------------------------------------------------------------------- 679*cdf0e10cSrcweir ScriptsStorage::~ScriptsStorage() 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir //-------------------------------------------------------------------- 684*cdf0e10cSrcweir bool ScriptsStorage::commit() 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir return lcl_commitStorage_nothrow( m_xScriptsStorage ); 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir //-------------------------------------------------------------------- 690*cdf0e10cSrcweir void ScriptsStorage::bind( const Reference< XModel >& _rxDocument ) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir OSL_PRECOND( !isValid(), "ScriptsStorage:bind: did not bother, yet, to check whether this is allowed!" ); 693*cdf0e10cSrcweir try 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY_THROW ); 696*cdf0e10cSrcweir Reference< XStorage > xDocStorage( xStorageDoc->getDocumentStorage(), UNO_QUERY_THROW ); 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir // the the "Scripts" storage exist, or if it does not (yet) exist and we are in write mode 699*cdf0e10cSrcweir // => open the storage 700*cdf0e10cSrcweir if ( ( xDocStorage->hasByName( lcl_getScriptsStorageName() ) 701*cdf0e10cSrcweir && xDocStorage->isStorageElement( lcl_getScriptsStorageName() ) 702*cdf0e10cSrcweir ) 703*cdf0e10cSrcweir || !xDocStorage->hasByName( lcl_getScriptsStorageName() ) 704*cdf0e10cSrcweir ) 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir m_xScriptsStorage.set( 707*cdf0e10cSrcweir xDocStorage->openStorageElement( 708*cdf0e10cSrcweir lcl_getScriptsStorageName(), ElementModes::READWRITE 709*cdf0e10cSrcweir ), 710*cdf0e10cSrcweir UNO_QUERY_THROW 711*cdf0e10cSrcweir ); 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir catch( const Exception& ) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 717*cdf0e10cSrcweir ERR_BIND_SCRIPT_STORAGE_FAILED, 718*cdf0e10cSrcweir ::comphelper::DocumentInfo::getDocumentTitle( _rxDocument ), 719*cdf0e10cSrcweir ::cppu::getCaughtException() 720*cdf0e10cSrcweir ) ); 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir //-------------------------------------------------------------------- 725*cdf0e10cSrcweir bool ScriptsStorage::hasScripts( const ScriptType _eType ) const 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir OSL_PRECOND( isValid(), "ScriptsStorage::hasScripts: illegal call!" ); 728*cdf0e10cSrcweir if ( !isValid() ) 729*cdf0e10cSrcweir return false; 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir const ::rtl::OUString& rSubStorageName( lcl_getScriptsSubStorageName( _eType ) ); 732*cdf0e10cSrcweir return m_xScriptsStorage->hasByName( rSubStorageName ) 733*cdf0e10cSrcweir && m_xScriptsStorage->isStorageElement( rSubStorageName ); 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir //-------------------------------------------------------------------- 737*cdf0e10cSrcweir SharedStorage ScriptsStorage::getScriptsRoot( const ScriptType _eType ) const 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir SharedStorage xStorage; 740*cdf0e10cSrcweir if ( isValid() ) 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir xStorage.reset( m_xScriptsStorage->openStorageElement( 743*cdf0e10cSrcweir lcl_getScriptsSubStorageName( _eType ), ElementModes::READWRITE 744*cdf0e10cSrcweir ) ); 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir return xStorage; 747*cdf0e10cSrcweir } 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir //-------------------------------------------------------------------- 750*cdf0e10cSrcweir ::std::set< ::rtl::OUString > ScriptsStorage::getElementNames() const 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir Sequence< ::rtl::OUString > aElementNames; 753*cdf0e10cSrcweir if ( isValid() ) 754*cdf0e10cSrcweir aElementNames = m_xScriptsStorage->getElementNames(); 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir ::std::set< ::rtl::OUString > aNames; 757*cdf0e10cSrcweir ::std::copy( 758*cdf0e10cSrcweir aElementNames.getConstArray(), 759*cdf0e10cSrcweir aElementNames.getConstArray() + aElementNames.getLength(), 760*cdf0e10cSrcweir ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aNames, aNames.end() ) 761*cdf0e10cSrcweir ); 762*cdf0e10cSrcweir return aNames; 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir //-------------------------------------------------------------------- 766*cdf0e10cSrcweir void ScriptsStorage::removeScriptTypeStorage( const ScriptType _eType ) const 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir ::rtl::OUString sSubStorageName( lcl_getScriptsSubStorageName( _eType ) ); 769*cdf0e10cSrcweir if ( m_xScriptsStorage->hasByName( sSubStorageName ) ) 770*cdf0e10cSrcweir m_xScriptsStorage->removeElement( sSubStorageName ); 771*cdf0e10cSrcweir } 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir //-------------------------------------------------------------------- 774*cdf0e10cSrcweir bool ScriptsStorage::removeFromDocument( const Reference< XModel >& _rxDocument, MigrationLog& _rLogger ) 775*cdf0e10cSrcweir { 776*cdf0e10cSrcweir try 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY_THROW ); 779*cdf0e10cSrcweir Reference< XStorage > xDocStorage( xStorageDoc->getDocumentStorage(), UNO_QUERY_THROW ); 780*cdf0e10cSrcweir xDocStorage->removeElement( lcl_getScriptsStorageName() ); 781*cdf0e10cSrcweir } 782*cdf0e10cSrcweir catch( const Exception& ) 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir _rLogger.logFailure( MigrationError( 785*cdf0e10cSrcweir ERR_REMOVE_SCRIPTS_STORAGE_FAILED, 786*cdf0e10cSrcweir ::comphelper::DocumentInfo::getDocumentTitle( _rxDocument ), 787*cdf0e10cSrcweir ::cppu::getCaughtException() 788*cdf0e10cSrcweir ) ) ; 789*cdf0e10cSrcweir return false; 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir return true; 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir //==================================================================== 795*cdf0e10cSrcweir //= ProgressDelegator 796*cdf0e10cSrcweir //==================================================================== 797*cdf0e10cSrcweir class ProgressDelegator : public IProgressConsumer 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir public: 800*cdf0e10cSrcweir ProgressDelegator( IMigrationProgress& _rDelegator, 801*cdf0e10cSrcweir const ::rtl::OUString& _rObjectName, 802*cdf0e10cSrcweir const ::rtl::OUString& _rAction 803*cdf0e10cSrcweir ) 804*cdf0e10cSrcweir :m_rDelegator( _rDelegator ) 805*cdf0e10cSrcweir ,m_sObjectName( _rObjectName ) 806*cdf0e10cSrcweir ,m_sAction( _rAction ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir } 809*cdf0e10cSrcweir virtual ~ProgressDelegator() 810*cdf0e10cSrcweir { 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir // IProgressConsumer 814*cdf0e10cSrcweir virtual void start( sal_uInt32 _nRange ) 815*cdf0e10cSrcweir { 816*cdf0e10cSrcweir m_rDelegator.startObject( m_sObjectName, m_sAction, _nRange ); 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir virtual void advance( sal_uInt32 _nValue ) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir m_rDelegator.setObjectProgressValue( _nValue ); 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir virtual void end() 823*cdf0e10cSrcweir { 824*cdf0e10cSrcweir m_rDelegator.endObject(); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir private: 828*cdf0e10cSrcweir IMigrationProgress& m_rDelegator; 829*cdf0e10cSrcweir ::rtl::OUString m_sObjectName; 830*cdf0e10cSrcweir ::rtl::OUString m_sAction; 831*cdf0e10cSrcweir }; 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir //==================================================================== 834*cdf0e10cSrcweir //= PhaseGuard 835*cdf0e10cSrcweir //==================================================================== 836*cdf0e10cSrcweir class PhaseGuard 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir public: 839*cdf0e10cSrcweir PhaseGuard( ProgressMixer& _rMixer ) 840*cdf0e10cSrcweir :m_rMixer( _rMixer ) 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir } 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir PhaseGuard( ProgressMixer& _rMixer, const PhaseID _nID, const sal_uInt32 _nPhaseRange ) 845*cdf0e10cSrcweir :m_rMixer( _rMixer ) 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir start( _nID, _nPhaseRange ); 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir ~PhaseGuard() 851*cdf0e10cSrcweir { 852*cdf0e10cSrcweir m_rMixer.endPhase(); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir void start( const PhaseID _nID, const sal_uInt32 _nPhaseRange ) 856*cdf0e10cSrcweir { 857*cdf0e10cSrcweir m_rMixer.startPhase( _nID, _nPhaseRange ); 858*cdf0e10cSrcweir } 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir private: 861*cdf0e10cSrcweir ProgressMixer& m_rMixer; 862*cdf0e10cSrcweir }; 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir //==================================================================== 865*cdf0e10cSrcweir //= MigrationEngine_Impl - declaration 866*cdf0e10cSrcweir //==================================================================== 867*cdf0e10cSrcweir class MigrationEngine_Impl 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir public: 870*cdf0e10cSrcweir MigrationEngine_Impl( 871*cdf0e10cSrcweir const ::comphelper::ComponentContext& _rContext, 872*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument >& _rxDocument, 873*cdf0e10cSrcweir IMigrationProgress& _rProgress, 874*cdf0e10cSrcweir MigrationLog& _rLogger 875*cdf0e10cSrcweir ); 876*cdf0e10cSrcweir ~MigrationEngine_Impl(); 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir inline size_t getFormCount() const { return m_nFormCount; } 879*cdf0e10cSrcweir inline size_t getReportCount()const { return m_nReportCount; } 880*cdf0e10cSrcweir bool migrateAll(); 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir private: 883*cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 884*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument > m_xDocument; 885*cdf0e10cSrcweir const Reference< XModel > m_xDocumentModel; 886*cdf0e10cSrcweir IMigrationProgress& m_rProgress; 887*cdf0e10cSrcweir MigrationLog& m_rLogger; 888*cdf0e10cSrcweir mutable DocumentID m_nCurrentDocumentID; 889*cdf0e10cSrcweir SubDocuments m_aSubDocs; 890*cdf0e10cSrcweir size_t m_nFormCount; 891*cdf0e10cSrcweir size_t m_nReportCount; 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir private: 894*cdf0e10cSrcweir /** collects a description of all sub documents of our database document 895*cdf0e10cSrcweir 896*cdf0e10cSrcweir @return 897*cdf0e10cSrcweir <TRUE/> if and only if collecting the documents was successful 898*cdf0e10cSrcweir */ 899*cdf0e10cSrcweir bool impl_collectSubDocuments_nothrow(); 900*cdf0e10cSrcweir 901*cdf0e10cSrcweir /** migrates the macros/scripts of the given sub document 902*cdf0e10cSrcweir */ 903*cdf0e10cSrcweir bool impl_handleDocument_nothrow( const SubDocument& _rDocument ) const; 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir /** checks the structure of the 'Scripts' folder of a sub document 906*cdf0e10cSrcweir for unknown elements 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir @return 909*cdf0e10cSrcweir <TRUE/> if and only if the 'Scripts' folder contains known elements only. 910*cdf0e10cSrcweir */ 911*cdf0e10cSrcweir bool impl_checkScriptStorageStructure_nothrow( const SubDocument& _rDocument ) const; 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir /** migrates the scripts of the given "storage-based" script type 914*cdf0e10cSrcweir */ 915*cdf0e10cSrcweir bool impl_migrateScriptStorage_nothrow( 916*cdf0e10cSrcweir const SubDocument& _rDocument, 917*cdf0e10cSrcweir const ScriptType _eScriptType, 918*cdf0e10cSrcweir ProgressMixer& _rProgress, 919*cdf0e10cSrcweir const PhaseID _nPhaseID 920*cdf0e10cSrcweir ) const; 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir /** migrates the content of the given "container based" libraries (Basic/Dialogs) 923*cdf0e10cSrcweir */ 924*cdf0e10cSrcweir bool impl_migrateContainerLibraries_nothrow( 925*cdf0e10cSrcweir const SubDocument& _rDocument, 926*cdf0e10cSrcweir const ScriptType _eScriptType, 927*cdf0e10cSrcweir ProgressMixer& _rProgress, 928*cdf0e10cSrcweir const PhaseID _nPhaseID 929*cdf0e10cSrcweir ) const; 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir /** adjusts the events for the given dialog/element, taking into account the new names 932*cdf0e10cSrcweir of the moved libraries 933*cdf0e10cSrcweir */ 934*cdf0e10cSrcweir void impl_adjustDialogElementEvents_throw( 935*cdf0e10cSrcweir const Reference< XInterface >& _rxElement 936*cdf0e10cSrcweir ) const; 937*cdf0e10cSrcweir 938*cdf0e10cSrcweir /** adjusts the events in the given dialog, and its controls, taking into account the new names 939*cdf0e10cSrcweir of the moved libraries 940*cdf0e10cSrcweir */ 941*cdf0e10cSrcweir bool impl_adjustDialogEvents_nothrow( 942*cdf0e10cSrcweir Any& _inout_rDialogLibraryElement, 943*cdf0e10cSrcweir const ::rtl::OUString& _rDocName, 944*cdf0e10cSrcweir const ::rtl::OUString& _rDialogLibName, 945*cdf0e10cSrcweir const ::rtl::OUString& _rDialogName 946*cdf0e10cSrcweir ) const; 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir /** adjust the document-events which refer to macros/scripts in the document, taking into 949*cdf0e10cSrcweir account the new names of the moved libraries 950*cdf0e10cSrcweir */ 951*cdf0e10cSrcweir bool impl_adjustDocumentEvents_nothrow( 952*cdf0e10cSrcweir const SubDocument& _rDocument 953*cdf0e10cSrcweir ) const; 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir /** adjusts the script references bound to form component events 956*cdf0e10cSrcweir */ 957*cdf0e10cSrcweir bool impl_adjustFormComponentEvents_nothrow( 958*cdf0e10cSrcweir const SubDocument& _rDocument 959*cdf0e10cSrcweir ) const; 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir /** adjusts the script references for the elements of the given form component container 962*cdf0e10cSrcweir */ 963*cdf0e10cSrcweir void impl_adjustFormComponentEvents_throw( 964*cdf0e10cSrcweir const Reference< XIndexAccess >& _rxComponentContainer 965*cdf0e10cSrcweir ) const; 966*cdf0e10cSrcweir 967*cdf0e10cSrcweir /** adjusts the library name in the given script URL, so that it reflects 968*cdf0e10cSrcweir the new name of the library 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir @return <TRUE/> 971*cdf0e10cSrcweir if and only if adjustments to the script code have been made 972*cdf0e10cSrcweir */ 973*cdf0e10cSrcweir bool impl_adjustScriptLibrary_nothrow( 974*cdf0e10cSrcweir const ::rtl::OUString& _rScriptType, 975*cdf0e10cSrcweir ::rtl::OUString& _inout_rScriptCode 976*cdf0e10cSrcweir ) const; 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir bool impl_adjustScriptLibrary_nothrow( Any& _inout_rScriptDescriptor ) const; 979*cdf0e10cSrcweir bool impl_adjustScriptLibrary_nothrow( ScriptEventDescriptor& _inout_rScriptEvent ) const; 980*cdf0e10cSrcweir 981*cdf0e10cSrcweir /** asks the user for a password for the given library, and unprotects the library 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir @return <TRUE/> 984*cdf0e10cSrcweir if and only if the library could be successfully unprotected 985*cdf0e10cSrcweir */ 986*cdf0e10cSrcweir bool impl_unprotectPasswordLibrary_throw( 987*cdf0e10cSrcweir const Reference< XLibraryContainerPassword >& _rxPasswordManager, 988*cdf0e10cSrcweir const ScriptType _eScriptType, 989*cdf0e10cSrcweir const ::rtl::OUString& _rLibraryName 990*cdf0e10cSrcweir ) const; 991*cdf0e10cSrcweir }; 992*cdf0e10cSrcweir 993*cdf0e10cSrcweir //==================================================================== 994*cdf0e10cSrcweir //= MigrationEngine_Impl - implementation 995*cdf0e10cSrcweir //==================================================================== 996*cdf0e10cSrcweir //-------------------------------------------------------------------- 997*cdf0e10cSrcweir MigrationEngine_Impl::MigrationEngine_Impl( const ::comphelper::ComponentContext& _rContext, 998*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument >& _rxDocument, IMigrationProgress& _rProgress, MigrationLog& _rLogger ) 999*cdf0e10cSrcweir :m_aContext( _rContext ) 1000*cdf0e10cSrcweir ,m_xDocument( _rxDocument ) 1001*cdf0e10cSrcweir ,m_xDocumentModel( _rxDocument, UNO_QUERY_THROW ) 1002*cdf0e10cSrcweir ,m_rProgress( _rProgress ) 1003*cdf0e10cSrcweir ,m_rLogger( _rLogger ) 1004*cdf0e10cSrcweir ,m_nCurrentDocumentID( - 1 ) 1005*cdf0e10cSrcweir ,m_aSubDocs() 1006*cdf0e10cSrcweir ,m_nFormCount( 0 ) 1007*cdf0e10cSrcweir ,m_nReportCount( 0 ) 1008*cdf0e10cSrcweir { 1009*cdf0e10cSrcweir OSL_VERIFY( impl_collectSubDocuments_nothrow() ); 1010*cdf0e10cSrcweir } 1011*cdf0e10cSrcweir 1012*cdf0e10cSrcweir //-------------------------------------------------------------------- 1013*cdf0e10cSrcweir MigrationEngine_Impl::~MigrationEngine_Impl() 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir } 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir //-------------------------------------------------------------------- 1018*cdf0e10cSrcweir bool MigrationEngine_Impl::migrateAll() 1019*cdf0e10cSrcweir { 1020*cdf0e10cSrcweir if ( m_aSubDocs.empty() ) 1021*cdf0e10cSrcweir { 1022*cdf0e10cSrcweir OSL_ENSURE( false, "MigrationEngine_Impl::migrateAll: no forms/reports found!" ); 1023*cdf0e10cSrcweir // The whole migration wizard is not expected to be called when there are no forms/reports 1024*cdf0e10cSrcweir // with macros, not to mention when there are no forms/reports at all. 1025*cdf0e10cSrcweir return false; 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir // initialize global progress 1029*cdf0e10cSrcweir sal_Int32 nOverallRange( m_aSubDocs.size() ); 1030*cdf0e10cSrcweir String sProgressSkeleton = String( MacroMigrationResId( STR_OVERALL_PROGRESS ) ); 1031*cdf0e10cSrcweir sProgressSkeleton.SearchAndReplaceAscii( "$overall$", String::CreateFromInt32( nOverallRange ) ); 1032*cdf0e10cSrcweir 1033*cdf0e10cSrcweir m_rProgress.start( nOverallRange ); 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir for ( SubDocuments::const_iterator doc = m_aSubDocs.begin(); 1036*cdf0e10cSrcweir doc != m_aSubDocs.end(); 1037*cdf0e10cSrcweir ++doc 1038*cdf0e10cSrcweir ) 1039*cdf0e10cSrcweir { 1040*cdf0e10cSrcweir sal_Int32 nOverallProgressValue( doc - m_aSubDocs.begin() + 1 ); 1041*cdf0e10cSrcweir // update overall progress text 1042*cdf0e10cSrcweir ::rtl::OUString sOverallProgress( sProgressSkeleton ); 1043*cdf0e10cSrcweir ::comphelper::string::searchAndReplaceAsciiI( sOverallProgress, "$current$", ::rtl::OUString::valueOf( nOverallProgressValue ) ); 1044*cdf0e10cSrcweir m_rProgress.setOverallProgressText( sOverallProgress ); 1045*cdf0e10cSrcweir 1046*cdf0e10cSrcweir // migrate document 1047*cdf0e10cSrcweir if ( !impl_handleDocument_nothrow( *doc ) ) 1048*cdf0e10cSrcweir return false; 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir // update overall progress vallue 1051*cdf0e10cSrcweir m_rProgress.setOverallProgressValue( nOverallProgressValue ); 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir // commit the root storage of the database document, for all changes made so far to take effect 1055*cdf0e10cSrcweir if ( !lcl_commitDocumentStorage_nothrow( m_xDocumentModel, m_rLogger ) ) 1056*cdf0e10cSrcweir return false; 1057*cdf0e10cSrcweir 1058*cdf0e10cSrcweir // save the document 1059*cdf0e10cSrcweir if ( !lcl_storeDocument_nothrow( m_xDocumentModel, m_rLogger ) ) 1060*cdf0e10cSrcweir return false; 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir return true; 1063*cdf0e10cSrcweir } 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir //-------------------------------------------------------------------- 1066*cdf0e10cSrcweir namespace 1067*cdf0e10cSrcweir { 1068*cdf0e10cSrcweir void lcl_collectHierarchicalElementNames_throw( 1069*cdf0e10cSrcweir const Reference< XNameAccess >& _rxContainer, const ::rtl::OUString& _rContainerLoc, 1070*cdf0e10cSrcweir SubDocuments& _out_rDocs, const SubDocumentType _eType, size_t& _io_counter ) 1071*cdf0e10cSrcweir { 1072*cdf0e10cSrcweir const ::rtl::OUString sHierarhicalBase( 1073*cdf0e10cSrcweir _rContainerLoc.getLength() ? ::rtl::OUStringBuffer( _rContainerLoc ).appendAscii( "/" ).makeStringAndClear() 1074*cdf0e10cSrcweir : ::rtl::OUString() ); 1075*cdf0e10cSrcweir 1076*cdf0e10cSrcweir Sequence< ::rtl::OUString > aElementNames( _rxContainer->getElementNames() ); 1077*cdf0e10cSrcweir for ( const ::rtl::OUString* elementName = aElementNames.getConstArray(); 1078*cdf0e10cSrcweir elementName != aElementNames.getConstArray() + aElementNames.getLength(); 1079*cdf0e10cSrcweir ++elementName 1080*cdf0e10cSrcweir ) 1081*cdf0e10cSrcweir { 1082*cdf0e10cSrcweir Any aElement( _rxContainer->getByName( *elementName ) ); 1083*cdf0e10cSrcweir ::rtl::OUString sElementName( ::rtl::OUStringBuffer( sHierarhicalBase ).append( *elementName ) ); 1084*cdf0e10cSrcweir 1085*cdf0e10cSrcweir Reference< XNameAccess > xSubContainer( aElement, UNO_QUERY ); 1086*cdf0e10cSrcweir if ( xSubContainer.is() ) 1087*cdf0e10cSrcweir { 1088*cdf0e10cSrcweir lcl_collectHierarchicalElementNames_throw( xSubContainer, sElementName, _out_rDocs, _eType, _io_counter ); 1089*cdf0e10cSrcweir } 1090*cdf0e10cSrcweir else 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir Reference< XCommandProcessor > xCommandProcessor( aElement, UNO_QUERY ); 1093*cdf0e10cSrcweir OSL_ENSURE( xCommandProcessor.is(), "lcl_collectHierarchicalElementNames_throw: no container, and no comand processor? What *is* it, then?!" ); 1094*cdf0e10cSrcweir if ( xCommandProcessor.is() ) 1095*cdf0e10cSrcweir { 1096*cdf0e10cSrcweir _out_rDocs.push_back( SubDocument( xCommandProcessor, sElementName, _eType, ++_io_counter ) ); 1097*cdf0e10cSrcweir } 1098*cdf0e10cSrcweir } 1099*cdf0e10cSrcweir } 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir } 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir //-------------------------------------------------------------------- 1104*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_collectSubDocuments_nothrow() 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir OSL_PRECOND( m_xDocument.is(), "MigrationEngine_Impl::impl_collectSubDocuments_nothrow: invalid document!" ); 1107*cdf0e10cSrcweir if ( !m_xDocument.is() ) 1108*cdf0e10cSrcweir return false; 1109*cdf0e10cSrcweir 1110*cdf0e10cSrcweir try 1111*cdf0e10cSrcweir { 1112*cdf0e10cSrcweir Reference< XNameAccess > xDocContainer( m_xDocument->getFormDocuments(), UNO_SET_THROW ); 1113*cdf0e10cSrcweir m_nFormCount = 0; 1114*cdf0e10cSrcweir lcl_collectHierarchicalElementNames_throw( xDocContainer, ::rtl::OUString(), m_aSubDocs, eForm, m_nFormCount ); 1115*cdf0e10cSrcweir 1116*cdf0e10cSrcweir xDocContainer.set( m_xDocument->getReportDocuments(), UNO_SET_THROW ); 1117*cdf0e10cSrcweir m_nReportCount = 0; 1118*cdf0e10cSrcweir lcl_collectHierarchicalElementNames_throw( xDocContainer, ::rtl::OUString(), m_aSubDocs, eReport, m_nReportCount ); 1119*cdf0e10cSrcweir } 1120*cdf0e10cSrcweir catch( const Exception& ) 1121*cdf0e10cSrcweir { 1122*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1123*cdf0e10cSrcweir ERR_COLLECTING_DOCUMENTS_FAILED, 1124*cdf0e10cSrcweir ::cppu::getCaughtException() 1125*cdf0e10cSrcweir ) ); 1126*cdf0e10cSrcweir return false; 1127*cdf0e10cSrcweir } 1128*cdf0e10cSrcweir return true; 1129*cdf0e10cSrcweir } 1130*cdf0e10cSrcweir 1131*cdf0e10cSrcweir //-------------------------------------------------------------------- 1132*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_handleDocument_nothrow( const SubDocument& _rDocument ) const 1133*cdf0e10cSrcweir { 1134*cdf0e10cSrcweir OSL_ENSURE( m_nCurrentDocumentID == -1, 1135*cdf0e10cSrcweir "MigrationEngine_Impl::impl_handleDocument_nothrow: there already is a current document!"); 1136*cdf0e10cSrcweir m_nCurrentDocumentID = m_rLogger.startedDocument( _rDocument.eType, _rDocument.sHierarchicalName ); 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir // start the progress 1139*cdf0e10cSrcweir ::rtl::OUString sObjectName( lcl_getSubDocumentDescription( _rDocument ) ); 1140*cdf0e10cSrcweir m_rProgress.startObject( sObjectName, ::rtl::OUString(), DEFAULT_DOC_PROGRESS_RANGE ); 1141*cdf0e10cSrcweir 1142*cdf0e10cSrcweir // ----------------- 1143*cdf0e10cSrcweir // load the document 1144*cdf0e10cSrcweir ::rtl::Reference< ProgressCapture > pStatusIndicator( new ProgressCapture( sObjectName, m_rProgress ) ); 1145*cdf0e10cSrcweir SubDocument aSubDocument( _rDocument ); 1146*cdf0e10cSrcweir OpenDocResult eResult = lcl_loadSubDocument_nothrow( aSubDocument, pStatusIndicator.get(), m_rLogger ); 1147*cdf0e10cSrcweir if ( eResult != eOpenedDoc ) 1148*cdf0e10cSrcweir { 1149*cdf0e10cSrcweir pStatusIndicator->dispose(); 1150*cdf0e10cSrcweir m_rProgress.endObject(); 1151*cdf0e10cSrcweir m_rLogger.finishedDocument( m_nCurrentDocumentID ); 1152*cdf0e10cSrcweir m_nCurrentDocumentID = -1; 1153*cdf0e10cSrcweir return ( eResult == eIgnoreDoc ); 1154*cdf0e10cSrcweir } 1155*cdf0e10cSrcweir 1156*cdf0e10cSrcweir // ----------------- 1157*cdf0e10cSrcweir // migrate the libraries 1158*cdf0e10cSrcweir ProgressDelegator aDelegator( m_rProgress, sObjectName, String( MacroMigrationResId( STR_MIGRATING_LIBS ) ) ); 1159*cdf0e10cSrcweir ProgressMixer aProgressMixer( aDelegator ); 1160*cdf0e10cSrcweir aProgressMixer.registerPhase( PHASE_JAVASCRIPT, 1 ); 1161*cdf0e10cSrcweir aProgressMixer.registerPhase( PHASE_BEANSHELL, 1 ); 1162*cdf0e10cSrcweir aProgressMixer.registerPhase( PHASE_PYTHON, 1 ); 1163*cdf0e10cSrcweir aProgressMixer.registerPhase( PHASE_JAVA, 1 ); 1164*cdf0e10cSrcweir aProgressMixer.registerPhase( PHASE_BASIC, 5 ); 1165*cdf0e10cSrcweir // more weight than then others, assuming that usually, there are much more Basic macros than any other scripts 1166*cdf0e10cSrcweir aProgressMixer.registerPhase( PHASE_DIALOGS, 1 ); 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir bool bSuccess = impl_checkScriptStorageStructure_nothrow( aSubDocument ); 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir // migrate storage-based script libraries (which can be handled by mere storage operations) 1171*cdf0e10cSrcweir bSuccess = bSuccess 1172*cdf0e10cSrcweir && impl_migrateScriptStorage_nothrow( aSubDocument, eJavaScript, aProgressMixer, PHASE_JAVASCRIPT ) 1173*cdf0e10cSrcweir && impl_migrateScriptStorage_nothrow( aSubDocument, eBeanShell, aProgressMixer, PHASE_BEANSHELL ) 1174*cdf0e10cSrcweir && impl_migrateScriptStorage_nothrow( aSubDocument, ePython, aProgressMixer, PHASE_PYTHON ) 1175*cdf0e10cSrcweir && impl_migrateScriptStorage_nothrow( aSubDocument, eJava, aProgressMixer, PHASE_JAVA ); 1176*cdf0e10cSrcweir 1177*cdf0e10cSrcweir // migrate Basic and dialog libraries 1178*cdf0e10cSrcweir bSuccess = bSuccess 1179*cdf0e10cSrcweir && impl_migrateContainerLibraries_nothrow( aSubDocument, eBasic, aProgressMixer, PHASE_BASIC ) 1180*cdf0e10cSrcweir && impl_migrateContainerLibraries_nothrow( aSubDocument, eDialog, aProgressMixer, PHASE_DIALOGS ); 1181*cdf0e10cSrcweir // order matters: First Basic scripts, then dialogs. So we can adjust references from the latter 1182*cdf0e10cSrcweir // to the former 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir // adjust the events in the document 1185*cdf0e10cSrcweir // (note that errors are ignored here - failure to convert a script reference 1186*cdf0e10cSrcweir // is not considered a critical error) 1187*cdf0e10cSrcweir if ( bSuccess ) 1188*cdf0e10cSrcweir { 1189*cdf0e10cSrcweir impl_adjustDocumentEvents_nothrow( aSubDocument ); 1190*cdf0e10cSrcweir impl_adjustFormComponentEvents_nothrow( aSubDocument ); 1191*cdf0e10cSrcweir } 1192*cdf0e10cSrcweir 1193*cdf0e10cSrcweir // ----------------- 1194*cdf0e10cSrcweir // clean up 1195*cdf0e10cSrcweir // store the sub document, including removal of the (now obsolete) "Scripts" sub folder 1196*cdf0e10cSrcweir if ( m_rLogger.movedAnyLibrary( m_nCurrentDocumentID ) ) 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir bSuccess = bSuccess 1199*cdf0e10cSrcweir && ScriptsStorage::removeFromDocument( aSubDocument.xDocument, m_rLogger ) 1200*cdf0e10cSrcweir && lcl_commitDocumentStorage_nothrow( aSubDocument.xDocument, m_rLogger ) 1201*cdf0e10cSrcweir && lcl_storeEmbeddedDocument_nothrow( aSubDocument ); 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir // unload in any case, even if we were not successful 1205*cdf0e10cSrcweir bSuccess = lcl_unloadSubDocument_nothrow( aSubDocument, m_rLogger ) 1206*cdf0e10cSrcweir && bSuccess; 1207*cdf0e10cSrcweir 1208*cdf0e10cSrcweir pStatusIndicator->dispose(); 1209*cdf0e10cSrcweir 1210*cdf0e10cSrcweir // end the progress, just in case the ProgressCapture didn't receive the XStatusIndicator::end event 1211*cdf0e10cSrcweir m_rProgress.endObject(); 1212*cdf0e10cSrcweir 1213*cdf0e10cSrcweir m_rLogger.finishedDocument( m_nCurrentDocumentID ); 1214*cdf0e10cSrcweir m_nCurrentDocumentID = -1; 1215*cdf0e10cSrcweir return bSuccess; 1216*cdf0e10cSrcweir } 1217*cdf0e10cSrcweir 1218*cdf0e10cSrcweir //-------------------------------------------------------------------- 1219*cdf0e10cSrcweir namespace 1220*cdf0e10cSrcweir { 1221*cdf0e10cSrcweir static ::rtl::OUString lcl_createTargetLibName( const SubDocument& _rDocument, 1222*cdf0e10cSrcweir const ::rtl::OUString& _rSourceLibName, const Reference< XNameAccess >& _rxTargetContainer ) 1223*cdf0e10cSrcweir { 1224*cdf0e10cSrcweir // The new library name is composed from the prefix, the base name, and the old library name. 1225*cdf0e10cSrcweir const ::rtl::OUString sPrefix( ::rtl::OUString::createFromAscii( _rDocument.eType == eForm ? "Form_" : "Report_" ) ); 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir ::rtl::OUString sBaseName( _rDocument.sHierarchicalName.copy( 1228*cdf0e10cSrcweir _rDocument.sHierarchicalName.lastIndexOf( '/' ) + 1 ) ); 1229*cdf0e10cSrcweir // Normalize this name. In our current storage implementation (and script containers in a document 1230*cdf0e10cSrcweir // are finally mapped to sub storages of the document storage), not all characters are allowed. 1231*cdf0e10cSrcweir // The bug requesting to change this is #i95409#. 1232*cdf0e10cSrcweir // Unfortunately, the storage implementation does not complain if you use invalid characters/names, but instead 1233*cdf0e10cSrcweir // it silently accepts them, and produces garbage in the file (#i95408). 1234*cdf0e10cSrcweir // So, until especially the former is fixed, we need to strip the name from all invalid characters. 1235*cdf0e10cSrcweir // #i95865# / 2008-11-06 / frank.schoenheit@sun.com 1236*cdf0e10cSrcweir 1237*cdf0e10cSrcweir // The general idea is to replace invalid characters with '_'. However, since "valid" essentially means 1238*cdf0e10cSrcweir // ASCII only, this implies that for a lot of languages, we would simply replace everything with '_', 1239*cdf0e10cSrcweir // which of course is not desired. 1240*cdf0e10cSrcweir // So, we use a heuristics: If the name contains at most 3 invalid characters, and as many valid as invalid 1241*cdf0e10cSrcweir // characters, then we use the replacement. Otherwise, we just use a unambiguous number for the sub document. 1242*cdf0e10cSrcweir sal_Int32 nValid=0, nInvalid=0; 1243*cdf0e10cSrcweir const sal_Unicode* pBaseName = sBaseName.getStr(); 1244*cdf0e10cSrcweir const sal_Int32 nBaseNameLen = sBaseName.getLength(); 1245*cdf0e10cSrcweir for ( sal_Int32 i=0; i<nBaseNameLen; ++i ) 1246*cdf0e10cSrcweir { 1247*cdf0e10cSrcweir if ( ::comphelper::OStorageHelper::IsValidZipEntryFileName( pBaseName + i, 1, sal_False ) ) 1248*cdf0e10cSrcweir ++nValid; 1249*cdf0e10cSrcweir else 1250*cdf0e10cSrcweir ++nInvalid; 1251*cdf0e10cSrcweir } 1252*cdf0e10cSrcweir if ( ( nInvalid <= 3 ) && ( nInvalid * 2 <= nValid ) ) 1253*cdf0e10cSrcweir { // not "too many" invalid => replace them 1254*cdf0e10cSrcweir ::rtl::OUStringBuffer aReplacement; 1255*cdf0e10cSrcweir aReplacement.ensureCapacity( nBaseNameLen ); 1256*cdf0e10cSrcweir aReplacement.append( sBaseName ); 1257*cdf0e10cSrcweir const sal_Unicode* pReplacement = aReplacement.getStr(); 1258*cdf0e10cSrcweir for ( sal_Int32 i=0; i<nBaseNameLen; ++i ) 1259*cdf0e10cSrcweir { 1260*cdf0e10cSrcweir if ( !::comphelper::OStorageHelper::IsValidZipEntryFileName( pReplacement + i, 1, sal_False ) ) 1261*cdf0e10cSrcweir aReplacement.setCharAt( i, '_' ); 1262*cdf0e10cSrcweir } 1263*cdf0e10cSrcweir sBaseName = aReplacement.makeStringAndClear(); 1264*cdf0e10cSrcweir 1265*cdf0e10cSrcweir ::rtl::OUStringBuffer aNewLibNameAttempt; 1266*cdf0e10cSrcweir aNewLibNameAttempt.append( sPrefix ); 1267*cdf0e10cSrcweir aNewLibNameAttempt.append( sBaseName ); 1268*cdf0e10cSrcweir aNewLibNameAttempt.appendAscii( "_" ); 1269*cdf0e10cSrcweir aNewLibNameAttempt.append( _rSourceLibName ); 1270*cdf0e10cSrcweir ::rtl::OUString sTargetName( aNewLibNameAttempt.makeStringAndClear() ); 1271*cdf0e10cSrcweir if ( !_rxTargetContainer->hasByName( sTargetName ) ) 1272*cdf0e10cSrcweir return sTargetName; 1273*cdf0e10cSrcweir } 1274*cdf0e10cSrcweir 1275*cdf0e10cSrcweir // "too many" invalid characters, or the name composed with the base name was already used. 1276*cdf0e10cSrcweir // (The latter is valid, since there can be multiple sub documents with the same base name, 1277*cdf0e10cSrcweir // in different levels in the hierarchy.) 1278*cdf0e10cSrcweir // In this case, just use the umambiguous sub document number. 1279*cdf0e10cSrcweir ::rtl::OUStringBuffer aNewLibName; 1280*cdf0e10cSrcweir aNewLibName.append( sPrefix ); 1281*cdf0e10cSrcweir aNewLibName.append( ::rtl::OUString::valueOf( sal_Int64( _rDocument.nNumber ) ) ); 1282*cdf0e10cSrcweir aNewLibName.appendAscii( "_" ); 1283*cdf0e10cSrcweir aNewLibName.append( _rSourceLibName ); 1284*cdf0e10cSrcweir return aNewLibName.makeStringAndClear(); 1285*cdf0e10cSrcweir } 1286*cdf0e10cSrcweir } 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir //-------------------------------------------------------------------- 1289*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_checkScriptStorageStructure_nothrow( const SubDocument& _rDocument ) const 1290*cdf0e10cSrcweir { 1291*cdf0e10cSrcweir OSL_PRECOND( _rDocument.xDocument.is(), "MigrationEngine_Impl::impl_checkScriptStorageStructure_nothrow: invalid document!" ); 1292*cdf0e10cSrcweir if ( !_rDocument.xDocument.is() ) 1293*cdf0e10cSrcweir return false; 1294*cdf0e10cSrcweir 1295*cdf0e10cSrcweir try 1296*cdf0e10cSrcweir { 1297*cdf0e10cSrcweir // the root storage of the document whose scripts are to be migrated 1298*cdf0e10cSrcweir ScriptsStorage aDocStorage( _rDocument.xDocument, m_rLogger ); 1299*cdf0e10cSrcweir if ( !aDocStorage.isValid() ) 1300*cdf0e10cSrcweir { // no scripts at all, or no scripts of the given type 1301*cdf0e10cSrcweir return !m_rLogger.hadFailure(); 1302*cdf0e10cSrcweir } 1303*cdf0e10cSrcweir ::std::set< ::rtl::OUString > aElementNames( aDocStorage.getElementNames() ); 1304*cdf0e10cSrcweir 1305*cdf0e10cSrcweir ScriptType aKnownStorageBasedTypes[] = { 1306*cdf0e10cSrcweir eBeanShell, eJavaScript, ePython, eJava 1307*cdf0e10cSrcweir }; 1308*cdf0e10cSrcweir for ( size_t i=0; i<sizeof( aKnownStorageBasedTypes ) / sizeof( aKnownStorageBasedTypes[0] ); ++i ) 1309*cdf0e10cSrcweir aElementNames.erase( lcl_getScriptsSubStorageName( aKnownStorageBasedTypes[i] ) ); 1310*cdf0e10cSrcweir 1311*cdf0e10cSrcweir if ( !aElementNames.empty() ) 1312*cdf0e10cSrcweir { 1313*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1314*cdf0e10cSrcweir ERR_UNKNOWN_SCRIPT_FOLDER, 1315*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1316*cdf0e10cSrcweir *aElementNames.begin() 1317*cdf0e10cSrcweir ) ); 1318*cdf0e10cSrcweir return false; 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir } 1321*cdf0e10cSrcweir catch( const Exception& ) 1322*cdf0e10cSrcweir { 1323*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1324*cdf0e10cSrcweir ERR_EXAMINING_SCRIPTS_FOLDER_FAILED, 1325*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1326*cdf0e10cSrcweir ::cppu::getCaughtException() 1327*cdf0e10cSrcweir ) ); 1328*cdf0e10cSrcweir return false; 1329*cdf0e10cSrcweir } 1330*cdf0e10cSrcweir return true; 1331*cdf0e10cSrcweir } 1332*cdf0e10cSrcweir 1333*cdf0e10cSrcweir //-------------------------------------------------------------------- 1334*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_migrateScriptStorage_nothrow( const SubDocument& _rDocument, 1335*cdf0e10cSrcweir const ScriptType _eScriptType, ProgressMixer& _rProgress, const PhaseID _nPhaseID ) const 1336*cdf0e10cSrcweir { 1337*cdf0e10cSrcweir OSL_PRECOND( _rDocument.xDocument.is(), "MigrationEngine_Impl::impl_migrateScriptStorage_nothrow: invalid document!" ); 1338*cdf0e10cSrcweir if ( !_rDocument.xDocument.is() ) 1339*cdf0e10cSrcweir return false; 1340*cdf0e10cSrcweir 1341*cdf0e10cSrcweir ScriptsStorage aDatabaseScripts( m_rLogger ); 1342*cdf0e10cSrcweir // the scripts of our complete database document - created on demand only 1343*cdf0e10cSrcweir SharedStorage xTargetStorage; 1344*cdf0e10cSrcweir // the target for moving the scripts storages - created on demand only 1345*cdf0e10cSrcweir 1346*cdf0e10cSrcweir PhaseGuard aPhase( _rProgress ); 1347*cdf0e10cSrcweir bool bSuccess = false; 1348*cdf0e10cSrcweir Any aException; 1349*cdf0e10cSrcweir try 1350*cdf0e10cSrcweir { 1351*cdf0e10cSrcweir // the root storage of the document whose scripts are to be migrated 1352*cdf0e10cSrcweir ScriptsStorage aDocStorage( _rDocument.xDocument, m_rLogger ); 1353*cdf0e10cSrcweir if ( !aDocStorage.isValid() 1354*cdf0e10cSrcweir || !aDocStorage.hasScripts( _eScriptType ) 1355*cdf0e10cSrcweir ) 1356*cdf0e10cSrcweir { 1357*cdf0e10cSrcweir // no scripts at all, or no scripts of the given type 1358*cdf0e10cSrcweir _rProgress.startPhase( _nPhaseID, 1 ); 1359*cdf0e10cSrcweir _rProgress.endPhase(); 1360*cdf0e10cSrcweir return !m_rLogger.hadFailure(); 1361*cdf0e10cSrcweir } 1362*cdf0e10cSrcweir 1363*cdf0e10cSrcweir SharedStorage xScriptsRoot( aDocStorage.getScriptsRoot( _eScriptType ) ); 1364*cdf0e10cSrcweir if ( !xScriptsRoot.is() ) 1365*cdf0e10cSrcweir throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "internal error" ) ), NULL ); 1366*cdf0e10cSrcweir 1367*cdf0e10cSrcweir // loop through the script libraries 1368*cdf0e10cSrcweir Sequence< ::rtl::OUString > aStorageElements( xScriptsRoot->getElementNames() ); 1369*cdf0e10cSrcweir aPhase.start( _nPhaseID, aStorageElements.getLength() ); 1370*cdf0e10cSrcweir 1371*cdf0e10cSrcweir for ( const ::rtl::OUString* element = aStorageElements.getConstArray(); 1372*cdf0e10cSrcweir element != aStorageElements.getConstArray() + aStorageElements.getLength(); 1373*cdf0e10cSrcweir ++element 1374*cdf0e10cSrcweir ) 1375*cdf0e10cSrcweir { 1376*cdf0e10cSrcweir bool bIsScriptLibrary = xScriptsRoot->isStorageElement( *element ); 1377*cdf0e10cSrcweir OSL_ENSURE( bIsScriptLibrary, 1378*cdf0e10cSrcweir "MigrationEngine_Impl::impl_migrateScriptStorage_nothrow: warning: unknown scripts storage structure!" ); 1379*cdf0e10cSrcweir // we cannot handle this. We would need to copy this stream to the respective scripts storage 1380*cdf0e10cSrcweir // of the database document, but we cannot guarantee that the name is not used, yet, and we cannot 1381*cdf0e10cSrcweir // simply rename the thing. 1382*cdf0e10cSrcweir if ( !bIsScriptLibrary ) 1383*cdf0e10cSrcweir { 1384*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1385*cdf0e10cSrcweir ERR_UNEXPECTED_LIBSTORAGE_ELEMENT, 1386*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1387*cdf0e10cSrcweir getScriptTypeDisplayName( _eScriptType ), 1388*cdf0e10cSrcweir *element 1389*cdf0e10cSrcweir ) ); 1390*cdf0e10cSrcweir return false; 1391*cdf0e10cSrcweir } 1392*cdf0e10cSrcweir 1393*cdf0e10cSrcweir // ensure we have access to the DBDoc's scripts storage 1394*cdf0e10cSrcweir if ( !aDatabaseScripts.isValid() ) 1395*cdf0e10cSrcweir { // not needed 'til now 1396*cdf0e10cSrcweir aDatabaseScripts.bind( m_xDocumentModel ); 1397*cdf0e10cSrcweir if ( aDatabaseScripts.isValid() ) 1398*cdf0e10cSrcweir xTargetStorage = aDatabaseScripts.getScriptsRoot( _eScriptType ); 1399*cdf0e10cSrcweir 1400*cdf0e10cSrcweir if ( !xTargetStorage.is() ) 1401*cdf0e10cSrcweir { 1402*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1403*cdf0e10cSrcweir ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED, 1404*cdf0e10cSrcweir getScriptTypeDisplayName( _eScriptType ) 1405*cdf0e10cSrcweir ) ); 1406*cdf0e10cSrcweir return false; 1407*cdf0e10cSrcweir } 1408*cdf0e10cSrcweir } 1409*cdf0e10cSrcweir 1410*cdf0e10cSrcweir // move the library to the DBDoc's scripts library, under the new name 1411*cdf0e10cSrcweir ::rtl::OUString sNewLibName( lcl_createTargetLibName( _rDocument, *element, xTargetStorage.getTyped().get() ) ); 1412*cdf0e10cSrcweir xScriptsRoot->moveElementTo( *element, xTargetStorage, sNewLibName ); 1413*cdf0e10cSrcweir 1414*cdf0e10cSrcweir // log the fact that we moved the library 1415*cdf0e10cSrcweir m_rLogger.movedLibrary( m_nCurrentDocumentID, _eScriptType, *element, sNewLibName ); 1416*cdf0e10cSrcweir 1417*cdf0e10cSrcweir // progress 1418*cdf0e10cSrcweir _rProgress.advancePhase( element - aStorageElements.getConstArray() ); 1419*cdf0e10cSrcweir } 1420*cdf0e10cSrcweir 1421*cdf0e10cSrcweir // commit the storages, so the changes we made persist 1422*cdf0e10cSrcweir if ( !lcl_commitStorage_nothrow( xScriptsRoot ) 1423*cdf0e10cSrcweir || ( xTargetStorage.is() && !lcl_commitStorage_nothrow( xTargetStorage ) ) 1424*cdf0e10cSrcweir ) 1425*cdf0e10cSrcweir { 1426*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1427*cdf0e10cSrcweir ERR_COMMITTING_SCRIPT_STORAGES_FAILED, 1428*cdf0e10cSrcweir getScriptTypeDisplayName( _eScriptType ), 1429*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ) 1430*cdf0e10cSrcweir ) ); 1431*cdf0e10cSrcweir return false; 1432*cdf0e10cSrcweir } 1433*cdf0e10cSrcweir 1434*cdf0e10cSrcweir // now that the concrete scripts storage does not have any elements anymore, 1435*cdf0e10cSrcweir // remove it 1436*cdf0e10cSrcweir xScriptsRoot.reset( NULL ); // need to reset the storage to be allowed to remove it 1437*cdf0e10cSrcweir aDocStorage.removeScriptTypeStorage( _eScriptType ); 1438*cdf0e10cSrcweir 1439*cdf0e10cSrcweir // done so far 1440*cdf0e10cSrcweir bSuccess = aDocStorage.commit() 1441*cdf0e10cSrcweir && aDatabaseScripts.commit(); 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir catch( const Exception& ) 1444*cdf0e10cSrcweir { 1445*cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 1446*cdf0e10cSrcweir bSuccess = false; 1447*cdf0e10cSrcweir } 1448*cdf0e10cSrcweir 1449*cdf0e10cSrcweir // log the error, if any 1450*cdf0e10cSrcweir if ( !bSuccess ) 1451*cdf0e10cSrcweir { 1452*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1453*cdf0e10cSrcweir ERR_GENERAL_SCRIPT_MIGRATION_FAILURE, 1454*cdf0e10cSrcweir getScriptTypeDisplayName( _eScriptType ), 1455*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1456*cdf0e10cSrcweir aException 1457*cdf0e10cSrcweir ) ); 1458*cdf0e10cSrcweir } 1459*cdf0e10cSrcweir 1460*cdf0e10cSrcweir return bSuccess; 1461*cdf0e10cSrcweir } 1462*cdf0e10cSrcweir 1463*cdf0e10cSrcweir //-------------------------------------------------------------------- 1464*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow( const SubDocument& _rDocument, 1465*cdf0e10cSrcweir const ScriptType _eScriptType, ProgressMixer& _rProgress, const PhaseID _nPhaseID ) const 1466*cdf0e10cSrcweir { 1467*cdf0e10cSrcweir OSL_PRECOND( ( _eScriptType == eBasic ) || ( _eScriptType == eDialog ), 1468*cdf0e10cSrcweir "MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow: illegal script type!" ); 1469*cdf0e10cSrcweir 1470*cdf0e10cSrcweir bool bSuccess = false; 1471*cdf0e10cSrcweir PhaseGuard aPhase( _rProgress ); 1472*cdf0e10cSrcweir Any aException; 1473*cdf0e10cSrcweir do // artificial loop for flow control only 1474*cdf0e10cSrcweir { 1475*cdf0e10cSrcweir try 1476*cdf0e10cSrcweir { 1477*cdf0e10cSrcweir // access library container of the sub document 1478*cdf0e10cSrcweir Reference< XEmbeddedScripts > xSubDocScripts( _rDocument.xDocument, UNO_QUERY ); 1479*cdf0e10cSrcweir if ( !xSubDocScripts.is() ) 1480*cdf0e10cSrcweir { // no script support in the sub document -> nothing to migrate 1481*cdf0e10cSrcweir // (though ... this is suspicious, at least ...) 1482*cdf0e10cSrcweir bSuccess = true; 1483*cdf0e10cSrcweir break; 1484*cdf0e10cSrcweir } 1485*cdf0e10cSrcweir 1486*cdf0e10cSrcweir Reference< XStorageBasedLibraryContainer > xSourceLibraries( 1487*cdf0e10cSrcweir _eScriptType == eBasic ? xSubDocScripts->getBasicLibraries() : xSubDocScripts->getDialogLibraries(), 1488*cdf0e10cSrcweir UNO_QUERY_THROW 1489*cdf0e10cSrcweir ); 1490*cdf0e10cSrcweir Reference< XLibraryContainerPassword > xSourcePasswords( xSourceLibraries, UNO_QUERY ); 1491*cdf0e10cSrcweir OSL_ENSURE( xSourcePasswords.is(), 1492*cdf0e10cSrcweir "MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow: suspicious: no password management for the source libraries!" ); 1493*cdf0e10cSrcweir 1494*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSourceLibNames( xSourceLibraries->getElementNames() ); 1495*cdf0e10cSrcweir aPhase.start( _nPhaseID, aSourceLibNames.getLength() ); 1496*cdf0e10cSrcweir 1497*cdf0e10cSrcweir if ( !xSourceLibraries->hasElements() ) 1498*cdf0e10cSrcweir { 1499*cdf0e10cSrcweir bSuccess = true; 1500*cdf0e10cSrcweir break; 1501*cdf0e10cSrcweir } 1502*cdf0e10cSrcweir 1503*cdf0e10cSrcweir // create library containers for the document - those will be the target for the migration 1504*cdf0e10cSrcweir Reference< XStorageBasedDocument > xStorageDoc( m_xDocument, UNO_QUERY_THROW ); 1505*cdf0e10cSrcweir Reference< XStorageBasedLibraryContainer > xTargetLibraries; 1506*cdf0e10cSrcweir if ( _eScriptType == eBasic ) 1507*cdf0e10cSrcweir { 1508*cdf0e10cSrcweir xTargetLibraries.set( DocumentScriptLibraryContainer::create( 1509*cdf0e10cSrcweir m_aContext.getUNOContext(), xStorageDoc ), UNO_QUERY_THROW ); 1510*cdf0e10cSrcweir } 1511*cdf0e10cSrcweir else 1512*cdf0e10cSrcweir { 1513*cdf0e10cSrcweir xTargetLibraries.set( DocumentDialogLibraryContainer::create( 1514*cdf0e10cSrcweir m_aContext.getUNOContext(), xStorageDoc ), UNO_QUERY_THROW ); 1515*cdf0e10cSrcweir } 1516*cdf0e10cSrcweir 1517*cdf0e10cSrcweir // copy all libs to the target, with potentially renaming them 1518*cdf0e10cSrcweir const ::rtl::OUString* pSourceLibBegin = aSourceLibNames.getConstArray(); 1519*cdf0e10cSrcweir const ::rtl::OUString* pSourceLibEnd = pSourceLibBegin + aSourceLibNames.getLength(); 1520*cdf0e10cSrcweir for ( const ::rtl::OUString* pSourceLibName = pSourceLibBegin; 1521*cdf0e10cSrcweir pSourceLibName != pSourceLibEnd; 1522*cdf0e10cSrcweir ++pSourceLibName 1523*cdf0e10cSrcweir ) 1524*cdf0e10cSrcweir { 1525*cdf0e10cSrcweir // if the library is password-protected, ask the user to unprotect it 1526*cdf0e10cSrcweir if ( xSourcePasswords.is() 1527*cdf0e10cSrcweir && xSourcePasswords->isLibraryPasswordProtected( *pSourceLibName ) 1528*cdf0e10cSrcweir && !xSourcePasswords->isLibraryPasswordVerified( *pSourceLibName ) 1529*cdf0e10cSrcweir ) 1530*cdf0e10cSrcweir { 1531*cdf0e10cSrcweir if ( !impl_unprotectPasswordLibrary_throw( xSourcePasswords, _eScriptType, *pSourceLibName ) ) 1532*cdf0e10cSrcweir { 1533*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1534*cdf0e10cSrcweir ERR_PASSWORD_VERIFICATION_FAILED, 1535*cdf0e10cSrcweir _rDocument.sHierarchicalName, 1536*cdf0e10cSrcweir getScriptTypeDisplayName( _eScriptType ), 1537*cdf0e10cSrcweir *pSourceLibName 1538*cdf0e10cSrcweir ) ); 1539*cdf0e10cSrcweir return false; 1540*cdf0e10cSrcweir } 1541*cdf0e10cSrcweir } 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir ::rtl::OUString sNewLibName( lcl_createTargetLibName( _rDocument, *pSourceLibName, xTargetLibraries.get() ) ); 1544*cdf0e10cSrcweir 1545*cdf0e10cSrcweir if ( xSourceLibraries->isLibraryLink( *pSourceLibName ) ) 1546*cdf0e10cSrcweir { 1547*cdf0e10cSrcweir // just re-create the link in the target library 1548*cdf0e10cSrcweir xTargetLibraries->createLibraryLink( 1549*cdf0e10cSrcweir sNewLibName, 1550*cdf0e10cSrcweir xSourceLibraries->getLibraryLinkURL( *pSourceLibName ), 1551*cdf0e10cSrcweir xSourceLibraries->isLibraryReadOnly( *pSourceLibName ) 1552*cdf0e10cSrcweir ); 1553*cdf0e10cSrcweir } 1554*cdf0e10cSrcweir else 1555*cdf0e10cSrcweir { 1556*cdf0e10cSrcweir if ( !xSourceLibraries->isLibraryLoaded( *pSourceLibName ) ) 1557*cdf0e10cSrcweir xSourceLibraries->loadLibrary( *pSourceLibName ); 1558*cdf0e10cSrcweir 1559*cdf0e10cSrcweir // copy the content of this particular libary 1560*cdf0e10cSrcweir Reference< XNameAccess > xSourceLib( xSourceLibraries->getByName( *pSourceLibName ), UNO_QUERY_THROW ); 1561*cdf0e10cSrcweir Reference< XNameContainer > xTargetLib( xTargetLibraries->createLibrary( sNewLibName ), UNO_QUERY_THROW ); 1562*cdf0e10cSrcweir 1563*cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibElementNames( xSourceLib->getElementNames() ); 1564*cdf0e10cSrcweir for ( const ::rtl::OUString* pSourceElementName = aLibElementNames.getConstArray(); 1565*cdf0e10cSrcweir pSourceElementName != aLibElementNames.getConstArray() + aLibElementNames.getLength(); 1566*cdf0e10cSrcweir ++pSourceElementName 1567*cdf0e10cSrcweir ) 1568*cdf0e10cSrcweir { 1569*cdf0e10cSrcweir Any aElement = xSourceLib->getByName( *pSourceElementName ); 1570*cdf0e10cSrcweir OSL_ENSURE( aElement.hasValue(), 1571*cdf0e10cSrcweir "MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow: invalid (empty) lib element!" ); 1572*cdf0e10cSrcweir 1573*cdf0e10cSrcweir // if this is a dialog, adjust the references to scripts 1574*cdf0e10cSrcweir if ( _eScriptType == eDialog ) 1575*cdf0e10cSrcweir { 1576*cdf0e10cSrcweir impl_adjustDialogEvents_nothrow( aElement, lcl_getSubDocumentDescription( _rDocument ), 1577*cdf0e10cSrcweir *pSourceLibName, *pSourceElementName ); 1578*cdf0e10cSrcweir } 1579*cdf0e10cSrcweir 1580*cdf0e10cSrcweir xTargetLib->insertByName( *pSourceElementName, aElement ); 1581*cdf0e10cSrcweir } 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir // transfer the read-only flag 1584*cdf0e10cSrcweir xTargetLibraries->setLibraryReadOnly( 1585*cdf0e10cSrcweir sNewLibName, xSourceLibraries->isLibraryReadOnly( *pSourceLibName ) ); 1586*cdf0e10cSrcweir } 1587*cdf0e10cSrcweir 1588*cdf0e10cSrcweir // remove the source lib 1589*cdf0e10cSrcweir xSourceLibraries->removeLibrary( *pSourceLibName ); 1590*cdf0e10cSrcweir 1591*cdf0e10cSrcweir // tell the logger 1592*cdf0e10cSrcweir m_rLogger.movedLibrary( m_nCurrentDocumentID, _eScriptType, *pSourceLibName, sNewLibName ); 1593*cdf0e10cSrcweir 1594*cdf0e10cSrcweir // tell the progress 1595*cdf0e10cSrcweir _rProgress.advancePhase( pSourceLibName - pSourceLibBegin ); 1596*cdf0e10cSrcweir } 1597*cdf0e10cSrcweir 1598*cdf0e10cSrcweir // clean up 1599*cdf0e10cSrcweir xSourceLibraries->storeLibraries(); 1600*cdf0e10cSrcweir 1601*cdf0e10cSrcweir xTargetLibraries->storeLibraries(); 1602*cdf0e10cSrcweir Reference< XStorage > xTargetRoot( xTargetLibraries->getRootLocation(), UNO_QUERY_THROW ); 1603*cdf0e10cSrcweir bSuccess = lcl_commitStorage_nothrow( xTargetRoot ); 1604*cdf0e10cSrcweir } 1605*cdf0e10cSrcweir catch( const Exception& ) 1606*cdf0e10cSrcweir { 1607*cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 1608*cdf0e10cSrcweir bSuccess = false; 1609*cdf0e10cSrcweir } 1610*cdf0e10cSrcweir } while ( false ); 1611*cdf0e10cSrcweir 1612*cdf0e10cSrcweir // log the error, if any 1613*cdf0e10cSrcweir if ( !bSuccess ) 1614*cdf0e10cSrcweir { 1615*cdf0e10cSrcweir m_rLogger.logFailure( MigrationError( 1616*cdf0e10cSrcweir ERR_GENERAL_MACRO_MIGRATION_FAILURE, 1617*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1618*cdf0e10cSrcweir aException 1619*cdf0e10cSrcweir ) ); 1620*cdf0e10cSrcweir } 1621*cdf0e10cSrcweir 1622*cdf0e10cSrcweir return bSuccess; 1623*cdf0e10cSrcweir } 1624*cdf0e10cSrcweir 1625*cdf0e10cSrcweir //-------------------------------------------------------------------- 1626*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow( const ::rtl::OUString& _rScriptType, 1627*cdf0e10cSrcweir ::rtl::OUString& _inout_rScriptCode ) const 1628*cdf0e10cSrcweir { 1629*cdf0e10cSrcweir OSL_PRECOND( _inout_rScriptCode.getLength(), "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: invalid script!" ); 1630*cdf0e10cSrcweir if ( !_inout_rScriptCode.getLength() ) 1631*cdf0e10cSrcweir return false; 1632*cdf0e10cSrcweir 1633*cdf0e10cSrcweir bool bSuccess = false; 1634*cdf0e10cSrcweir Any aException; 1635*cdf0e10cSrcweir try 1636*cdf0e10cSrcweir { 1637*cdf0e10cSrcweir if ( !_rScriptType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Script" ) ) 1638*cdf0e10cSrcweir || !_rScriptType.getLength() 1639*cdf0e10cSrcweir ) 1640*cdf0e10cSrcweir { 1641*cdf0e10cSrcweir OSL_ENSURE( false, 1642*cdf0e10cSrcweir "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: no or unknown script type!" ); 1643*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1644*cdf0e10cSrcweir ERR_UNKNOWN_SCRIPT_TYPE, 1645*cdf0e10cSrcweir _rScriptType 1646*cdf0e10cSrcweir ) ); 1647*cdf0e10cSrcweir return false; 1648*cdf0e10cSrcweir } 1649*cdf0e10cSrcweir 1650*cdf0e10cSrcweir // analyze the script URI 1651*cdf0e10cSrcweir Reference< XUriReferenceFactory > xUriRefFac = UriReferenceFactory::create( m_aContext.getUNOContext() ); 1652*cdf0e10cSrcweir Reference< XVndSunStarScriptUrlReference > xUri( xUriRefFac->parse( _inout_rScriptCode ), UNO_QUERY_THROW ); 1653*cdf0e10cSrcweir 1654*cdf0e10cSrcweir ::rtl::OUString sScriptLanguage = xUri->getParameter( 1655*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "language" ) ) ); 1656*cdf0e10cSrcweir ScriptType eScriptType = eBasic; 1657*cdf0e10cSrcweir if ( !lcl_getScriptTypeFromLanguage( sScriptLanguage, eScriptType ) ) 1658*cdf0e10cSrcweir { 1659*cdf0e10cSrcweir OSL_ENSURE( false, 1660*cdf0e10cSrcweir "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: unknown script language!" ); 1661*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1662*cdf0e10cSrcweir ERR_UNKNOWN_SCRIPT_LANGUAGE, 1663*cdf0e10cSrcweir sScriptLanguage 1664*cdf0e10cSrcweir ) ); 1665*cdf0e10cSrcweir return false; 1666*cdf0e10cSrcweir } 1667*cdf0e10cSrcweir 1668*cdf0e10cSrcweir ::rtl::OUString sLocation = xUri->getParameter( 1669*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) ); 1670*cdf0e10cSrcweir if ( !sLocation.equalsAscii( "document" ) ) 1671*cdf0e10cSrcweir { 1672*cdf0e10cSrcweir // only document libraries must be migrated, of course 1673*cdf0e10cSrcweir return false; 1674*cdf0e10cSrcweir } 1675*cdf0e10cSrcweir 1676*cdf0e10cSrcweir ::rtl::OUString sScriptName = xUri->getName(); 1677*cdf0e10cSrcweir sal_Int32 nLibModuleSeparator = sScriptName.indexOf( '.' ); 1678*cdf0e10cSrcweir if ( nLibModuleSeparator < 0 ) 1679*cdf0e10cSrcweir { 1680*cdf0e10cSrcweir OSL_ENSURE( false, 1681*cdf0e10cSrcweir "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: invalid/unknown location format!" ); 1682*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1683*cdf0e10cSrcweir ERR_UNKNOWN_SCRIPT_NAME_FORMAT, 1684*cdf0e10cSrcweir sScriptName 1685*cdf0e10cSrcweir ) ); 1686*cdf0e10cSrcweir return false; 1687*cdf0e10cSrcweir } 1688*cdf0e10cSrcweir 1689*cdf0e10cSrcweir // replace the library name 1690*cdf0e10cSrcweir ::rtl::OUString sLibrary = sScriptName.copy( 0, nLibModuleSeparator ); 1691*cdf0e10cSrcweir ::rtl::OUString sNewLibName = m_rLogger.getNewLibraryName( 1692*cdf0e10cSrcweir m_nCurrentDocumentID, eScriptType, sLibrary ); 1693*cdf0e10cSrcweir OSL_ENSURE( sLibrary != sNewLibName, 1694*cdf0e10cSrcweir "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: a library which has not been migrated?" ); 1695*cdf0e10cSrcweir 1696*cdf0e10cSrcweir ::rtl::OUStringBuffer aNewLocation; 1697*cdf0e10cSrcweir aNewLocation.append( sNewLibName ); 1698*cdf0e10cSrcweir aNewLocation.append( sScriptName.copy( nLibModuleSeparator ) ); 1699*cdf0e10cSrcweir xUri->setName( aNewLocation.makeStringAndClear() ); 1700*cdf0e10cSrcweir 1701*cdf0e10cSrcweir // update the new script URL 1702*cdf0e10cSrcweir _inout_rScriptCode = xUri->getUriReference(); 1703*cdf0e10cSrcweir bSuccess = true; 1704*cdf0e10cSrcweir } 1705*cdf0e10cSrcweir catch( const Exception& ) 1706*cdf0e10cSrcweir { 1707*cdf0e10cSrcweir aException = ::cppu::getCaughtException(); 1708*cdf0e10cSrcweir bSuccess = false; 1709*cdf0e10cSrcweir } 1710*cdf0e10cSrcweir 1711*cdf0e10cSrcweir // log the failure, if any 1712*cdf0e10cSrcweir if ( !bSuccess ) 1713*cdf0e10cSrcweir { 1714*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1715*cdf0e10cSrcweir ERR_SCRIPT_TRANSLATION_FAILURE, 1716*cdf0e10cSrcweir _rScriptType, 1717*cdf0e10cSrcweir _inout_rScriptCode, 1718*cdf0e10cSrcweir aException 1719*cdf0e10cSrcweir ) ); 1720*cdf0e10cSrcweir } 1721*cdf0e10cSrcweir 1722*cdf0e10cSrcweir return bSuccess; 1723*cdf0e10cSrcweir } 1724*cdf0e10cSrcweir 1725*cdf0e10cSrcweir //-------------------------------------------------------------------- 1726*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow( ScriptEventDescriptor& _inout_rScriptEvent ) const 1727*cdf0e10cSrcweir { 1728*cdf0e10cSrcweir if ( _inout_rScriptEvent.ScriptType.getLength() && _inout_rScriptEvent.ScriptCode.getLength() ) 1729*cdf0e10cSrcweir return impl_adjustScriptLibrary_nothrow( _inout_rScriptEvent.ScriptType, _inout_rScriptEvent.ScriptCode ); 1730*cdf0e10cSrcweir return false; 1731*cdf0e10cSrcweir } 1732*cdf0e10cSrcweir 1733*cdf0e10cSrcweir //-------------------------------------------------------------------- 1734*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow( Any& _inout_rScriptDescriptor ) const 1735*cdf0e10cSrcweir { 1736*cdf0e10cSrcweir ::comphelper::NamedValueCollection aScriptDesc( _inout_rScriptDescriptor ); 1737*cdf0e10cSrcweir 1738*cdf0e10cSrcweir ::rtl::OUString sScriptType; 1739*cdf0e10cSrcweir ::rtl::OUString sScript; 1740*cdf0e10cSrcweir try 1741*cdf0e10cSrcweir { 1742*cdf0e10cSrcweir OSL_VERIFY( aScriptDesc.get_ensureType( "EventType", sScriptType ) ); 1743*cdf0e10cSrcweir OSL_VERIFY( aScriptDesc.get_ensureType( "Script", sScript ) ); 1744*cdf0e10cSrcweir } 1745*cdf0e10cSrcweir catch( const Exception& ) 1746*cdf0e10cSrcweir { 1747*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1748*cdf0e10cSrcweir ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT, 1749*cdf0e10cSrcweir ::cppu::getCaughtException() 1750*cdf0e10cSrcweir ) ); 1751*cdf0e10cSrcweir } 1752*cdf0e10cSrcweir 1753*cdf0e10cSrcweir if ( sScriptType.getLength() && sScript.getLength() ) 1754*cdf0e10cSrcweir if ( !impl_adjustScriptLibrary_nothrow( sScriptType, sScript ) ) 1755*cdf0e10cSrcweir return false; 1756*cdf0e10cSrcweir 1757*cdf0e10cSrcweir aScriptDesc.put( "Script", sScript ); 1758*cdf0e10cSrcweir _inout_rScriptDescriptor <<= aScriptDesc.getPropertyValues(); 1759*cdf0e10cSrcweir return true; 1760*cdf0e10cSrcweir } 1761*cdf0e10cSrcweir 1762*cdf0e10cSrcweir //-------------------------------------------------------------------- 1763*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_adjustDocumentEvents_nothrow( const SubDocument& _rDocument ) const 1764*cdf0e10cSrcweir { 1765*cdf0e10cSrcweir try 1766*cdf0e10cSrcweir { 1767*cdf0e10cSrcweir Reference< XEventsSupplier > xSuppEvents( _rDocument.xDocument, UNO_QUERY ); 1768*cdf0e10cSrcweir if ( !xSuppEvents.is() ) 1769*cdf0e10cSrcweir // this is allowed. E.g. new-style reports currently do not support this 1770*cdf0e10cSrcweir return true; 1771*cdf0e10cSrcweir 1772*cdf0e10cSrcweir Reference< XNameReplace > xEvents( xSuppEvents->getEvents(), UNO_SET_THROW ); 1773*cdf0e10cSrcweir Sequence< ::rtl::OUString > aEventNames = xEvents->getElementNames(); 1774*cdf0e10cSrcweir 1775*cdf0e10cSrcweir Any aEvent; 1776*cdf0e10cSrcweir for ( const ::rtl::OUString* eventName = aEventNames.getConstArray(); 1777*cdf0e10cSrcweir eventName != aEventNames.getConstArray() + aEventNames.getLength(); 1778*cdf0e10cSrcweir ++eventName 1779*cdf0e10cSrcweir ) 1780*cdf0e10cSrcweir { 1781*cdf0e10cSrcweir aEvent = xEvents->getByName( *eventName ); 1782*cdf0e10cSrcweir if ( !aEvent.hasValue() ) 1783*cdf0e10cSrcweir continue; 1784*cdf0e10cSrcweir 1785*cdf0e10cSrcweir // translate 1786*cdf0e10cSrcweir if ( !impl_adjustScriptLibrary_nothrow( aEvent ) ) 1787*cdf0e10cSrcweir continue; 1788*cdf0e10cSrcweir 1789*cdf0e10cSrcweir // put back 1790*cdf0e10cSrcweir xEvents->replaceByName( *eventName, aEvent ); 1791*cdf0e10cSrcweir } 1792*cdf0e10cSrcweir } 1793*cdf0e10cSrcweir catch( const Exception& ) 1794*cdf0e10cSrcweir { 1795*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1796*cdf0e10cSrcweir ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED, 1797*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1798*cdf0e10cSrcweir ::cppu::getCaughtException() 1799*cdf0e10cSrcweir ) ); 1800*cdf0e10cSrcweir return false; 1801*cdf0e10cSrcweir } 1802*cdf0e10cSrcweir return true; 1803*cdf0e10cSrcweir } 1804*cdf0e10cSrcweir 1805*cdf0e10cSrcweir //-------------------------------------------------------------------- 1806*cdf0e10cSrcweir void MigrationEngine_Impl::impl_adjustDialogElementEvents_throw( const Reference< XInterface >& _rxElement ) const 1807*cdf0e10cSrcweir { 1808*cdf0e10cSrcweir Reference< XScriptEventsSupplier > xEventsSupplier( _rxElement, UNO_QUERY_THROW ); 1809*cdf0e10cSrcweir Reference< XNameReplace > xEvents( xEventsSupplier->getEvents(), UNO_QUERY_THROW ); 1810*cdf0e10cSrcweir Sequence< ::rtl::OUString > aEventNames( xEvents->getElementNames() ); 1811*cdf0e10cSrcweir 1812*cdf0e10cSrcweir const ::rtl::OUString* eventName = aEventNames.getArray(); 1813*cdf0e10cSrcweir const ::rtl::OUString* eventNamesEnd = eventName + aEventNames.getLength(); 1814*cdf0e10cSrcweir 1815*cdf0e10cSrcweir ScriptEventDescriptor aScriptEvent; 1816*cdf0e10cSrcweir for ( ; eventName != eventNamesEnd; ++eventName ) 1817*cdf0e10cSrcweir { 1818*cdf0e10cSrcweir OSL_VERIFY( xEvents->getByName( *eventName ) >>= aScriptEvent ); 1819*cdf0e10cSrcweir 1820*cdf0e10cSrcweir if ( !impl_adjustScriptLibrary_nothrow( aScriptEvent ) ) 1821*cdf0e10cSrcweir continue; 1822*cdf0e10cSrcweir 1823*cdf0e10cSrcweir xEvents->replaceByName( *eventName, makeAny( aScriptEvent ) ); 1824*cdf0e10cSrcweir } 1825*cdf0e10cSrcweir } 1826*cdf0e10cSrcweir 1827*cdf0e10cSrcweir //-------------------------------------------------------------------- 1828*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_adjustDialogEvents_nothrow( Any& _inout_rDialogLibraryElement, 1829*cdf0e10cSrcweir const ::rtl::OUString& _rDocName, const ::rtl::OUString& _rDialogLibName, const ::rtl::OUString& _rDialogName ) const 1830*cdf0e10cSrcweir { 1831*cdf0e10cSrcweir try 1832*cdf0e10cSrcweir { 1833*cdf0e10cSrcweir // load a dialog model from the stream describing it 1834*cdf0e10cSrcweir Reference< XInputStreamProvider > xISP( _inout_rDialogLibraryElement, UNO_QUERY_THROW ); 1835*cdf0e10cSrcweir Reference< XInputStream > xInput( xISP->createInputStream(), UNO_QUERY_THROW ); 1836*cdf0e10cSrcweir 1837*cdf0e10cSrcweir Reference< XNameContainer > xDialogModel( m_aContext.createComponent( "com.sun.star.awt.UnoControlDialogModel" ), UNO_QUERY_THROW ); 1838*cdf0e10cSrcweir ::xmlscript::importDialogModel( xInput, xDialogModel, m_aContext.getUNOContext() ); 1839*cdf0e10cSrcweir 1840*cdf0e10cSrcweir // adjust the events of the dialog 1841*cdf0e10cSrcweir impl_adjustDialogElementEvents_throw( xDialogModel ); 1842*cdf0e10cSrcweir 1843*cdf0e10cSrcweir // adjust the events of the controls 1844*cdf0e10cSrcweir Sequence< ::rtl::OUString > aControlNames( xDialogModel->getElementNames() ); 1845*cdf0e10cSrcweir const ::rtl::OUString* controlName = aControlNames.getConstArray(); 1846*cdf0e10cSrcweir const ::rtl::OUString* controlNamesEnd = controlName + aControlNames.getLength(); 1847*cdf0e10cSrcweir for ( ; controlName != controlNamesEnd; ++controlName ) 1848*cdf0e10cSrcweir { 1849*cdf0e10cSrcweir impl_adjustDialogElementEvents_throw( Reference< XInterface >( xDialogModel->getByName( *controlName ), UNO_QUERY ) ); 1850*cdf0e10cSrcweir } 1851*cdf0e10cSrcweir 1852*cdf0e10cSrcweir // export dialog model 1853*cdf0e10cSrcweir xISP = ::xmlscript::exportDialogModel( xDialogModel, m_aContext.getUNOContext() ); 1854*cdf0e10cSrcweir _inout_rDialogLibraryElement <<= xISP; 1855*cdf0e10cSrcweir } 1856*cdf0e10cSrcweir catch( const Exception& ) 1857*cdf0e10cSrcweir { 1858*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1859*cdf0e10cSrcweir ERR_ADJUSTING_DIALOG_EVENTS_FAILED, 1860*cdf0e10cSrcweir _rDocName, 1861*cdf0e10cSrcweir _rDialogLibName, 1862*cdf0e10cSrcweir _rDialogName, 1863*cdf0e10cSrcweir ::cppu::getCaughtException() 1864*cdf0e10cSrcweir ) ); 1865*cdf0e10cSrcweir return false; 1866*cdf0e10cSrcweir } 1867*cdf0e10cSrcweir return true; 1868*cdf0e10cSrcweir } 1869*cdf0e10cSrcweir 1870*cdf0e10cSrcweir //-------------------------------------------------------------------- 1871*cdf0e10cSrcweir void MigrationEngine_Impl::impl_adjustFormComponentEvents_throw( const Reference< XIndexAccess >& _rxComponentContainer ) const 1872*cdf0e10cSrcweir { 1873*cdf0e10cSrcweir FormComponentIterator aCompIter( _rxComponentContainer ); 1874*cdf0e10cSrcweir while ( aCompIter.hasMore() ) 1875*cdf0e10cSrcweir { 1876*cdf0e10cSrcweir // 1. adjust the component's scripts of the current component 1877*cdf0e10cSrcweir FormComponentScripts aComponent( aCompIter.next() ); 1878*cdf0e10cSrcweir Sequence< ScriptEventDescriptor > aEvents( aComponent.getEvents() ); 1879*cdf0e10cSrcweir 1880*cdf0e10cSrcweir bool bChangedComponentEvents = false; 1881*cdf0e10cSrcweir for ( ScriptEventDescriptor* scriptEvent = aEvents.getArray(); 1882*cdf0e10cSrcweir scriptEvent != aEvents.getArray() + aEvents.getLength(); 1883*cdf0e10cSrcweir ++scriptEvent 1884*cdf0e10cSrcweir ) 1885*cdf0e10cSrcweir { 1886*cdf0e10cSrcweir if ( !impl_adjustScriptLibrary_nothrow( *scriptEvent ) ) 1887*cdf0e10cSrcweir continue; 1888*cdf0e10cSrcweir 1889*cdf0e10cSrcweir bChangedComponentEvents = true; 1890*cdf0e10cSrcweir } 1891*cdf0e10cSrcweir 1892*cdf0e10cSrcweir if ( bChangedComponentEvents ) 1893*cdf0e10cSrcweir aComponent.setEvents( aEvents ); 1894*cdf0e10cSrcweir 1895*cdf0e10cSrcweir // 2. step down if the component is a container itself 1896*cdf0e10cSrcweir Reference< XIndexAccess > xContainer( aComponent.getComponent(), UNO_QUERY ); 1897*cdf0e10cSrcweir if ( xContainer.is() ) 1898*cdf0e10cSrcweir impl_adjustFormComponentEvents_throw( xContainer ); 1899*cdf0e10cSrcweir } 1900*cdf0e10cSrcweir } 1901*cdf0e10cSrcweir 1902*cdf0e10cSrcweir //-------------------------------------------------------------------- 1903*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_adjustFormComponentEvents_nothrow( const SubDocument& _rDocument ) const 1904*cdf0e10cSrcweir { 1905*cdf0e10cSrcweir try 1906*cdf0e10cSrcweir { 1907*cdf0e10cSrcweir DrawPageIterator aPageIter( _rDocument.xDocument ); 1908*cdf0e10cSrcweir while ( aPageIter.hasMore() ) 1909*cdf0e10cSrcweir { 1910*cdf0e10cSrcweir Reference< XFormsSupplier > xSuppForms( aPageIter.next(), UNO_QUERY_THROW ); 1911*cdf0e10cSrcweir Reference< XIndexAccess > xForms( xSuppForms->getForms(), UNO_QUERY_THROW ); 1912*cdf0e10cSrcweir impl_adjustFormComponentEvents_throw( xForms ); 1913*cdf0e10cSrcweir } 1914*cdf0e10cSrcweir } 1915*cdf0e10cSrcweir catch( const Exception& ) 1916*cdf0e10cSrcweir { 1917*cdf0e10cSrcweir m_rLogger.logRecoverable( MigrationError( 1918*cdf0e10cSrcweir ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED, 1919*cdf0e10cSrcweir lcl_getSubDocumentDescription( _rDocument ), 1920*cdf0e10cSrcweir ::cppu::getCaughtException() 1921*cdf0e10cSrcweir ) ); 1922*cdf0e10cSrcweir return false; 1923*cdf0e10cSrcweir } 1924*cdf0e10cSrcweir return true; 1925*cdf0e10cSrcweir } 1926*cdf0e10cSrcweir 1927*cdf0e10cSrcweir //-------------------------------------------------------------------- 1928*cdf0e10cSrcweir bool MigrationEngine_Impl::impl_unprotectPasswordLibrary_throw( const Reference< XLibraryContainerPassword >& _rxPasswordManager, 1929*cdf0e10cSrcweir const ScriptType _eScriptType, const ::rtl::OUString& _rLibraryName ) const 1930*cdf0e10cSrcweir { 1931*cdf0e10cSrcweir // a human-readable description of the affected library 1932*cdf0e10cSrcweir ::rtl::OUString sLibraryDescription( String( 1933*cdf0e10cSrcweir MacroMigrationResId( STR_LIBRARY_TYPE_AND_NAME ) ) ); 1934*cdf0e10cSrcweir ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, "$type$", 1935*cdf0e10cSrcweir getScriptTypeDisplayName( _eScriptType ) ); 1936*cdf0e10cSrcweir ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, "$library$", 1937*cdf0e10cSrcweir _rLibraryName ); 1938*cdf0e10cSrcweir 1939*cdf0e10cSrcweir InteractionHandler aHandler( m_aContext, m_xDocumentModel ); 1940*cdf0e10cSrcweir ::rtl::OUString sPassword; 1941*cdf0e10cSrcweir while ( true ) 1942*cdf0e10cSrcweir { 1943*cdf0e10cSrcweir if ( !aHandler.requestDocumentPassword( sLibraryDescription, sPassword ) ) 1944*cdf0e10cSrcweir // aborted by the user 1945*cdf0e10cSrcweir return false; 1946*cdf0e10cSrcweir 1947*cdf0e10cSrcweir bool bSuccessVerification = _rxPasswordManager->verifyLibraryPassword( _rLibraryName, sPassword ); 1948*cdf0e10cSrcweir if ( bSuccessVerification ) 1949*cdf0e10cSrcweir return true; 1950*cdf0e10cSrcweir } 1951*cdf0e10cSrcweir 1952*cdf0e10cSrcweir } 1953*cdf0e10cSrcweir 1954*cdf0e10cSrcweir //==================================================================== 1955*cdf0e10cSrcweir //= MigrationEngine 1956*cdf0e10cSrcweir //==================================================================== 1957*cdf0e10cSrcweir //-------------------------------------------------------------------- 1958*cdf0e10cSrcweir MigrationEngine::MigrationEngine( const ::comphelper::ComponentContext& _rContext, 1959*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument >& _rxDocument, IMigrationProgress& _rProgress, 1960*cdf0e10cSrcweir MigrationLog& _rLogger ) 1961*cdf0e10cSrcweir :m_pImpl( new MigrationEngine_Impl( _rContext, _rxDocument, _rProgress, _rLogger ) ) 1962*cdf0e10cSrcweir { 1963*cdf0e10cSrcweir } 1964*cdf0e10cSrcweir 1965*cdf0e10cSrcweir //-------------------------------------------------------------------- 1966*cdf0e10cSrcweir MigrationEngine::~MigrationEngine() 1967*cdf0e10cSrcweir { 1968*cdf0e10cSrcweir } 1969*cdf0e10cSrcweir 1970*cdf0e10cSrcweir //-------------------------------------------------------------------- 1971*cdf0e10cSrcweir sal_Int32 MigrationEngine::getFormCount() const 1972*cdf0e10cSrcweir { 1973*cdf0e10cSrcweir return m_pImpl->getFormCount(); 1974*cdf0e10cSrcweir } 1975*cdf0e10cSrcweir 1976*cdf0e10cSrcweir //-------------------------------------------------------------------- 1977*cdf0e10cSrcweir sal_Int32 MigrationEngine::getReportCount() const 1978*cdf0e10cSrcweir { 1979*cdf0e10cSrcweir return m_pImpl->getReportCount(); 1980*cdf0e10cSrcweir } 1981*cdf0e10cSrcweir 1982*cdf0e10cSrcweir //-------------------------------------------------------------------- 1983*cdf0e10cSrcweir bool MigrationEngine::migrateAll() 1984*cdf0e10cSrcweir { 1985*cdf0e10cSrcweir return m_pImpl->migrateAll(); 1986*cdf0e10cSrcweir } 1987*cdf0e10cSrcweir 1988*cdf0e10cSrcweir //........................................................................ 1989*cdf0e10cSrcweir } // namespace dbmm 1990*cdf0e10cSrcweir //........................................................................ 1991