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 "outputwrap.hxx"
28cdf0e10cSrcweir #include "contentsink.hxx"
29cdf0e10cSrcweir #include "pdfihelper.hxx"
30cdf0e10cSrcweir #include "wrapper.hxx"
31cdf0e10cSrcweir #include "pdfparse.hxx"
32cdf0e10cSrcweir #include "../pdfiadaptor.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <sal/main.h>
35cdf0e10cSrcweir #include <osl/process.h>
36cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
39cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace ::pdfi;
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir 
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc,argv)45cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	if( argc != 5 )
48cdf0e10cSrcweir 		return 1;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	::rtl::OUString aBaseURL, aTmpURL, aSrcURL, aDstURL, aIniUrl;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     TreeVisitorFactorySharedPtr pTreeFactory;
53cdf0e10cSrcweir     if( rtl_str_compare(argv[1], "-writer") == 0 )
54cdf0e10cSrcweir         pTreeFactory = createWriterTreeVisitorFactory();
55cdf0e10cSrcweir     else if( rtl_str_compare(argv[1], "-draw") == 0 )
56cdf0e10cSrcweir         pTreeFactory = createDrawTreeVisitorFactory();
57cdf0e10cSrcweir     else if( rtl_str_compare(argv[1], "-impress") == 0 )
58cdf0e10cSrcweir         pTreeFactory = createImpressTreeVisitorFactory();
59cdf0e10cSrcweir     else
60cdf0e10cSrcweir         return 1;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     osl_getProcessWorkingDir(&aBaseURL.pData);
63cdf0e10cSrcweir     osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[2]).pData,
64cdf0e10cSrcweir                                   &aTmpURL.pData );
65cdf0e10cSrcweir     osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aSrcURL.pData);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[3]).pData,
68cdf0e10cSrcweir                                   &aTmpURL.pData );
69cdf0e10cSrcweir     osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aDstURL.pData);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[4]).pData,
72cdf0e10cSrcweir 								&aTmpURL.pData );
73cdf0e10cSrcweir     osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aIniUrl.pData);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     // bootstrap UNO
76cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFactory;
77cdf0e10cSrcweir     uno::Reference< uno::XComponentContext > xCtx;
78cdf0e10cSrcweir     try
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         xCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
81cdf0e10cSrcweir         xFactory = uno::Reference< lang::XMultiServiceFactory >(  xCtx->getServiceManager(),
82cdf0e10cSrcweir                                                                   uno::UNO_QUERY );
83cdf0e10cSrcweir         if( xFactory.is() )
84cdf0e10cSrcweir             ::comphelper::setProcessServiceFactory( xFactory );
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir     catch( uno::Exception& )
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     if( !xFactory.is() )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
93cdf0e10cSrcweir         return 1;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	pdfi::PDFIRawAdaptor aAdaptor( xCtx );
97cdf0e10cSrcweir     aAdaptor.setTreeVisitorFactory(pTreeFactory);
98cdf0e10cSrcweir 	aAdaptor.odfConvert( aSrcURL, new OutputWrap(aDstURL), NULL );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	return 0;
101cdf0e10cSrcweir }
102