bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / CreateElemTContext.cxx
blob8e0a32f3255bd23134a4f02f4814a0253c2f2c71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
28 #include <osl/diagnose.h>
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::xml::sax;
32 using namespace ::xmloff::token;
34 TYPEINIT1( XMLCreateElemTransformerContext, XMLTransformerContext );
36 XMLCreateElemTransformerContext::XMLCreateElemTransformerContext(
37 XMLTransformerBase& rImp,
38 const OUString& rQName,
39 sal_uInt16 nActionMap ) :
40 XMLTransformerContext( rImp, rQName ),
41 m_nActionMap( nActionMap )
45 XMLCreateElemTransformerContext::~XMLCreateElemTransformerContext()
49 void XMLCreateElemTransformerContext::StartElement(
50 const Reference< XAttributeList >& rAttrList )
52 Reference< XAttributeList > xAttrList( rAttrList );
54 XMLTransformerContextVector aChildContexts;
56 XMLMutableAttributeList *pMutableAttrList = 0;
57 XMLTransformerActions *pActions =
58 GetTransformer().GetUserDefinedActions( m_nActionMap );
59 OSL_ENSURE( pActions, "go no actions" );
60 if( pActions )
62 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
63 for( sal_Int16 i=0; i < nAttrCount; ++i )
65 const OUString& rAttrName = xAttrList->getNameByIndex( i );
66 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
67 OUString aLocalName;
68 sal_uInt16 nPrefix =
69 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
70 &aLocalName );
72 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
73 XMLTransformerActions::const_iterator aIter =
74 pActions->find( aKey );
75 if( !(aIter == pActions->end() ) )
77 if( !pMutableAttrList )
79 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
80 xAttrList = pMutableAttrList;
82 sal_uInt32 nAction = (*aIter).second.m_nActionType;
83 switch( nAction )
85 case XML_ATACTION_MOVE_TO_ELEM:
87 OUString aElemQName(
88 GetTransformer().GetNamespaceMap().GetQNameByKey(
89 (*aIter).second.GetQNamePrefixFromParam1(),
90 ::xmloff::token::GetXMLToken(
91 (*aIter).second.GetQNameTokenFromParam1()) ) );
92 XMLTransformerContext *pContext =
93 new XMLPersTextContentTContext( GetTransformer(),
94 aElemQName );
95 pContext->Characters( rAttrValue );
96 XMLTransformerContextVector::value_type aVal(
97 pContext );
98 aChildContexts.push_back( aVal );
99 pMutableAttrList->RemoveAttributeByIndex( i );
100 --i;
101 --nAttrCount;
103 break;
104 default:
105 OSL_ENSURE( false, "unknown action" );
106 break;
111 XMLTransformerContext::StartElement( xAttrList );
113 XMLTransformerContextVector::iterator aIter = aChildContexts.begin();
115 for( ; aIter != aChildContexts.end(); ++aIter )
117 (*aIter)->Export();
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */