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