bump product version to 5.0.4.1
[LibreOffice.git] / sdext / source / pdfimport / services.cxx
blob6e0d175d4b507e8d44afcb79e209b8d70618f0c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "pdfiadaptor.hxx"
22 #include "filterdet.hxx"
23 #include "treevisitorfactory.hxx"
25 #include <cppuhelper/factory.hxx>
26 #include <cppuhelper/implementationentry.hxx>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::registry;
34 namespace
36 static Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext )
38 return *(new pdfi::PDFIHybridAdaptor( _rxContext ));
41 static Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext )
43 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.WriterPDFImport", _rxContext );
45 pAdaptor->setTreeVisitorFactory(pdfi::createWriterTreeVisitorFactory());
46 pAdaptor->enableToplevelText(); // TEMP! TEMP!
48 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
51 static Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext )
53 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.DrawPDFImport", _rxContext );
55 pAdaptor->setTreeVisitorFactory(pdfi::createDrawTreeVisitorFactory());
57 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
60 static Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext )
62 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.ImpressPDFImport", _rxContext );
64 pAdaptor->setTreeVisitorFactory(pdfi::createImpressTreeVisitorFactory());
66 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
69 static Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext )
71 return *(new pdfi::PDFDetector( _rxContext ) );
75 namespace
77 typedef Reference< XInterface > (SAL_CALL * ComponentFactory)( const Reference< XComponentContext >& );
79 struct ComponentDescription
81 const sal_Char* pAsciiServiceName;
82 const sal_Char* pAsciiImplementationName;
83 ComponentFactory pFactory;
85 ComponentDescription()
86 :pAsciiServiceName( NULL )
87 ,pAsciiImplementationName( NULL )
88 ,pFactory( NULL )
91 ComponentDescription( const sal_Char* _pAsciiServiceName, const sal_Char* _pAsciiImplementationName, ComponentFactory _pFactory )
92 :pAsciiServiceName( _pAsciiServiceName )
93 ,pAsciiImplementationName( _pAsciiImplementationName )
94 ,pFactory( _pFactory )
99 static const ComponentDescription* lcl_getComponents()
101 static const ComponentDescription aDescriptions[] = {
102 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ),
103 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ),
104 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ),
105 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ),
106 ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.PDFDetector", Create_PDFDetector ),
107 ComponentDescription()
109 return aDescriptions;
113 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL pdfimport_component_getFactory(
114 const sal_Char* pImplementationName,
115 SAL_UNUSED_PARAMETER void* /*pServiceManager*/,
116 SAL_UNUSED_PARAMETER void* /*pRegistryKey*/ )
118 OUString sImplementationName( OUString::createFromAscii( pImplementationName ) );
120 Reference< XSingleComponentFactory > xFactory;
122 const ComponentDescription* pComponents = lcl_getComponents();
123 while ( pComponents->pAsciiServiceName != NULL )
125 if ( sImplementationName.equalsAscii( pComponents->pAsciiImplementationName ) )
127 Sequence< OUString > sServices(1);
128 sServices[0] = OUString::createFromAscii( pComponents->pAsciiServiceName );
130 xFactory = ::cppu::createSingleComponentFactory(
131 pComponents->pFactory,
132 sImplementationName,
133 sServices,
134 NULL
136 break;
139 ++pComponents;
142 // by definition, objects returned via this C API need to ber acquired once
143 xFactory->acquire();
144 return xFactory.get();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */