1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include <rtl/ustrbuf.hxx> 27 #include <com/sun/star/io/XInputStream.hpp> 28 #include <xmloff/xmluconv.hxx> 29 #include <xmloff/xmlexp.hxx> 30 #include "xmloff/xmlnmspe.hxx" 31 #include "XMLBase64Export.hxx" 32 33 using namespace ::com::sun::star::uno; 34 using namespace ::com::sun::star::io; 35 using ::rtl::OUString; 36 using ::rtl::OUStringBuffer; 37 38 #define INPUT_BUFFER_SIZE 54 39 #define OUTPUT_BUFFER_SIZE 72 40 41 XMLBase64Export::XMLBase64Export( SvXMLExport& rExp ) : 42 rExport( rExp ){ 43 } 44 45 sal_Bool XMLBase64Export::exportXML( const Reference < XInputStream> & rIn ) 46 { 47 sal_Bool bRet = sal_True; 48 try 49 { 50 Sequence < sal_Int8 > aInBuff( INPUT_BUFFER_SIZE ); 51 OUStringBuffer aOutBuff( OUTPUT_BUFFER_SIZE ); 52 sal_Int32 nRead; 53 do 54 { 55 nRead = rIn->readBytes( aInBuff, INPUT_BUFFER_SIZE ); 56 if( nRead > 0 ) 57 { 58 GetExport().GetMM100UnitConverter().encodeBase64( aOutBuff, 59 aInBuff ); 60 GetExport().Characters( aOutBuff.makeStringAndClear() ); 61 if( nRead == INPUT_BUFFER_SIZE ) 62 GetExport().IgnorableWhitespace(); 63 } 64 } 65 while( nRead == INPUT_BUFFER_SIZE ); 66 } 67 catch( ... ) 68 { 69 bRet = sal_False; 70 } 71 72 return bRet; 73 } 74 75 sal_Bool XMLBase64Export::exportElement( 76 const Reference < XInputStream > & rIn, 77 sal_uInt16 nNamespace, 78 enum ::xmloff::token::XMLTokenEnum eName ) 79 { 80 SvXMLElementExport aElem( GetExport(), nNamespace, eName, sal_True, 81 sal_True ); 82 return exportXML( rIn ); 83 } 84 85 sal_Bool XMLBase64Export::exportOfficeBinaryDataElement( 86 const Reference < XInputStream > & rIn ) 87 { 88 return exportElement( rIn, XML_NAMESPACE_OFFICE, 89 ::xmloff::token::XML_BINARY_DATA ); 90 } 91 92