Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / transform / ChartOASISTContext.cxx
blob2a7c507af1f8cb72c31b6db713d471b24a479011
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "ChartOASISTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include <xmloff/xmlnmspe.hxx>
23 #include "ActionMapTypesOASIS.hxx"
24 #include "AttrTransformerAction.hxx"
25 #include "TransformerActions.hxx"
26 #include "TransformerBase.hxx"
27 #include <osl/diagnose.h>
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::xml::sax;
31 using namespace ::xmloff::token;
33 XMLChartOASISTransformerContext::XMLChartOASISTransformerContext(
34 XMLTransformerBase& rImp,
35 const OUString& rQName ) :
36 XMLTransformerContext( rImp, rQName )
40 XMLChartOASISTransformerContext::~XMLChartOASISTransformerContext()
44 void XMLChartOASISTransformerContext::StartElement(
45 const Reference< XAttributeList >& rAttrList )
47 XMLTransformerActions *pActions =
48 GetTransformer().GetUserDefinedActions( OASIS_CHART_ACTIONS );
49 OSL_ENSURE( pActions, "go no actions" );
51 OUString aAddInName;
52 Reference< XAttributeList > xAttrList( rAttrList );
53 XMLMutableAttributeList *pMutableAttrList = nullptr;
54 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
55 for( sal_Int16 i=0; i < nAttrCount; i++ )
57 const OUString& rAttrName = xAttrList->getNameByIndex( i );
58 OUString aLocalName;
59 sal_uInt16 nPrefix =
60 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
61 &aLocalName );
62 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
63 XMLTransformerActions::const_iterator aIter =
64 pActions->find( aKey );
65 if( !(aIter == pActions->end() ) )
67 if( !pMutableAttrList )
69 pMutableAttrList =
70 new XMLMutableAttributeList( xAttrList );
71 xAttrList = pMutableAttrList;
73 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
74 switch( (*aIter).second.m_nActionType )
76 case XML_ATACTION_IN2INCH:
78 OUString aAttrValue( rAttrValue );
79 if( XMLTransformerBase::ReplaceSingleInWithInch(
80 aAttrValue ) )
81 pMutableAttrList->SetValueByIndex( i, aAttrValue );
83 break;
84 case XML_ATACTION_DECODE_STYLE_NAME_REF:
86 OUString aAttrValue( rAttrValue );
87 if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
88 pMutableAttrList->SetValueByIndex( i, aAttrValue );
90 break;
91 case XML_ATACTION_REMOVE_ANY_NAMESPACE_PREFIX:
92 OSL_ENSURE( IsXMLToken( aLocalName, XML_CLASS ),
93 "unexpected class token" );
95 OUString aChartClass;
96 sal_uInt16 nValuePrefix =
97 GetTransformer().GetNamespaceMap().GetKeyByAttrName(
98 rAttrValue,
99 &aChartClass );
100 if( XML_NAMESPACE_CHART == nValuePrefix )
102 pMutableAttrList->SetValueByIndex( i, aChartClass );
104 else if ( XML_NAMESPACE_OOO == nValuePrefix )
106 pMutableAttrList->SetValueByIndex( i,
107 GetXMLToken(XML_ADD_IN ) );
108 aAddInName = aChartClass;
111 break;
112 default:
113 OSL_ENSURE( false, "unknown action" );
114 break;
119 if( !aAddInName.isEmpty() )
121 OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
122 XML_NAMESPACE_CHART,
123 GetXMLToken( XML_ADD_IN_NAME ) ) );
124 // coverity[var_deref_model] - pMutableAttrList is assigned in a superset of the enclosing if condition entry logic
125 pMutableAttrList->AddAttribute( aAttrQName, aAddInName );
128 XMLTransformerContext::StartElement( xAttrList );
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */