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>
30 using namespace ::com::sun::star
;
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
,
38 XML_TOK_SYMBOL_IMAGE_END
= XML_TOK_UNKNOWN
41 static const SvXMLTokenMapEntry aSymbolImageAttrTokenMap
[] =
43 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_HREF
, XML_TOK_SYMBOL_IMAGE_HREF
},
44 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_TYPE
, XML_TOK_SYMBOL_IMAGE_TYPE
},
45 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_ACTUATE
, XML_TOK_SYMBOL_IMAGE_ACTUATE
},
46 { XML_NAMESPACE_XLINK
, ::xmloff::token::XML_SHOW
, XML_TOK_SYMBOL_IMAGE_SHOW
},
50 XMLSymbolImageContext::XMLSymbolImageContext(
51 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
52 const OUString
& rLName
,
53 const XMLPropertyState
& rProp
,
54 ::std::vector
< XMLPropertyState
> &rProps
) :
55 XMLElementPropertyContext(
56 rImport
, nPrfx
, rLName
, rProp
, rProps
)
60 XMLSymbolImageContext::~XMLSymbolImageContext()
63 void XMLSymbolImageContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
65 SvXMLTokenMap
aTokenMap( aSymbolImageAttrTokenMap
);
68 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
69 for( sal_Int16 i
= 0; i
< nAttrCount
; i
++ )
71 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
73 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
75 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
77 switch( aTokenMap
.Get( nPrefix
, aLocalName
) )
79 case XML_TOK_SYMBOL_IMAGE_HREF
:
82 case XML_TOK_SYMBOL_IMAGE_ACTUATE
:
83 case XML_TOK_SYMBOL_IMAGE_TYPE
:
84 case XML_TOK_SYMBOL_IMAGE_SHOW
:
85 // these values are currently not interpreted
86 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
92 SvXMLImportContext
* XMLSymbolImageContext::CreateChildContext(
93 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
94 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
96 SvXMLImportContext
* pContext
= nullptr;
97 if( xmloff::token::IsXMLToken( rLocalName
,
98 xmloff::token::XML_BINARY_DATA
) )
100 if( msURL
.isEmpty() && ! mxBase64Stream
.is() )
102 mxBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
103 if( mxBase64Stream
.is() )
104 pContext
= new XMLBase64ImportContext( GetImport(), nPrefix
,
105 rLocalName
, xAttrList
,
111 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
117 void XMLSymbolImageContext::EndElement()
119 OUString sResolvedURL
;
121 if( !msURL
.isEmpty() )
123 sResolvedURL
= GetImport().ResolveGraphicObjectURL( msURL
, false );
125 else if( mxBase64Stream
.is() )
127 sResolvedURL
= GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream
);
128 mxBase64Stream
= nullptr;
131 if( !sResolvedURL
.isEmpty())
133 // aProp is a member of XMLElementPropertyContext
134 aProp
.maValue
<<= sResolvedURL
;
138 XMLElementPropertyContext::EndElement();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */