Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <rtl/ustrbuf.hxx>
22 :
23 : #include <com/sun/star/io/XInputStream.hpp>
24 :
25 : #include <sax/tools/converter.hxx>
26 :
27 : #include <xmloff/xmlexp.hxx>
28 : #include "xmloff/xmlnmspe.hxx"
29 : #include "XMLBase64Export.hxx"
30 :
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::io;
33 : using ::rtl::OUString;
34 : using ::rtl::OUStringBuffer;
35 :
36 : #define INPUT_BUFFER_SIZE 54
37 : #define OUTPUT_BUFFER_SIZE 72
38 :
39 0 : XMLBase64Export::XMLBase64Export( SvXMLExport& rExp ) :
40 0 : rExport( rExp ){
41 0 : }
42 :
43 0 : sal_Bool XMLBase64Export::exportXML( const Reference < XInputStream> & rIn )
44 : {
45 0 : sal_Bool bRet = sal_True;
46 : try
47 : {
48 0 : Sequence < sal_Int8 > aInBuff( INPUT_BUFFER_SIZE );
49 0 : OUStringBuffer aOutBuff( OUTPUT_BUFFER_SIZE );
50 : sal_Int32 nRead;
51 0 : do
52 : {
53 0 : nRead = rIn->readBytes( aInBuff, INPUT_BUFFER_SIZE );
54 0 : if( nRead > 0 )
55 : {
56 0 : ::sax::Converter::encodeBase64( aOutBuff, aInBuff );
57 0 : GetExport().Characters( aOutBuff.makeStringAndClear() );
58 0 : if( nRead == INPUT_BUFFER_SIZE )
59 0 : GetExport().IgnorableWhitespace();
60 : }
61 : }
62 0 : while( nRead == INPUT_BUFFER_SIZE );
63 : }
64 0 : catch( ... )
65 : {
66 0 : bRet = sal_False;
67 : }
68 :
69 0 : return bRet;
70 : }
71 :
72 0 : sal_Bool XMLBase64Export::exportElement(
73 : const Reference < XInputStream > & rIn,
74 : sal_uInt16 nNamespace,
75 : enum ::xmloff::token::XMLTokenEnum eName )
76 : {
77 0 : SvXMLElementExport aElem( GetExport(), nNamespace, eName, sal_True,
78 0 : sal_True );
79 0 : return exportXML( rIn );
80 : }
81 :
82 0 : sal_Bool XMLBase64Export::exportOfficeBinaryDataElement(
83 : const Reference < XInputStream > & rIn )
84 : {
85 : return exportElement( rIn, XML_NAMESPACE_OFFICE,
86 0 : ::xmloff::token::XML_BINARY_DATA );
87 : }
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|