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 "ChartOOoTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include <xmloff/xmlnamespace.hxx>
23 #include "ActionMapTypesOOo.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 XMLChartOOoTransformerContext::XMLChartOOoTransformerContext(
34 XMLTransformerBase
& rImp
,
35 const OUString
& rQName
) :
36 XMLTransformerContext( rImp
, rQName
)
40 XMLChartOOoTransformerContext::~XMLChartOOoTransformerContext()
44 void XMLChartOOoTransformerContext::StartElement(
45 const Reference
< XAttributeList
>& rAttrList
)
47 XMLTransformerActions
*pActions
=
48 GetTransformer().GetUserDefinedActions( OOO_CHART_ACTIONS
);
49 OSL_ENSURE( pActions
, "go no actions" );
51 sal_Int16 nClassName
= -1;
53 Reference
< XAttributeList
> xAttrList( rAttrList
);
54 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
55 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
56 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
58 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
61 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
63 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
64 XMLTransformerActions::const_iterator aIter
=
65 pActions
->find( aKey
);
66 if( aIter
!= pActions
->end() )
68 if( !pMutableAttrList
)
71 new XMLMutableAttributeList( xAttrList
);
72 xAttrList
= pMutableAttrList
;
74 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
75 switch( (*aIter
).second
.m_nActionType
)
77 case XML_ATACTION_INCH2IN
:
79 OUString
aAttrValue( rAttrValue
);
80 if( XMLTransformerBase::ReplaceSingleInchWithIn(
82 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
85 case XML_ATACTION_ENCODE_STYLE_NAME_REF
:
87 OUString
aAttrValue( rAttrValue
);
88 if( GetTransformer().EncodeStyleName(aAttrValue
) )
89 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
92 case XML_ATACTION_ADD_NAMESPACE_PREFIX
:
93 OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName
, XML_CLASS
),
94 "unexpected class token" );
95 if( ::xmloff::token::IsXMLToken( rAttrValue
, XML_ADD_IN
) )
101 OUString
aAttrValue( rAttrValue
);
102 sal_uInt16 nValPrefix
=
103 static_cast<sal_uInt16
>((*aIter
).second
.m_nParam1
);
104 GetTransformer().AddNamespacePrefix( aAttrValue
,
106 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
109 case XML_ATACTION_REMOVE
:
110 OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName
, XML_ADD_IN_NAME
),
111 "unexpected class token" );
112 aAddInName
= rAttrValue
;
113 pMutableAttrList
->RemoveAttributeByIndex( i
);
118 OSL_ENSURE( false, "unknown action" );
124 if( nClassName
!= -1 && !aAddInName
.isEmpty() )
126 GetTransformer().AddNamespacePrefix( aAddInName
, XML_NAMESPACE_OOO
);
127 pMutableAttrList
->SetValueByIndex( nClassName
, aAddInName
);
130 XMLTransformerContext::StartElement( xAttrList
);
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */