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