merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / core / XMLBase64Export.cxx
blobcae9b456d1efd9736955ee663ecca72a17137260
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLBase64Export.cxx,v $
10 * $Revision: 1.8 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <rtl/ustrbuf.hxx>
34 #include <com/sun/star/io/XInputStream.hpp>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlexp.hxx>
37 #include "xmlnmspe.hxx"
38 #include "XMLBase64Export.hxx"
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::io;
42 using ::rtl::OUString;
43 using ::rtl::OUStringBuffer;
45 #define INPUT_BUFFER_SIZE 54
46 #define OUTPUT_BUFFER_SIZE 72
48 XMLBase64Export::XMLBase64Export( SvXMLExport& rExp ) :
49 rExport( rExp ){
52 sal_Bool XMLBase64Export::exportXML( const Reference < XInputStream> & rIn )
54 sal_Bool bRet = sal_True;
55 try
57 Sequence < sal_Int8 > aInBuff( INPUT_BUFFER_SIZE );
58 OUStringBuffer aOutBuff( OUTPUT_BUFFER_SIZE );
59 sal_Int32 nRead;
62 nRead = rIn->readBytes( aInBuff, INPUT_BUFFER_SIZE );
63 if( nRead > 0 )
65 GetExport().GetMM100UnitConverter().encodeBase64( aOutBuff,
66 aInBuff );
67 GetExport().Characters( aOutBuff.makeStringAndClear() );
68 if( nRead == INPUT_BUFFER_SIZE )
69 GetExport().IgnorableWhitespace();
72 while( nRead == INPUT_BUFFER_SIZE );
74 catch( ... )
76 bRet = sal_False;
79 return bRet;
82 sal_Bool XMLBase64Export::exportElement(
83 const Reference < XInputStream > & rIn,
84 sal_uInt16 nNamespace,
85 enum ::xmloff::token::XMLTokenEnum eName )
87 SvXMLElementExport aElem( GetExport(), nNamespace, eName, sal_True,
88 sal_True );
89 return exportXML( rIn );
92 sal_Bool XMLBase64Export::exportOfficeBinaryDataElement(
93 const Reference < XInputStream > & rIn )
95 return exportElement( rIn, XML_NAMESPACE_OFFICE,
96 ::xmloff::token::XML_BINARY_DATA );