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 "CreateElemTContext.hxx" 31 #include "MutableAttrList.hxx" 32 #ifndef _XMLOFF_TRANSFORMERBASE_HXX 33 #include "TransformerBase.hxx" 34 #endif 35 #include "TransformerActions.hxx" 36 #include "TContextVector.hxx" 37 #include "FlatTContext.hxx" 38 #include "AttrTransformerAction.hxx" 39 #include <xmloff/nmspmap.hxx> 40 41 using ::rtl::OUString; 42 using namespace ::com::sun::star::uno; 43 using namespace ::com::sun::star::xml::sax; 44 using namespace ::xmloff::token; 45 46 TYPEINIT1( XMLCreateElemTransformerContext, XMLTransformerContext ); 47 48 XMLCreateElemTransformerContext::XMLCreateElemTransformerContext( 49 XMLTransformerBase& rImp, 50 const OUString& rQName, 51 sal_uInt16 nActionMap ) : 52 XMLTransformerContext( rImp, rQName ), 53 m_nActionMap( nActionMap ) 54 { 55 } 56 57 XMLCreateElemTransformerContext::~XMLCreateElemTransformerContext() 58 { 59 } 60 61 void XMLCreateElemTransformerContext::StartElement( 62 const Reference< XAttributeList >& rAttrList ) 63 { 64 Reference< XAttributeList > xAttrList( rAttrList ); 65 66 XMLTransformerContextVector aChildContexts; 67 68 XMLMutableAttributeList *pMutableAttrList = 0; 69 XMLTransformerActions *pActions = 70 GetTransformer().GetUserDefinedActions( m_nActionMap ); 71 OSL_ENSURE( pActions, "go no actions" ); 72 if( pActions ) 73 { 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 const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 79 OUString aLocalName; 80 sal_uInt16 nPrefix = 81 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, 82 &aLocalName ); 83 84 XMLTransformerActions::key_type aKey( nPrefix, aLocalName ); 85 XMLTransformerActions::const_iterator aIter = 86 pActions->find( aKey ); 87 if( !(aIter == pActions->end() ) ) 88 { 89 if( !pMutableAttrList ) 90 { 91 pMutableAttrList = new XMLMutableAttributeList( xAttrList ); 92 xAttrList = pMutableAttrList; 93 } 94 sal_uInt32 nAction = (*aIter).second.m_nActionType; 95 switch( nAction ) 96 { 97 case XML_ATACTION_MOVE_TO_ELEM: 98 { 99 OUString aElemQName( 100 GetTransformer().GetNamespaceMap().GetQNameByKey( 101 (*aIter).second.GetQNamePrefixFromParam1(), 102 ::xmloff::token::GetXMLToken( 103 (*aIter).second.GetQNameTokenFromParam1()) ) ); 104 XMLTransformerContext *pContext = 105 new XMLPersTextContentTContext( GetTransformer(), 106 aElemQName ); 107 pContext->Characters( rAttrValue ); 108 XMLTransformerContextVector::value_type aVal( 109 pContext ); 110 aChildContexts.push_back( aVal ); 111 pMutableAttrList->RemoveAttributeByIndex( i ); 112 --i; 113 --nAttrCount; 114 } 115 break; 116 default: 117 OSL_ENSURE( !this, "unknown action" ); 118 break; 119 } 120 } 121 } 122 } 123 XMLTransformerContext::StartElement( xAttrList ); 124 125 XMLTransformerContextVector::iterator aIter = aChildContexts.begin(); 126 127 for( ; aIter != aChildContexts.end(); ++aIter ) 128 { 129 (*aIter)->Export(); 130 } 131 } 132