1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLBase64ImportContext.cxx,v $
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 <xmloff/xmlimp.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <com/sun/star/io/XOutputStream.hpp>
36 #include <xmloff/XMLBase64ImportContext.hxx>
38 using ::rtl::OUString
;
39 using ::rtl::OUStringBuffer
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::xml::sax
;
43 using namespace ::com::sun::star::io
;
45 //-----------------------------------------------------------------------------
47 TYPEINIT1( XMLBase64ImportContext
, SvXMLImportContext
);
50 XMLBase64ImportContext::XMLBase64ImportContext(
51 SvXMLImport
& rImport
, USHORT nPrfx
, const OUString
& rLName
,
52 const Reference
< XAttributeList
>&,
53 const Reference
< XOutputStream
>& rOut
) :
54 SvXMLImportContext( rImport
, nPrfx
, rLName
),
59 XMLBase64ImportContext::~XMLBase64ImportContext()
64 void XMLBase64ImportContext::EndElement()
69 void XMLBase64ImportContext::Characters( const ::rtl::OUString
& rChars
)
71 OUString
sTrimmedChars( rChars
. trim() );
72 if( sTrimmedChars
.getLength() )
75 if( sBase64CharsLeft
)
77 sChars
= sBase64CharsLeft
;
78 sChars
+= sTrimmedChars
;
79 sBase64CharsLeft
= OUString();
83 sChars
= sTrimmedChars
;
85 Sequence
< sal_Int8
> aBuffer( (sChars
.getLength() / 4) * 3 );
86 sal_Int32 nCharsDecoded
=
87 GetImport().GetMM100UnitConverter().
88 decodeBase64SomeChars( aBuffer
, sChars
);
89 xOut
->writeBytes( aBuffer
);
90 if( nCharsDecoded
!= sChars
.getLength() )
91 sBase64CharsLeft
= sChars
.copy( nCharsDecoded
);