163bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
363bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
463bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
563bba73cSAndrew Rist  * distributed with this work for additional information
663bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
763bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
863bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
963bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
1063bba73cSAndrew Rist  *
1163bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1263bba73cSAndrew Rist  *
1363bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1463bba73cSAndrew Rist  * software distributed under the License is distributed on an
1563bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1663bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
1763bba73cSAndrew Rist  * specific language governing permissions and limitations
1863bba73cSAndrew Rist  * under the License.
1963bba73cSAndrew Rist  *
2063bba73cSAndrew Rist  *************************************************************/
2163bba73cSAndrew Rist 
2263bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
27cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
28cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
29cdf0e10cSrcweir #include <xmloff/XMLBase64ImportContext.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using ::rtl::OUString;
32cdf0e10cSrcweir using ::rtl::OUStringBuffer;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
36cdf0e10cSrcweir using namespace ::com::sun::star::io;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //-----------------------------------------------------------------------------
39cdf0e10cSrcweir 
40cdf0e10cSrcweir TYPEINIT1( XMLBase64ImportContext, SvXMLImportContext );
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
XMLBase64ImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> &,const Reference<XOutputStream> & rOut)43cdf0e10cSrcweir XMLBase64ImportContext::XMLBase64ImportContext(
44cdf0e10cSrcweir 		SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
45cdf0e10cSrcweir 		const Reference< XAttributeList >&,
46cdf0e10cSrcweir 		const Reference< XOutputStream >& rOut ) :
47cdf0e10cSrcweir 	SvXMLImportContext( rImport, nPrfx, rLName ),
48cdf0e10cSrcweir 	xOut( rOut )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
~XMLBase64ImportContext()52cdf0e10cSrcweir XMLBase64ImportContext::~XMLBase64ImportContext()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
EndElement()57cdf0e10cSrcweir void XMLBase64ImportContext::EndElement()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	xOut->closeOutput();
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
Characters(const::rtl::OUString & rChars)62cdf0e10cSrcweir void XMLBase64ImportContext::Characters( const ::rtl::OUString& rChars )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	OUString sTrimmedChars( rChars. trim() );
65cdf0e10cSrcweir 	if( sTrimmedChars.getLength() )
66cdf0e10cSrcweir 	{
67cdf0e10cSrcweir 		OUString sChars;
68*24c56ab9SHerbert Dürr 		if( !sBase64CharsLeft.isEmpty() )
69cdf0e10cSrcweir 		{
70cdf0e10cSrcweir 			sChars = sBase64CharsLeft;
71cdf0e10cSrcweir 			sChars += sTrimmedChars;
72cdf0e10cSrcweir 			sBase64CharsLeft = OUString();
73cdf0e10cSrcweir 		}
74cdf0e10cSrcweir 		else
75cdf0e10cSrcweir 		{
76cdf0e10cSrcweir 			sChars = sTrimmedChars;
77cdf0e10cSrcweir 		}
78cdf0e10cSrcweir 		Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 );
79cdf0e10cSrcweir 		sal_Int32 nCharsDecoded =
80cdf0e10cSrcweir 			GetImport().GetMM100UnitConverter().
81cdf0e10cSrcweir 				decodeBase64SomeChars( aBuffer, sChars );
82cdf0e10cSrcweir 		xOut->writeBytes( aBuffer );
83cdf0e10cSrcweir 		if( nCharsDecoded != sChars.getLength() )
84cdf0e10cSrcweir 			sBase64CharsLeft = sChars.copy( nCharsDecoded );
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88