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 "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>
28 :
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::xml::sax;
31 : using namespace ::xmloff::token;
32 :
33 0 : TYPEINIT1( XMLChartOASISTransformerContext, XMLTransformerContext );
34 :
35 0 : XMLChartOASISTransformerContext::XMLChartOASISTransformerContext(
36 : XMLTransformerBase& rImp,
37 : const OUString& rQName ) :
38 0 : XMLTransformerContext( rImp, rQName )
39 : {
40 0 : }
41 :
42 0 : XMLChartOASISTransformerContext::~XMLChartOASISTransformerContext()
43 : {
44 0 : }
45 :
46 0 : void XMLChartOASISTransformerContext::StartElement(
47 : const Reference< XAttributeList >& rAttrList )
48 : {
49 : XMLTransformerActions *pActions =
50 0 : GetTransformer().GetUserDefinedActions( OASIS_CHART_ACTIONS );
51 : OSL_ENSURE( pActions, "go no actions" );
52 :
53 0 : OUString aAddInName;
54 0 : Reference< XAttributeList > xAttrList( rAttrList );
55 0 : XMLMutableAttributeList *pMutableAttrList = 0;
56 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
57 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
58 : {
59 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
60 0 : OUString aLocalName;
61 : sal_uInt16 nPrefix =
62 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
63 0 : &aLocalName );
64 0 : XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
65 : XMLTransformerActions::const_iterator aIter =
66 0 : pActions->find( aKey );
67 0 : if( !(aIter == pActions->end() ) )
68 : {
69 0 : if( !pMutableAttrList )
70 : {
71 : pMutableAttrList =
72 0 : new XMLMutableAttributeList( xAttrList );
73 0 : xAttrList = pMutableAttrList;
74 : }
75 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
76 0 : switch( (*aIter).second.m_nActionType )
77 : {
78 : case XML_ATACTION_IN2INCH:
79 : {
80 0 : OUString aAttrValue( rAttrValue );
81 0 : if( XMLTransformerBase::ReplaceSingleInWithInch(
82 : aAttrValue ) )
83 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
84 : }
85 0 : break;
86 : case XML_ATACTION_DECODE_STYLE_NAME_REF:
87 : {
88 0 : OUString aAttrValue( rAttrValue );
89 0 : if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
90 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
91 : }
92 0 : break;
93 : case XML_ATACTION_REMOVE_ANY_NAMESPACE_PREFIX:
94 : OSL_ENSURE( IsXMLToken( aLocalName, XML_CLASS ),
95 : "unexpected class token" );
96 : {
97 0 : OUString aChartClass;
98 : sal_uInt16 nValuePrefix =
99 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName(
100 : rAttrValue,
101 0 : &aChartClass );
102 0 : if( XML_NAMESPACE_CHART == nValuePrefix )
103 : {
104 0 : pMutableAttrList->SetValueByIndex( i, aChartClass );
105 : }
106 0 : else if ( XML_NAMESPACE_OOO == nValuePrefix )
107 : {
108 : pMutableAttrList->SetValueByIndex( i,
109 0 : GetXMLToken(XML_ADD_IN ) );
110 0 : aAddInName = aChartClass;
111 0 : }
112 : }
113 0 : break;
114 : default:
115 : OSL_ENSURE( false, "unknown action" );
116 0 : break;
117 0 : }
118 : }
119 0 : }
120 :
121 0 : if( !aAddInName.isEmpty() )
122 : {
123 0 : OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
124 : XML_NAMESPACE_CHART,
125 0 : GetXMLToken( XML_ADD_IN_NAME ) ) );
126 : // coverity[var_deref_model] - pMutableAttrList is assigned in a superset of the enclosing if condition entry logic
127 0 : pMutableAttrList->AddAttribute( aAttrQName, aAddInName );
128 : }
129 :
130 0 : XMLTransformerContext::StartElement( xAttrList );
131 0 : }
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|