Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-05-11 21:14:45+0000
Modified:
   dba/dbaccess/source/ext/macromigration/docerrorhandling.cxx
   dba/dbaccess/source/ext/macromigration/docerrorhandling.hxx

Log:
 extend this to a full-blown (well, kind of) InteractionHandler wrapper class

File Changes:

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

File [changed]: docerrorhandling.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/docerrorhandling.cxx?r1=1.3.2.1&r2=1.3.2.2
Delta lines:  +82 -19
---------------------
--- docerrorhandling.cxx        2008-05-08 13:46:14+0000        1.3.2.1
+++ docerrorhandling.cxx        2008-05-11 21:14:42+0000        1.3.2.2
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: docerrorhandling.cxx,v $
- * $Revision: 1.3.2.1 $
+ * $Revision: 1.3.2.2 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -34,8 +34,8 @@
 #include "docerrorhandling.hxx"
 
 /** === begin UNO includes === **/
-#include <com/sun/star/task/XInteractionHandler.hpp>
 #include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/task/DocumentPasswordRequest.hpp>
 /** === end UNO includes === **/
 
 #include <comphelper/componentcontext.hxx>
@@ -59,34 +59,97 @@
        using ::com::sun::star::uno::RuntimeException;
        using ::com::sun::star::uno::Any;
        using ::com::sun::star::uno::makeAny;
-    using ::com::sun::star::sdb::XOfficeDatabaseDocument;
     using ::com::sun::star::task::XInteractionHandler;
     using ::com::sun::star::frame::XModel;
+    using ::com::sun::star::task::DocumentPasswordRequest;
+    using ::com::sun::star::task::InteractionClassification_QUERY;
+    using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER;
+    using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER;
        /** === end UNO using === **/
 
        //====================================================================
-       //= DocumentErrorHandling
+       //= InteractionHandler_Data
+       //====================================================================
+    struct InteractionHandler_Data
+    {
+        Reference< XInteractionHandler >    xHandler;
+
+        InteractionHandler_Data( const Reference< XInteractionHandler >& 
_rxHandler )
+            :xHandler( _rxHandler )
+        {
+        }
+
+        InteractionHandler_Data( const ::comphelper::ComponentContext& 
_rContext )
+            :xHandler( _rContext.createComponent( 
"com.sun.star.task.InteractionHandler" ), UNO_QUERY_THROW )
+        {
+        }
+    };
+
+       //====================================================================
+       //= InteractionHandler
        //====================================================================
        //--------------------------------------------------------------------
-    void DocumentErrorHandling::reportError( const 
::comphelper::ComponentContext& _rContext, const Reference< 
XOfficeDatabaseDocument >& _rxDocument,  const Any& _rError )
+    InteractionHandler::InteractionHandler( const 
::comphelper::ComponentContext& _rContext )
+        :m_pData( new InteractionHandler_Data( _rContext ) )
     {
-        try
+    }
+
+       //--------------------------------------------------------------------
+    InteractionHandler::InteractionHandler( const Reference< 
XInteractionHandler >& _rxHandler )
+        :m_pData( new InteractionHandler_Data( _rxHandler ) )
         {
-            Reference< XInteractionHandler > xHandler( 
_rContext.createComponent( "com.sun.star.task.InteractionHandler" ), 
UNO_QUERY_THROW );
-            // check whether the DB doc has an own interaction handler set
-            Reference< XModel > xDocModel( _rxDocument, UNO_QUERY_THROW );
-            ::comphelper::NamedValueCollection aDocArgs( xDocModel->getArgs() 
);
-            xHandler = aDocArgs.getOrDefault( "InteractionHandler", xHandler );
+    }
 
-            ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( 
new ::comphelper::OInteractionRequest( _rError ) );
-            ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( 
new ::comphelper::OInteractionApprove );
-            pRequest->addContinuation( pApprove.get() );
-            xHandler->handle( pRequest.get() );
+       //--------------------------------------------------------------------
+    InteractionHandler::InteractionHandler( const 
::comphelper::ComponentContext& _rContext, const Reference< XModel >& 
_rxDocument )
+        :m_pData( new InteractionHandler_Data( _rContext ) )
+    {
+        // check whether the doumentc has an own interaction handler set
+        ::comphelper::NamedValueCollection aDocArgs( _rxDocument->getArgs() );
+        m_pData->xHandler = aDocArgs.getOrDefault( "InteractionHandler", 
m_pData->xHandler );
+    }
+
+       //--------------------------------------------------------------------
+    InteractionHandler::~InteractionHandler()
+    {
         }
