update dev300-m58
[ooovba.git] / sdext / source / pdfimport / services.cxx
blob4317fb33a1296d308fa391b83d2bf78e68e826b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: services.cxx,v $
11 * $Revision: 1.2 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "pdfiadaptor.hxx"
36 #include "filterdet.hxx"
37 #include "treevisitorfactory.hxx"
39 #include <cppuhelper/factory.hxx>
40 #include <cppuhelper/implementationentry.hxx>
41 #include <comphelper/servicedecl.hxx>
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::registry;
49 namespace
51 static Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext )
53 return *(new pdfi::PDFIHybridAdaptor( _rxContext ));
56 static Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext )
58 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext );
60 pAdaptor->setTreeVisitorFactory(pdfi::createWriterTreeVisitorFactory());
61 pAdaptor->enableToplevelText(); // TEMP! TEMP!
63 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
66 static Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext )
68 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext );
70 pAdaptor->setTreeVisitorFactory(pdfi::createDrawTreeVisitorFactory());
72 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
75 static Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext )
77 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext );
79 pAdaptor->setTreeVisitorFactory(pdfi::createImpressTreeVisitorFactory());
81 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
84 static Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext )
86 return *(new pdfi::PDFDetector( _rxContext ) );
90 extern "C" void SAL_CALL component_getImplementationEnvironment(
91 const sal_Char **ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
93 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
96 namespace
98 typedef Reference< XInterface > (SAL_CALL * ComponentFactory)( const Reference< XComponentContext >& );
100 struct ComponentDescription
102 const sal_Char* pAsciiServiceName;
103 const sal_Char* pAsciiImplementationName;
104 ComponentFactory pFactory;
106 ComponentDescription()
107 :pAsciiServiceName( NULL )
108 ,pAsciiImplementationName( NULL )
109 ,pFactory( NULL )
112 ComponentDescription( const sal_Char* _pAsciiServiceName, const sal_Char* _pAsciiImplementationName, ComponentFactory _pFactory )
113 :pAsciiServiceName( _pAsciiServiceName )
114 ,pAsciiImplementationName( _pAsciiImplementationName )
115 ,pFactory( _pFactory )
120 static const ComponentDescription* lcl_getComponents()
122 static const ComponentDescription aDescriptions[] = {
123 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ),
124 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ),
125 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ),
126 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ),
127 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.PDFDetector", Create_PDFDetector ),
128 ComponentDescription()
130 return aDescriptions;
134 extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey )
136 Reference< XRegistryKey > xRootKey( static_cast< XRegistryKey* >( pRegistryKey ) );
138 ::rtl::OUString sRootKey( "/", 1, RTL_TEXTENCODING_ASCII_US );
140 const ComponentDescription* pComponents = lcl_getComponents();
141 while ( pComponents->pAsciiServiceName != NULL )
143 ::rtl::OUString sMainKeyName( sRootKey );
144 sMainKeyName += ::rtl::OUString::createFromAscii( pComponents->pAsciiImplementationName );
145 sMainKeyName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES" );
149 Reference< XRegistryKey > xNewKey( xRootKey->createKey( sMainKeyName ) );
150 xNewKey->createKey( ::rtl::OUString::createFromAscii( pComponents->pAsciiServiceName ) );
152 catch( Exception& )
154 OSL_ASSERT( "OModule::writeComponentInfos: something went wrong while creating the keys!" );
155 return sal_False;
157 ++pComponents;
159 return sal_True;
162 extern "C" void* SAL_CALL component_getFactory(
163 const sal_Char* pImplementationName, void* /*pServiceManager*/, void* /*pRegistryKey*/ )
165 ::rtl::OUString sImplementationName( ::rtl::OUString::createFromAscii( pImplementationName ) );
167 Reference< XSingleComponentFactory > xFactory;
169 const ComponentDescription* pComponents = lcl_getComponents();
170 while ( pComponents->pAsciiServiceName != NULL )
172 if ( 0 == sImplementationName.compareToAscii( pComponents->pAsciiImplementationName ) )
174 Sequence< ::rtl::OUString > sServices(1);
175 sServices[0] = ::rtl::OUString::createFromAscii( pComponents->pAsciiServiceName );
177 xFactory = ::cppu::createSingleComponentFactory(
178 pComponents->pFactory,
179 sImplementationName,
180 sServices,
181 NULL
183 break;
186 ++pComponents;
189 // by definition, objects returned via this C API need to ber acquired once
190 xFactory->acquire();
191 return xFactory.get();