diff options
author | Oliver Bolte <obo@openoffice.org> | 2009-09-08 04:57:32 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2009-09-08 04:57:32 +0000 |
commit | 69fc8dc7847e22a4139ed59e9873c08a32edf092 (patch) | |
tree | 64b30dfeb64b4d6b3446e0e99ba9fc9ce66b06cc /sc/source/ui/docshell/docsh8.cxx | |
parent | fbeb3ce4a4fc1cf2a4a171709cfeb677971cf577 (diff) |
CWS-TOOLING: integrate CWS oj18
2009-08-21 15:08:49 +0200 oj r275263 : wrong check
2009-08-21 08:56:01 +0200 oj r275215 : missing not
2009-08-20 07:27:13 +0200 oj r275164 : use new method from global
2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale
2009-08-18 10:39:32 +0200 oj r275082 : missing header include
2009-08-18 10:09:44 +0200 oj r275081 : new methods at global
2009-08-18 10:09:00 +0200 oj r275080 : unused var
2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml
2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55)
2009-08-17 13:29:44 +0200 oj r275047 : compile error
2009-08-17 13:27:47 +0200 oj r275045 : compile error
2009-08-17 11:44:54 +0200 oj r275040 : add dep
2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl
2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl
2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code
2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc
2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand
2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char
2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc
2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator
2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc
2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled
2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger
2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files
2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files
2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand
2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand
2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl
2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
Diffstat (limited to 'sc/source/ui/docshell/docsh8.cxx')
-rw-r--r-- | sc/source/ui/docshell/docsh8.cxx | 199 |
1 files changed, 78 insertions, 121 deletions
diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx index 149856b4aa6b..d58777b9b5d5 100644 --- a/sc/source/ui/docshell/docsh8.cxx +++ b/sc/source/ui/docshell/docsh8.cxx @@ -43,13 +43,14 @@ #include <ucbhelper/content.hxx> #include <unotools/sharedunocomponent.hxx> #include <comphelper/processfactory.hxx> -#include <connectivity/dbcharset.hxx> #include <svx/txenctab.hxx> +#include <svx/dbcharsethelper.hxx> #include <com/sun/star/sdb/CommandType.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdbc/XDriverAccess.hpp> #include <com/sun/star/sdbc/XDriverManager.hpp> #include <com/sun/star/sdbc/XResultSetUpdate.hpp> #include <com/sun/star/sdbc/XRow.hpp> @@ -104,6 +105,61 @@ using namespace com::sun::star; #define SC_ROWCOUNT_ERROR (-1) +namespace +{ + ULONG lcl_getDBaseConnection(uno::Reference<sdbc::XDriverManager>& _rDrvMgr,uno::Reference<sdbc::XConnection>& _rConnection,String& _rTabName,const String& rFullFileName,rtl_TextEncoding eCharSet) + { + INetURLObject aURL; + aURL.SetSmartProtocol( INET_PROT_FILE ); + aURL.SetSmartURL( rFullFileName ); + _rTabName = aURL.getBase( INetURLObject::LAST_SEGMENT, true, + INetURLObject::DECODE_UNAMBIGUOUS ); + String aExtension = aURL.getExtension(); + aURL.removeSegment(); + aURL.removeFinalSlash(); + String aPath = aURL.GetMainURL(INetURLObject::NO_DECODE); + uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); + if (!xFactory.is()) return SCERR_EXPORT_CONNECT; + + _rDrvMgr.set( xFactory->createInstance( + rtl::OUString::createFromAscii( SC_SERVICE_DRVMAN ) ), + uno::UNO_QUERY); + DBG_ASSERT( _rDrvMgr.is(), "can't get DriverManager" ); + if (!_rDrvMgr.is()) return SCERR_EXPORT_CONNECT; + + // get connection + + String aConnUrl = String::CreateFromAscii("sdbc:dbase:"); + aConnUrl += aPath; + + svxform::ODataAccessCharsetHelper aHelper; + ::std::vector< rtl_TextEncoding > aEncodings; + aHelper.getSupportedTextEncodings( aEncodings ); + ::std::vector< rtl_TextEncoding >::iterator aIter = ::std::find(aEncodings.begin(),aEncodings.end(),(rtl_TextEncoding) eCharSet); + if ( aIter == aEncodings.end() ) + { + DBG_ERRORFILE( "DBaseImport: dbtools::OCharsetMap doesn't know text encoding" ); + return SCERR_IMPORT_CONNECT; + } // if ( aIter == aMap.end() ) + rtl::OUString aCharSetStr; + if ( RTL_TEXTENCODING_DONTKNOW != *aIter ) + { // it's not the virtual "system charset" + const char* pIanaName = rtl_getMimeCharsetFromTextEncoding( *aIter ); + OSL_ENSURE( pIanaName, "invalid mime name!" ); + if ( pIanaName ) + aCharSetStr = ::rtl::OUString::createFromAscii( pIanaName ); + } + + uno::Sequence<beans::PropertyValue> aProps(2); + aProps[0].Name = rtl::OUString::createFromAscii(SC_DBPROP_EXTENSION); + aProps[0].Value <<= rtl::OUString( aExtension ); + aProps[1].Name = rtl::OUString::createFromAscii(SC_DBPROP_CHARSET); + aProps[1].Value <<= aCharSetStr; + + _rConnection = _rDrvMgr->getConnectionWithInfo( aConnUrl, aProps ); + return 0L; + } +} // ----------------------------------------------------------------------- // MoveFile/KillFile/IsDocument: similar to SfxContentHelper @@ -201,48 +257,13 @@ ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet, try { - INetURLObject aURL; - aURL.SetSmartProtocol( INET_PROT_FILE ); - aURL.SetSmartURL( rFullFileName ); - String aTabName = aURL.getBase( INetURLObject::LAST_SEGMENT, true, - INetURLObject::DECODE_UNAMBIGUOUS ); - String aExtension = aURL.getExtension(); - aURL.removeSegment(); - aURL.removeFinalSlash(); - String aPath = aURL.GetMainURL(INetURLObject::NO_DECODE); - - uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); - if (!xFactory.is()) - return ERRCODE_IO_GENERAL; - - uno::Reference<sdbc::XDriverManager> xDrvMan( xFactory->createInstance( - rtl::OUString::createFromAscii( SC_SERVICE_DRVMAN ) ), - uno::UNO_QUERY); - DBG_ASSERT( xDrvMan.is(), "can't get DriverManager" ); - if (!xDrvMan.is()) return SCERR_IMPORT_CONNECT; - - String aConnUrl = String::CreateFromAscii("sdbc:dbase:"); - aConnUrl += aPath; - - dbtools::OCharsetMap aMap; - dbtools::OCharsetMap::CharsetIterator aIter = aMap.find( (rtl_TextEncoding) eCharSet ); - if ( aIter == aMap.end() ) - { - DBG_ERRORFILE( "DBaseImport: dbtools::OCharsetMap doesn't know text encoding" ); - return SCERR_IMPORT_CONNECT; - } - rtl::OUString aCharSetStr = (*aIter).getIanaName(); - - uno::Sequence<beans::PropertyValue> aProps(2); - aProps[0].Name = rtl::OUString::createFromAscii(SC_DBPROP_EXTENSION); - aProps[0].Value <<= rtl::OUString( aExtension ); - aProps[1].Name = rtl::OUString::createFromAscii(SC_DBPROP_CHARSET); - aProps[1].Value <<= aCharSetStr; - - uno::Reference<sdbc::XConnection> xConnection = - xDrvMan->getConnectionWithInfo( aConnUrl, aProps ); - DBG_ASSERT( xConnection.is(), "can't get Connection" ); - if (!xConnection.is()) return SCERR_IMPORT_CONNECT; + String aTabName; + uno::Reference<sdbc::XDriverManager> xDrvMan; + uno::Reference<sdbc::XConnection> xConnection; + ULONG nRet = lcl_getDBaseConnection(xDrvMan,xConnection,aTabName,rFullFileName,eCharSet); + if ( !xConnection.is() || !xDrvMan.is() ) + return nRet; + ::utl::DisposableComponent aConnectionHelper(xConnection); long nRowCount = 0; if ( nRowCount < 0 ) @@ -252,10 +273,11 @@ ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet, } ScProgress aProgress( this, ScGlobal::GetRscString( STR_LOAD_DOC ), nRowCount ); - + uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); uno::Reference<sdbc::XRowSet> xRowSet( xFactory->createInstance( rtl::OUString::createFromAscii( SC_SERVICE_ROWSET ) ), uno::UNO_QUERY); + ::utl::DisposableComponent aRowSetHelper(xRowSet); uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY ); DBG_ASSERT( xRowProp.is(), "can't get RowSet" ); if (!xRowProp.is()) return SCERR_IMPORT_CONNECT; @@ -369,9 +391,6 @@ ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet, if ( nRowCount ) aProgress.SetStateOnPercent( nRow ); } - - comphelper::disposeComponent( xRowSet ); - comphelper::disposeComponent( xConnection ); } catch ( sdbc::SQLException& ) { @@ -733,91 +752,29 @@ ULONG ScDocShell::DBaseExport( const String& rFullFileName, CharSet eCharSet, BO aColNames.getArray(), aColTypes.getArray(), aColLengths.getArray(), aColScales.getArray(), bHasMemo, eCharSet ); - - INetURLObject aURL; - aURL.SetSmartProtocol( INET_PROT_FILE ); - aURL.SetSmartURL( rFullFileName ); - String aTabName = aURL.getBase( INetURLObject::LAST_SEGMENT, true, - INetURLObject::DECODE_UNAMBIGUOUS ); - String aExtension = aURL.getExtension(); - aURL.removeSegment(); - aURL.removeFinalSlash(); - String aPath = aURL.GetMainURL(INetURLObject::NO_DECODE); - // also needed for exception catch SCROW nDocRow = 0; ScFieldEditEngine aEditEngine( aDocument.GetEditPool() ); String aString; + String aTabName; try { - uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); - if (!xFactory.is()) return SCERR_EXPORT_CONNECT; - - uno::Reference<sdbc::XDriverManager> xDrvMan( xFactory->createInstance( - rtl::OUString::createFromAscii( SC_SERVICE_DRVMAN ) ), - uno::UNO_QUERY); - DBG_ASSERT( xDrvMan.is(), "can't get DriverManager" ); - if (!xDrvMan.is()) return SCERR_EXPORT_CONNECT; - - // get connection - - String aConnUrl = String::CreateFromAscii("sdbc:dbase:"); - aConnUrl += aPath; - - dbtools::OCharsetMap aMap; - dbtools::OCharsetMap::CharsetIterator aIter = aMap.find( (rtl_TextEncoding) eCharSet ); - if ( aIter == aMap.end() ) - { - DBG_ERRORFILE( "DBaseExport: dbtools::OCharsetMap doesn't know text encoding" ); - return SCERR_EXPORT_CONNECT; - } - rtl::OUString aCharSetStr = (*aIter).getIanaName(); - - uno::Sequence<beans::PropertyValue> aProps(2); - aProps[0].Name = rtl::OUString::createFromAscii(SC_DBPROP_EXTENSION); - aProps[0].Value <<= rtl::OUString( aExtension ); - aProps[1].Name = rtl::OUString::createFromAscii(SC_DBPROP_CHARSET); - aProps[1].Value <<= aCharSetStr; - - uno::Reference<sdbc::XConnection> xConnection = - xDrvMan->getConnectionWithInfo( aConnUrl, aProps ); - DBG_ASSERT( xConnection.is(), "can't get Connection" ); - if (!xConnection.is()) return SCERR_EXPORT_CONNECT; + uno::Reference<sdbc::XDriverManager> xDrvMan; + uno::Reference<sdbc::XConnection> xConnection; + ULONG nRet = lcl_getDBaseConnection(xDrvMan,xConnection,aTabName,rFullFileName,eCharSet); + if ( !xConnection.is() || !xDrvMan.is() ) + return nRet; ::utl::DisposableComponent aConnectionHelper(xConnection); // get dBase driver - - uno::Reference<sdbc::XDriver> xDriver; - BOOL bDriverFound = FALSE; - - uno::Reference<container::XEnumerationAccess> xEnAcc( xDrvMan, uno::UNO_QUERY ); - DBG_ASSERT( xEnAcc.is(), "can't get DriverManager EnumerationAccess" ); - if (!xEnAcc.is()) return SCERR_EXPORT_CONNECT; - - uno::Reference<container::XEnumeration> xEnum = xEnAcc->createEnumeration(); - DBG_ASSERT( xEnum.is(), "can't get DriverManager Enumeration" ); - if (!xEnum.is()) return SCERR_EXPORT_CONNECT; - - while ( xEnum->hasMoreElements() && !bDriverFound ) - { - uno::Any aElement = xEnum->nextElement(); - if ( aElement >>= xDriver ) - if ( xDriver.is() && xDriver->acceptsURL( aConnUrl ) ) - bDriverFound = TRUE; - } - - DBG_ASSERT( bDriverFound, "can't get dBase driver" ); - if (!bDriverFound) return SCERR_EXPORT_CONNECT; + uno::Reference< sdbc::XDriverAccess> xAccess(xDrvMan,uno::UNO_QUERY); + uno::Reference< sdbcx::XDataDefinitionSupplier > xDDSup( xAccess->getDriverByURL( xConnection->getMetaData()->getURL() ), uno::UNO_QUERY ); + if ( !xDDSup.is() ) + return SCERR_EXPORT_CONNECT; // create table - - uno::Reference<sdbcx::XDataDefinitionSupplier> xDDSup( xDriver, uno::UNO_QUERY ); - DBG_ASSERT( xDDSup.is(), "can't get XDataDefinitionSupplier" ); - if (!xDDSup.is()) return SCERR_EXPORT_CONNECT; - - uno::Reference<sdbcx::XTablesSupplier> xTablesSupp = - xDDSup->getDataDefinitionByConnection( xConnection ); + uno::Reference<sdbcx::XTablesSupplier> xTablesSupp =xDDSup->getDataDefinitionByConnection( xConnection ); DBG_ASSERT( xTablesSupp.is(), "can't get Data Definition" ); if (!xTablesSupp.is()) return SCERR_EXPORT_CONNECT; @@ -893,7 +850,7 @@ ULONG ScDocShell::DBaseExport( const String& rFullFileName, CharSet eCharSet, BO // if (!xConnection.is()) return SCERR_EXPORT_CONNECT; // get row set for writing - + uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); uno::Reference<sdbc::XRowSet> xRowSet( xFactory->createInstance( rtl::OUString::createFromAscii( SC_SERVICE_ROWSET ) ), uno::UNO_QUERY); |