Tag: cws_src680_dba24c
User: fs      
Date: 2007-10-22 20:59:32+0000
Modified:
   dba/dbaccess/source/core/dataaccess/ModelImpl.cxx
   dba/dbaccess/source/core/dataaccess/ModelImpl.hxx

Log:
 #i73705# #i52527#, the final step: encapsulate the MacroMode handling (no 
public attribute anymore) / properly determine whether embedded documents 
contain macros

File Changes:

Directory: /dba/dbaccess/source/core/dataaccess/
================================================

File [changed]: ModelImpl.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.cxx?r1=1.19.22.2&r2=1.19.22.3
Delta lines:  +140 -23
----------------------
--- ModelImpl.cxx       2007-10-22 10:27:31+0000        1.19.22.2
+++ ModelImpl.cxx       2007-10-22 20:59:29+0000        1.19.22.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: ModelImpl.cxx,v $
  *
- *  $Revision: 1.19.22.2 $
+ *  $Revision: 1.19.22.3 $
  *
- *  last change: $Author: fs $ $Date: 2007/10/22 10:27:31 $
+ *  last change: $Author: fs $ $Date: 2007/10/22 20:59:29 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -80,6 +80,7 @@
 #include <tools/diagnose_ex.h>
 #include <tools/errcode.hxx>
 #include <tools/urlobj.hxx>
+#include <unotools/sharedunocomponent.hxx>
 
 #include <algorithm>
 
@@ -114,7 +115,7 @@
 //........................................................................
 
 //========================================================================
-//= DocumentStorageAccess
+//= SharedMutex
 //========================================================================
 //------------------------------------------------------------------------
 SharedMutex::SharedMutex()
@@ -247,8 +248,8 @@
 {
        Sequence< ::rtl::OUString > aRet(2);
        sal_Int32 nPos = 0;
-       aRet[nPos++] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("forms"));
-       aRet[nPos++] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("reports"));
+    aRet[nPos++] = m_pModelImplementation->getObjectContainerStorageName( 
ODatabaseModelImpl::E_FORM );
+    aRet[nPos++] = m_pModelImplementation->getObjectContainerStorageName( 
ODatabaseModelImpl::E_REPORT );
        return aRet;
 }
 
@@ -268,11 +269,8 @@
 
     if ( m_pModelImplementation && m_bPropagateCommitToRoot )
     {
-        TStorages::iterator aFind = 
m_pModelImplementation->m_aStorages.find(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("database")));
-        Reference<XStorage> xStorage(aEvent.Source,UNO_QUERY);
-           if  (   ( aFind != m_pModelImplementation->m_aStorages.end() )
-            &&  ( aFind->second == xStorage )
-            )
+        Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
+        if ( m_pModelImplementation->isDatabaseStorage( xStorage ) )
            {
             m_pModelImplementation->commitRootStorage();
         }
@@ -429,6 +427,60 @@
 }
 
 // 
-----------------------------------------------------------------------------
+namespace
+{
+    // 
.........................................................................
+    ::rtl::OUString lcl_getContainerStorageName_throw( 
ODatabaseModelImpl::ObjectType _eType )
+    {
+        const sal_Char* pAsciiName( NULL );
+        switch ( _eType )
+        {
+        case ODatabaseModelImpl::E_FORM:   pAsciiName = "forms"; break;
+        case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
+        case ODatabaseModelImpl::E_QUERY:  pAsciiName = "queries"; break;
+        case ODatabaseModelImpl::E_TABLE:  pAsciiName = "tables"; break;
+        default:
+            throw RuntimeException();
+        }
+        return ::rtl::OUString::createFromAscii( pAsciiName );
+    }
+
+    // 
.........................................................................
+    bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const 
ODatabaseModelImpl::ObjectType _eType )
+    {
+        bool bSomeDocHasMacros = false;
+
+        const OContentHelper_Impl& rContainerData( 
*_rModel.getObjectContainer( _eType ).get() );
+        const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< 
const ODefinitionContainer_Impl& >( rContainerData );
+
+        try
+        {
+            ::utl::SharedUNOComponent< XStorage > xContainerStorage( 
_rModel.getStorage(
+                _rModel.getObjectContainerStorageName( _eType ), 
ElementModes::READ ) );
+
+            for (   ODefinitionContainer_Impl::const_iterator object = 
rObjectDefinitions.begin();
+                    ( object != rObjectDefinitions.end() ) && 
!bSomeDocHasMacros;
+                    ++object
+                )
+            {
+                ::utl::SharedUNOComponent< XStorage > xObjectStor( 
xContainerStorage->openStorageElement(
+                    object->second->m_aProps.sPersistentName, 
ElementModes::READ ) );
+
+                // TODO: opening the storage is too expensive, find some 
hasByHierarchicalName or so
+
+                bSomeDocHasMacros = 
::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
+            }
+        }
+        catch( const Exception& )
+        {
+               DBG_UNHANDLED_EXCEPTION();
+        }
+
+        return bSomeDocHasMacros;
+    }
+}
+
+// 
-----------------------------------------------------------------------------
 void ODatabaseModelImpl::reset()
 {
        m_bReadOnly = sal_False;
@@ -496,9 +548,9 @@
                        {
                                xConn->close();
                        }
-                       catch(Exception)
+                       catch(const Exception&)
                        {
-                               OSL_ENSURE(0,"Exception catched while closing a 
connection!");
+                               DBG_UNHANDLED_EXCEPTION();
                        }
                }
        }
@@ -707,21 +759,20 @@
        TStorages::iterator aFind = m_aStorages.find(_sStorageName);
        if ( aFind == m_aStorages.end() )
        {
-               Reference<XStorage> xMyStorage = getStorage();
-               Reference<XNameAccess> xNames(xMyStorage,UNO_QUERY);
-               if ( xMyStorage.is() )
-               {
                        try
                        {
-                               xStorage = 
xMyStorage->openStorageElement(_sStorageName, m_bDocumentReadOnly ? 
ElementModes::READ : nMode);
+                   Reference< XStorage > xMyStorage( getStorage() );
+            if ( xMyStorage.is() )
+                   {
+                               xStorage = xMyStorage->openStorageElement( 
_sStorageName, m_bDocumentReadOnly ? ElementModes::READ : nMode );
                 Reference<XTransactionBroadcaster> xBroad(xStorage,UNO_QUERY);
                 if ( xBroad.is() )
                     xBroad->addTransactionListener( getDocumentStorageAccess() 
);
                                aFind = 
m_aStorages.insert(TStorages::value_type(_sStorageName,xStorage)).first;
                        }
-                       catch(Exception&)
-                       {
                        }
+               catch( const Exception& )
+               {
                }
        }
 
@@ -931,6 +982,61 @@
 }
 
 // 
-----------------------------------------------------------------------------
+TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
+{
+    OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, 
"ODatabaseModelImpl::getObjectContainer: illegal index!" );
+    TContentPtr& rContentPtr = m_aContainer[ _eType ];
+
+    if ( !rContentPtr.get() )
+       {
+               rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
+               rContentPtr->m_pDataSource = this;
+               rContentPtr->m_aProps.aTitle = 
lcl_getContainerStorageName_throw( _eType );
+       }
+    return rContentPtr;
+}
+
+// 
-----------------------------------------------------------------------------
+bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
+{
+    return m_aMacroMode.adjustMacroMode( NULL );
+}
+
+// 
-----------------------------------------------------------------------------
+void ODatabaseModelImpl::checkMacrosOnLoading()
+{
+    ::comphelper::NamedValueCollection aArgs( m_aArgs );
+    Reference< XInteractionHandler > xInteraction;
+    xInteraction = aArgs.getOrDefault( "InteractionHandler", xInteraction );
+    m_aMacroMode.checkMacrosOnLoading( xInteraction );
+}
+
+// 
-----------------------------------------------------------------------------
+void ODatabaseModelImpl::resetMacroExecutionMode()
+{
+    m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
+}
+
+// 
-----------------------------------------------------------------------------
+bool ODatabaseModelImpl::isDatabaseStorage( const Reference< XStorage >& 
_rxStorage ) const
+{
+    TStorages::const_iterator pos = m_aStorages.find( ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM( "database" ) ) );
+       if  (   ( pos != m_aStorages.end() )
+        &&  ( pos->second == _rxStorage )
+        )
+       {
+        return true;
+    }
+    return false;
+}
+
+// 
-----------------------------------------------------------------------------
+::rtl::OUString ODatabaseModelImpl::getObjectContainerStorageName( const 
ObjectType _eType )
+{
+    return lcl_getContainerStorageName_throw( _eType );
+}
+
+// 
-----------------------------------------------------------------------------
 sal_Int16 ODatabaseModelImpl::getImposedMacroExecMode() const
 {
     sal_Int16 nMacroExecMode( MacroExecMode::USE_CONFIG );
@@ -966,8 +1072,19 @@
 // 
-----------------------------------------------------------------------------
 bool ODatabaseModelImpl::documentStorageHasMacros() const
 {
-    // TODO: check all the storages of our embedded forms and reports
-    return ::sfx2::DocumentMacroMode::storageHasMacros( m_xStorage );
+    // does our root storage contain macros?
+    if ( ::sfx2::DocumentMacroMode::storageHasMacros( m_xStorage ) )
+        return true;
+
+    // do we have forms with macros?
+    if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( 
*this ), E_FORM ) )
+        return true;
+
+    // do we have report with macros?
+    if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( 
*this ), E_REPORT ) )
+        return true;
+
+    return false;
 }
 
 // 
-----------------------------------------------------------------------------

File [changed]: ModelImpl.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.15.22.2&r2=1.15.22.3
Delta lines:  +49 -14
---------------------
--- ModelImpl.hxx       2007-10-22 10:27:31+0000        1.15.22.2
+++ ModelImpl.hxx       2007-10-22 20:59:29+0000        1.15.22.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: ModelImpl.hxx,v $
  *
- *  $Revision: 1.15.22.2 $
+ *  $Revision: 1.15.22.3 $
  *
- *  last change: $Author: fs $ $Date: 2007/10/22 10:27:31 $
+ *  last change: $Author: fs $ $Date: 2007/10/22 20:59:29 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -142,15 +142,7 @@
 class ODatabaseModelImpl    :public ::rtl::IReference
                             ,public ::sfx2::IMacroDocumentAccess
 {
-private:
-    ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel >    
    m_xModel;
-    ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource 
>        m_xDataSource;
-
-    DocumentStorageAccess*                                                     
 m_pStorageAccess;
-    ::rtl::Reference< SharedMutex >                                            
 m_xMutex;
-
 public:
-
        enum ObjectType
        {
                E_FORM   = 0,
@@ -158,13 +150,23 @@
                E_QUERY  = 2,
                E_TABLE  = 3
        };
-       OWeakConnectionArray            m_aConnections;
 
-       ::com::sun::star::uno::Reference< 
::com::sun::star::lang::XMultiServiceFactory >        m_xServiceFactory;
+private:
+    ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel >    
    m_xModel;
+    ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource 
>        m_xDataSource;
 
-       ::std::vector<TContentPtr>              m_aContainer;
+    DocumentStorageAccess*                                                     
 m_pStorageAccess;
+    ::rtl::Reference< SharedMutex >                                            
 m_xMutex;
+       ::std::vector< TContentPtr >                                            
    m_aContainer;   // one for each ObjectType
        TStorages                                               m_aStorages;
+    ::sfx2::DocumentMacroMode                                                  
 m_aMacroMode;
+
+public:
+       OWeakConnectionArray            m_aConnections;
 
+       ::com::sun::star::uno::Reference< 
::com::sun::star::lang::XMultiServiceFactory >        m_xServiceFactory;
+
+public:
        ::com::sun::star::uno::WeakReference< 
::com::sun::star::container::XNameAccess >        m_xCommandDefinitions;
        ::com::sun::star::uno::WeakReference< 
::com::sun::star::container::XNameAccess >        m_xTableDefinitions;
 
@@ -201,7 +203,6 @@
        ::com::sun::star::uno::Sequence< ::rtl::OUString >      
m_aTableTypeFilter;
        ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue 
>
                                                                                
                                m_aArgs;
-    ::sfx2::DocumentMacroMode                           m_aMacroMode;
 
 
     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>  
                        m_xSharedConnectionManager;
@@ -340,6 +341,40 @@
     /// returns a all known data source settings, including their default 
values
     static const AsciiPropertyValue* getDefaultDataSourceSettings();
 
+    /** retrieves the requested container of objects 
(forms/reports/tables/queries)
+    */
+    TContentPtr&    getObjectContainer( const ObjectType _eType );
+
+    /** determines whether the given storage is the storage of our embedded 
database (named "database"), if any
+    */
+    bool            isDatabaseStorage( const ::com::sun::star::uno::Reference< 
::com::sun::star::embed::XStorage >& _rxStorage ) const;
+
+    /** returns the name of the storage which is used to stored objects of the 
given type, if applicable
+    */
+    static ::rtl::OUString
+                    getObjectContainerStorageName( const ObjectType _eType );
+
+    /** checks our document's macro execution mode, using the interaction 
handler as supplied with our
+        load arguments
+    */
+    void            checkMacrosOnLoading();
+
+    /** adjusts our document's macro execution mode, without using any UI, 
assuming the user
+        would reject execution of macros, if she would have been asked.
+
+        If checkMacrosOnLoading has been called before (and thus the macro 
execution mode
+        is already adjusted), then the current execution mode is simply 
returned.
+
+        @return
+            whether or not macro execution is allowed
+    */
+    bool            adjustMacroMode_AutoReject();
+
+    /** resets our macro execute mode, so next time  the checkMacrosOnLoading 
is called, it will
+        behave as if it has never been called before
+    */
+    void            resetMacroExecutionMode();
+
 private:
     // IMacroDocumentAccess overridables
     virtual sal_Int16 getImposedMacroExecMode() const;




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

Reply via email to