LibreOffice Module sdext (master)  1
services.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #include "pdfiadaptor.hxx"
22 #include "filterdet.hxx"
23 #include <treevisitorfactory.hxx>
24 
25 #include <cppuhelper/factory.hxx>
26 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
27 
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;
32 
33 
34 namespace
35 {
36  Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext )
37  {
38  return *(new pdfi::PDFIHybridAdaptor( _rxContext ));
39  }
40 
41  Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext )
42  {
43  pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.WriterPDFImport", _rxContext );
44 
46 
47  return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
48  }
49 
50  Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext )
51  {
52  pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.DrawPDFImport", _rxContext );
53 
55 
56  return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
57  }
58 
59  Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext )
60  {
61  pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( "org.libreoffice.comp.documents.ImpressPDFImport", _rxContext );
62 
64 
65  return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
66  }
67 
68  Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext )
69  {
70  return *(new pdfi::PDFDetector( _rxContext ) );
71  }
72 }
73 
74 namespace
75 {
76  typedef Reference< XInterface > (* ComponentFactory)( const Reference< XComponentContext >& );
77 
78  struct ComponentDescription
79  {
80  const char* pAsciiServiceName;
81  const char* pAsciiImplementationName;
82  ComponentFactory pFactory;
83 
84  ComponentDescription()
85  :pAsciiServiceName( nullptr )
86  ,pAsciiImplementationName( nullptr )
87  ,pFactory( nullptr )
88  {
89  }
90  ComponentDescription( const char* _pAsciiServiceName, const char* _pAsciiImplementationName, ComponentFactory _pFactory )
91  :pAsciiServiceName( _pAsciiServiceName )
92  ,pAsciiImplementationName( _pAsciiImplementationName )
93  ,pFactory( _pFactory )
94  {
95  }
96  };
97 
98  const ComponentDescription* lcl_getComponents()
99  {
100  static const ComponentDescription aDescriptions[] = {
101  ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ),
102  ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ),
103  ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ),
104  ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ),
105  ComponentDescription( "com.sun.star.document.ImportFilter", "org.libreoffice.comp.documents.PDFDetector", Create_PDFDetector ),
106  ComponentDescription()
107  };
108  return aDescriptions;
109  }
110 }
111 
112 extern "C" SAL_DLLPUBLIC_EXPORT void* pdfimport_component_getFactory(
113  const char* pImplementationName,
114  SAL_UNUSED_PARAMETER void* /*pServiceManager*/,
115  SAL_UNUSED_PARAMETER void* /*pRegistryKey*/ )
116 {
117  OUString sImplementationName( OUString::createFromAscii( pImplementationName ) );
118 
119  Reference< XSingleComponentFactory > xFactory;
120 
121  const ComponentDescription* pComponents = lcl_getComponents();
122  while ( pComponents->pAsciiServiceName != nullptr )
123  {
124  if ( sImplementationName.equalsAscii( pComponents->pAsciiImplementationName ) )
125  {
126  Sequence< OUString > sServices(1);
127  sServices[0] = OUString::createFromAscii( pComponents->pAsciiServiceName );
128 
129  xFactory = ::cppu::createSingleComponentFactory(
130  pComponents->pFactory,
131  sImplementationName,
132  sServices
133  );
134  break;
135  }
136 
137  ++pComponents;
138  }
139 
140  // by definition, objects returned via this C API need to ber acquired once
141  xFactory->acquire();
142  return xFactory.get();
143 }
144 
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char sImplementationName[]
Adapts raw pdf import to XImportFilter interface.
Definition: pdfiadaptor.hxx:82
SAL_DLLPUBLIC_EXPORT void * pdfimport_component_getFactory(const char *pImplementationName, SAL_UNUSED_PARAMETER void *, SAL_UNUSED_PARAMETER void *)
Definition: services.cxx:112
TreeVisitorFactorySharedPtr createWriterTreeVisitorFactory()
TreeVisitorFactorySharedPtr createImpressTreeVisitorFactory()
void setTreeVisitorFactory(const TreeVisitorFactorySharedPtr &rVisitorFactory)
Set factory object used to create the tree visitors.
Reference< XSingleServiceFactory > xFactory
TreeVisitorFactorySharedPtr createDrawTreeVisitorFactory()