xref: /trunk/main/ucb/source/ucp/gio/gio_provider.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
29*cdf0e10cSrcweir #include <ucbhelper/contenthelper.hxx>
30*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentCreationException.hpp>
31*cdf0e10cSrcweir #include "gio_provider.hxx"
32*cdf0e10cSrcweir #include "gio_content.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <stdio.h>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir using namespace com::sun::star;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace gio
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
41*cdf0e10cSrcweir ContentProvider::queryContent(
42*cdf0e10cSrcweir             const uno::Reference<
43*cdf0e10cSrcweir                     com::sun::star::ucb::XContentIdentifier >& Identifier )
44*cdf0e10cSrcweir     throw( com::sun::star::ucb::IllegalIdentifierException,
45*cdf0e10cSrcweir            uno::RuntimeException )
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir #ifdef DEBUG
48*cdf0e10cSrcweir     fprintf(stderr, "QueryContent: '%s'",
49*cdf0e10cSrcweir        (const sal_Char *)rtl::OUStringToOString
50*cdf0e10cSrcweir        (Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8));
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     // Check, if a content with given id already exists...
56*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xContent = queryExistingContent( Identifier ).get();
57*cdf0e10cSrcweir     if ( xContent.is() )
58*cdf0e10cSrcweir         return xContent;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     try
61*cdf0e10cSrcweir     {
62*cdf0e10cSrcweir         xContent = new ::gio::Content(m_xSMgr, this, Identifier);
63*cdf0e10cSrcweir     }
64*cdf0e10cSrcweir     catch ( com::sun::star::ucb::ContentCreationException const & )
65*cdf0e10cSrcweir     {
66*cdf0e10cSrcweir         throw com::sun::star::ucb::IllegalIdentifierException();
67*cdf0e10cSrcweir     }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     if ( !xContent->getIdentifier().is() )
70*cdf0e10cSrcweir         throw com::sun::star::ucb::IllegalIdentifierException();
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir     return xContent;
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir ContentProvider::ContentProvider(
76*cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
77*cdf0e10cSrcweir : ::ucbhelper::ContentProviderImplHelper( rSMgr )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir ContentProvider::~ContentProvider()
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir XINTERFACE_IMPL_3( ContentProvider,
86*cdf0e10cSrcweir                    lang::XTypeProvider,
87*cdf0e10cSrcweir                    lang::XServiceInfo,
88*cdf0e10cSrcweir                    com::sun::star::ucb::XContentProvider );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( ContentProvider,
91*cdf0e10cSrcweir                       lang::XTypeProvider,
92*cdf0e10cSrcweir                       lang::XServiceInfo,
93*cdf0e10cSrcweir                       com::sun::star::ucb::XContentProvider );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir XSERVICEINFO_IMPL_1( ContentProvider,
96*cdf0e10cSrcweir                      rtl::OUString::createFromAscii(
97*cdf0e10cSrcweir                        "com.sun.star.comp.GIOContentProvider" ),
98*cdf0e10cSrcweir                      rtl::OUString::createFromAscii(
99*cdf0e10cSrcweir                        "com.sun.star.ucb.GIOContentProvider" ) );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
106*cdf0e10cSrcweir     const sal_Char  **ppEnvTypeName, uno_Environment **)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory( const sal_Char *pImplName,
112*cdf0e10cSrcweir     void *pServiceManager, void * )
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     void * pRet = 0;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMgr
117*cdf0e10cSrcweir         (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
118*cdf0e10cSrcweir     uno::Reference< lang::XSingleServiceFactory > xFactory;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     g_type_init();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     if ( !::gio::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
123*cdf0e10cSrcweir         xFactory = ::gio::ContentProvider::createServiceFactory( xSMgr );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     if ( xFactory.is() )
126*cdf0e10cSrcweir     {
127*cdf0e10cSrcweir         xFactory->acquire();
128*cdf0e10cSrcweir         pRet = xFactory.get();
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     return pRet;
132*cdf0e10cSrcweir }
133