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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sdext.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "pdfiadaptor.hxx" 32*cdf0e10cSrcweir #include "filterdet.hxx" 33*cdf0e10cSrcweir #include "treevisitorfactory.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 36*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace ::com::sun::star; 39*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 40*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 41*cdf0e10cSrcweir using namespace ::com::sun::star::registry; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir static Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir return *(new pdfi::PDFIHybridAdaptor( _rxContext )); 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir static Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext ); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir pAdaptor->setTreeVisitorFactory(pdfi::createWriterTreeVisitorFactory()); 56*cdf0e10cSrcweir pAdaptor->enableToplevelText(); // TEMP! TEMP! 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor)); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir static Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir pAdaptor->setTreeVisitorFactory(pdfi::createDrawTreeVisitorFactory()); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor)); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir static Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext ); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir pAdaptor->setTreeVisitorFactory(pdfi::createImpressTreeVisitorFactory()); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor)); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir static Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir return *(new pdfi::PDFDetector( _rxContext ) ); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment( 86*cdf0e10cSrcweir const sal_Char **ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir namespace 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir typedef Reference< XInterface > (SAL_CALL * ComponentFactory)( const Reference< XComponentContext >& ); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir struct ComponentDescription 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir const sal_Char* pAsciiServiceName; 98*cdf0e10cSrcweir const sal_Char* pAsciiImplementationName; 99*cdf0e10cSrcweir ComponentFactory pFactory; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir ComponentDescription() 102*cdf0e10cSrcweir :pAsciiServiceName( NULL ) 103*cdf0e10cSrcweir ,pAsciiImplementationName( NULL ) 104*cdf0e10cSrcweir ,pFactory( NULL ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir ComponentDescription( const sal_Char* _pAsciiServiceName, const sal_Char* _pAsciiImplementationName, ComponentFactory _pFactory ) 108*cdf0e10cSrcweir :pAsciiServiceName( _pAsciiServiceName ) 109*cdf0e10cSrcweir ,pAsciiImplementationName( _pAsciiImplementationName ) 110*cdf0e10cSrcweir ,pFactory( _pFactory ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir }; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir static const ComponentDescription* lcl_getComponents() 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir static const ComponentDescription aDescriptions[] = { 118*cdf0e10cSrcweir ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ), 119*cdf0e10cSrcweir ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ), 120*cdf0e10cSrcweir ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ), 121*cdf0e10cSrcweir ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ), 122*cdf0e10cSrcweir ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.PDFDetector", Create_PDFDetector ), 123*cdf0e10cSrcweir ComponentDescription() 124*cdf0e10cSrcweir }; 125*cdf0e10cSrcweir return aDescriptions; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir Reference< XRegistryKey > xRootKey( static_cast< XRegistryKey* >( pRegistryKey ) ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir ::rtl::OUString sRootKey( "/", 1, RTL_TEXTENCODING_ASCII_US ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir const ComponentDescription* pComponents = lcl_getComponents(); 136*cdf0e10cSrcweir while ( pComponents->pAsciiServiceName != NULL ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir ::rtl::OUString sMainKeyName( sRootKey ); 139*cdf0e10cSrcweir sMainKeyName += ::rtl::OUString::createFromAscii( pComponents->pAsciiImplementationName ); 140*cdf0e10cSrcweir sMainKeyName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES" ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir try 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir Reference< XRegistryKey > xNewKey( xRootKey->createKey( sMainKeyName ) ); 145*cdf0e10cSrcweir xNewKey->createKey( ::rtl::OUString::createFromAscii( pComponents->pAsciiServiceName ) ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir catch( Exception& ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir OSL_ASSERT( "OModule::writeComponentInfos: something went wrong while creating the keys!" ); 150*cdf0e10cSrcweir return sal_False; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir ++pComponents; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir return sal_True; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir extern "C" void* SAL_CALL component_getFactory( 158*cdf0e10cSrcweir const sal_Char* pImplementationName, void* /*pServiceManager*/, void* /*pRegistryKey*/ ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir ::rtl::OUString sImplementationName( ::rtl::OUString::createFromAscii( pImplementationName ) ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir Reference< XSingleComponentFactory > xFactory; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir const ComponentDescription* pComponents = lcl_getComponents(); 165*cdf0e10cSrcweir while ( pComponents->pAsciiServiceName != NULL ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir if ( 0 == sImplementationName.compareToAscii( pComponents->pAsciiImplementationName ) ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir Sequence< ::rtl::OUString > sServices(1); 170*cdf0e10cSrcweir sServices[0] = ::rtl::OUString::createFromAscii( pComponents->pAsciiServiceName ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir xFactory = ::cppu::createSingleComponentFactory( 173*cdf0e10cSrcweir pComponents->pFactory, 174*cdf0e10cSrcweir sImplementationName, 175*cdf0e10cSrcweir sServices, 176*cdf0e10cSrcweir NULL 177*cdf0e10cSrcweir ); 178*cdf0e10cSrcweir break; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir ++pComponents; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // by definition, objects returned via this C API need to ber acquired once 185*cdf0e10cSrcweir xFactory->acquire(); 186*cdf0e10cSrcweir return xFactory.get(); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189