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