1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
6 * Fridrich Strba <fridrich.strba@bluewin.ch>
7 * Thorsten Behrens <tbehrens@novell.com>
9 * Copyright (C) 2008, Novell Inc.
10 * Parts copyright 2005 by Sun Microsystems, Inc.
12 * The Contents of this file are made available subject to
13 * the terms of GNU Lesser General Public License Version 2.1.
15 ************************************************************************/
17 // MARKER(update_precomp.py): autogen include statement, do not remove
18 #include "precompiled_filter.hxx"
20 #include "../svgreader.hxx"
21 #include "odfserializer.hxx"
24 #include <osl/file.hxx>
25 #include <osl/process.h>
26 #include <rtl/bootstrap.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <cppuhelper/bootstrap.hxx>
30 #include <cppuhelper/servicefactory.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/oslfile2streamwrap.hxx>
34 using namespace ::com::sun::star
;
38 class OutputWrap
: public cppu::WeakImplHelper1
<
45 explicit OutputWrap( const rtl::OUString
& rURL
) : maFile(rURL
)
47 maFile
.open(osl_File_OpenFlag_Create
|OpenFlag_Write
);
50 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
)
53 sal_uInt64
nBytesWritten(0);
54 maFile
.write(aData
.getConstArray(),aData
.getLength(),nBytesWritten
);
57 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
)
61 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
)
68 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
72 OSL_TRACE( "Invocation: svg2odf <base_url> <dst_url> <ini_file>. Exiting" );
76 ::rtl::OUString aBaseURL
, aTmpURL
, aSrcURL
, aDstURL
, aIniUrl
;
78 osl_getProcessWorkingDir(&aBaseURL
.pData
);
79 osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv
[1]).pData
,
81 osl_getAbsoluteFileURL(aBaseURL
.pData
,aTmpURL
.pData
,&aSrcURL
.pData
);
83 osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv
[2]).pData
,
85 osl_getAbsoluteFileURL(aBaseURL
.pData
,aTmpURL
.pData
,&aDstURL
.pData
);
87 osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv
[3]).pData
,
89 osl_getAbsoluteFileURL(aBaseURL
.pData
,aTmpURL
.pData
,&aIniUrl
.pData
);
92 uno::Reference
< lang::XMultiServiceFactory
> xFactory
;
93 uno::Reference
< uno::XComponentContext
> xCtx
;
96 xCtx
= ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl
);
97 xFactory
= uno::Reference
< lang::XMultiServiceFactory
>(xCtx
->getServiceManager(),
100 ::comphelper::setProcessServiceFactory( xFactory
);
102 catch( uno::Exception
& )
108 OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting." );
112 osl::File
aInputFile(aSrcURL
);
113 if( osl::FileBase::E_None
!=aInputFile
.open(OpenFlag_Read
) )
115 OSL_TRACE( "Cannot open input file" );
119 svgi::SVGReader
aReader(xFactory
,
120 uno::Reference
<io::XInputStream
>(
121 new comphelper::OSLInputStreamWrapper(aInputFile
)),
122 svgi::createSerializer(new OutputWrap(aDstURL
)));
123 return aReader
.parseAndConvert() ? 0 : 1;