Tag: cws_src680_dba30
User: fs      
Date: 05/03/30 02:14:54

Modified:
 /dba/dbaccess/source/filter/xml/
  dbloader2.cxx

Log:
 RESYNC: (1.7-1.10); FILE MERGED

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.7.6.1&r2=1.7.6.2
Delta lines:  +100 -42
----------------------
--- dbloader2.cxx       24 Mar 2005 10:48:40 -0000      1.7.6.1
+++ dbloader2.cxx       30 Mar 2005 10:14:51 -0000      1.7.6.2
@@ -92,9 +92,18 @@
 #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTLISTENER_HPP_
 #include <com/sun/star/document/XEventListener.hpp>
 #endif
+#ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
+#include <com/sun/star/sdb/XDocumentDataSource.hpp>
+#endif
 #ifndef _COM_SUN_STAR_FRAME_XLOADEVENTLISTENER_HPP_
 #include <com/sun/star/frame/XLoadEventListener.hpp>
 #endif
+#ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
+#include <com/sun/star/embed/XStorage.hpp>
+#endif
+#ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
+#include <com/sun/star/embed/ElementModes.hpp>
+#endif
 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #endif
@@ -125,6 +134,9 @@
 #ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
 #include <com/sun/star/document/XFilter.hpp>
 #endif
+#ifndef _COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
+#include <com/sun/star/util/XURLTransformer.hpp>
+#endif
 
 #ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
 #include <com/sun/star/registry/XRegistryKey.hpp>
@@ -153,6 +165,9 @@
 #ifndef _COMPHELPER_PROCESSFACTORY_HXX_
 #include <comphelper/processfactory.hxx>
 #endif
+#ifndef _COMPHELPER_TYPES_HXX_
+#include <comphelper/types.hxx>
+#endif
 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX_
 #include <comphelper/sequenceashashmap.hxx>
 #endif
@@ -174,6 +189,9 @@
 #ifndef _COMPHELPER_STLTYPES_HXX_
 #include <comphelper/stl_types.hxx>
 #endif
+#ifndef _COMPHELPER_STORAGEHELPER_HXX
+#include <comphelper/storagehelper.hxx>
+#endif
 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
 #include <com/sun/star/task/XJobExecutor.hpp>
 #endif
@@ -186,13 +204,18 @@
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::ucb;
 using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::util;
 using namespace ::com::sun::star::frame;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::container;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::document;
 using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::sdb;
+using namespace ::com::sun::star::embed;
+namespace css = ::com::sun::star;
 using namespace ::com::sun::star::ui::dialogs;
+namespace css = ::com::sun::star;
 
 // -------------------------------------------------------------------------
 namespace dbaxml
@@ -200,6 +223,7 @@
 
 class DBTypeDetection : public ::cppu::WeakImplHelper2< 
XExtendedFilterDetection, XServiceInfo>
 {
+       Reference< XMultiServiceFactory > m_xServiceFactory;
 public:
        DBTypeDetection(const Reference< XMultiServiceFactory >&);
 
@@ -221,6 +245,7 @@
 };
 // -------------------------------------------------------------------------
 DBTypeDetection::DBTypeDetection(const Reference< XMultiServiceFactory >& 
_rxFactory)
+: m_xServiceFactory(_rxFactory)
 {
 }
 // -------------------------------------------------------------------------
@@ -235,6 +260,18 @@
                INetURLObject aURL(sTemp);
                if ( aURL.GetExtension().equalsIgnoreAsciiCaseAscii("odb") )
                        return 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBase"));
+               else
+               {
+                       Reference<XPropertySet> 
xProp(::comphelper::OStorageHelper::GetStorageFromURL(sTemp,ElementModes::READ,m_xServiceFactory),UNO_QUERY);
+                       if ( xProp.is() )
+                       {
+                               ::rtl::OUString sMediaType;
+                               xProp->getPropertyValue( 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")) ) >>= sMediaType;
+                               if ( 
sMediaType.equalsAscii("application/vnd.sun.xml.base") )
+                                       return 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBase"));
+                               ::comphelper::disposeComponent(xProp);
+                       }
+               }
        }
        return ::rtl::OUString();
 }
@@ -379,33 +416,31 @@
 {
 
        // first check if preview is true, if so return with out creating a 
controller. Preview is not supported
-       const PropertyValue* pIter      = rArgs.getConstArray();
-       const PropertyValue* pEnd       = pIter + rArgs.getLength();
-
-       for ( ; pIter != pEnd; ++pIter )
-       {
-               if ( ( 0 == pIter->Name.compareToAscii( "Preview" ) ) )
-               {
-                       sal_Bool bPreview = sal_False;
-                       pIter->Value >>= bPreview;
+       ::comphelper::SequenceAsHashMap lDescriptor(rArgs);
+       sal_Bool            bPreview = 
lDescriptor.getUnpackedValueOrDefault(INFO_PREVIEW          , sal_False         
                        );
                        if ( bPreview )
                        {
                                if (rListener.is())
                                        rListener->loadCancelled(this);
                                return;
                        }
-               }
-       }
+       Reference< XModel > xModel   = 
lDescriptor.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model")),
 Reference< XModel >());
 
        m_xFrame        = rFrame;
        m_xListener = rListener;
        m_aURL          = rURL;
        m_aArgs         = rArgs;
 
-       Reference< XSingleServiceFactory > 
xDatabaseContext(m_xServiceFactory->createInstance(SERVICE_SDB_DATABASECONTEXT),
 UNO_QUERY);
-       Reference<XComponent> xComponent;
        sal_Bool bCreateNew = sal_False;
        sal_Bool bInteractive = sal_False;
+       Reference<XDocumentDataSource> xDocumentDataSource;
+       /* 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. */
+       if ( !xModel.is() )
+       {
+               Reference< XSingleServiceFactory > 
xDatabaseContext(m_xServiceFactory->createInstance(SERVICE_SDB_DATABASECONTEXT),
 UNO_QUERY);         
        if ( xDatabaseContext.is() )
        {
                bCreateNew = 
rURL.match(SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::E_DATABASE));
@@ -416,13 +451,35 @@
                        aCreationArgs[0] <<= 
NamedValue(INFO_POOLURL,makeAny(rURL));
                }
                else
-                       bInteractive = 
rURL.match(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?Interactive")), 
SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::E_DATABASE).getLength()
 );
-               
xComponent.set(xDatabaseContext->createInstanceWithArguments(aCreationArgs),UNO_QUERY);
+            {
+                try
+                {
+                    Reference< XURLTransformer > xTransformer(
+                        m_xServiceFactory->createInstance(
+                            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"com.sun.star.util.URLTransformer" ) ) ),
+                        UNO_QUERY
+                    );
+                    OSL_ENSURE( xTransformer.is(), "DBContentLoader::load: 
could not create an URLTransformer!" );
+                    if ( xTransformer.is() )
+                    {
+                        URL aURL;
+                        aURL.Complete = m_aURL;
+                        xTransformer->parseStrict( aURL );
+                        bInteractive = aURL.Arguments.equalsAscii( 
"Interactive" );
+                    }
+                }
+                catch( const Exception& )
+                {
+                       OSL_ENSURE( sal_False, "DBContentLoader::load: caught 
an exception while analyzing the URL!" );
+                }
        }
 
+            
xDocumentDataSource.set(xDatabaseContext->createInstanceWithArguments(aCreationArgs),UNO_QUERY_THROW);
+                       
xModel.set(xDocumentDataSource->getDatabaseDocument(),UNO_QUERY);
+               }
+       }
 
        sal_Bool bSuccess = sal_True;
-       Reference<XModel> xModel(xComponent,UNO_QUERY);
        if ( !bCreateNew && xModel.is() && !xModel->getURL().getLength() )
        {
                try
@@ -528,24 +585,24 @@
            }
     }
 
-       if (bSuccess && rListener.is())
+       if (bSuccess)
        {
                if ( xController.is() && rFrame.is() )
                        xController->attachFrame(rFrame);
         try
         {
-            Reference< ::com::sun::star::document::XEventListener > 
xDocEventBroadcaster(m_xServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.GlobalEventBroadcaster"))),
-                UNO_QUERY);
-            if ( xDocEventBroadcaster.is() )
-            {
-                ::com::sun::star::document::EventObject aEvent(xModel, 
bCreateNew ? ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnNew")) : 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnLoad")));
+            Reference< css::container::XSet > 
xModelCollection(m_xServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.GlobalEventBroadcaster"))),UNO_QUERY_THROW);
+            xModelCollection->insert(css::uno::makeAny(xModel));
+
+            Reference< css::document::XEventListener > 
xDocEventBroadcaster(xModel,UNO_QUERY_THROW);
+            css::document::EventObject aEvent(xModel, bCreateNew ? 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnNew")) : 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnLoad")));
                 xDocEventBroadcaster->notifyEvent(aEvent);
             }
-        }
         catch(Exception)
         {
-            OSL_ENSURE(0,"Could not create GlobalEventBroadcaster!");
+            OSL_ENSURE(0,"Could not add database model to global model 
collection and broadcast the events OnNew/OnLoad!");
         }
+        if ( rListener.is() )
                rListener->loadFinished(this);
 
                if ( bStartTableWizard )
@@ -616,3 +673,4 @@
        xNewKey->setAsciiValue( 
::rtl::OUString::createFromAscii("private:factory/sdatabase") );
 }
 // 
-----------------------------------------------------------------------------
+




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

Reply via email to