-        catch( const Exception& )
+
+       //--------------------------------------------------------------------
+    bool InteractionHandler::requestDocumentPassword( const ::rtl::OUString& 
_rDocumentName, ::rtl::OUString& _io_rPassword )
         {
-               DBG_UNHANDLED_EXCEPTION();
+        // create request
+        DocumentPasswordRequest aRequest(
+            ::rtl::OUString(), NULL,
+            InteractionClassification_QUERY,
+            _io_rPassword.getLength() ? PasswordRequestMode_PASSWORD_REENTER : 
PasswordRequestMode_PASSWORD_ENTER,
+            _rDocumentName
+        );
+
+        ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new 
::comphelper::OInteractionRequest( makeAny( aRequest ) ) );
+        ::rtl::Reference< ::comphelper::OInteractionPassword > pPassword( new 
::comphelper::OInteractionPassword( _io_rPassword ) );
+        ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new 
::comphelper::OInteractionAbort );
+        pRequest->addContinuation( pPassword.get() );
+        pRequest->addContinuation( pAbort.get() );
+
+        // handle
+        m_pData->xHandler->handle( pRequest.get() );
+
+        // finish up
+        if ( pAbort->wasSelected() )
+            return false;
+
+        _io_rPassword = pPassword->getPassword();
+        return true;
         }
+
+       //--------------------------------------------------------------------
+    void InteractionHandler::reportError( const Any& _rError )
+    {
+        ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new 
::comphelper::OInteractionRequest( _rError ) );
+        ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new 
::comphelper::OInteractionApprove );
+        pRequest->addContinuation( pApprove.get() );
+
+        m_pData->xHandler->handle( pRequest.get() );
     }
 
 //........................................................................

File [changed]: docerrorhandling.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/docerrorhandling.hxx?r1=1.3&r2=1.3.2.1
Delta lines:  +53 -15
---------------------
--- docerrorhandling.hxx        2008-04-10 13:11:31+0000        1.3
+++ docerrorhandling.hxx        2008-05-11 21:14:42+0000        1.3.2.1
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: docerrorhandling.hxx,v $
- * $Revision: 1.3 $
+ * $Revision: 1.3.2.1 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -32,13 +32,16 @@
 #define DBACCESS_DOCERRORHANDLING_HXX
 
 /** === begin UNO includes === **/
-#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
 /** === end UNO includes === **/
 
 namespace comphelper {
     class ComponentContext;
 }
 
+#include <memory>
+
 //........................................................................
 namespace dbmm
 {
@@ -47,19 +50,54 @@
        //====================================================================
        //= DocumentErrorHandling
        //====================================================================
-       class DocumentErrorHandling
+    struct InteractionHandler_Data;
+    /** wraps common operations with an interaction handler.
+    */
+    class InteractionHandler
        {
     public:
+        /** creates an interaction handler by instantiating a 
css.task.InteractionHandler
+            component at the given component context.
+        */
+        InteractionHandler( const ::comphelper::ComponentContext& _rContext );
+
+        /** creates an InteractionHandler instance, using the given existing 
UNO handler.
+        */
+        InteractionHandler( const ::com::sun::star::uno::Reference< 
::com::sun::star::task::XInteractionHandler >& _rxHandler );
+
+        /** creates an interaction handler by instantiating a 
css.task.InteractionHandler
+            component at the given component context, or using the given 
document's interaction handler,
+            if one is specified in the document's media descriptor.
+        */
+        InteractionHandler( const ::comphelper::ComponentContext& _rContext, 
const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& 
_rxDocument );
+
+        /** destructor
+        */
+        ~InteractionHandler();
+
+        /** requests a document password
+            @param _rDocumentName
+                the document name
+            @param _io_rPassword    
+                the initial password on method entry, the password as entered 
by the user on method leave
+            @return
+                <TRUE/> if and only if the user entered a password, and 
confirmed with OK, <FALSE/>
+                if the user aborted the request.
+        */
+        bool    requestDocumentPassword(
+                    const ::rtl::OUString& _rDocumentName,
+                          ::rtl::OUString& _io_rPassword
+                );
+
         /** reports the given error (usually an exception caught on the 
caller's side)
-            to the user, using the document's interaction handler, if present. 
If the document
-            does not have an own interaction handler, the given component 
context is used
-            to create a new one.
-        */
-        static void reportError(
-                const ::comphelper::ComponentContext& _rContext,
-                const ::com::sun::star::uno::Reference< 
::com::sun::star::sdb::XOfficeDatabaseDocument >& _rxDocument,
+            to the user
+        */
+        void    reportError(
                 const ::com::sun::star::uno::Any& _rError
                );
+
+    private:
+        ::std::auto_ptr< InteractionHandler_Data >  m_pData;
        };
 
 //........................................................................




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

Reply via email to