20#include <com/sun/star/ucb/XCommandEnvironment.hpp>
21#include <com/sun/star/io/IOException.hpp>
22#include <com/sun/star/io/XOutputStream.hpp>
23#include <com/sun/star/embed/XPackageStructureCreator.hpp>
24#include <com/sun/star/lang/XServiceInfo.hpp>
40class OPackageStructureCreator :
public ::cppu::WeakImplHelper< embed::XPackageStructureCreator,
44 OPackageStructureCreator() {}
47 virtual void SAL_CALL convertToPackage(
const OUString& aFolderUrl,
const uno::Reference< io::XOutputStream >& xTargetStream )
override;
56void SAL_CALL OPackageStructureCreator::convertToPackage(
const OUString& aFolderUrl,
57 const uno::Reference< io::XOutputStream >& xTargetStream )
59 uno::Reference< ucb::XCommandEnvironment > xComEnv;
61 if ( !xTargetStream.is() )
62 throw io::IOException();
64 bool bSuccess =
false;
68 OUString aTempURL = ::utl::CreateTempURL();
79 if ( !aTempURL.isEmpty() )
81 SvFileStream aTempStream( aTempURL, StreamMode::STD_READWRITE );
83 aStorage->CopyTo( aTargetStorage.
get() );
84 aTargetStorage->Commit();
86 if ( aStorage->GetError() || aTargetStorage->GetError() || aTempStream.GetError() )
87 throw io::IOException();
89 aTargetStorage =
nullptr;
92 aTempStream.Seek( 0 );
94 uno::Sequence< sal_Int8 >
aSeq( 32000 );
97 if (
aSeq.getLength() < 32000 )
98 aSeq.realloc( 32000 );
100 nRead = aTempStream.ReadBytes(
aSeq.getArray(), 32000);
102 aSeq.realloc( nRead );
103 xTargetStream->writeBytes(
aSeq );
104 }
while (aTempStream.good() && nRead);
106 if ( aTempStream.GetError() )
107 throw io::IOException();
113 catch (
const uno::RuntimeException&)
115 if ( !aTempURL.isEmpty() )
116 ::utl::UCBContentHelper::Kill( aTempURL );
120 catch (
const io::IOException&)
122 if ( !aTempURL.isEmpty() )
123 ::utl::UCBContentHelper::Kill( aTempURL );
127 catch (
const uno::Exception&)
131 if ( !aTempURL.isEmpty() )
132 ::utl::UCBContentHelper::Kill( aTempURL );
136 throw io::IOException();
139OUString SAL_CALL OPackageStructureCreator::getImplementationName()
141 return "com.sun.star.comp.embed.PackageStructureCreator";
144sal_Bool SAL_CALL OPackageStructureCreator::supportsService(
const OUString& ServiceName )
149uno::Sequence< OUString > SAL_CALL OPackageStructureCreator::getSupportedServiceNames()
151 return {
"com.sun.star.embed.PackageStructureCreator",
"com.sun.star.comp.embed.PackageStructureCreator" };
156extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
158 css::uno::XComponentContext *,
159 css::uno::Sequence<css::uno::Any>
const &)
161 return cppu::acquire(
new OPackageStructureCreator());
static bool create(const OUString &rURL, const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnv, const css::uno::Reference< css::uno::XComponentContext > &rCtx, Content &rContent)
Sequence< sal_Int8 > aSeq
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_embed_PackageStructureCreator_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)