Files
libreoffice/dbaccess/source/ui/browser/dbloader.cxx

353 lines
14 KiB
C++
Raw Normal View History

2000-10-26 13:46:14 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-10-26 13:46:14 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2000-10-26 13:46:14 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-10-26 13:46:14 +00:00
*
* $RCSfile: dbloader.cxx,v $
2008-10-16 06:57:26 +00:00
* $Revision: 1.36.2.3 $
2000-10-26 13:46:14 +00:00
*
* This file is part of OpenOffice.org.
2000-10-26 13:46:14 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-10-26 13:46:14 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-10-26 13:46:14 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-10-26 13:46:14 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#include "dbu_reghelper.hxx"
#include "dbustrings.hrc"
#include "UITools.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XSet.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/frame/XController2.hpp>
2000-10-26 13:46:14 +00:00
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XFrameLoader.hpp>
#include <com/sun/star/frame/XLoadEventListener.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
2000-10-26 13:46:14 +00:00
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
2000-10-26 13:46:14 +00:00
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>
#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/frame/XModule.hpp>
/** === end UNO includes === **/
#include <com/sun/star/sdbc/XDataSource.hpp>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/componentcontext.hxx>
#include <cppuhelper/implbase2.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <tools/diagnose_ex.h>
#include <tools/urlobj.hxx>
2002-10-08 06:26:17 +00:00
#include <vcl/svapp.hxx>
2000-10-26 13:46:14 +00:00
using namespace ::com::sun::star;
2000-10-26 13:46:14 +00:00
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
2000-10-26 13:46:14 +00:00
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::registry;
using ::com::sun::star::sdbc::XDataSource;
2001-02-14 13:37:35 +00:00
using namespace dbaui;
2000-10-26 13:46:14 +00:00
class DBContentLoader : public ::cppu::WeakImplHelper2< XFrameLoader, XServiceInfo>
{
private:
::rtl::OUString m_aURL;
Sequence< PropertyValue> m_aArgs;
Reference< XLoadEventListener > m_xListener;
Reference< XFrame > m_xFrame;
Reference< XMultiServiceFactory > m_xServiceFactory;
public:
DBContentLoader(const Reference< XMultiServiceFactory >&);
~DBContentLoader();
// XServiceInfo
::rtl::OUString SAL_CALL getImplementationName() throw( );
sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( );
Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( );
// static methods
static ::rtl::OUString getImplementationName_Static() throw( )
{
2001-01-05 11:08:57 +00:00
return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.DBContentLoader");
2000-10-26 13:46:14 +00:00
}
static Sequence< ::rtl::OUString> getSupportedServiceNames_Static(void) throw( );
static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
// XLoader
virtual void SAL_CALL load( const Reference< XFrame > & _rFrame, const ::rtl::OUString& _rURL,
const Sequence< PropertyValue >& _rArgs,
2001-09-13 13:15:52 +00:00
const Reference< XLoadEventListener > & _rListener) throw(::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL cancel(void) throw();
2000-10-26 13:46:14 +00:00
};
DBG_NAME(DBContentLoader)
2000-10-26 13:46:14 +00:00
DBContentLoader::DBContentLoader(const Reference< XMultiServiceFactory >& _rxFactory)
:m_xServiceFactory(_rxFactory)
{
DBG_CTOR(DBContentLoader,NULL);
2000-10-26 13:46:14 +00:00
}
// -------------------------------------------------------------------------
DBContentLoader::~DBContentLoader()
{
DBG_DTOR(DBContentLoader,NULL);
2000-10-26 13:46:14 +00:00
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
extern "C" void SAL_CALL createRegistryInfo_DBContentLoader()
{
static ::dbaui::OMultiInstanceAutoRegistration< DBContentLoader > aAutoRegistration;
2000-10-26 13:46:14 +00:00
}
// -------------------------------------------------------------------------
2000-10-31 11:44:37 +00:00
Reference< XInterface > SAL_CALL DBContentLoader::Create( const Reference< XMultiServiceFactory > & rSMgr )
2000-10-26 13:46:14 +00:00
{
return *(new DBContentLoader(rSMgr));
}
// -------------------------------------------------------------------------
// XServiceInfo
::rtl::OUString SAL_CALL DBContentLoader::getImplementationName() throw( )
{
return getImplementationName_Static();
}
// -------------------------------------------------------------------------
// XServiceInfo
sal_Bool SAL_CALL DBContentLoader::supportsService(const ::rtl::OUString& ServiceName) throw( )
{
Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
const ::rtl::OUString * pBegin = aSNL.getConstArray();
const ::rtl::OUString * pEnd = pBegin + aSNL.getLength();
for( ; pBegin != pEnd; ++pBegin)
if( *pBegin == ServiceName )
return sal_True;
return sal_False;
}
// -------------------------------------------------------------------------
// XServiceInfo
Sequence< ::rtl::OUString > SAL_CALL DBContentLoader::getSupportedServiceNames(void) throw( )
{
return getSupportedServiceNames_Static();
}
// -------------------------------------------------------------------------
// ORegistryServiceManager_Static
Sequence< ::rtl::OUString > DBContentLoader::getSupportedServiceNames_Static(void) throw( )
{
Sequence< ::rtl::OUString > aSNS( 2 );
2000-11-08 08:27:29 +00:00
aSNS.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.FrameLoader");
aSNS.getArray()[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ContentLoader");
2000-10-26 13:46:14 +00:00
return aSNS;
}
// -------------------------------------------------------------------------
extern "C" void SAL_CALL writeDBLoaderInfo(void* pRegistryKey)
{
Reference< XRegistryKey> xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey));
// register content loader for dispatch
::rtl::OUString aImpl = ::rtl::OUString::createFromAscii("/");
aImpl += DBContentLoader::getImplementationName_Static();
::rtl::OUString aImpltwo = aImpl;
aImpltwo += ::rtl::OUString::createFromAscii("/UNO/Loader");
Reference< XRegistryKey> xNewKey = xKey->createKey( aImpltwo );
aImpltwo = aImpl;
aImpltwo += ::rtl::OUString::createFromAscii("/Loader");
Reference< XRegistryKey > xLoaderKey = xKey->createKey( aImpltwo );
xNewKey = xLoaderKey->createKey( ::rtl::OUString::createFromAscii("Pattern") );
xNewKey->setAsciiValue( ::rtl::OUString::createFromAscii(".component:DB*") );
}
// -----------------------------------------------------------------------
void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const ::rtl::OUString& rURL,
const Sequence< PropertyValue >& rArgs,
2001-09-13 13:15:52 +00:00
const Reference< XLoadEventListener > & rListener) throw(::com::sun::star::uno::RuntimeException)
2000-10-26 13:46:14 +00:00
{
m_xFrame = rFrame;
m_xListener = rListener;
m_aURL = rURL;
m_aArgs = rArgs;
::comphelper::ComponentContext aContext( m_xServiceFactory );
struct ServiceNameToImplName
{
const sal_Char* pAsciiServiceName;
const sal_Char* pAsciiImplementationName;
ServiceNameToImplName( const sal_Char* _pService, const sal_Char* _pImpl )
:pAsciiServiceName( _pService )
,pAsciiImplementationName( _pImpl )
{
}
} aImplementations[] = {
ServiceNameToImplName( URL_COMPONENT_FORMGRIDVIEW, "org.openoffice.comp.dbu.OFormGridView" ),
ServiceNameToImplName( URL_COMPONENT_DATASOURCEBROWSER, "org.openoffice.comp.dbu.ODatasourceBrowser" ),
ServiceNameToImplName( URL_COMPONENT_QUERYDESIGN, "org.openoffice.comp.dbu.OQueryDesign" ),
ServiceNameToImplName( URL_COMPONENT_TABLEDESIGN, "org.openoffice.comp.dbu.OTableDesign" ),
ServiceNameToImplName( URL_COMPONENT_RELATIONDESIGN, "org.openoffice.comp.dbu.ORelationDesign" ),
ServiceNameToImplName( URL_COMPONENT_VIEWDESIGN, "org.openoffice.comp.dbu.OViewDesign" )
};
INetURLObject aParser( rURL );
Reference< XController2 > xController;
const ::rtl::OUString sComponentURL( aParser.GetMainURL( INetURLObject::DECODE_TO_IURI ) );
for ( size_t i=0; i < sizeof( aImplementations ) / sizeof( aImplementations[0] ); ++i )
{
if ( sComponentURL.equalsAscii( aImplementations[i].pAsciiServiceName ) )
{
aContext.createComponent( aImplementations[i].pAsciiImplementationName, xController );
break;
}
}
// if a data source browser is loaded without its tree pane, then we assume it to be a
// table data view, effectively. In this case, we need to adjust the module identifier.
// 2008-02-05 / i85879 / frank.schoenheit@sun.com
::comphelper::NamedValueCollection aLoadArgs( rArgs );
if ( sComponentURL == URL_COMPONENT_DATASOURCEBROWSER )
{
sal_Bool bDisableBrowser = ( sal_False == aLoadArgs.getOrDefault( "ShowTreeViewButton", sal_True ) ) // compatibility name
|| ( sal_False == aLoadArgs.getOrDefault( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_True ) );
if ( bDisableBrowser )
{
try
{
Reference< XModule > xModule( xController, UNO_QUERY_THROW );
xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TableDataView" ) ) );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
}
if ( sComponentURL == URL_COMPONENT_REPORTDESIGN )
{
sal_Bool bPreview = aLoadArgs.getOrDefault( "Preview", sal_False );
if ( bPreview )
{ // report designs cannot be previewed
if ( rListener.is() )
rListener->loadCancelled( this );
return;
}
Reference< XModel > xReportModel( aLoadArgs.getOrDefault( "Model", Reference< XModel >() ) );
if ( xReportModel.is() )
{
xController.set( m_xServiceFactory->createInstance(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.ReportDesign" ) ) ), UNO_QUERY );
if ( xController.is() )
{
xController->attachModel( xReportModel );
xReportModel->connectController( xController.get() );
xReportModel->setCurrentController( xController.get() );
}
}
}
2000-10-26 13:46:14 +00:00
sal_Bool bSuccess = xController.is();
Reference< XModel > xDatabaseDocument;
if ( bSuccess )
2000-10-26 13:46:14 +00:00
{
Reference< XDataSource > xDataSource ( aLoadArgs.getOrDefault( "DataSource", Reference< XDataSource >() ) );
::rtl::OUString sDataSourceName( aLoadArgs.getOrDefault( "DataSourceName", ::rtl::OUString() ) );
Reference< XConnection > xConnection ( aLoadArgs.getOrDefault( "ActiveConnection", Reference< XConnection >() ) );
if ( xDataSource.is() )
2000-10-26 13:46:14 +00:00
{
xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
}
else if ( sDataSourceName.getLength() )
{
CWS-TOOLING: integrate CWS dba31e 2008-11-19 12:36:23 +0100 msc r263980 : i96104 2008-11-19 12:31:19 +0100 msc r263979 : i96104 2008-11-19 12:21:55 +0100 msc r263977 : i96104 2008-11-19 12:18:53 +0100 msc r263976 : i96104 2008-11-18 09:09:45 +0100 oj r263746 : disable color entry when area is set 2008-11-18 08:37:52 +0100 oj r263741 : #remove sub report entry 2008-11-17 11:20:25 +0100 fs r263708 : #i10000# 2008-11-17 11:06:52 +0100 fs r263706 : minimal version now is 3.1 2008-11-12 22:25:59 +0100 fs r263621 : #i96150# 2008-11-12 22:20:02 +0100 fs r263620 : rebased to m34 2008-11-12 21:39:41 +0100 fs r263618 : MANUAL REBASE: rebase CWS dba31d to DEV300_m34 2008-11-12 13:54:58 +0100 fs r263597 : #i96134# MediaDescriptor.URL is to be preferred over MediaDescriptor.FileName. Nonetheless, ensure both are handled 2008-11-12 13:53:40 +0100 fs r263596 : #i96134# re-enabled the code for #i41897#, a better fix is to come 2008-11-12 12:48:21 +0100 fs r263585 : #i96134# disable saving URLs of file-base databases relatively 2008-11-11 16:11:11 +0100 msc r263566 : #i96104# 2008-11-05 09:09:47 +0100 oj r263342 : #i88727# color noe added 2008-11-05 08:41:43 +0100 oj r263341 : #i77916# zoom added 2008-11-04 21:24:15 +0100 fs r263339 : disposing: call disposeAndClear without own mutex locked - some of our listeners insist on locking the SolarMutex, which sometimes led to deadlocks on the complex test cases 2008-11-04 21:23:15 +0100 fs r263338 : remove SolarMutex locking - this happned in CWS dba31c (in the CVS version), which this CWS was created from, but seems to got lost during resync 2008-11-04 20:49:50 +0100 fs r263335 : docu formatting 2008-11-04 20:06:39 +0100 fs r263334 : #i95826# use m_aMutex, not a DocumentGuard (wrongly resolved merge conflicts) 2008-11-04 17:36:29 +0100 fs r263332 : #i92688# properly revoke as XEventListener from m_xActiveController when disposing 2008-11-04 14:49:34 +0100 fs r263324 : #i92322# enable Input Required if EmptyIsNULL does not exist at the control 2008-10-31 11:10:04 +0100 oj r262857 : merge from cvs to svn 2008-10-31 09:46:45 +0100 oj r262853 : merge from cvs to svn 2008-10-31 08:46:37 +0100 oj r262849 : merge from cvs to svn 2008-10-31 08:44:24 +0100 oj r262848 : merge from cvs to svn 2008-10-31 08:43:33 +0100 oj r262847 : merge from cvs to svn 2008-10-31 08:42:28 +0100 oj r262846 : merge from cvs to svn 2008-10-31 08:41:58 +0100 oj r262845 : merge from cvs to svn 2008-10-31 08:41:32 +0100 oj r262844 : merge from cvs to svn 2008-10-28 12:19:50 +0100 oj r262733 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:42 +0100 oj r262732 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:36 +0100 oj r262731 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:31 +0100 oj r262730 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:22 +0100 oj r262729 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:18 +0100 oj r262728 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:10 +0100 oj r262727 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:06 +0100 oj r262726 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:05 +0100 oj r262725 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:01 +0100 oj r262724 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:50 +0100 oj r262723 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:41 +0100 oj r262722 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:40 +0100 oj r262721 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:27 +0100 oj r262720 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:10 +0100 oj r262719 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:01 +0100 oj r262718 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:17:39 +0100 oj r262717 : #iXXXXX#: migrate CWS dba31e to SVN
2008-12-01 12:31:27 +00:00
::dbtools::SQLExceptionInfo aError;
xDataSource.set( getDataSourceByName( sDataSourceName, NULL, m_xServiceFactory, &aError ) );
xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
}
else if ( xConnection.is() )
{
Reference< XChild > xAsChild( xConnection, UNO_QUERY );
if ( xAsChild.is() )
{
OSL_ENSURE( Reference< XDataSource >( xAsChild->getParent(), UNO_QUERY ).is(),
"DBContentLoader::load: a connection whose parent is no data source?" );
xDatabaseDocument.set( getDataSourceOrModel( xAsChild->getParent() ), UNO_QUERY );
}
2000-10-26 13:46:14 +00:00
}
// init controller
::vos::OGuard aGuard(Application::GetSolarMutex());
try
2000-10-26 13:46:14 +00:00
{
Reference<XInitialization > xIni(xController,UNO_QUERY);
PropertyValue aFrame(::rtl::OUString::createFromAscii("Frame"),0,makeAny(rFrame),PropertyState_DIRECT_VALUE);
Sequence< Any > aInitArgs(m_aArgs.getLength()+1);
Any* pBegin = aInitArgs.getArray();
Any* pEnd = pBegin + aInitArgs.getLength();
*pBegin <<= aFrame;
const PropertyValue* pIter = m_aArgs.getConstArray();
for(++pBegin;pBegin != pEnd;++pBegin,++pIter)
{
*pBegin <<= *pIter;
}
2000-10-26 13:46:14 +00:00
xIni->initialize(aInitArgs);
}
catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION();
}
2000-10-26 13:46:14 +00:00
}
// assign controller and frame
if ( bSuccess )
{
if ( xController.is() && rFrame.is() )
{
rFrame->setComponent( xController->getComponentWindow(), xController.get() );
xController->attachFrame(rFrame);
}
if ( rListener.is() )
rListener->loadFinished( this );
}
else
if ( rListener.is() )
rListener->loadCancelled( this );
2000-10-26 13:46:14 +00:00
}
// -----------------------------------------------------------------------
2001-09-13 13:15:52 +00:00
void DBContentLoader::cancel(void) throw()
2000-10-26 13:46:14 +00:00
{
}