1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2f86921cSAndrew Rist * distributed with this work for additional information
6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at
10*2f86921cSAndrew Rist *
11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist *
13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the
17*2f86921cSAndrew Rist * specific language governing permissions and limitations
18*2f86921cSAndrew Rist * under the License.
19*2f86921cSAndrew Rist *
20*2f86921cSAndrew Rist *************************************************************/
21*2f86921cSAndrew Rist
22*2f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
25cdf0e10cSrcweir #include <ucbhelper/contenthelper.hxx>
26cdf0e10cSrcweir #include <com/sun/star/ucb/ContentCreationException.hpp>
27cdf0e10cSrcweir #include "gio_provider.hxx"
28cdf0e10cSrcweir #include "gio_content.hxx"
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <stdio.h>
31cdf0e10cSrcweir
32cdf0e10cSrcweir using namespace com::sun::star;
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace gio
35cdf0e10cSrcweir {
36cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
queryContent(const uno::Reference<com::sun::star::ucb::XContentIdentifier> & Identifier)37cdf0e10cSrcweir ContentProvider::queryContent(
38cdf0e10cSrcweir const uno::Reference<
39cdf0e10cSrcweir com::sun::star::ucb::XContentIdentifier >& Identifier )
40cdf0e10cSrcweir throw( com::sun::star::ucb::IllegalIdentifierException,
41cdf0e10cSrcweir uno::RuntimeException )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir #ifdef DEBUG
44cdf0e10cSrcweir fprintf(stderr, "QueryContent: '%s'",
45cdf0e10cSrcweir (const sal_Char *)rtl::OUStringToOString
46cdf0e10cSrcweir (Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8));
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir
49cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
50cdf0e10cSrcweir
51cdf0e10cSrcweir // Check, if a content with given id already exists...
52cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier ).get();
53cdf0e10cSrcweir if ( xContent.is() )
54cdf0e10cSrcweir return xContent;
55cdf0e10cSrcweir
56cdf0e10cSrcweir try
57cdf0e10cSrcweir {
58cdf0e10cSrcweir xContent = new ::gio::Content(m_xSMgr, this, Identifier);
59cdf0e10cSrcweir }
60cdf0e10cSrcweir catch ( com::sun::star::ucb::ContentCreationException const & )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir throw com::sun::star::ucb::IllegalIdentifierException();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
65cdf0e10cSrcweir if ( !xContent->getIdentifier().is() )
66cdf0e10cSrcweir throw com::sun::star::ucb::IllegalIdentifierException();
67cdf0e10cSrcweir
68cdf0e10cSrcweir return xContent;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
ContentProvider(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)71cdf0e10cSrcweir ContentProvider::ContentProvider(
72cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
73cdf0e10cSrcweir : ::ucbhelper::ContentProviderImplHelper( rSMgr )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
~ContentProvider()77cdf0e10cSrcweir ContentProvider::~ContentProvider()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir XINTERFACE_IMPL_3( ContentProvider,
82cdf0e10cSrcweir lang::XTypeProvider,
83cdf0e10cSrcweir lang::XServiceInfo,
84cdf0e10cSrcweir com::sun::star::ucb::XContentProvider );
85cdf0e10cSrcweir
86cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( ContentProvider,
87cdf0e10cSrcweir lang::XTypeProvider,
88cdf0e10cSrcweir lang::XServiceInfo,
89cdf0e10cSrcweir com::sun::star::ucb::XContentProvider );
90cdf0e10cSrcweir
91cdf0e10cSrcweir XSERVICEINFO_IMPL_1( ContentProvider,
92cdf0e10cSrcweir rtl::OUString::createFromAscii(
93cdf0e10cSrcweir "com.sun.star.comp.GIOContentProvider" ),
94cdf0e10cSrcweir rtl::OUString::createFromAscii(
95cdf0e10cSrcweir "com.sun.star.ucb.GIOContentProvider" ) );
96cdf0e10cSrcweir
97cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
98cdf0e10cSrcweir
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)101cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
102cdf0e10cSrcweir const sal_Char **ppEnvTypeName, uno_Environment **)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)107cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory( const sal_Char *pImplName,
108cdf0e10cSrcweir void *pServiceManager, void * )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir void * pRet = 0;
111cdf0e10cSrcweir
112cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr
113cdf0e10cSrcweir (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
114cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory;
115cdf0e10cSrcweir
116cdf0e10cSrcweir g_type_init();
117cdf0e10cSrcweir
118cdf0e10cSrcweir if ( !::gio::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
119cdf0e10cSrcweir xFactory = ::gio::ContentProvider::createServiceFactory( xSMgr );
120cdf0e10cSrcweir
121cdf0e10cSrcweir if ( xFactory.is() )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir xFactory->acquire();
124cdf0e10cSrcweir pRet = xFactory.get();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir return pRet;
128cdf0e10cSrcweir }
129