Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / core / XMLBase64ImportContext.cxx
blobc44ddd907d3dfa7b9d8bc96ad2f993fdb173805b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <com/sun/star/io/XOutputStream.hpp>
22 #include <sax/tools/converter.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/XMLBase64ImportContext.hxx>
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::xml::sax;
29 using namespace ::com::sun::star::io;
32 XMLBase64ImportContext::XMLBase64ImportContext(
33 SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
34 const Reference< XAttributeList >&,
35 const Reference< XOutputStream >& rOut ) :
36 SvXMLImportContext( rImport, nPrfx, rLName ),
37 xOut( rOut )
41 XMLBase64ImportContext::~XMLBase64ImportContext()
45 void XMLBase64ImportContext::EndElement()
47 xOut->closeOutput();
50 void XMLBase64ImportContext::Characters( const OUString& rChars )
52 OUString sTrimmedChars( rChars. trim() );
53 if( !sTrimmedChars.isEmpty() )
55 OUString sChars;
56 if( !sBase64CharsLeft.isEmpty() )
58 sChars = sBase64CharsLeft;
59 sChars += sTrimmedChars;
60 sBase64CharsLeft.clear();
62 else
64 sChars = sTrimmedChars;
66 Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 );
67 sal_Int32 const nCharsDecoded =
68 ::sax::Converter::decodeBase64SomeChars( aBuffer, sChars );
69 xOut->writeBytes( aBuffer );
70 if( nCharsDecoded != sChars.getLength() )
71 sBase64CharsLeft = sChars.copy( nCharsDecoded );
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */