1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_ucb.hxx" 30 31 #include <ucbhelper/contentidentifier.hxx> 32 #include <libgnomevfs/gnome-vfs-init.h> 33 #include "gvfs_provider.hxx" 34 #include "gvfs_content.hxx" 35 36 using namespace com::sun::star; 37 using namespace gvfs; 38 39 //========================================================================= 40 //========================================================================= 41 // 42 // ContentProvider Implementation. 43 // 44 //========================================================================= 45 //========================================================================= 46 47 ContentProvider::ContentProvider( 48 const uno::Reference< lang::XMultiServiceFactory >& rSMgr ) 49 : ::ucbhelper::ContentProviderImplHelper( rSMgr ) 50 { 51 } 52 // sdafas 53 //========================================================================= 54 // virtual 55 ContentProvider::~ContentProvider() 56 { 57 } 58 59 //========================================================================= 60 // 61 // XInterface methods. 62 // 63 //========================================================================= 64 65 XINTERFACE_IMPL_3( ContentProvider, 66 lang::XTypeProvider, 67 lang::XServiceInfo, 68 com::sun::star::ucb::XContentProvider ); 69 70 //========================================================================= 71 // 72 // XTypeProvider methods. 73 // 74 //========================================================================= 75 76 XTYPEPROVIDER_IMPL_3( ContentProvider, 77 lang::XTypeProvider, 78 lang::XServiceInfo, 79 com::sun::star::ucb::XContentProvider ); 80 81 //========================================================================= 82 // 83 // XServiceInfo methods. 84 // 85 //========================================================================= 86 87 XSERVICEINFO_IMPL_1( ContentProvider, 88 rtl::OUString::createFromAscii( 89 "com.sun.star.comp.GnomeVFSContentProvider" ), 90 rtl::OUString::createFromAscii( 91 "com.sun.star.ucb.GnomeVFSContentProvider" ) ); 92 //========================================================================= 93 // 94 // Service factory implementation. 95 // 96 //========================================================================= 97 98 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider ); 99 100 //========================================================================= 101 // 102 // XContentProvider methods. 103 // 104 //========================================================================= 105 106 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL 107 ContentProvider::queryContent( 108 const uno::Reference< 109 com::sun::star::ucb::XContentIdentifier >& Identifier ) 110 throw( com::sun::star::ucb::IllegalIdentifierException, 111 uno::RuntimeException ) 112 { 113 #ifdef DEBUG 114 g_warning ("QueryContent: '%s'", 115 (const sal_Char *)rtl::OUStringToOString 116 (Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8)); 117 #endif 118 119 osl::MutexGuard aGuard( m_aMutex ); 120 121 // Check, if a content with given id already exists... 122 uno::Reference< com::sun::star::ucb::XContent > xContent 123 = queryExistingContent( Identifier ).get(); 124 if ( xContent.is() ) 125 return xContent; 126 127 try 128 { 129 xContent = new ::gvfs::Content(m_xSMgr, this, Identifier ); 130 registerNewContent( xContent ); 131 } 132 catch ( com::sun::star::ucb::ContentCreationException const & ) 133 { 134 throw com::sun::star::ucb::IllegalIdentifierException(); 135 } 136 137 if ( !xContent->getIdentifier().is() ) 138 throw com::sun::star::ucb::IllegalIdentifierException(); 139 140 return xContent; 141 } 142 143 144 //============================ shlib entry points ============================================= 145 146 extern "C" void SAL_CALL 147 component_getImplementationEnvironment( const sal_Char **ppEnvTypeName, 148 uno_Environment **/*ppEnv*/ ) 149 { 150 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 151 } 152 153 extern "C" void * SAL_CALL 154 component_getFactory( const sal_Char *pImplName, 155 void *pServiceManager, 156 void */*pRegistryKey*/ ) 157 { 158 void * pRet = 0; 159 160 { 161 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 162 if (!gnome_vfs_initialized ()) 163 gnome_vfs_init (); 164 if (!auth_queue) 165 auth_queue = g_private_new( auth_queue_destroy ); 166 } 167 168 uno::Reference< lang::XMultiServiceFactory > xSMgr 169 (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) ); 170 uno::Reference< lang::XSingleServiceFactory > xFactory; 171 172 if ( !::gvfs::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) ) 173 xFactory = ::gvfs::ContentProvider::createServiceFactory( xSMgr ); 174 175 if ( xFactory.is() ) { 176 xFactory->acquire(); 177 pRet = xFactory.get(); 178 } 179 180 return pRet; 181 } 182 183 184