Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-05-08 10:09:05+0000
Modified:
   dba/dbaccess/source/ext/macromigration/migrationengine.cxx

Log:
 break the migration of there is an unknown folder below a 'Scripts' folder 
(else it would silently be deleted, since we cannot handle it)

File Changes:

Directory: /dba/dbaccess/source/ext/macromigration/
===================================================

File [changed]: migrationengine.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/migrationengine.cxx?r1=1.4.2.6&r2=1.4.2.7
Delta lines:  +84 -6
--------------------
--- migrationengine.cxx 2008-05-07 08:36:27+0000        1.4.2.6
+++ migrationengine.cxx 2008-05-08 10:09:02+0000        1.4.2.7
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: migrationengine.cxx,v $
- * $Revision: 1.4.2.6 $
+ * $Revision: 1.4.2.7 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -584,6 +584,11 @@
         SharedStorage
                 getScriptsRoot( const ScriptType _eType ) const;
 
+        /** returns the names of the elements in the "Scripts" storage
+        */
+        ::std::set< ::rtl::OUString >
+                getElementNames() const;
+
         /** removes the sub storage for a given script type
             @precond
                 the respective storage is empty
@@ -708,6 +713,22 @@
     }
 
     //--------------------------------------------------------------------
+    ::std::set< ::rtl::OUString > ScriptsStorage::getElementNames() const
+    {
+        Sequence< ::rtl::OUString > aElementNames;
+        if ( isValid() )
+            aElementNames = m_xScriptsStorage->getElementNames();
+
+        ::std::set< ::rtl::OUString > aNames;
+        ::std::copy(
+            aElementNames.getConstArray(),
+            aElementNames.getConstArray() + aElementNames.getLength(),
+            ::std::insert_iterator< ::std::set< ::rtl::OUString > >( aNames, 
aNames.end() )
+        );
+        return aNames;
+    }
+
+    //--------------------------------------------------------------------
     void ScriptsStorage::removeScriptTypeStorage( const ScriptType _eType ) 
const
     {
         OSL_PRECOND( isWriteable(), "ScriptsStorage::removeScriptTypeStorage: 
not writeable!" );
@@ -820,7 +841,15 @@
         */
         bool    impl_handleDocument_nothrow( const SubDocument& _rDocument ) 
const;
 
-        /** migrates the scripts of the given "storage-based" script typ
+        /** checks the structure of the 'Scripts' folder of a sub document
+            for unknown elements
+
+            @return
+                <TRUE/> if and only if the 'Scripts' folder contains known 
elements only.
+        */
+        bool    impl_checkScriptStorageStructure_nothrow( const SubDocument& 
_rDocument ) const;
+
+        /** migrates the scripts of the given "storage-based" script type
         */
         bool    impl_migrateScriptStorage_nothrow(
                     const SubDocument& _rDocument,
@@ -853,7 +882,9 @@
 
         /** adjusts the script references for the elements of the given form 
component container
         */
-        void    impl_adjustFormComponentEvents_throw( const Reference< 
XIndexAccess >& _rxComponentContainer ) const;
+        void    impl_adjustFormComponentEvents_throw(
+                    const Reference< XIndexAccess >& _rxComponentContainer
+                ) const;
 
         /** adjusts the library name in the given script URL, so that it 
reflects
             the new name of the library
@@ -1046,9 +1077,11 @@
             // more weight than then others, assuming that usually, there are 
much more Basic macros than any other scripts
         aProgressMixer.registerPhase( PHASE_DIALOGS, 1 );
 
+        bool bSuccess = impl_checkScriptStorageStructure_nothrow( aSubDocument 
);
+
         // migrate storage-based script libraries (which can be handled by 
mere storage operations)
-        bool bSuccess =
-                impl_migrateScriptStorage_nothrow( aSubDocument, eJavaScript, 
aProgressMixer, PHASE_JAVASCRIPT )
+        bSuccess = bSuccess
+            &&  impl_migrateScriptStorage_nothrow( aSubDocument, eJavaScript, 
aProgressMixer, PHASE_JAVASCRIPT )
             &&  impl_migrateScriptStorage_nothrow( aSubDocument, eBeanShell, 
aProgressMixer, PHASE_BEANSHELL )
             &&  impl_migrateScriptStorage_nothrow( aSubDocument, ePython, 
aProgressMixer, PHASE_PYTHON )
             &&  impl_migrateScriptStorage_nothrow( aSubDocument, eJava, 
aProgressMixer, PHASE_JAVA );
@@ -1123,6 +1156,51 @@
     }
 
     //--------------------------------------------------------------------
+    bool MigrationEngine_Impl::impl_checkScriptStorageStructure_nothrow( const 
SubDocument& _rDocument ) const
+    {
+        OSL_PRECOND( _rDocument.xDocument.is(), 
"MigrationEngine_Impl::impl_checkScriptStorageStructure_nothrow: invalid 
document!" );
+        if ( !_rDocument.xDocument.is() )
+            return false;
+
+        try
+        {
+            // the root storage of the document whose scripts are to be 
migrated
+            ScriptsStorage aDocStorage( _rDocument.xDocument, 
ScriptsStorage::WRITE, m_rLogger );
+            if  ( !aDocStorage.isValid() )
+            {   // no scripts at all, or no scripts of the given type
+                return !m_rLogger.hadFailure();
+            }
+            ::std::set< ::rtl::OUString > aElementNames( 
aDocStorage.getElementNames() );
+
+            ScriptType aKnownStorageBasedTypes[] = {
+                eBeanShell, eJavaScript, ePython, eJava
+            };
+            for ( size_t i=0; i<sizeof( aKnownStorageBasedTypes ) / sizeof( 
aKnownStorageBasedTypes[0] ); ++i )
+                aElementNames.erase( lcl_getScriptsSubStorageName( 
aKnownStorageBasedTypes[i] ) );
+
+            if ( !aElementNames.empty() )
+            {
+                m_rLogger.logFailure( MigrationError(
+                    ERR_UNKNOWN_SCRIPT_FOLDER,
+                    lcl_getSubDocumentDescription( _rDocument ),
+                    *aElementNames.begin()
+                ) );
+                return false;
+            }
+        }
+        catch( const Exception& )
+        {
+            m_rLogger.logFailure( MigrationError(
+                ERR_EXAMINING_SCRIPTS_FOLDER_FAILED,
+                lcl_getSubDocumentDescription( _rDocument ),
+                ::cppu::getCaughtException()
+            ) );
+            return false;
+        }
+        return true;
+    }
+
+    //--------------------------------------------------------------------
     bool MigrationEngine_Impl::impl_migrateScriptStorage_nothrow( const 
SubDocument& _rDocument,
         const ScriptType _eScriptType, ProgressMixer& _rProgress, const 
PhaseID _nPhaseID ) const
     {
@@ -1149,7 +1227,7 @@
                 // no scripts at all, or no scripts of the given type
                 _rProgress.startPhase( _nPhaseID, 1 );
                 _rProgress.endPhase();
-                return true;
+                return !m_rLogger.hadFailure();
             }
 
             SharedStorage xScriptsRoot( aDocStorage.getScriptsRoot( 
_eScriptType ) );




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to