LibreOffice Module xmloff (master)  1
XMLReplacementImageContext.cxx
Go to the documentation of this file.
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 #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>
29 #include <sal/log.hxx>
30 
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;
35 using namespace css;
36 using namespace ::xmloff::token;
37 
39  SvXMLImport& rImport,
40  sal_Int32 /*nElement*/,
41  const Reference< XFastAttributeList > & rAttrList,
42  const Reference< XPropertySet > & rPropSet ) :
43  SvXMLImportContext( rImport ),
44  m_xPropSet( rPropSet )
45 {
46  m_sHRef = rAttrList->getOptionalValue(XML_ELEMENT(XLINK, XML_HREF));
47 }
48 
50 {
51 }
52 
54 {
55  OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
56  "neither URL nor base64 image data given" );
57  uno::Reference<graphic::XGraphic> xGraphic;
58 
59  try
60  {
61  if( !m_sHRef.isEmpty() )
62  {
63  xGraphic = GetImport().loadGraphicByURL(m_sHRef);
64  }
65  else if( m_xBase64Stream.is() )
66  {
68  m_xBase64Stream = nullptr;
69  }
70  }
71  catch (uno::Exception const &)
72  {}
73 
74  Reference < XPropertySetInfo > xPropSetInfo = m_xPropSet->getPropertySetInfo();
75 
76  if (xGraphic.is() && xPropSetInfo->hasPropertyByName("Graphic"))
77  {
78  m_xPropSet->setPropertyValue("Graphic", uno::makeAny(xGraphic));
79  }
80 }
81 
82 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLReplacementImageContext::createFastChildContext(
83  sal_Int32 nElement,
84  const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
85 {
86  if( nElement == XML_ELEMENT(OFFICE, XML_BINARY_DATA) &&
87  !m_xBase64Stream.is() )
88  {
90  if( m_xBase64Stream.is() )
91  return new XMLBase64ImportContext( GetImport(),
93  }
94 
95  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
96  return nullptr;
97 }
98 
99 
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::graphic::XGraphic > loadGraphicFromBase64(css::uno::Reference< css::io::XOutputStream > const &rxOutputStream)
Definition: xmlimp.cxx:1280
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:56
css::uno::Reference< css::graphic::XGraphic > loadGraphicByURL(OUString const &rURL)
Definition: xmlimp.cxx:1258
XMLReplacementImageContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &rAttrList, const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
Definition: xmlimp.cxx:1292
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:96
css::uno::Reference< css::io::XOutputStream > m_xBase64Stream
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:116
css::uno::Reference< css::beans::XPropertySet > m_xPropSet
Reference< XGraphic > xGraphic