From 15b6c3350ffd2c67394843bd92ab70d277b9c0b2 Mon Sep 17 00:00:00 2001 From: RĂ¼diger Timm Date: Thu, 27 Jan 2005 13:26:27 +0000 Subject: INTEGRATION: CWS tbe17 (1.1.2); FILE ADDED 2005/01/18 10:34:38 tbe 1.1.2.1: #118803# Implement SO7 -> 8 migration for Basic --- .../source/migration/services/basicmigration.cxx | 311 +++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 desktop/source/migration/services/basicmigration.cxx (limited to 'desktop/source/migration/services/basicmigration.cxx') diff --git a/desktop/source/migration/services/basicmigration.cxx b/desktop/source/migration/services/basicmigration.cxx new file mode 100644 index 000000000000..ea78639dab65 --- /dev/null +++ b/desktop/source/migration/services/basicmigration.cxx @@ -0,0 +1,311 @@ +/************************************************************************* + * + * $RCSfile: basicmigration.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: rt $ $Date: 2005-01-27 14:26:27 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DESKTOP_BASICMIGRATION_HXX_ +#include "basicmigration.hxx" +#endif + +#ifndef _URLOBJ_HXX +#include +#endif +#ifndef _UTL_BOOTSTRAP_HXX +#include +#endif + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +//......................................................................... +namespace migration +{ +//......................................................................... + + + static ::rtl::OUString sSourceUserBasic = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/basic" ) ); + static ::rtl::OUString sTargetUserBasic = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/user/__basic_70" ) ); + + + // ============================================================================= + // component operations + // ============================================================================= + + ::rtl::OUString BasicMigration_getImplementationName() + { + static ::rtl::OUString* pImplName = 0; + if ( !pImplName ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pImplName ) + { + static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.desktop.migration.Basic" ) ); + pImplName = &aImplName; + } + } + return *pImplName; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > BasicMigration_getSupportedServiceNames() + { + static Sequence< ::rtl::OUString >* pNames = 0; + if ( !pNames ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pNames ) + { + static Sequence< ::rtl::OUString > aNames(1); + aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.migration.Basic" ) ); + pNames = &aNames; + } + } + return *pNames; + } + + // ============================================================================= + // BasicMigration + // ============================================================================= + + BasicMigration::BasicMigration() + { + } + + // ----------------------------------------------------------------------------- + + BasicMigration::~BasicMigration() + { + } + + // ----------------------------------------------------------------------------- + + TStringVectorPtr BasicMigration::getFiles( const ::rtl::OUString& rBaseURL ) const + { + TStringVectorPtr aResult( new TStringVector ); + ::osl::Directory aDir( rBaseURL); + + if ( aDir.open() == ::osl::FileBase::E_None ) + { + // iterate over directory content + TStringVector aSubDirs; + ::osl::DirectoryItem aItem; + while ( aDir.getNextItem( aItem ) == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aFileStatus( FileStatusMask_FileURL ); + if ( aItem.getFileStatus( aFileStatus ) == ::osl::FileBase::E_None ) + { + if ( aFileStatus.getFileType() == ::osl::FileStatus::Directory ) + aSubDirs.push_back( aFileStatus.getFileURL() ); + else + aResult->push_back( aFileStatus.getFileURL() ); + } + } + + // iterate recursive over subfolders + TStringVector::const_iterator aI = aSubDirs.begin(); + while ( aI != aSubDirs.end() ) + { + TStringVectorPtr aSubResult = getFiles( *aI ); + aResult->insert( aResult->end(), aSubResult->begin(), aSubResult->end() ); + ++aI; + } + } + + return aResult; + } + + // ----------------------------------------------------------------------------- + + ::osl::FileBase::RC BasicMigration::checkAndCreateDirectory( INetURLObject& rDirURL ) + { + ::osl::FileBase::RC aResult = ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + if ( aResult == ::osl::FileBase::E_NOENT ) + { + INetURLObject aBaseURL( rDirURL ); + aBaseURL.removeSegment(); + checkAndCreateDirectory( aBaseURL ); + return ::osl::Directory::create( rDirURL.GetMainURL( INetURLObject::DECODE_TO_IURI ) ); + } + else + { + return aResult; + } + } + + // ----------------------------------------------------------------------------- + + void BasicMigration::copyFiles() + { + ::rtl::OUString sTargetDir; + ::utl::Bootstrap::PathStatus aStatus = ::utl::Bootstrap::locateUserInstallation( sTargetDir ); + if ( aStatus == ::utl::Bootstrap::PATH_EXISTS ) + { + sTargetDir += sTargetUserBasic; + TStringVectorPtr aFileList = getFiles( m_sSourceDir ); + TStringVector::const_iterator aI = aFileList->begin(); + while ( aI != aFileList->end() ) + { + ::rtl::OUString sLocalName = aI->copy( m_sSourceDir.getLength() ); + ::rtl::OUString sTargetName = sTargetDir + sLocalName; + INetURLObject aURL( sTargetName ); + aURL.removeSegment(); + checkAndCreateDirectory( aURL ); + ::osl::FileBase::RC aResult = ::osl::File::copy( *aI, sTargetName ); + if ( aResult != ::osl::FileBase::E_None ) + { + ::rtl::OString aMsg( "BasicMigration::copyFiles: cannot copy " ); + aMsg += ::rtl::OUStringToOString( *aI, RTL_TEXTENCODING_UTF8 ) + " to " + + ::rtl::OUStringToOString( sTargetName, RTL_TEXTENCODING_UTF8 ); + OSL_ENSURE( sal_False, aMsg.getStr() ); + } + ++aI; + } + } + else + { + OSL_ENSURE( sal_False, "BasicMigration::copyFiles: no user installation!" ); + } + } + + // ----------------------------------------------------------------------------- + // XServiceInfo + // ----------------------------------------------------------------------------- + + ::rtl::OUString BasicMigration::getImplementationName() throw (RuntimeException) + { + return BasicMigration_getImplementationName(); + } + + // ----------------------------------------------------------------------------- + + sal_Bool BasicMigration::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) + { + Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; + } + + // ----------------------------------------------------------------------------- + + Sequence< ::rtl::OUString > BasicMigration::getSupportedServiceNames() throw (RuntimeException) + { + return BasicMigration_getSupportedServiceNames(); + } + + // ----------------------------------------------------------------------------- + // XInitialization + // ----------------------------------------------------------------------------- + + void BasicMigration::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + const Any* pIter = aArguments.getConstArray(); + const Any* pEnd = pIter + aArguments.getLength(); + for ( ; pIter != pEnd ; ++pIter ) + { + beans::NamedValue aValue; + *pIter >>= aValue; + if ( aValue.Name.equalsAscii( "UserData" ) ) + { + sal_Bool bSuccess = aValue.Value >>= m_sSourceDir; + OSL_ENSURE( bSuccess == sal_True, "BasicMigration::initialize: argument UserData has wrong type!" ); + m_sSourceDir += sSourceUserBasic; + break; + } + } + } + + // ----------------------------------------------------------------------------- + // XJob + // ----------------------------------------------------------------------------- + + Any BasicMigration::execute( const Sequence< beans::NamedValue >& Arguments ) + throw (lang::IllegalArgumentException, Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + + copyFiles(); + + return Any(); + } + + // ============================================================================= + // component operations + // ============================================================================= + + Reference< XInterface > SAL_CALL BasicMigration_create( + Reference< XComponentContext > const & xContext ) + SAL_THROW( () ) + { + return static_cast< lang::XTypeProvider * >( new BasicMigration() ); + } + + // ----------------------------------------------------------------------------- + +//......................................................................... +} // namespace migration +//......................................................................... -- cgit