1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "outputwrap.hxx"
32 #include "contentsink.hxx"
33 #include "pdfihelper.hxx"
34 #include "wrapper.hxx"
35 #include "pdfparse.hxx"
36 #include "../pdfiadaptor.hxx"
37 
38 #include <sal/main.h>
39 #include <osl/process.h>
40 #include <rtl/bootstrap.hxx>
41 
42 #include <cppuhelper/bootstrap.hxx>
43 #include <cppuhelper/servicefactory.hxx>
44 #include <comphelper/processfactory.hxx>
45 
46 using namespace ::pdfi;
47 using namespace ::com::sun::star;
48 
49 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
50 {
51 	if( argc != 5 )
52 		return 1;
53 
54 	::rtl::OUString aBaseURL, aTmpURL, aSrcURL, aDstURL, aIniUrl;
55 
56     TreeVisitorFactorySharedPtr pTreeFactory;
57     if( rtl_str_compare(argv[1], "-writer") == 0 )
58         pTreeFactory = createWriterTreeVisitorFactory();
59     else if( rtl_str_compare(argv[1], "-draw") == 0 )
60         pTreeFactory = createDrawTreeVisitorFactory();
61     else if( rtl_str_compare(argv[1], "-impress") == 0 )
62         pTreeFactory = createImpressTreeVisitorFactory();
63     else
64         return 1;
65 
66     osl_getProcessWorkingDir(&aBaseURL.pData);
67     osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[2]).pData,
68                                   &aTmpURL.pData );
69     osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aSrcURL.pData);
70 
71     osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[3]).pData,
72                                   &aTmpURL.pData );
73     osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aDstURL.pData);
74 
75 	osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[4]).pData,
76 								&aTmpURL.pData );
77     osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aIniUrl.pData);
78 
79     // bootstrap UNO
80     uno::Reference< lang::XMultiServiceFactory > xFactory;
81     uno::Reference< uno::XComponentContext > xCtx;
82     try
83     {
84         xCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
85         xFactory = uno::Reference< lang::XMultiServiceFactory >(  xCtx->getServiceManager(),
86                                                                   uno::UNO_QUERY );
87         if( xFactory.is() )
88             ::comphelper::setProcessServiceFactory( xFactory );
89     }
90     catch( uno::Exception& )
91     {
92     }
93 
94     if( !xFactory.is() )
95     {
96         OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
97         return 1;
98     }
99 
100 	pdfi::PDFIRawAdaptor aAdaptor( xCtx );
101     aAdaptor.setTreeVisitorFactory(pTreeFactory);
102 	aAdaptor.odfConvert( aSrcURL, new OutputWrap(aDstURL), NULL );
103 
104 	return 0;
105 }
106