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