Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-05-11 21:13:11+0000
Modified:
   dba/dbaccess/source/ext/macromigration/migrationengine.cxx

Log:
 handle password-proteced libraries, by asking the user

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.8&r2=1.4.2.9
Delta lines:  +102 -17
----------------------
--- migrationengine.cxx 2008-05-08 13:47:20+0000        1.4.2.8
+++ migrationengine.cxx 2008-05-11 21:13:09+0000        1.4.2.9
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: migrationengine.cxx,v $
- * $Revision: 1.4.2.8 $
+ * $Revision: 1.4.2.9 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -65,12 +65,14 @@
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/script/XEventAttacherManager.hpp>
+#include <com/sun/star/script/XLibraryContainerPassword.hpp>
 /** === end UNO includes === **/
 
 #include <comphelper/documentinfo.hxx>
+#include <comphelper/interaction.hxx>
+#include <comphelper/namedvaluecollection.hxx>
 #include <comphelper/string.hxx>
 #include <comphelper/types.hxx>
-#include <comphelper/namedvaluecollection.hxx>
 #include <cppuhelper/exc_hlp.hxx>
 #include <tools/string.hxx>
 #include <tools/diagnose_ex.h>
@@ -135,6 +137,7 @@
     using ::com::sun::star::container::XIndexAccess;
     using ::com::sun::star::script::XEventAttacherManager;
     using ::com::sun::star::script::ScriptEventDescriptor;
+    using ::com::sun::star::script::XLibraryContainerPassword;
     /** === end UNO using === **/
     namespace ElementModes = ::com::sun::star::embed::ElementModes;
 
@@ -801,6 +804,37 @@
     };
 
        //====================================================================
+       //= PhaseGuard
+       //====================================================================
+    class PhaseGuard
+    {
+    public:
+        PhaseGuard( ProgressMixer& _rMixer )
+            :m_rMixer( _rMixer )
+        {
+        }
+
+        PhaseGuard( ProgressMixer& _rMixer, const PhaseID _nID, const 
sal_uInt32 _nPhaseRange )
+            :m_rMixer( _rMixer )
+        {
+            start( _nID, _nPhaseRange );
+        }
+
+        ~PhaseGuard()
+        {
+            m_rMixer.endPhase();
+        }
+
+        void start( const PhaseID _nID, const sal_uInt32 _nPhaseRange )
+        {
+            m_rMixer.startPhase( _nID, _nPhaseRange );
+        }
+
+    private:
+        ProgressMixer&  m_rMixer;
+    };
+
+       //====================================================================
        //= MigrationEngine_Impl - declaration
        //====================================================================
     class MigrationEngine_Impl
@@ -899,6 +933,17 @@
 
         bool    impl_adjustScriptLibrary_nothrow( Any& 
_inout_rScriptDescriptor ) const;
         bool    impl_adjustScriptLibrary_nothrow( ScriptEventDescriptor& 
_inout_rScriptEvent ) const;
+
+        /** asks the user for a password for the given library, and unprotects 
the library
+
+            @return <TRUE/>
+                if and only if the library could be successfully unprotected
+        */
+        bool    impl_unprotectPasswordLibrary_throw(
+                    const Reference< XLibraryContainerPassword >& 
_rxPasswordManager,
+                    const ScriptType _eScriptType,
+                    const ::rtl::OUString& _rLibraryName
+                ) const;
     };
 
        //====================================================================
@@ -1213,7 +1258,7 @@
         SharedStorage xTargetStorage;
             // the target for moving the scripts storages - created on demand 
only
 
-        bool bPhaseStarted = false;
+        PhaseGuard aPhase( _rProgress );
         bool bSuccess = false;
         Any aException;
         try
@@ -1236,8 +1281,7 @@
 
             // loop through the script libraries
             Sequence< ::rtl::OUString > aStorageElements( 
xScriptsRoot->getElementNames() );
-            _rProgress.startPhase( _nPhaseID, aStorageElements.getLength() );
-            bPhaseStarted = true;
+            aPhase.start( _nPhaseID, aStorageElements.getLength() );
 
             for (   const ::rtl::OUString* element = 
aStorageElements.getConstArray();
                     element != aStorageElements.getConstArray() + 
aStorageElements.getLength();
@@ -1328,10 +1372,6 @@
             ) );
         }
 
