1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <WW8StreamImpl.hxx>
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/io/XSeekable.hpp>
24 #include <com/sun/star/io/XStream.hpp>
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 #include <doctokLoggers.hxx>
29 namespace writerfilter
{
32 using namespace ::com::sun::star
;
34 #if OSL_DEBUG_LEVEL > 1
35 TagLogger::Pointer_t
debug_logger(TagLogger::getInstance("DEBUG"));
38 WW8Stream::~WW8Stream()
42 WW8StreamImpl::WW8StreamImpl(uno::Reference
<uno::XComponentContext
> rContext
,
43 uno::Reference
<io::XInputStream
> rStream
)
44 : mrComponentContext(rContext
), mrStream(rStream
)
46 xFactory
= uno::Reference
<lang::XMultiComponentFactory
>
47 (mrComponentContext
->getServiceManager());
49 uno::Sequence
<uno::Any
> aArgs( 1 );
50 aArgs
[0] <<= mrStream
;
52 xOLESimpleStorage
= uno::Reference
<container::XNameContainer
>
53 (xFactory
->createInstanceWithArgumentsAndContext
54 ("com.sun.star.embed.OLESimpleStorage",
55 aArgs
, mrComponentContext
),
60 WW8StreamImpl::~WW8StreamImpl()
64 WW8Stream::Sequence
WW8StreamImpl::get(sal_uInt32 nOffset
,
65 sal_uInt32 nCount
) const
67 uno::Sequence
<sal_Int8
> aSequence
;
71 uno::Reference
< io::XSeekable
> xSeek( mrStream
, uno::UNO_QUERY_THROW
);
75 sal_Int32 nRead
= mrStream
->readBytes(aSequence
, nCount
);
77 Sequence
aReturnSequence(const_cast<const sal_uInt8
*>
78 (reinterpret_cast<sal_uInt8
*>
79 (&(aSequence
[0]))), nRead
);
81 return aReturnSequence
;
84 return WW8Stream::Sequence();
87 WW8Stream::Pointer_t
WW8StreamImpl::getSubStream(const OUString
& sId
)
89 WW8Stream::Pointer_t pResult
;
93 if (xOLESimpleStorage
.is())
95 if (xOLESimpleStorage
->hasByName(sId
))
97 uno::Reference
<io::XStream
> xNewStream
;
99 uno::Any aValue
= xOLESimpleStorage
->getByName(sId
);
100 aValue
>>= xNewStream
;
106 pNew(new WW8StreamImpl(mrComponentContext
,
107 xNewStream
->getInputStream()));
118 if (pResult
.get() == NULL
)
119 throw ExceptionNotFound("Stream not found");
124 string
WW8StreamImpl::getSubStreamNames() const
128 if (xOLESimpleStorage
.is())
130 uno::Sequence
<OUString
> aSeq
= xOLESimpleStorage
->getElementNames();
132 for (sal_uInt32 n
= 0;
133 n
< sal::static_int_cast
<sal_uInt32
>(aSeq
.getLength()); ++n
)
135 OUString aOUStr
= aSeq
[n
];
141 for (sal_uInt32 j
= 0;
142 j
< sal::static_int_cast
<sal_uInt32
>(aOUStr
.getLength()); ++j
)
144 if (isprint(aOUStr
[j
]))
146 sal_Unicode nC
= aOUStr
[j
];
149 sResult
+= sal::static_int_cast
<char>(nC
);
155 snprintf(sBuffer
, sizeof(sBuffer
), "\\u%x", aOUStr
[j
]);
165 uno::Sequence
<OUString
> WW8StreamImpl::getSubStreamUNames() const
167 return xOLESimpleStorage
->getElementNames();
170 void WW8StreamImpl::dump(OutputWithDepth
<string
> & o
) const
172 o
.addItem("<stream>");
175 sal_uInt32 nOffset
= 0;
176 sal_uInt32 nStep
= 16;
180 aSeq
= get(nOffset
, nStep
);
181 dumpLine(o
, aSeq
, nOffset
, nStep
);
185 while (aSeq
.getCount() == nStep
);
187 o
.addItem("</stream>");
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */