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 "ChartOOoTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include <xmloff/xmlnmspe.hxx>
23 #include "ActionMapTypesOOo.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 
XMLChartOOoTransformerContext(XMLTransformerBase & rImp,const OUString & rQName)33 XMLChartOOoTransformerContext::XMLChartOOoTransformerContext(
34         XMLTransformerBase& rImp,
35         const OUString& rQName ) :
36     XMLTransformerContext( rImp, rQName )
37 {
38 }
39 
~XMLChartOOoTransformerContext()40 XMLChartOOoTransformerContext::~XMLChartOOoTransformerContext()
41 {
42 }
43 
StartElement(const Reference<XAttributeList> & rAttrList)44 void XMLChartOOoTransformerContext::StartElement(
45     const Reference< XAttributeList >& rAttrList )
46 {
47     XMLTransformerActions *pActions =
48         GetTransformer().GetUserDefinedActions( OOO_CHART_ACTIONS );
49     OSL_ENSURE( pActions, "go no actions" );
50 
51     sal_Int16 nClassName = -1;
52     OUString aAddInName;
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++ )
57     {
58         const OUString& rAttrName = xAttrList->getNameByIndex( i );
59         OUString aLocalName;
60         sal_uInt16 nPrefix =
61             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
62                                                                  &aLocalName );
63         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
64         XMLTransformerActions::const_iterator aIter =
65             pActions->find( aKey );
66         if( aIter != pActions->end() )
67         {
68             if( !pMutableAttrList )
69             {
70                 pMutableAttrList =
71                         new XMLMutableAttributeList( xAttrList );
72                 xAttrList = pMutableAttrList;
73             }
74             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
75             switch( (*aIter).second.m_nActionType )
76             {
77             case XML_ATACTION_INCH2IN:
78                 {
79                     OUString aAttrValue( rAttrValue );
80                     if( XMLTransformerBase::ReplaceSingleInchWithIn(
81                                 aAttrValue ) )
82                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
83                 }
84                 break;
85             case XML_ATACTION_ENCODE_STYLE_NAME_REF:
86                 {
87                     OUString aAttrValue( rAttrValue );
88                     if( GetTransformer().EncodeStyleName(aAttrValue) )
89                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
90                 }
91                 break;
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 ) )
96                 {
97                     nClassName = i;
98                 }
99                 else
100                 {
101                     OUString aAttrValue( rAttrValue );
102                     sal_uInt16 nValPrefix =
103                         static_cast<sal_uInt16>((*aIter).second.m_nParam1);
104                     GetTransformer().AddNamespacePrefix( aAttrValue,
105                                                              nValPrefix );
106                     pMutableAttrList->SetValueByIndex( i, aAttrValue );
107                 }
108                 break;
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 );
114                 --i;
115                 --nAttrCount;
116                 break;
117             default:
118                 OSL_ENSURE( false, "unknown action" );
119                 break;
120             }
121         }
122     }
123 
124     if( nClassName != -1 && !aAddInName.isEmpty() )
125     {
126         GetTransformer().AddNamespacePrefix( aAddInName, XML_NAMESPACE_OOO );
127         pMutableAttrList->SetValueByIndex( nClassName, aAddInName );
128     }
129 
130     XMLTransformerContext::StartElement( xAttrList );
131 }
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
134