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