merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / gio / gio_provider.cxx
blobd799a38fd4ff3d1ff01eef82ad9a42632b0e279c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gio_provider.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <ucbhelper/contentidentifier.hxx>
32 #include <ucbhelper/contenthelper.hxx>
33 #include <com/sun/star/ucb/ContentCreationException.hpp>
34 #include "gio_provider.hxx"
35 #include "gio_content.hxx"
37 #include <stdio.h>
39 using namespace com::sun::star;
41 namespace gio
43 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
44 ContentProvider::queryContent(
45 const uno::Reference<
46 com::sun::star::ucb::XContentIdentifier >& Identifier )
47 throw( com::sun::star::ucb::IllegalIdentifierException,
48 uno::RuntimeException )
50 #ifdef DEBUG
51 fprintf(stderr, "QueryContent: '%s'",
52 (const sal_Char *)rtl::OUStringToOString
53 (Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8));
54 #endif
56 osl::MutexGuard aGuard( m_aMutex );
58 // Check, if a content with given id already exists...
59 uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier ).get();
60 if ( xContent.is() )
61 return xContent;
63 try
65 xContent = new ::gio::Content(m_xSMgr, this, Identifier);
67 catch ( com::sun::star::ucb::ContentCreationException const & )
69 throw com::sun::star::ucb::IllegalIdentifierException();
72 if ( !xContent->getIdentifier().is() )
73 throw com::sun::star::ucb::IllegalIdentifierException();
75 return xContent;
78 ContentProvider::ContentProvider(
79 const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
80 : ::ucbhelper::ContentProviderImplHelper( rSMgr )
84 ContentProvider::~ContentProvider()
88 XINTERFACE_IMPL_3( ContentProvider,
89 lang::XTypeProvider,
90 lang::XServiceInfo,
91 com::sun::star::ucb::XContentProvider );
93 XTYPEPROVIDER_IMPL_3( ContentProvider,
94 lang::XTypeProvider,
95 lang::XServiceInfo,
96 com::sun::star::ucb::XContentProvider );
98 XSERVICEINFO_IMPL_1( ContentProvider,
99 rtl::OUString::createFromAscii(
100 "com.sun.star.comp.GIOContentProvider" ),
101 rtl::OUString::createFromAscii(
102 "com.sun.star.ucb.GIOContentProvider" ) );
104 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
108 static sal_Bool writeInfo( void *pRegistryKey,
109 const rtl::OUString &rImplementationName, uno::Sequence< rtl::OUString > const &rServiceNames )
111 rtl::OUString aKeyName( rtl::OUString::createFromAscii( "/" ) );
112 aKeyName += rImplementationName;
113 aKeyName += rtl::OUString::createFromAscii( "/UNO/SERVICES" );
115 uno::Reference< registry::XRegistryKey > xKey;
118 xKey = static_cast< registry::XRegistryKey * > (pRegistryKey )->createKey( aKeyName );
120 catch ( registry::InvalidRegistryException const & )
123 if ( !xKey.is() )
124 return sal_False;
126 sal_Bool bSuccess = sal_True;
128 for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
132 xKey->createKey( rServiceNames[ n ] );
134 catch ( registry::InvalidRegistryException const & )
136 bSuccess = sal_False;
137 break;
140 return bSuccess;
143 extern "C" void SAL_CALL component_getImplementationEnvironment(
144 const sal_Char **ppEnvTypeName, uno_Environment **)
146 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
149 extern "C" sal_Bool SAL_CALL component_writeInfo( void *, void *pRegistryKey )
151 return pRegistryKey &&
152 writeInfo( pRegistryKey,
153 ::gio::ContentProvider::getImplementationName_Static(),
154 ::gio::ContentProvider::getSupportedServiceNames_Static() );
157 extern "C" void * SAL_CALL component_getFactory( const sal_Char *pImplName,
158 void *pServiceManager, void * )
160 void * pRet = 0;
162 uno::Reference< lang::XMultiServiceFactory > xSMgr
163 (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
164 uno::Reference< lang::XSingleServiceFactory > xFactory;
166 g_type_init();
168 if ( !::gio::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
169 xFactory = ::gio::ContentProvider::createServiceFactory( xSMgr );
171 if ( xFactory.is() )
173 xFactory->acquire();
174 pRet = xFactory.get();
177 return pRet;