Line data Source code
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 "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 :
29 0 : TYPEINIT1( XMLSymbolImageContext, XMLElementPropertyContext );
30 :
31 : using namespace ::com::sun::star;
32 :
33 : enum SvXMLTokenMapAttrs
34 : {
35 : XML_TOK_SYMBOL_IMAGE_HREF,
36 : XML_TOK_SYMBOL_IMAGE_TYPE,
37 : XML_TOK_SYMBOL_IMAGE_ACTUATE,
38 : XML_TOK_SYMBOL_IMAGE_SHOW,
39 : XML_TOK_SYMBOL_IMAGE_END = XML_TOK_UNKNOWN
40 : };
41 :
42 : static const SvXMLTokenMapEntry aSymbolImageAttrTokenMap[] =
43 : {
44 : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_HREF, XML_TOK_SYMBOL_IMAGE_HREF },
45 : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_TYPE, XML_TOK_SYMBOL_IMAGE_TYPE },
46 : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_ACTUATE, XML_TOK_SYMBOL_IMAGE_ACTUATE },
47 : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_SHOW, XML_TOK_SYMBOL_IMAGE_SHOW },
48 : XML_TOKEN_MAP_END
49 : };
50 :
51 0 : XMLSymbolImageContext::XMLSymbolImageContext(
52 : SvXMLImport& rImport, sal_uInt16 nPrfx,
53 : const OUString& rLName,
54 : const XMLPropertyState& rProp,
55 : ::std::vector< XMLPropertyState > &rProps ) :
56 : XMLElementPropertyContext(
57 0 : rImport, nPrfx, rLName, rProp, rProps )
58 : {
59 0 : }
60 :
61 0 : XMLSymbolImageContext::~XMLSymbolImageContext()
62 0 : {}
63 :
64 0 : void XMLSymbolImageContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
65 : {
66 0 : SvXMLTokenMap aTokenMap( aSymbolImageAttrTokenMap );
67 0 : OUString aLocalName;
68 :
69 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
70 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
71 : {
72 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
73 : sal_uInt16 nPrefix =
74 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
75 0 : &aLocalName );
76 0 : const OUString& rValue = xAttrList->getValueByIndex( i );
77 :
78 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
79 : {
80 : case XML_TOK_SYMBOL_IMAGE_HREF:
81 0 : msURL = rValue;
82 0 : break;
83 : case XML_TOK_SYMBOL_IMAGE_ACTUATE:
84 : case XML_TOK_SYMBOL_IMAGE_TYPE:
85 : case XML_TOK_SYMBOL_IMAGE_SHOW:
86 : // these values are currently not interpreted
87 : // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
88 0 : break;
89 : }
90 0 : }
91 0 : }
92 :
93 0 : SvXMLImportContext* XMLSymbolImageContext::CreateChildContext(
94 : sal_uInt16 nPrefix, const OUString& rLocalName,
95 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
96 : {
97 0 : SvXMLImportContext* pContext = NULL;
98 0 : if( xmloff::token::IsXMLToken( rLocalName,
99 : xmloff::token::XML_BINARY_DATA ) )
100 : {
101 0 : if( msURL.isEmpty() && ! mxBase64Stream.is() )
102 : {
103 0 : mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
104 0 : if( mxBase64Stream.is() )
105 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
106 : rLocalName, xAttrList,
107 0 : mxBase64Stream );
108 : }
109 : }
110 0 : if( ! pContext )
111 : {
112 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
113 : }
114 :
115 0 : return pContext;
116 : }
117 :
118 0 : void XMLSymbolImageContext::EndElement()
119 : {
120 0 : OUString sResolvedURL;
121 :
122 0 : if( !msURL.isEmpty() )
123 : {
124 0 : sResolvedURL = GetImport().ResolveGraphicObjectURL( msURL, false );
125 : }
126 0 : else if( mxBase64Stream.is() )
127 : {
128 0 : sResolvedURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
129 0 : mxBase64Stream = 0;
130 : }
131 :
132 0 : if( !sResolvedURL.isEmpty())
133 : {
134 : // aProp is a member of XMLElementPropertyContext
135 0 : aProp.maValue <<= sResolvedURL;
136 0 : SetInsert( sal_True );
137 : }
138 :
139 0 : XMLElementPropertyContext::EndElement();
140 0 : }
141 :
142 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|