1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "CreateElemTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include "TransformerBase.hxx"
23 #include "TransformerActions.hxx"
24 #include "TContextVector.hxx"
25 #include "FlatTContext.hxx"
26 #include "AttrTransformerAction.hxx"
27 #include <xmloff/nmspmap.hxx>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::xml::sax
;
31 using namespace ::xmloff::token
;
33 TYPEINIT1( XMLCreateElemTransformerContext
, XMLTransformerContext
);
35 XMLCreateElemTransformerContext::XMLCreateElemTransformerContext(
36 XMLTransformerBase
& rImp
,
37 const OUString
& rQName
,
38 sal_uInt16 nActionMap
) :
39 XMLTransformerContext( rImp
, rQName
),
40 m_nActionMap( nActionMap
)
44 XMLCreateElemTransformerContext::~XMLCreateElemTransformerContext()
48 void XMLCreateElemTransformerContext::StartElement(
49 const Reference
< XAttributeList
>& rAttrList
)
51 Reference
< XAttributeList
> xAttrList( rAttrList
);
53 XMLTransformerContextVector aChildContexts
;
55 XMLMutableAttributeList
*pMutableAttrList
= 0;
56 XMLTransformerActions
*pActions
=
57 GetTransformer().GetUserDefinedActions( m_nActionMap
);
58 OSL_ENSURE( pActions
, "go no actions" );
61 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
62 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
64 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
65 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
68 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
71 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
72 XMLTransformerActions::const_iterator aIter
=
73 pActions
->find( aKey
);
74 if( !(aIter
== pActions
->end() ) )
76 if( !pMutableAttrList
)
78 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
79 xAttrList
= pMutableAttrList
;
81 sal_uInt32 nAction
= (*aIter
).second
.m_nActionType
;
84 case XML_ATACTION_MOVE_TO_ELEM
:
87 GetTransformer().GetNamespaceMap().GetQNameByKey(
88 (*aIter
).second
.GetQNamePrefixFromParam1(),
89 ::xmloff::token::GetXMLToken(
90 (*aIter
).second
.GetQNameTokenFromParam1()) ) );
91 XMLTransformerContext
*pContext
=
92 new XMLPersTextContentTContext( GetTransformer(),
94 pContext
->Characters( rAttrValue
);
95 XMLTransformerContextVector::value_type
aVal(
97 aChildContexts
.push_back( aVal
);
98 pMutableAttrList
->RemoveAttributeByIndex( i
);
104 OSL_ENSURE( !this, "unknown action" );
110 XMLTransformerContext::StartElement( xAttrList
);
112 XMLTransformerContextVector::iterator aIter
= aChildContexts
.begin();
114 for( ; aIter
!= aChildContexts
.end(); ++aIter
)
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */