merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / CreateElemTContext.cxx
blobcc667798eb3a0c91045f44f1da059e8dc36228cc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CreateElemTContext.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "CreateElemTContext.hxx"
34 #include "MutableAttrList.hxx"
35 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
36 #include "TransformerBase.hxx"
37 #endif
38 #include "TransformerActions.hxx"
39 #include "TContextVector.hxx"
40 #include "FlatTContext.hxx"
41 #include "AttrTransformerAction.hxx"
42 #include <xmloff/nmspmap.hxx>
44 using ::rtl::OUString;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::xml::sax;
47 using namespace ::xmloff::token;
49 TYPEINIT1( XMLCreateElemTransformerContext, XMLTransformerContext );
51 XMLCreateElemTransformerContext::XMLCreateElemTransformerContext(
52 XMLTransformerBase& rImp,
53 const OUString& rQName,
54 sal_uInt16 nActionMap ) :
55 XMLTransformerContext( rImp, rQName ),
56 m_nActionMap( nActionMap )
60 XMLCreateElemTransformerContext::~XMLCreateElemTransformerContext()
64 void XMLCreateElemTransformerContext::StartElement(
65 const Reference< XAttributeList >& rAttrList )
67 Reference< XAttributeList > xAttrList( rAttrList );
69 XMLTransformerContextVector aChildContexts;
71 XMLMutableAttributeList *pMutableAttrList = 0;
72 XMLTransformerActions *pActions =
73 GetTransformer().GetUserDefinedActions( m_nActionMap );
74 OSL_ENSURE( pActions, "go no actions" );
75 if( pActions )
77 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
78 for( sal_Int16 i=0; i < nAttrCount; ++i )
80 const OUString& rAttrName = xAttrList->getNameByIndex( i );
81 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
82 OUString aLocalName;
83 sal_uInt16 nPrefix =
84 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
85 &aLocalName );
87 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
88 XMLTransformerActions::const_iterator aIter =
89 pActions->find( aKey );
90 if( !(aIter == pActions->end() ) )
92 if( !pMutableAttrList )
94 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
95 xAttrList = pMutableAttrList;
97 sal_uInt32 nAction = (*aIter).second.m_nActionType;
98 switch( nAction )
100 case XML_ATACTION_MOVE_TO_ELEM:
102 OUString aElemQName(
103 GetTransformer().GetNamespaceMap().GetQNameByKey(
104 (*aIter).second.GetQNamePrefixFromParam1(),
105 ::xmloff::token::GetXMLToken(
106 (*aIter).second.GetQNameTokenFromParam1()) ) );
107 XMLTransformerContext *pContext =
108 new XMLPersTextContentTContext( GetTransformer(),
109 aElemQName );
110 pContext->Characters( rAttrValue );
111 XMLTransformerContextVector::value_type aVal(
112 pContext );
113 aChildContexts.push_back( aVal );
114 pMutableAttrList->RemoveAttributeByIndex( i );
115 --i;
116 --nAttrCount;
118 break;
119 default:
120 OSL_ENSURE( !this, "unknown action" );
121 break;
126 XMLTransformerContext::StartElement( xAttrList );
128 XMLTransformerContextVector::iterator aIter = aChildContexts.begin();
130 for( ; aIter != aChildContexts.end(); ++aIter )
132 (*aIter)->Export();