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 
34 namespace {
35 
37 {
38  XML_TOK_SYMBOL_IMAGE_HREF,
39  XML_TOK_SYMBOL_IMAGE_TYPE,
40  XML_TOK_SYMBOL_IMAGE_ACTUATE,
41  XML_TOK_SYMBOL_IMAGE_SHOW,
42 };
43 
44 }
45 
47  SvXMLImport& rImport, sal_Int32 nElement,
48  const XMLPropertyState& rProp,
49  ::std::vector< XMLPropertyState > &rProps ) :
51  rImport, nElement, rProp, rProps )
52 {
53 }
54 
56 {}
57 
59  sal_Int32 /*nElement*/,
60  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
61 {
62  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
63  {
64  const OUString sValue = aIter.toString();
65 
66  switch( aIter.getToken() )
67  {
68  case XML_ELEMENT(XLINK, XML_HREF):
69  msURL = sValue;
70  break;
71  case XML_ELEMENT(XLINK, XML_ACTUATE):
72  case XML_ELEMENT(XLINK, XML_TYPE):
73  case XML_ELEMENT(XLINK, XML_SHOW):
74  // these values are currently not interpreted
75  // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
76  break;
77  default:
78  SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue);
79  }
80  }
81 }
82 
83 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLSymbolImageContext::createFastChildContext(
84  sal_Int32 nElement,
85  const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
86 {
87  if( (nElement & TOKEN_MASK) == xmloff::token::XML_BINARY_DATA )
88  {
89  if( msURL.isEmpty() && ! mxBase64Stream.is() )
90  {
92  if( mxBase64Stream.is() )
94  }
95  }
96  SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
97  return nullptr;
98 }
99 
101 {
102  uno::Reference<graphic::XGraphic> xGraphic;
103 
104  if (!msURL.isEmpty())
105  {
106  xGraphic = GetImport().loadGraphicByURL(msURL);
107  }
108  else if (mxBase64Stream.is())
109  {
111  mxBase64Stream = nullptr;
112  }
113 
114  if (xGraphic.is())
115  {
116  // aProp is a member of XMLElementPropertyContext
117  aProp.maValue <<= xGraphic;
118  SetInsert( true );
119  }
120 
122 }
123 
124 /* 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:1381
css::uno::Reference< css::io::XOutputStream > mxBase64Stream
SvXMLTokenMapAttrs
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
css::uno::Reference< css::graphic::XGraphic > loadGraphicByURL(OUString const &rURL)
Definition: xmlimp.cxx:1359
XMLSymbolImageContext(SvXMLImport &rImport, sal_Int32 nElement, const XMLPropertyState &rProp,::std::vector< XMLPropertyState > &rProps)
virtual ~XMLSymbolImageContext() override
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:2025
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
Definition: xmlimp.cxx:1393
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
css::uno::Any maValue
Definition: maptype.hxx:125
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:122
#define SAL_WARN(area, stream)
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:91
Reference< XGraphic > xGraphic