1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8StreamImpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <WW8StreamImpl.hxx>
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/io/XSeekable.hpp>
35 #include <com/sun/star/io/XStream.hpp>
36 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
38 #include <doctokLoggers.hxx>
40 namespace writerfilter
{
43 using namespace ::com::sun::star
;
45 TagLogger::Pointer_t
debug_logger(TagLogger::getInstance("DEBUG"));
47 WW8Stream::~WW8Stream()
51 WW8StreamImpl::WW8StreamImpl(uno::Reference
<uno::XComponentContext
> rContext
,
52 uno::Reference
<io::XInputStream
> rStream
)
53 : mrComponentContext(rContext
), mrStream(rStream
)
55 xFactory
= uno::Reference
<lang::XMultiComponentFactory
>
56 (mrComponentContext
->getServiceManager());
58 uno::Sequence
<uno::Any
> aArgs( 1 );
59 aArgs
[0] <<= mrStream
;
61 xOLESimpleStorage
= uno::Reference
<container::XNameContainer
>
62 (xFactory
->createInstanceWithArgumentsAndContext
63 (::rtl::OUString::createFromAscii
64 ("com.sun.star.embed.OLESimpleStorage"),
65 aArgs
, mrComponentContext
),
70 WW8StreamImpl::~WW8StreamImpl()
74 WW8Stream::Sequence
WW8StreamImpl::get(sal_uInt32 nOffset
,
75 sal_uInt32 nCount
) const
77 uno::Sequence
<sal_Int8
> aSequence
;
81 uno::Reference
< io::XSeekable
> xSeek( mrStream
, uno::UNO_QUERY_THROW
);
85 sal_Int32 nRead
= mrStream
->readBytes(aSequence
, nCount
);
87 Sequence
aReturnSequence(const_cast<const sal_uInt8
*>
88 (reinterpret_cast<sal_uInt8
*>
89 (&(aSequence
[0]))), nRead
);
91 return aReturnSequence
;
94 return WW8Stream::Sequence();
97 WW8Stream::Pointer_t
WW8StreamImpl::getSubStream(const ::rtl::OUString
& sId
)
99 WW8Stream::Pointer_t pResult
;
103 if (xOLESimpleStorage
.is())
105 if (xOLESimpleStorage
->hasByName(sId
))
107 uno::Reference
<io::XStream
> xNewStream
;
109 uno::Any aValue
= xOLESimpleStorage
->getByName(sId
);
110 aValue
>>= xNewStream
;
116 pNew(new WW8StreamImpl(mrComponentContext
,
117 xNewStream
->getInputStream()));
128 if (pResult
.get() == NULL
)
129 throw ExceptionNotFound("Stream not found");
134 string
WW8StreamImpl::getSubStreamNames() const
138 if (xOLESimpleStorage
.is())
140 uno::Sequence
<rtl::OUString
> aSeq
= xOLESimpleStorage
->getElementNames();
142 for (sal_uInt32 n
= 0;
143 n
< sal::static_int_cast
<sal_uInt32
>(aSeq
.getLength()); ++n
)
145 rtl::OUString aOUStr
= aSeq
[n
];
152 aOUStr
.convertToString(&aOStr
, RTL_TEXTENCODING_ASCII_US
,
153 OUSTRING_TO_OSTRING_CVTFLAGS
);
156 sResult
+= aOStr
.getStr();
159 for (sal_uInt32 j
= 0;
160 j
< sal::static_int_cast
<sal_uInt32
>(aOUStr
.getLength()); ++j
)
162 if (isprint(aOUStr
[j
]))
164 sal_Unicode nC
= aOUStr
[j
];
167 sResult
+= sal::static_int_cast
<char>(nC
);
173 snprintf(sBuffer
, sizeof(sBuffer
), "\\u%x", aOUStr
[j
]);
183 uno::Sequence
<rtl::OUString
> WW8StreamImpl::getSubStreamUNames() const
185 return xOLESimpleStorage
->getElementNames();
188 void WW8StreamImpl::dump(OutputWithDepth
<string
> & o
) const
190 o
.addItem("<stream>");
193 sal_uInt32 nOffset
= 0;
194 sal_uInt32 nStep
= 16;
198 aSeq
= get(nOffset
, nStep
);
199 dumpLine(o
, aSeq
, nOffset
, nStep
);
203 while (aSeq
.getCount() == nStep
);
205 o
.addItem("</stream>");