Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "../svgreader.hxx"
21 : #include "odfserializer.hxx"
22 :
23 : #include <sal/main.h>
24 : #include <osl/file.hxx>
25 : #include <osl/process.h>
26 : #include <rtl/bootstrap.hxx>
27 :
28 : #include <cppuhelper/implbase1.hxx>
29 : #include <cppuhelper/bootstrap.hxx>
30 : #include <comphelper/processfactory.hxx>
31 : #include <comphelper/oslfile2streamwrap.hxx>
32 :
33 : using namespace ::com::sun::star;
34 :
35 : namespace
36 : {
37 0 : class OutputWrap : public cppu::WeakImplHelper1<
38 : io::XOutputStream>
39 : {
40 : osl::File maFile;
41 :
42 : public:
43 :
44 0 : explicit OutputWrap( const OUString& rURL ) : maFile(rURL)
45 : {
46 0 : maFile.open( osl_File_OpenFlag_Create|osl_File_OpenFlag_Write );
47 0 : }
48 :
49 0 : virtual void SAL_CALL writeBytes( const com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (com::sun::star::io::NotConnectedException,com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
50 :
51 : {
52 0 : sal_uInt64 nBytesWritten(0);
53 0 : maFile.write(aData.getConstArray(),aData.getLength(),nBytesWritten);
54 0 : }
55 :
56 0 : virtual void SAL_CALL flush() throw (com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
57 : {
58 0 : }
59 :
60 0 : virtual void SAL_CALL closeOutput() throw (com::sun::star::io::NotConnectedException, com::sun::star::io::BufferSizeExceededException, com::sun::star::io::IOException, com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
61 : {
62 0 : maFile.close();
63 0 : }
64 : };
65 : }
66 :
67 0 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
68 : {
69 0 : if( argc != 4 )
70 : {
71 : OSL_TRACE( "Invocation: svg2odf <base_url> <dst_url> <ini_file>. Exiting" );
72 0 : return 1;
73 : }
74 :
75 0 : OUString aBaseURL, aTmpURL, aSrcURL, aDstURL, aIniUrl;
76 :
77 0 : osl_getProcessWorkingDir(&aBaseURL.pData);
78 0 : osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[1]).pData,
79 0 : &aTmpURL.pData );
80 0 : osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aSrcURL.pData);
81 :
82 0 : osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[2]).pData,
83 0 : &aTmpURL.pData );
84 0 : osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aDstURL.pData);
85 :
86 0 : osl_getFileURLFromSystemPath( OUString::createFromAscii(argv[3]).pData,
87 0 : &aTmpURL.pData );
88 0 : osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aIniUrl.pData);
89 :
90 : // bootstrap UNO
91 0 : uno::Reference< lang::XMultiServiceFactory > xFactory;
92 0 : uno::Reference< uno::XComponentContext > xCtx;
93 : try
94 : {
95 0 : xCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
96 0 : xFactory = uno::Reference< lang::XMultiServiceFactory >(xCtx->getServiceManager(),
97 0 : uno::UNO_QUERY);
98 0 : if( xFactory.is() )
99 0 : ::comphelper::setProcessServiceFactory( xFactory );
100 : }
101 0 : catch( const uno::Exception& )
102 : {
103 : }
104 :
105 0 : if( !xFactory.is() )
106 : {
107 : OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting." );
108 0 : return 1;
109 : }
110 :
111 0 : osl::File aInputFile(aSrcURL);
112 0 : if( osl::FileBase::E_None!=aInputFile.open(osl_File_OpenFlag_Read) )
113 : {
114 : OSL_TRACE( "Cannot open input file" );
115 0 : return 1;
116 : }
117 :
118 : svgi::SVGReader aReader(xCtx,
119 : uno::Reference<io::XInputStream>(
120 0 : new comphelper::OSLInputStreamWrapper(aInputFile)),
121 0 : svgi::createSerializer(new OutputWrap(aDstURL)));
122 0 : return aReader.parseAndConvert() ? 0 : 1;
123 : }
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|