12#include <rtl/ustrbuf.hxx>
19#include <com/sun/star/uno/Any.hxx>
20#include <com/sun/star/container/XNameContainer.hpp>
21#include <com/sun/star/io/TempFile.hpp>
22#include <com/sun/star/io/XInputStream.hpp>
23#include <com/sun/star/io/XOutputStream.hpp>
24#include <com/sun/star/io/XSeekable.hpp>
25#include <com/sun/star/embed/XTransactedObject.hpp>
26#include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 Reference<XStream> tempFile = TempFile::create(
m_xContext);
41 OSL_ASSERT(tempFile.is());
52 Reference<XNameContainer> cont(
53 Reference<XMultiServiceFactory>(
m_xContext->getServiceManager(), UNO_QUERY_THROW)
54 ->createInstanceWithArguments(
"com.sun.star.embed.OLESimpleStorage",
args), UNO_QUERY);
61 Sequence<sal_Int8> oleData;
63 content, RTL_TEXTENCODING_UTF8));
65 Reference<XOutputStream> xOutput =
m_rootStream->getOutputStream();
66 xOutput->writeBytes(oleData);
69 Reference<XSeekable> xSeek(
m_rootStream->getInputStream(), UNO_QUERY);
73 Sequence<Any>
args{
Any(xSeek) };
74 Reference<XNameContainer> cont(
75 Reference<XMultiServiceFactory>(
m_xContext->getServiceManager(), UNO_QUERY_THROW)
76 ->createInstanceWithArguments(
"com.sun.star.embed.OLESimpleStorage",
args), UNO_QUERY);
88 Reference<XInputStream> subStream(
m_storage->getByName(streamName), UNO_QUERY);
94 Sequence<sal_Int8> aLength(4);
95 Reference<XSeekable> xSeek(subStream, UNO_QUERY);
98 int readbytes = subStream->readBytes(aLength, 4);
101 return "Can not read the length.";
103 sal_Int32
const oleLength = (
static_cast<sal_uInt8>(aLength[0]) << 0
U)
104 | (
static_cast<sal_uInt8>(aLength[1]) << 8U)
105 | (
static_cast<sal_uInt8>(aLength[2]) << 16U)
106 | (
static_cast<sal_uInt8>(aLength[3]) << 24U);
109 return "invalid oleLength";
111 Sequence<sal_Int8> content(oleLength);
113 readbytes = subStream->readBytes(content, oleLength);
114 if (oleLength < readbytes)
120 std::optional< ::ZipUtils::Inflater> decompresser(std::in_place,
false);
121 decompresser->setInput(content);
122 Sequence<sal_Int8>
result(oleLength);
123 decompresser->doInflateSegment(
result, 0, oleLength);
125 decompresser.reset();
127 OUStringBuffer buf(oleLength);
135 if ( streamName ==
"oledata.mso" )
149 if ( streamName ==
"oledata.mso" )
153 int oleLength =
static_cast<int>(xSeek->getLength());
156 Reference<XInputStream> xInput =
m_rootStream->getInputStream();
157 Sequence<sal_Int8> oledata(oleLength);
158 xInput->readBytes(oledata, oleLength);
160 OUStringBuffer buf(oleLength);
171 Sequence<sal_Int8> oledata;
173 OStringToOUString(content, RTL_TEXTENCODING_ASCII_US));
176 Reference<XInputStream> xInput = subStream->getInputStream();
177 Reference<XOutputStream> xOutput = subStream->getOutputStream();
179 Sequence<sal_Int8>
header{
180 static_cast<sal_Int8>((oledata.getLength() >> 0) & 0xFF),
181 static_cast<sal_Int8>((oledata.getLength() >> 8) & 0xFF),
182 static_cast<sal_Int8>((oledata.getLength() >> 16) & 0xFF),
183 static_cast<sal_Int8>((oledata.getLength() >> 24) & 0xFF)
185 xOutput->writeBytes(
header);
188 Sequence<sal_Int8> output(oledata.getLength());
189 std::optional< ::ZipUtils::Deflater> compresser(std::in_place, sal_Int32(3),
false);
190 compresser->setInputSegment(oledata);
191 compresser->finish();
192 int compressedDataLength = compresser->doDeflateSegment(output, oledata.getLength());
195 output.realloc(compressedDataLength);
198 xOutput->writeBytes(output);
200 Reference<XSeekable> xSeek(xInput, UNO_QUERY);
204 Reference<XTransactedObject> xTransact(
m_storage, UNO_QUERY);
207 m_storage->insertByName(streamName, entry);
constexpr sal_Int8 header[]
OString getByName(const OUString &streamName)
css::uno::Reference< XComponentContext > m_xContext
css::uno::Reference< XStream > createTempFile()
OString encodeSubStorage(const OUString &streamName)
void ensureCreateRootStorage()
void insertByName(const OUString &streamName, std::string_view content)
void initRootStorageFromBase64(std::string_view content)
css::uno::Reference< XNameContainer > m_storage
void insertSubStorage(const OUString &streamName, std::string_view content)
css::uno::Reference< XStream > m_rootStream
static void encode(OUStringBuffer &aStrBuffer, const css::uno::Sequence< sal_Int8 > &aPass)
static void decode(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)