1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include <rtl/ustrbuf.hxx> 31 #include <com/sun/star/io/XInputStream.hpp> 32 #include <xmloff/xmluconv.hxx> 33 #include <xmloff/xmlexp.hxx> 34 #include "xmloff/xmlnmspe.hxx" 35 #include "XMLBase64Export.hxx" 36 37 using namespace ::com::sun::star::uno; 38 using namespace ::com::sun::star::io; 39 using ::rtl::OUString; 40 using ::rtl::OUStringBuffer; 41 42 #define INPUT_BUFFER_SIZE 54 43 #define OUTPUT_BUFFER_SIZE 72 44 45 XMLBase64Export::XMLBase64Export( SvXMLExport& rExp ) : 46 rExport( rExp ){ 47 } 48 49 sal_Bool XMLBase64Export::exportXML( const Reference < XInputStream> & rIn ) 50 { 51 sal_Bool bRet = sal_True; 52 try 53 { 54 Sequence < sal_Int8 > aInBuff( INPUT_BUFFER_SIZE ); 55 OUStringBuffer aOutBuff( OUTPUT_BUFFER_SIZE ); 56 sal_Int32 nRead; 57 do 58 { 59 nRead = rIn->readBytes( aInBuff, INPUT_BUFFER_SIZE ); 60 if( nRead > 0 ) 61 { 62 GetExport().GetMM100UnitConverter().encodeBase64( aOutBuff, 63 aInBuff ); 64 GetExport().Characters( aOutBuff.makeStringAndClear() ); 65 if( nRead == INPUT_BUFFER_SIZE ) 66 GetExport().IgnorableWhitespace(); 67 } 68 } 69 while( nRead == INPUT_BUFFER_SIZE ); 70 } 71 catch( ... ) 72 { 73 bRet = sal_False; 74 } 75 76 return bRet; 77 } 78 79 sal_Bool XMLBase64Export::exportElement( 80 const Reference < XInputStream > & rIn, 81 sal_uInt16 nNamespace, 82 enum ::xmloff::token::XMLTokenEnum eName ) 83 { 84 SvXMLElementExport aElem( GetExport(), nNamespace, eName, sal_True, 85 sal_True ); 86 return exportXML( rIn ); 87 } 88 89 sal_Bool XMLBase64Export::exportOfficeBinaryDataElement( 90 const Reference < XInputStream > & rIn ) 91 { 92 return exportElement( rIn, XML_NAMESPACE_OFFICE, 93 ::xmloff::token::XML_BINARY_DATA ); 94 } 95 96