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