Bump for 3.6-28
[LibreOffice.git] / xmloff / source / chart / XMLSymbolImageContext.cxx
blobdc9b042f397b97e6762b6d5d6c890ee5c82dba79
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "XMLSymbolImageContext.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmltkmap.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/XMLBase64ImportContext.hxx>
36 #include <com/sun/star/io/XOutputStream.hpp>
38 TYPEINIT1( XMLSymbolImageContext, XMLElementPropertyContext );
40 using namespace ::com::sun::star;
42 enum SvXMLTokenMapAttrs
44 XML_TOK_SYMBOL_IMAGE_HREF,
45 XML_TOK_SYMBOL_IMAGE_TYPE,
46 XML_TOK_SYMBOL_IMAGE_ACTUATE,
47 XML_TOK_SYMBOL_IMAGE_SHOW,
48 XML_TOK_SYMBOL_IMAGE_END = XML_TOK_UNKNOWN
51 static SvXMLTokenMapEntry aSymbolImageAttrTokenMap[] =
53 { XML_NAMESPACE_XLINK, ::xmloff::token::XML_HREF, XML_TOK_SYMBOL_IMAGE_HREF },
54 { XML_NAMESPACE_XLINK, ::xmloff::token::XML_TYPE, XML_TOK_SYMBOL_IMAGE_TYPE },
55 { XML_NAMESPACE_XLINK, ::xmloff::token::XML_ACTUATE, XML_TOK_SYMBOL_IMAGE_ACTUATE },
56 { XML_NAMESPACE_XLINK, ::xmloff::token::XML_SHOW, XML_TOK_SYMBOL_IMAGE_SHOW },
57 XML_TOKEN_MAP_END
60 XMLSymbolImageContext::XMLSymbolImageContext(
61 SvXMLImport& rImport, sal_uInt16 nPrfx,
62 const ::rtl::OUString& rLName,
63 const XMLPropertyState& rProp,
64 ::std::vector< XMLPropertyState > &rProps ) :
65 XMLElementPropertyContext(
66 rImport, nPrfx, rLName, rProp, rProps )
70 XMLSymbolImageContext::~XMLSymbolImageContext()
73 void XMLSymbolImageContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
75 SvXMLTokenMap aTokenMap( aSymbolImageAttrTokenMap );
76 ::rtl::OUString aLocalName;
78 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
79 for( sal_Int16 i = 0; i < nAttrCount; i++ )
81 const ::rtl::OUString& rAttrName = xAttrList->getNameByIndex( i );
82 sal_uInt16 nPrefix =
83 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
84 &aLocalName );
85 const ::rtl::OUString& rValue = xAttrList->getValueByIndex( i );
87 switch( aTokenMap.Get( nPrefix, aLocalName ) )
89 case XML_TOK_SYMBOL_IMAGE_HREF:
90 msURL = rValue;
91 break;
92 case XML_TOK_SYMBOL_IMAGE_ACTUATE:
93 case XML_TOK_SYMBOL_IMAGE_TYPE:
94 case XML_TOK_SYMBOL_IMAGE_SHOW:
95 // these values are currently not interpreted
96 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
97 break;
102 SvXMLImportContext* XMLSymbolImageContext::CreateChildContext(
103 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
104 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
106 SvXMLImportContext* pContext = NULL;
107 if( xmloff::token::IsXMLToken( rLocalName,
108 xmloff::token::XML_BINARY_DATA ) )
110 if( msURL.isEmpty() && ! mxBase64Stream.is() )
112 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
113 if( mxBase64Stream.is() )
114 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
115 rLocalName, xAttrList,
116 mxBase64Stream );
119 if( ! pContext )
121 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
124 return pContext;
127 void XMLSymbolImageContext::EndElement()
129 ::rtl::OUString sResolvedURL;
131 if( !msURL.isEmpty() )
133 sResolvedURL = GetImport().ResolveGraphicObjectURL( msURL, sal_False );
135 else if( mxBase64Stream.is() )
137 sResolvedURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
138 mxBase64Stream = 0;
141 if( !sResolvedURL.isEmpty())
143 // aProp is a member of XMLElementPropertyContext
144 aProp.maValue <<= sResolvedURL;
145 SetInsert( sal_True );
148 XMLElementPropertyContext::EndElement();
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */