1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "ChartOOoTContext.hxx"
27 #include "MutableAttrList.hxx"
28 #include "xmloff/xmlnmspe.hxx"
29 #ifndef _XMLOFF_ACTIONMAPTYPESOOo_HXX
30 #include "ActionMapTypesOOo.hxx"
31 #endif
32 #include "AttrTransformerAction.hxx"
33 #include "TransformerActions.hxx"
34 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
35 #include "TransformerBase.hxx"
36 #endif
37 
38 using ::rtl::OUString;
39 
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::xml::sax;
42 using namespace ::xmloff::token;
43 
44 // -----------------------------------------------------------------------------
45 
46 TYPEINIT1( XMLChartOOoTransformerContext, XMLTransformerContext );
47 
48 XMLChartOOoTransformerContext::XMLChartOOoTransformerContext(
49 		XMLTransformerBase& rImp,
50 		const OUString& rQName ) :
51 	XMLTransformerContext( rImp, rQName )
52 {
53 }
54 
55 XMLChartOOoTransformerContext::~XMLChartOOoTransformerContext()
56 {
57 }
58 
59 void XMLChartOOoTransformerContext::StartElement(
60 	const Reference< XAttributeList >& rAttrList )
61 {
62 	XMLTransformerActions *pActions =
63 		GetTransformer().GetUserDefinedActions( OOO_CHART_ACTIONS );
64 	OSL_ENSURE( pActions, "go no actions" );
65 
66 	sal_Int16 nClassName = -1;
67 	OUString aAddInName;
68 	Reference< XAttributeList > xAttrList( rAttrList );
69 	XMLMutableAttributeList *pMutableAttrList = 0;
70 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
71 	for( sal_Int16 i=0; i < nAttrCount; i++ )
72 	{
73 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
74 		OUString aLocalName;
75 		sal_uInt16 nPrefix =
76 			GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
77 																 &aLocalName );
78 		XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
79 		XMLTransformerActions::const_iterator aIter =
80 			pActions->find( aKey );
81 		if( !(aIter == pActions->end() ) )
82 		{
83 			if( !pMutableAttrList )
84 			{
85 				pMutableAttrList =
86 						new XMLMutableAttributeList( xAttrList );
87 				xAttrList = pMutableAttrList;
88 			}
89 			const OUString& rAttrValue = xAttrList->getValueByIndex( i );
90 			switch( (*aIter).second.m_nActionType )
91 			{
92 			case XML_ATACTION_INCH2IN:
93 				{
94 					OUString aAttrValue( rAttrValue );
95 					if( XMLTransformerBase::ReplaceSingleInchWithIn(
96 								aAttrValue ) )
97 						pMutableAttrList->SetValueByIndex( i, aAttrValue );
98 				}
99 				break;
100 			case XML_ATACTION_ENCODE_STYLE_NAME_REF:
101 				{
102 					OUString aAttrValue( rAttrValue );
103 					if( GetTransformer().EncodeStyleName(aAttrValue) )
104 						pMutableAttrList->SetValueByIndex( i, aAttrValue );
105 				}
106 				break;
107 			case XML_ATACTION_ADD_NAMESPACE_PREFIX:
108 				OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName, XML_CLASS ),
109 					   		"unexpected class token" );
110 				if( ::xmloff::token::IsXMLToken( rAttrValue, XML_ADD_IN ) )
111 				{
112 					nClassName = i;
113 				}
114 				else
115 				{
116 					OUString aAttrValue( rAttrValue );
117 					sal_uInt16 nValPrefix =
118 						static_cast<sal_uInt16>((*aIter).second.m_nParam1);
119 					if( GetTransformer().AddNamespacePrefix( aAttrValue,
120 															 nValPrefix ) )
121 						pMutableAttrList->SetValueByIndex( i, aAttrValue );
122 				}
123 				break;
124 			case XML_ATACTION_REMOVE:
125 				OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName, XML_ADD_IN_NAME ),
126 					   		"unexpected class token" );
127 				aAddInName = rAttrValue;
128 				pMutableAttrList->RemoveAttributeByIndex( i );
129 				--i;
130 				--nAttrCount;
131 				break;
132 			default:
133 				OSL_ENSURE( !this, "unknown action" );
134 				break;
135 			}
136 		}
137 	}
138 
139 	if( nClassName != -1 && aAddInName.getLength() > 0 )
140 	{
141 		GetTransformer().AddNamespacePrefix( aAddInName, XML_NAMESPACE_OOO );
142 		pMutableAttrList->SetValueByIndex( nClassName, aAddInName );
143 	}
144 
145 	XMLTransformerContext::StartElement( xAttrList );
146 }
147