1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/graphic/XGraphic.hpp>
22 #include <osl/diagnose.h>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/XMLBase64ImportContext.hxx>
28 #include <XMLReplacementImageContext.hxx>
29 #include <sal/log.hxx>
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::makeAny
;
33 using namespace ::com::sun::star::xml::sax
;
34 using namespace ::com::sun::star::beans
;
36 using namespace ::xmloff::token
;
38 XMLReplacementImageContext::XMLReplacementImageContext(
40 sal_uInt16 nPrfx
, const OUString
& rLName
,
41 const Reference
< XAttributeList
> & rAttrList
,
42 const Reference
< XPropertySet
> & rPropSet
) :
43 SvXMLImportContext( rImport
, nPrfx
, rLName
),
44 m_xPropSet( rPropSet
)
46 rtl::Reference
< XMLTextImportHelper
> xTxtImport
=
47 GetImport().GetTextImport();
48 const SvXMLTokenMap
& rTokenMap
=
49 xTxtImport
->GetTextFrameAttrTokenMap();
51 sal_Int16 nAttrCount
= rAttrList
.is() ? rAttrList
->getLength() : 0;
52 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
54 const OUString
& rAttrName
= rAttrList
->getNameByIndex( i
);
55 const OUString
& rValue
= rAttrList
->getValueByIndex( i
);
59 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
61 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
63 case XML_TOK_TEXT_FRAME_HREF
:
70 XMLReplacementImageContext::~XMLReplacementImageContext()
74 void XMLReplacementImageContext::endFastElement(sal_Int32
)
76 OSL_ENSURE( !m_sHRef
.isEmpty() || m_xBase64Stream
.is(),
77 "neither URL nor base64 image data given" );
78 uno::Reference
<graphic::XGraphic
> xGraphic
;
82 if( !m_sHRef
.isEmpty() )
84 xGraphic
= GetImport().loadGraphicByURL(m_sHRef
);
86 else if( m_xBase64Stream
.is() )
88 xGraphic
= GetImport().loadGraphicFromBase64(m_xBase64Stream
);
89 m_xBase64Stream
= nullptr;
92 catch (uno::Exception
const &)
95 Reference
< XPropertySetInfo
> xPropSetInfo
= m_xPropSet
->getPropertySetInfo();
97 if (xGraphic
.is() && xPropSetInfo
->hasPropertyByName("Graphic"))
99 m_xPropSet
->setPropertyValue("Graphic", uno::makeAny(xGraphic
));
103 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLReplacementImageContext::createFastChildContext(
105 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& )
107 if( nElement
== XML_ELEMENT(OFFICE
, XML_BINARY_DATA
) &&
108 !m_xBase64Stream
.is() )
110 m_xBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
111 if( m_xBase64Stream
.is() )
112 return new XMLBase64ImportContext( GetImport(),
116 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */