1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "fsfactory.hxx" 32*cdf0e10cSrcweir #include "cppuhelper/factory.hxx" 33*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <ucbhelper/fileidentifierconverter.hxx> 40*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 41*cdf0e10cSrcweir #include <ucbhelper/content.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <unotools/tempfile.hxx> 44*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include "fsstorage.hxx" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::com::sun::star; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //------------------------------------------------------------------------- 52*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::impl_staticGetSupportedServiceNames() 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(2); 55*cdf0e10cSrcweir aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.FileSystemStorageFactory"); 56*cdf0e10cSrcweir aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.FileSystemStorageFactory"); 57*cdf0e10cSrcweir return aRet; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //------------------------------------------------------------------------- 61*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FSStorageFactory::impl_staticGetImplementationName() 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.FileSystemStorageFactory"); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //------------------------------------------------------------------------- 67*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::impl_staticCreateSelfInstance( 68*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir return uno::Reference< uno::XInterface >( *new FSStorageFactory( xServiceManager ) ); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //------------------------------------------------------------------------- 74*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance() 75*cdf0e10cSrcweir throw ( uno::Exception, 76*cdf0e10cSrcweir uno::RuntimeException ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir ::rtl::OUString aTempURL; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir aTempURL = ::utl::TempFile( NULL, sal_True ).GetURL(); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir if ( !aTempURL.getLength() ) 83*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: can not create tempfile 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir ::ucbhelper::Content aResultContent( 86*cdf0e10cSrcweir aTempURL, uno::Reference< ucb::XCommandEnvironment >() ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir return uno::Reference< uno::XInterface >( 89*cdf0e10cSrcweir static_cast< OWeakObject* >( 90*cdf0e10cSrcweir new FSStorage( aResultContent, 91*cdf0e10cSrcweir embed::ElementModes::READWRITE, 92*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >(), 93*cdf0e10cSrcweir m_xFactory ) ), 94*cdf0e10cSrcweir uno::UNO_QUERY ); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //------------------------------------------------------------------------- 98*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments( 99*cdf0e10cSrcweir const uno::Sequence< uno::Any >& aArguments ) 100*cdf0e10cSrcweir throw ( uno::Exception, 101*cdf0e10cSrcweir uno::RuntimeException ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir // The request for storage can be done with up to three arguments 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // The first argument specifies a source for the storage 106*cdf0e10cSrcweir // it must be URL. 107*cdf0e10cSrcweir // The second value is a mode the storage should be open in. 108*cdf0e10cSrcweir // And the third value is a media descriptor. 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir sal_Int32 nArgNum = aArguments.getLength(); 111*cdf0e10cSrcweir OSL_ENSURE( nArgNum < 4, "Wrong parameter number" ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir if ( !nArgNum ) 114*cdf0e10cSrcweir return createInstance(); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // first try to retrieve storage open mode if any 117*cdf0e10cSrcweir // by default the storage will be open in readonly mode 118*cdf0e10cSrcweir sal_Int32 nStorageMode = embed::ElementModes::READ; 119*cdf0e10cSrcweir if ( nArgNum >= 2 ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir if( !( aArguments[1] >>= nStorageMode ) ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Wrong second argument!\n" ); 124*cdf0e10cSrcweir throw uno::Exception(); // TODO: Illegal argument 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir // it's allways possible to read written storage in this implementation 127*cdf0e10cSrcweir nStorageMode |= embed::ElementModes::READ; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // retrieve storage source URL 131*cdf0e10cSrcweir ::rtl::OUString aURL; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if ( aArguments[0] >>= aURL ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir if ( !aURL.getLength() ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Empty URL is provided!\n" ); 138*cdf0e10cSrcweir throw uno::Exception(); // TODO: illegal argument 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir else 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Wrong first argument!\n" ); 144*cdf0e10cSrcweir throw uno::Exception(); // TODO: Illegal argument 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // retrieve mediadescriptor and set storage properties 148*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aDescr; 149*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropsToSet; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if ( nArgNum >= 3 ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir if( aArguments[2] >>= aDescr ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir aPropsToSet.realloc(1); 156*cdf0e10cSrcweir aPropsToSet[0].Name = ::rtl::OUString::createFromAscii( "URL" ); 157*cdf0e10cSrcweir aPropsToSet[0].Value <<= aURL; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir for ( sal_Int32 nInd = 0, nNumArgs = 1; nInd < aDescr.getLength(); nInd++ ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir if ( aDescr[nInd].Name.equalsAscii( "InteractionHandler" ) ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir aPropsToSet.realloc( ++nNumArgs ); 164*cdf0e10cSrcweir aPropsToSet[nNumArgs-1].Name = aDescr[nInd].Name; 165*cdf0e10cSrcweir aPropsToSet[nNumArgs-1].Value = aDescr[nInd].Value; 166*cdf0e10cSrcweir break; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir else 169*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Unacceptable property, will be ignored!\n" ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir else 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Wrong third argument!\n" ); 175*cdf0e10cSrcweir throw uno::Exception(); // TODO: Illegal argument 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // allow to use other ucp's 180*cdf0e10cSrcweir // if ( !isLocalNotFile_Impl( aURL ) ) 181*cdf0e10cSrcweir if ( aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.pkg", 16 ) 182*cdf0e10cSrcweir || aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.zip", 16 ) 183*cdf0e10cSrcweir || ::utl::UCBContentHelper::IsDocument( aURL ) ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir OSL_ENSURE( sal_False, "File system storages can be based only on file URLs!\n" ); // ??? 186*cdf0e10cSrcweir throw uno::Exception(); // TODO: illegal argument 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) ) 190*cdf0e10cSrcweir FSStorage::MakeFolderNoUI( aURL, sal_False ); 191*cdf0e10cSrcweir else if ( !::utl::UCBContentHelper::IsFolder( aURL ) ) 192*cdf0e10cSrcweir throw io::IOException(); // there is no such folder 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir ::ucbhelper::Content aResultContent( 195*cdf0e10cSrcweir aURL, uno::Reference< ucb::XCommandEnvironment >() ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // create storage based on source 198*cdf0e10cSrcweir return uno::Reference< uno::XInterface >( 199*cdf0e10cSrcweir static_cast< OWeakObject* >( new FSStorage( aResultContent, 200*cdf0e10cSrcweir nStorageMode, 201*cdf0e10cSrcweir aPropsToSet, 202*cdf0e10cSrcweir m_xFactory ) ), 203*cdf0e10cSrcweir uno::UNO_QUERY ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //------------------------------------------------------------------------- 207*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FSStorageFactory::getImplementationName() 208*cdf0e10cSrcweir throw ( uno::RuntimeException ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir return impl_staticGetImplementationName(); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //------------------------------------------------------------------------- 214*cdf0e10cSrcweir sal_Bool SAL_CALL FSStorageFactory::supportsService( const ::rtl::OUString& ServiceName ) 215*cdf0e10cSrcweir throw ( uno::RuntimeException ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) 220*cdf0e10cSrcweir if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) 221*cdf0e10cSrcweir return sal_True; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir return sal_False; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir //------------------------------------------------------------------------- 227*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames() 228*cdf0e10cSrcweir throw ( uno::RuntimeException ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir return impl_staticGetSupportedServiceNames(); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir //------------------------------------------------------------------------- 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir extern "C" 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment ( 238*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory ( 244*cdf0e10cSrcweir const sal_Char * pImplementationName, void * pServiceManager, void * /* pRegistryKey */) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir void * pResult = 0; 247*cdf0e10cSrcweir if (pServiceManager) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory; 250*cdf0e10cSrcweir if (FSStorageFactory::impl_staticGetImplementationName().compareToAscii (pImplementationName) == 0) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir xFactory = cppu::createOneInstanceFactory ( 253*cdf0e10cSrcweir reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager), 254*cdf0e10cSrcweir FSStorageFactory::impl_staticGetImplementationName(), 255*cdf0e10cSrcweir FSStorageFactory::impl_staticCreateSelfInstance, 256*cdf0e10cSrcweir FSStorageFactory::impl_staticGetSupportedServiceNames() ); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir if (xFactory.is()) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir xFactory->acquire(); 261*cdf0e10cSrcweir pResult = xFactory.get(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir return pResult; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir } // extern "C" 268*cdf0e10cSrcweir 269