1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: facreg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/dllapi.h"
35 #include <sal/config.h>
37 #include <com/sun/star/container/XSet.hpp>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
40 #include <cppuhelper/factory.hxx>
41 #include <uno/lbnames.h>
44 using namespace com::sun::star
;
46 #define SERVICE( className ) \
47 extern OUString SAL_CALL className##_getImplementationName() throw(); \
48 extern uno::Sequence< OUString > SAL_CALL className##_getSupportedServiceNames() throw();\
49 extern uno::Reference< uno::XInterface > SAL_CALL className##_createInstance( \
50 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) \
51 throw( uno::Exception )
53 #define SERVICE2( className ) \
54 extern OUString SAL_CALL className##_getImplementationName() throw(); \
55 extern uno::Sequence< OUString > SAL_CALL className##_getSupportedServiceNames() throw();\
56 extern uno::Reference< uno::XInterface > SAL_CALL className##_createInstance( \
57 const uno::Reference< uno::XComponentContext > & xContext ) \
58 throw( uno::Exception )
61 namespace core
{ SERVICE( FilterDetect
); }
62 namespace ppt
{ SERVICE( PowerPointImport
); }
63 namespace xls
{ SERVICE( BiffDetector
); }
64 namespace xls
{ SERVICE( ExcelFilter
); }
65 namespace xls
{ SERVICE( ExcelBiffFilter
); }
66 namespace shape
{ SERVICE( ShapeContextHandler
); }
67 namespace shape
{ SERVICE( FastTokenHandlerService
); }
68 namespace docprop
{ SERVICE2( OOXMLDocPropImportImpl
); }
69 namespace xls
{ SERVICE2( OOXMLFormulaParser
); }
78 OOX_DLLPUBLIC
void SAL_CALL
component_getImplementationEnvironment( const sal_Char
** ppEnvTypeName
, uno_Environment
** )
80 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
83 void SAL_CALL
writeInfo( registry::XRegistryKey
* pRegistryKey
, const OUString
& rImplementationName
, const uno::Sequence
< OUString
>& rServices
)
85 uno::Reference
< registry::XRegistryKey
> xNewKey(
86 pRegistryKey
->createKey(
87 OUString( sal_Unicode( '/' ) ) + rImplementationName
+ OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) ) );
89 for( sal_Int32 i
= 0; i
< rServices
.getLength(); i
++ )
90 xNewKey
->createKey( rServices
.getConstArray()[i
]);
93 #define WRITEINFO(className)\
94 writeInfo( pKey, className##_getImplementationName(), className##_getSupportedServiceNames() )
96 OOX_DLLPUBLIC sal_Bool SAL_CALL
component_writeInfo( void * , void * pRegistryKey
)
102 registry::XRegistryKey
*pKey
= reinterpret_cast< registry::XRegistryKey
* >( pRegistryKey
);
104 WRITEINFO( ::oox::core::FilterDetect
);
105 WRITEINFO( ::oox::ppt::PowerPointImport
);
106 WRITEINFO( ::oox::xls::BiffDetector
);
107 WRITEINFO( ::oox::xls::ExcelFilter
);
108 WRITEINFO( ::oox::xls::ExcelBiffFilter
);
109 WRITEINFO( ::oox::shape::ShapeContextHandler
);
110 WRITEINFO( ::oox::shape::FastTokenHandlerService
);
111 WRITEINFO( ::oox::docprop::OOXMLDocPropImportImpl
);
112 WRITEINFO( ::oox::xls::OOXMLFormulaParser
);
114 catch (registry::InvalidRegistryException
&)
116 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
122 #define SINGLEFACTORY(classname)\
123 if( classname##_getImplementationName().equalsAsciiL( pImplName, nImplNameLen ) )\
125 xFactory = ::cppu::createSingleFactory( xMSF,\
126 classname##_getImplementationName(),\
127 classname##_createInstance,\
128 classname##_getSupportedServiceNames() );\
131 #define SINGLEFACTORY2(classname)\
132 if( classname##_getImplementationName().equalsAsciiL( pImplName, nImplNameLen ) )\
134 xCompFactory = ::cppu::createSingleComponentFactory(\
135 classname##_createInstance,\
136 classname##_getImplementationName(),\
137 classname##_getSupportedServiceNames() );\
140 OOX_DLLPUBLIC
void * SAL_CALL
component_getFactory( const sal_Char
* pImplName
, void * pServiceManager
, void * )
143 if( pServiceManager
)
145 uno::Reference
< lang::XMultiServiceFactory
> xMSF( reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
) );
147 uno::Reference
< lang::XSingleServiceFactory
> xFactory
;
148 uno::Reference
< lang::XSingleComponentFactory
> xCompFactory
;
150 const sal_Int32 nImplNameLen
= strlen( pImplName
);
152 SINGLEFACTORY( ::oox::core::FilterDetect
)
153 else SINGLEFACTORY( oox::ppt::PowerPointImport
)
154 else SINGLEFACTORY( ::oox::xls::BiffDetector
)
155 else SINGLEFACTORY( ::oox::xls::ExcelFilter
)
156 else SINGLEFACTORY( ::oox::xls::ExcelBiffFilter
)
157 else SINGLEFACTORY( ::oox::shape::ShapeContextHandler
)
158 else SINGLEFACTORY( ::oox::shape::FastTokenHandlerService
)
159 else SINGLEFACTORY2( ::oox::docprop::OOXMLDocPropImportImpl
)
160 else SINGLEFACTORY2( ::oox::xls::OOXMLFormulaParser
)
165 pRet
= xFactory
.get();
167 else if ( xCompFactory
.is() )
169 xCompFactory
->acquire();
170 pRet
= xCompFactory
.get();