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 .
21 #include <rtl/ustrbuf.hxx>
23 #include <com/sun/star/io/XInputStream.hpp>
25 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlnmspe.hxx>
29 #include "XMLBase64Export.hxx"
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::io
;
34 #define INPUT_BUFFER_SIZE 54
35 #define OUTPUT_BUFFER_SIZE 72
37 XMLBase64Export::XMLBase64Export( SvXMLExport
& rExp
) :
41 bool XMLBase64Export::exportXML( const Reference
< XInputStream
> & rIn
)
46 Sequence
< sal_Int8
> aInBuff( INPUT_BUFFER_SIZE
);
47 OUStringBuffer
aOutBuff( OUTPUT_BUFFER_SIZE
);
51 nRead
= rIn
->readBytes( aInBuff
, INPUT_BUFFER_SIZE
);
54 ::sax::Converter::encodeBase64( aOutBuff
, aInBuff
);
55 GetExport().Characters( aOutBuff
.makeStringAndClear() );
56 if( nRead
== INPUT_BUFFER_SIZE
)
57 GetExport().IgnorableWhitespace();
60 while( nRead
== INPUT_BUFFER_SIZE
);
70 bool XMLBase64Export::exportElement(
71 const Reference
< XInputStream
> & rIn
,
72 sal_uInt16 nNamespace
,
73 enum ::xmloff::token::XMLTokenEnum eName
)
75 SvXMLElementExport
aElem( GetExport(), nNamespace
, eName
, true, true );
76 return exportXML( rIn
);
79 bool XMLBase64Export::exportOfficeBinaryDataElement(
80 const Reference
< XInputStream
> & rIn
)
82 return exportElement( rIn
, XML_NAMESPACE_OFFICE
,
83 ::xmloff::token::XML_BINARY_DATA
);
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */