Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-05-07 08:30:55+0000
Modified:
   dba/dbaccess/source/filter/xml/dbloader2.cxx

Log:
 #i49133# support XModel2::createViewController, 
MediaDescriptor::ViewControllerName, MediaDescriptor::Model / some more 
changes, especially for being able to reload a document

File Changes:

Directory: /dba/dbaccess/source/filter/xml/
===========================================

File [changed]: dbloader2.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/filter/xml/dbloader2.cxx?r1=1.32.28.2&r2=1.32.28.3
Delta lines:  +76 -98
---------------------
--- dbloader2.cxx       2008-04-15 13:11:35+0000        1.32.28.2
+++ dbloader2.cxx       2008-05-07 08:30:52+0000        1.32.28.3
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: dbloader2.cxx,v $
- * $Revision: 1.32.28.2 $
+ * $Revision: 1.32.28.3 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -48,7 +48,7 @@
 #include <com/sun/star/frame/XFrameLoader.hpp>
 #include <com/sun/star/frame/XFramesSupplier.hpp>
 #include <com/sun/star/frame/XLoadEventListener.hpp>
-#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/frame/XModel2.hpp>
 #include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -139,34 +139,34 @@
 {
        try
        {
-               ::comphelper::SequenceAsHashMap aTemp(Descriptor);
-               Reference< XInputStream > xInStream = 
aTemp.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream")),
 Reference< XInputStream >() );
-
-               Reference<XPropertySet> xProp;
+        ::comphelper::NamedValueCollection aMedia( Descriptor );
+               Reference< XInputStream > xInStream( aMedia.getOrDefault( 
"InputStream",  Reference< XInputStream >() ) );
+               Reference< XPropertySet > xStorageProperties;
                if ( xInStream.is() )
                {
-                       xProp.set( 
::comphelper::OStorageHelper::GetStorageFromInputStream(
+                       xStorageProperties.set( 
::comphelper::OStorageHelper::GetStorageFromInputStream(
                 xInStream, m_aContext.getLegacyServiceFactory() ), UNO_QUERY );
                }
                else
                {
-                       ::rtl::OUString sTemp = 
aTemp.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL")),::rtl::OUString());
+            ::rtl::OUString sURL = aMedia.getOrDefault( "URL", 
::rtl::OUString() );
+            ::rtl::OUString sSalvagedURL( aMedia.getOrDefault( "SalvagedFile", 
::rtl::OUString() ) );
 
-                       if ( sTemp.getLength() )
+            ::rtl::OUString sFileLocation( sSalvagedURL.getLength() ? 
sSalvagedURL : sURL );
+                       if ( sFileLocation.getLength() )
                        {
-                               INetURLObject aURL(sTemp);
-                               xProp.set( 
::comphelper::OStorageHelper::GetStorageFromURL(
-                    sTemp, ElementModes::READ, 
m_aContext.getLegacyServiceFactory() ), UNO_QUERY );
+                               xStorageProperties.set( 
::comphelper::OStorageHelper::GetStorageFromURL(
+                    sFileLocation, ElementModes::READ, 
m_aContext.getLegacyServiceFactory() ), UNO_QUERY );
                        }
                }
 
-               if ( xProp.is() )
+               if ( xStorageProperties.is() )
                {
                        ::rtl::OUString sMediaType;
-                       xProp->getPropertyValue( INFO_MEDIATYPE ) >>= 
sMediaType;
+                       xStorageProperties->getPropertyValue( INFO_MEDIATYPE ) 
>>= sMediaType;
                        if ( 
sMediaType.equalsAscii(MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII) || 
sMediaType.equalsAscii(MIMETYPE_VND_SUN_XML_BASE_ASCII) )
                                return 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBase"));
-                       ::comphelper::disposeComponent(xProp);
+                       ::comphelper::disposeComponent(xStorageProperties);
                }
        } catch(Exception&){}
        return ::rtl::OUString();
@@ -394,7 +394,6 @@
                const Sequence< PropertyValue >& rArgs,
                const Reference< XLoadEventListener > & rListener) 
throw(::com::sun::star::uno::RuntimeException)
 {
-
        // first check if preview is true, if so return with out creating a 
controller. Preview is not supported
     ::comphelper::NamedValueCollection aMediaDesc( rArgs );
     sal_Bool bPreview = aMediaDesc.getOrDefault( "Preview", sal_False );
@@ -427,15 +426,20 @@
             aMediaDesc.put( "InteractionHandler", xHandler );
     }
 
-    /* special mode: use already loaded model ...
-        In such case no filter name will be selected and no URL will be given!
-        Such informations are not neccessary. We have to create a new view only
-        and call setComponent() at the corresponding frame. */
+    // it's allowed to pass an existing document
+    Reference< XOfficeDatabaseDocument > xExistentDBDoc;
+    xModel.set( aMediaDesc.getOrDefault( "Model", xExistentDBDoc ), UNO_QUERY 
);
+    aMediaDesc.remove( "Model" );
+
+    // also, it's allowed to specify the type of view which should be created
+    ::rtl::OUString sViewName = aMediaDesc.getOrDefault( "ViewName", 
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ) );
+    aMediaDesc.remove( "ViewName" );
+
        if ( !xModel.is() )
        {
                Reference< XSingleServiceFactory > xDatabaseContext;
-        if ( m_aContext.createComponent( 
(::rtl::OUString)SERVICE_SDB_DATABASECONTEXT, xDatabaseContext ) )
-               {
+        if ( !m_aContext.createComponent( 
(::rtl::OUString)SERVICE_SDB_DATABASECONTEXT, xDatabaseContext ) )
+            throw RuntimeException( ::rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM( "css.sdb.DatabaseContext not available" ) ), NULL 
);
             sal_Bool bInteractive = sal_False;
 
                        ::rtl::OUString sFactoryName = 
SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::E_DATABASE);
@@ -457,9 +461,7 @@
                 const ::rtl::OUString sURL = xModel->getURL();
                 if ( bCreateNew )
                 {
-                    Sequence< PropertyValue > aDocResource;
-                    aMediaDesc >>= aDocResource;
-                    xModel->attachResource( sURL, aDocResource );
+                xModel->attachResource( sURL, aMediaDesc.getPropertyValues() );
                 }
 
                 if ( bInteractive )
@@ -470,7 +472,6 @@
                 }
             }
                }
-       }
 
     if ( !xModel.is() )
     {
@@ -484,9 +485,7 @@
                try
                {
             aMediaDesc.put( "FileName", _rURL );
-            Sequence< PropertyValue > aDocResource;
-            aMediaDesc >>= aDocResource;
-                       xModel->attachResource( _rURL, aDocResource );
+                       xModel->attachResource( _rURL, 
aMediaDesc.getPropertyValues() );
                }
                catch(const Exception&)
                {
@@ -495,53 +494,32 @@
                }
        }
 
-    Reference< XController > xController;
+    Reference< XController2 > xController;
     if ( bSuccess )
     {
-        bSuccess = m_aContext.createComponent( 
"org.openoffice.comp.dbu.OApplicationController", xController );
-           if ( bSuccess )
-           {
-                   xController->attachModel(xModel);
-                   xModel->setCurrentController(xController);
-
-                   ::vos::OGuard aGuard(Application::GetSolarMutex());
-
-                   // and initialize
                    try
                    {
-                Sequence< PropertyValue > aLoadArgs;
-                aMediaDesc >>= aLoadArgs;
-
-                           Reference<XInitialization > 
xIni(xController,UNO_QUERY);
-                Sequence< Any > aInitArgs( aLoadArgs.getLength() + 1 );
+            Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW );
+            xController = xModel2->createViewController( sViewName, Sequence< 
PropertyValue >(), rFrame );
 
-                           Any* pArgIter = aInitArgs.getArray();
-                           Any* pEnd   = pArgIter + aInitArgs.getLength();
-                           *pArgIter++ <<= PropertyValue(
-                            ::rtl::OUString::createFromAscii( "Frame" ),
-                            0,
-                            makeAny( rFrame ),
-                            PropertyState_DIRECT_VALUE );
-
-                           const PropertyValue* pIter = 
aLoadArgs.getConstArray();
-                           for(++pArgIter;pArgIter != pEnd;++pArgIter,++pIter)
+            bSuccess = xController.is();
+            if ( bSuccess )
                            {
-                                   *pArgIter <<= *pIter;
+                xController->attachModel( xModel );
+                rFrame->setComponent( xController->getComponentWindow(), 
xController.get() );
+                xModel->setCurrentController( xController.get() );
+                xController->attachFrame( rFrame );
                            }
-
-                           xIni->initialize(aInitArgs);
                    }
-                   catch(Exception&)
+        catch( const Exception& )
                    {
+               DBG_UNHANDLED_EXCEPTION();
                            bSuccess = sal_False;
                    }
            }
-    }
 
        if (bSuccess)
        {
-               if ( xController.is() && rFrame.is() )
-                       xController->attachFrame(rFrame);
         try
         {
             Reference< css::container::XSet > xModelCollection;




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

Reply via email to