1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26
27 #include "pdfiadaptor.hxx"
28 #include "filterdet.hxx"
29 #include "treevisitorfactory.hxx"
30
31 #include <cppuhelper/factory.hxx>
32 #include <cppuhelper/implementationentry.hxx>
33
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::registry;
38
39
40 namespace
41 {
Create_PDFIHybridAdaptor(const Reference<XComponentContext> & _rxContext)42 static Reference< XInterface > Create_PDFIHybridAdaptor( const Reference< XComponentContext >& _rxContext )
43 {
44 return *(new pdfi::PDFIHybridAdaptor( _rxContext ));
45 }
46
Create_PDFIRawAdaptor_Writer(const Reference<XComponentContext> & _rxContext)47 static Reference< XInterface > Create_PDFIRawAdaptor_Writer( const Reference< XComponentContext >& _rxContext )
48 {
49 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext );
50
51 pAdaptor->setTreeVisitorFactory(pdfi::createWriterTreeVisitorFactory());
52 pAdaptor->enableToplevelText(); // TEMP! TEMP!
53
54 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
55 }
56
Create_PDFIRawAdaptor_Draw(const Reference<XComponentContext> & _rxContext)57 static Reference< XInterface > Create_PDFIRawAdaptor_Draw( const Reference< XComponentContext >& _rxContext )
58 {
59 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext );
60
61 pAdaptor->setTreeVisitorFactory(pdfi::createDrawTreeVisitorFactory());
62
63 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
64 }
65
Create_PDFIRawAdaptor_Impress(const Reference<XComponentContext> & _rxContext)66 static Reference< XInterface > Create_PDFIRawAdaptor_Impress( const Reference< XComponentContext >& _rxContext )
67 {
68 pdfi::PDFIRawAdaptor* pAdaptor = new pdfi::PDFIRawAdaptor( _rxContext );
69
70 pAdaptor->setTreeVisitorFactory(pdfi::createImpressTreeVisitorFactory());
71
72 return uno::Reference<uno::XInterface>(static_cast<xml::XImportFilter*>(pAdaptor));
73 }
74
Create_PDFDetector(const Reference<XComponentContext> & _rxContext)75 static Reference< XInterface > Create_PDFDetector( const Reference< XComponentContext >& _rxContext )
76 {
77 return *(new pdfi::PDFDetector( _rxContext ) );
78 }
79 }
80
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)81 extern "C" void SAL_CALL component_getImplementationEnvironment(
82 const sal_Char **ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
83 {
84 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
85 }
86
87 namespace
88 {
89 typedef Reference< XInterface > (SAL_CALL * ComponentFactory)( const Reference< XComponentContext >& );
90
91 struct ComponentDescription
92 {
93 const sal_Char* pAsciiServiceName;
94 const sal_Char* pAsciiImplementationName;
95 ComponentFactory pFactory;
96
ComponentDescription__anon04a5deff0211::ComponentDescription97 ComponentDescription()
98 :pAsciiServiceName( NULL )
99 ,pAsciiImplementationName( NULL )
100 ,pFactory( NULL )
101 {
102 }
ComponentDescription__anon04a5deff0211::ComponentDescription103 ComponentDescription( const sal_Char* _pAsciiServiceName, const sal_Char* _pAsciiImplementationName, ComponentFactory _pFactory )
104 :pAsciiServiceName( _pAsciiServiceName )
105 ,pAsciiImplementationName( _pAsciiImplementationName )
106 ,pFactory( _pFactory )
107 {
108 }
109 };
110
lcl_getComponents()111 static const ComponentDescription* lcl_getComponents()
112 {
113 static const ComponentDescription aDescriptions[] = {
114 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.HybridPDFImport", Create_PDFIHybridAdaptor ),
115 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.WriterPDFImport", Create_PDFIRawAdaptor_Writer ),
116 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.DrawPDFImport", Create_PDFIRawAdaptor_Draw ),
117 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.ImpressPDFImport", Create_PDFIRawAdaptor_Impress ),
118 ComponentDescription( "com.sun.star.document.ImportFilter", "com.sun.star.comp.documents.PDFDetector", Create_PDFDetector ),
119 ComponentDescription()
120 };
121 return aDescriptions;
122 }
123 }
124
component_writeInfo(void *,void * pRegistryKey)125 extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey )
126 {
127 Reference< XRegistryKey > xRootKey( static_cast< XRegistryKey* >( pRegistryKey ) );
128
129 ::rtl::OUString sRootKey( "/", 1, RTL_TEXTENCODING_ASCII_US );
130
131 const ComponentDescription* pComponents = lcl_getComponents();
132 while ( pComponents->pAsciiServiceName != NULL )
133 {
134 ::rtl::OUString sMainKeyName( sRootKey );
135 sMainKeyName += ::rtl::OUString::createFromAscii( pComponents->pAsciiImplementationName );
136 sMainKeyName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES" );
137
138 try
139 {
140 Reference< XRegistryKey > xNewKey( xRootKey->createKey( sMainKeyName ) );
141 xNewKey->createKey( ::rtl::OUString::createFromAscii( pComponents->pAsciiServiceName ) );
142 }
143 catch( Exception& )
144 {
145 OSL_ASSERT( "OModule::writeComponentInfos: something went wrong while creating the keys!" );
146 return sal_False;
147 }
148 ++pComponents;
149 }
150 return sal_True;
151 }
152
component_getFactory(const sal_Char * pImplementationName,void *,void *)153 extern "C" void* SAL_CALL component_getFactory(
154 const sal_Char* pImplementationName, void* /*pServiceManager*/, void* /*pRegistryKey*/ )
155 {
156 ::rtl::OUString sImplementationName( ::rtl::OUString::createFromAscii( pImplementationName ) );
157
158 Reference< XSingleComponentFactory > xFactory;
159
160 const ComponentDescription* pComponents = lcl_getComponents();
161 while ( pComponents->pAsciiServiceName != NULL )
162 {
163 if ( 0 == sImplementationName.compareToAscii( pComponents->pAsciiImplementationName ) )
164 {
165 Sequence< ::rtl::OUString > sServices(1);
166 sServices[0] = ::rtl::OUString::createFromAscii( pComponents->pAsciiServiceName );
167
168 xFactory = ::cppu::createSingleComponentFactory(
169 pComponents->pFactory,
170 sImplementationName,
171 sServices,
172 NULL
173 );
174 break;
175 }
176
177 ++pComponents;
178 }
179
180 // by definition, objects returned via this C API need to ber acquired once
181 xFactory->acquire();
182 return xFactory.get();
183 }
184
185