merge the formfield patch from ooo-build
[ooovba.git] / filter / source / svg / test / svg2odf.cxx
bloba271ce0aab5725f27401a3f700d00aabf26b67fe
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * Author:
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"
23 #include <sal/main.h>
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;
36 namespace
38 class OutputWrap : public cppu::WeakImplHelper1<
39 io::XOutputStream>
41 osl::File maFile;
43 public:
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)
63 maFile.close();
68 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
70 if( argc != 4 )
72 OSL_TRACE( "Invocation: svg2odf <base_url> <dst_url> <ini_file>. Exiting" );
73 return 1;
76 ::rtl::OUString aBaseURL, aTmpURL, aSrcURL, aDstURL, aIniUrl;
78 osl_getProcessWorkingDir(&aBaseURL.pData);
79 osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[1]).pData,
80 &aTmpURL.pData );
81 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aSrcURL.pData);
83 osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[2]).pData,
84 &aTmpURL.pData );
85 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aDstURL.pData);
87 osl_getFileURLFromSystemPath( rtl::OUString::createFromAscii(argv[3]).pData,
88 &aTmpURL.pData );
89 osl_getAbsoluteFileURL(aBaseURL.pData,aTmpURL.pData,&aIniUrl.pData);
91 // bootstrap UNO
92 uno::Reference< lang::XMultiServiceFactory > xFactory;
93 uno::Reference< uno::XComponentContext > xCtx;
94 try
96 xCtx = ::cppu::defaultBootstrap_InitialComponentContext(aIniUrl);
97 xFactory = uno::Reference< lang::XMultiServiceFactory >(xCtx->getServiceManager(),
98 uno::UNO_QUERY);
99 if( xFactory.is() )
100 ::comphelper::setProcessServiceFactory( xFactory );
102 catch( uno::Exception& )
106 if( !xFactory.is() )
108 OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting." );
109 return 1;
112 osl::File aInputFile(aSrcURL);
113 if( osl::FileBase::E_None!=aInputFile.open(OpenFlag_Read) )
115 OSL_TRACE( "Cannot open input file" );
116 return 1;
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;