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 "XMLSymbolImageContext.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmltkmap.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include <xmloff/XMLBase64ImportContext.hxx>
27 #include <com/sun/star/io/XOutputStream.hpp>
28 #include <com/sun/star/graphic/XGraphic.hpp>
32 enum SvXMLTokenMapAttrs
34 XML_TOK_SYMBOL_IMAGE_HREF
,
35 XML_TOK_SYMBOL_IMAGE_TYPE
,
36 XML_TOK_SYMBOL_IMAGE_ACTUATE
,
37 XML_TOK_SYMBOL_IMAGE_SHOW
,
40 static const SvXMLTokenMapEntry aSymbolImageAttrTokenMap
[] =
42 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_HREF
, XML_TOK_SYMBOL_IMAGE_HREF
},
43 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_TYPE
, XML_TOK_SYMBOL_IMAGE_TYPE
},
44 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_ACTUATE
, XML_TOK_SYMBOL_IMAGE_ACTUATE
},
45 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_SHOW
, XML_TOK_SYMBOL_IMAGE_SHOW
},
49 XMLSymbolImageContext::XMLSymbolImageContext(
50 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
51 const OUString
& rLName
,
52 const XMLPropertyState
& rProp
,
53 ::std::vector
< XMLPropertyState
> &rProps
) :
54 XMLElementPropertyContext(
55 rImport
, nPrfx
, rLName
, rProp
, rProps
)
59 XMLSymbolImageContext::~XMLSymbolImageContext()
62 void XMLSymbolImageContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
64 static const SvXMLTokenMap
aTokenMap( aSymbolImageAttrTokenMap
);
67 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
68 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
70 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
72 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
74 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
76 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
78 case XML_TOK_SYMBOL_IMAGE_HREF
:
81 case XML_TOK_SYMBOL_IMAGE_ACTUATE
:
82 case XML_TOK_SYMBOL_IMAGE_TYPE
:
83 case XML_TOK_SYMBOL_IMAGE_SHOW
:
84 // these values are currently not interpreted
85 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
91 SvXMLImportContextRef
XMLSymbolImageContext::CreateChildContext(
92 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
93 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
95 SvXMLImportContext
* pContext
= nullptr;
96 if( xmloff::token::IsXMLToken( rLocalName
,
97 xmloff::token::XML_BINARY_DATA
) )
99 if( msURL
.isEmpty() && ! mxBase64Stream
.is() )
101 mxBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
102 if( mxBase64Stream
.is() )
103 pContext
= new XMLBase64ImportContext( GetImport(), nPrefix
,
104 rLocalName
, xAttrList
,
110 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
116 void XMLSymbolImageContext::EndElement()
118 uno::Reference
<graphic::XGraphic
> xGraphic
;
120 if (!msURL
.isEmpty())
122 xGraphic
= GetImport().loadGraphicByURL(msURL
);
124 else if (mxBase64Stream
.is())
126 xGraphic
= GetImport().loadGraphicFromBase64(mxBase64Stream
);
127 mxBase64Stream
= nullptr;
132 // aProp is a member of XMLElementPropertyContext
133 aProp
.maValue
<<= xGraphic
;
137 XMLElementPropertyContext::EndElement();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */