xref: /trunk/main/xmloff/source/transform/ChartOOoTContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "ChartOOoTContext.hxx"
31 #include "MutableAttrList.hxx"
32 #include "xmloff/xmlnmspe.hxx"
33 #ifndef _XMLOFF_ACTIONMAPTYPESOOo_HXX
34 #include "ActionMapTypesOOo.hxx"
35 #endif
36 #include "AttrTransformerAction.hxx"
37 #include "TransformerActions.hxx"
38 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
39 #include "TransformerBase.hxx"
40 #endif
41 
42 using ::rtl::OUString;
43 
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::xml::sax;
46 using namespace ::xmloff::token;
47 
48 // -----------------------------------------------------------------------------
49 
50 TYPEINIT1( XMLChartOOoTransformerContext, XMLTransformerContext );
51 
52 XMLChartOOoTransformerContext::XMLChartOOoTransformerContext(
53         XMLTransformerBase& rImp,
54         const OUString& rQName ) :
55     XMLTransformerContext( rImp, rQName )
56 {
57 }
58 
59 XMLChartOOoTransformerContext::~XMLChartOOoTransformerContext()
60 {
61 }
62 
63 void XMLChartOOoTransformerContext::StartElement(
64     const Reference< XAttributeList >& rAttrList )
65 {
66     XMLTransformerActions *pActions =
67         GetTransformer().GetUserDefinedActions( OOO_CHART_ACTIONS );
68     OSL_ENSURE( pActions, "go no actions" );
69 
70     sal_Int16 nClassName = -1;
71     OUString aAddInName;
72     Reference< XAttributeList > xAttrList( rAttrList );
73     XMLMutableAttributeList *pMutableAttrList = 0;
74     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
75     for( sal_Int16 i=0; i < nAttrCount; i++ )
76     {
77         const OUString& rAttrName = xAttrList->getNameByIndex( i );
78         OUString aLocalName;
79         sal_uInt16 nPrefix =
80             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
81                                                                  &aLocalName );
82         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
83         XMLTransformerActions::const_iterator aIter =
84             pActions->find( aKey );
85         if( !(aIter == pActions->end() ) )
86         {
87             if( !pMutableAttrList )
88             {
89                 pMutableAttrList =
90                         new XMLMutableAttributeList( xAttrList );
91                 xAttrList = pMutableAttrList;
92             }
93             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
94             switch( (*aIter).second.m_nActionType )
95             {
96             case XML_ATACTION_INCH2IN:
97                 {
98                     OUString aAttrValue( rAttrValue );
99                     if( XMLTransformerBase::ReplaceSingleInchWithIn(
100                                 aAttrValue ) )
101                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
102                 }
103                 break;
104             case XML_ATACTION_ENCODE_STYLE_NAME_REF:
105                 {
106                     OUString aAttrValue( rAttrValue );
107                     if( GetTransformer().EncodeStyleName(aAttrValue) )
108                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
109                 }
110                 break;
111             case XML_ATACTION_ADD_NAMESPACE_PREFIX:
112                 OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName, XML_CLASS ),
113                             "unexpected class token" );
114                 if( ::xmloff::token::IsXMLToken( rAttrValue, XML_ADD_IN ) )
115                 {
116                     nClassName = i;
117                 }
118                 else
119                 {
120                     OUString aAttrValue( rAttrValue );
121                     sal_uInt16 nValPrefix =
122                         static_cast<sal_uInt16>((*aIter).second.m_nParam1);
123                     if( GetTransformer().AddNamespacePrefix( aAttrValue,
124                                                              nValPrefix ) )
125                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
126                 }
127                 break;
128             case XML_ATACTION_REMOVE:
129                 OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName, XML_ADD_IN_NAME ),
130                             "unexpected class token" );
131                 aAddInName = rAttrValue;
132                 pMutableAttrList->RemoveAttributeByIndex( i );
133                 --i;
134                 --nAttrCount;
135                 break;
136             default:
137                 OSL_ENSURE( !this, "unknown action" );
138                 break;
139             }
140         }
141     }
142 
143     if( nClassName != -1 && aAddInName.getLength() > 0 )
144     {
145         GetTransformer().AddNamespacePrefix( aAddInName, XML_NAMESPACE_OOO );
146         pMutableAttrList->SetValueByIndex( nClassName, aAddInName );
147     }
148 
149     XMLTransformerContext::StartElement( xAttrList );
150 }
151