-        // progress - we're done with this phase
-        if ( bPhaseStarted )
-            _rProgress.endPhase();
-
         return bSuccess;
     }
 
@@ -1343,7 +1383,7 @@
             "MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow: 
illegal script type!" );
 
         bool bSuccess = false;
-        bool bPhaseStarted = false;
+        PhaseGuard aPhase( _rProgress );
         Any aException;
         do  // artificial loop for flow control only
         {
@@ -1362,9 +1402,12 @@
                 _eScriptType == eBasic ? xSubDocScripts->getBasicLibraries() : 
xSubDocScripts->getDialogLibraries(),
                 UNO_QUERY_THROW
             );
+            Reference< XLibraryContainerPassword > xSourcePasswords( 
xSourceLibraries, UNO_QUERY );
+            OSL_ENSURE( xSourcePasswords.is(),
+                "MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow: 
suspicious: no password management for the source libraries!" );
+
             Sequence< ::rtl::OUString > aSourceLibNames( 
xSourceLibraries->getElementNames() );
-            _rProgress.startPhase( _nPhaseID, aSourceLibNames.getLength() );
-            bPhaseStarted = true;
+            aPhase.start( _nPhaseID, aSourceLibNames.getLength() );
 
             if ( !xSourceLibraries->hasElements() )
             {
@@ -1394,6 +1437,24 @@
                     ++pSourceLibName
                 )
             {
+                // if the library is password-protected, ask the user to 
unprotect it
+                if  (   xSourcePasswords.is()
+                    &&  xSourcePasswords->isLibraryPasswordProtected( 
*pSourceLibName )
+                    &&  !xSourcePasswords->isLibraryPasswordVerified( 
*pSourceLibName )
+                    )
+                {
+                    if ( !impl_unprotectPasswordLibrary_throw( 
xSourcePasswords, _eScriptType, *pSourceLibName ) )
+                    {
+                        m_rLogger.logFailure( MigrationError(
+                            ERR_PASSWORD_VERIFICATION_FAILED,
+                            lcl_getSubDocumentDescription( _rDocument ),
+                            getScriptTypeDisplayName( _eScriptType ),
+                            *pSourceLibName
+                        ) );
+                        return false;
+                    }
+                }
+
                 ::rtl::OUString sNewLibName( lcl_createTargetLibName( 
_rDocument, *pSourceLibName, xTargetLibraries.get() ) );
 
                 if ( xSourceLibraries->isLibraryLink( *pSourceLibName ) )
@@ -1460,15 +1521,11 @@
         {
             m_rLogger.logFailure( MigrationError(
                 ERR_GENERAL_MACRO_MIGRATION_FAILURE,
-                _rDocument.sHierarchicalName,
+                lcl_getSubDocumentDescription( _rDocument ),
                 aException
             ) );
         }
 
-        // progress - we're done with this phase
-        if ( bPhaseStarted )
-            _rProgress.endPhase();
-
         return bSuccess;
     }
 
@@ -1709,6 +1766,34 @@
         return true;
     }
 
+       //--------------------------------------------------------------------
+    bool MigrationEngine_Impl::impl_unprotectPasswordLibrary_throw( const 
Reference< XLibraryContainerPassword >& _rxPasswordManager,
+            const ScriptType _eScriptType, const ::rtl::OUString& 
_rLibraryName ) const
+    {
+        // a human-readable description of the affected library
+        ::rtl::OUString sLibraryDescription( String(
+            MacroMigrationResId( STR_LIBRARY_TYPE_AND_NAME ) ) );
+        ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, 
"$type$",
+            getScriptTypeDisplayName( _eScriptType ) );
+        ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, 
"$library$",
+            _rLibraryName );
+
+        InteractionHandler aHandler( m_aContext, m_xDocumentModel );
+        ::rtl::OUString sPassword;
+        while ( true )
+        {
+            if ( !aHandler.requestDocumentPassword( sLibraryDescription, 
sPassword ) )
+                // aborted by the user
+                return false;
+
+            bool bSuccessVerification = 
_rxPasswordManager->verifyLibraryPassword( _rLibraryName, sPassword );
+            if ( bSuccessVerification )
+                return true;
+        }
+
+        return false;
+    }
+
        //====================================================================
        //= MigrationEngine
        //====================================================================




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

Reply via email to