xref: /trunk/main/ucb/source/ucp/gio/gio_provider.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
41 #ifdef DEBUG
42     fprintf(stderr, "QueryContent: '%s'",
43        (const sal_Char *)rtl::OUStringToOString
44        (Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8));
45 #endif
46 
47     osl::MutexGuard aGuard( m_aMutex );
48 
49     // Check, if a content with given id already exists...
50     uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier ).get();
51     if ( xContent.is() )
52         return xContent;
53 
54     try
55     {
56         xContent = new ::gio::Content(m_xSMgr, this, Identifier);
57     }
58     catch ( com::sun::star::ucb::ContentCreationException const & )
59     {
60         throw com::sun::star::ucb::IllegalIdentifierException();
61     }
62 
63     if ( !xContent->getIdentifier().is() )
64         throw com::sun::star::ucb::IllegalIdentifierException();
65 
66     return xContent;
67 }
68 
ContentProvider(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)69 ContentProvider::ContentProvider(
70     const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
71 : ::ucbhelper::ContentProviderImplHelper( rSMgr )
72 {
73 }
74 
~ContentProvider()75 ContentProvider::~ContentProvider()
76 {
77 }
78 
79 XINTERFACE_IMPL_3( ContentProvider,
80                    lang::XTypeProvider,
81                    lang::XServiceInfo,
82                    com::sun::star::ucb::XContentProvider );
83 
84 XTYPEPROVIDER_IMPL_3( ContentProvider,
85                       lang::XTypeProvider,
86                       lang::XServiceInfo,
87                       com::sun::star::ucb::XContentProvider );
88 
89 XSERVICEINFO_IMPL_1( ContentProvider,
90                      rtl::OUString::createFromAscii(
91                        "com.sun.star.comp.GIOContentProvider" ),
92                      rtl::OUString::createFromAscii(
93                        "com.sun.star.ucb.GIOContentProvider" ) );
94 
95 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
96 
97 }
98 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)99 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
100     const sal_Char  **ppEnvTypeName, uno_Environment **)
101 {
102     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
103 }
104 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)105 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char *pImplName,
106     void *pServiceManager, void * )
107 {
108     void * pRet = 0;
109 
110     uno::Reference< lang::XMultiServiceFactory > xSMgr
111         (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
112     uno::Reference< lang::XSingleServiceFactory > xFactory;
113 
114     g_type_init();
115 
116     if ( !::gio::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
117         xFactory = ::gio::ContentProvider::createServiceFactory( xSMgr );
118 
119     if ( xFactory.is() )
120     {
121         xFactory->acquire();
122         pRet = xFactory.get();
123     }
124 
125     return pRet;
126 }
127