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/.
10 #include "XMLBase64ImportContext.hxx"
12 #include <comphelper/base64.hxx>
14 using namespace com::sun::star
;
16 namespace writerperfect::exp
18 XMLBase64ImportContext::XMLBase64ImportContext(XMLImport
& rImport
)
19 : XMLImportContext(rImport
)
23 void XMLBase64ImportContext::startElement(
24 const OUString
& /*rName*/,
25 const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
29 void XMLBase64ImportContext::endElement(const OUString
& /*rName*/)
31 m_aBinaryData
.append(static_cast<const unsigned char*>(m_aStream
.GetData()),
35 void XMLBase64ImportContext::characters(const OUString
& rChars
)
37 OUString
aTrimmedChars(rChars
.trim());
39 if (aTrimmedChars
.isEmpty())
43 if (!m_aBase64CharsLeft
.isEmpty())
45 aChars
= m_aBase64CharsLeft
+ aTrimmedChars
;
46 m_aBase64CharsLeft
.clear();
49 aChars
= aTrimmedChars
;
51 uno::Sequence
<sal_Int8
> aBuffer((aChars
.getLength() / 4) * 3);
52 const sal_Int32 nCharsDecoded
= comphelper::Base64::decodeSomeChars(aBuffer
, aChars
);
53 m_aStream
.WriteBytes(aBuffer
.getArray(), aBuffer
.getLength());
54 if (nCharsDecoded
!= aChars
.getLength())
55 m_aBase64CharsLeft
= aChars
.copy(nCharsDecoded
);
58 const librevenge::RVNGBinaryData
& XMLBase64ImportContext::getBinaryData() const
63 } // namespace writerperfect::exp
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */