LibreOffice Module xmloff (master)  1
XMLSymbolImageContext.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 
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmltkmap.hxx>
23 #include <xmloff/xmlnamespace.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/namespacemap.hxx>
27 #include <com/sun/star/io/XOutputStream.hpp>
28 #include <com/sun/star/graphic/XGraphic.hpp>
29 #include <sal/log.hxx>
30 
31 using namespace css;
32 using namespace xmloff::token;
33 
35  SvXMLImport& rImport, sal_Int32 nElement,
36  const XMLPropertyState& rProp,
37  ::std::vector< XMLPropertyState > &rProps ) :
39  rImport, nElement, rProp, rProps )
40 {
41 }
42 
44 {}
45 
47  sal_Int32 /*nElement*/,
48  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
49 {
50  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
51  {
52  const OUString sValue = aIter.toString();
53 
54  switch( aIter.getToken() )
55  {
56  case XML_ELEMENT(XLINK, XML_HREF):
57  msURL = sValue;
58  break;
59  case XML_ELEMENT(XLINK, XML_ACTUATE):
60  case XML_ELEMENT(XLINK, XML_TYPE):
61  case XML_ELEMENT(XLINK, XML_SHOW):
62  // these values are currently not interpreted
63  // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
64  break;
65  default:
66  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
67  }
68  }
69 }
70 
71 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLSymbolImageContext::createFastChildContext(
72  sal_Int32 nElement,
73  const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
74 {
75  if( (nElement & TOKEN_MASK) == xmloff::token::XML_BINARY_DATA )
76  {
77  if( msURL.isEmpty() && ! mxBase64Stream.is() )
78  {
80  if( mxBase64Stream.is() )
82  }
83  }
84  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
85  return nullptr;
86 }
87 
88 void XMLSymbolImageContext::endFastElement(sal_Int32 nElement)
89 {
90  uno::Reference<graphic::XGraphic> xGraphic;
91 
92  if (!msURL.isEmpty())
93  {
94  xGraphic = GetImport().loadGraphicByURL(msURL);
95  }
96  else if (mxBase64Stream.is())
97  {
99  mxBase64Stream = nullptr;
100  }
101 
102  if (xGraphic.is())
103  {
104  // aProp is a member of XMLElementPropertyContext
105  aProp.maValue <<= xGraphic;
106  SetInsert( true );
107  }
108 
110 }
111 
112 /* 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:1293
css::uno::Reference< css::io::XOutputStream > mxBase64Stream
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
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 ...
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
css::uno::Reference< css::graphic::XGraphic > loadGraphicByURL(OUString const &rURL)
Definition: xmlimp.cxx:1271
XMLSymbolImageContext(SvXMLImport &rImport, sal_Int32 nElement, const XMLPropertyState &rProp,::std::vector< XMLPropertyState > &rProps)
virtual ~XMLSymbolImageContext() override
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
Definition: xmlimp.cxx:1305
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
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 ...
css::uno::Any maValue
Definition: maptype.hxx:125
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:122
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:119