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