Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / transform / CreateElemTContext.cxx
blob48fad335200dd5504e1b961481010898c571b2f2
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 <sal/config.h>
22 #include <vector>
24 #include "CreateElemTContext.hxx"
25 #include "MutableAttrList.hxx"
26 #include "TransformerBase.hxx"
27 #include "TransformerActions.hxx"
28 #include "FlatTContext.hxx"
29 #include "AttrTransformerAction.hxx"
30 #include <xmloff/nmspmap.hxx>
31 #include <osl/diagnose.h>
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
35 using namespace ::xmloff::token;
37 XMLCreateElemTransformerContext::XMLCreateElemTransformerContext(
38 XMLTransformerBase& rImp,
39 const OUString& rQName,
40 sal_uInt16 nActionMap ) :
41 XMLTransformerContext( rImp, rQName ),
42 m_nActionMap( nActionMap )
46 XMLCreateElemTransformerContext::~XMLCreateElemTransformerContext()
50 void XMLCreateElemTransformerContext::StartElement(
51 const Reference< XAttributeList >& rAttrList )
53 Reference< XAttributeList > xAttrList( rAttrList );
55 std::vector<rtl::Reference<XMLTransformerContext>> aChildContexts;
57 XMLMutableAttributeList *pMutableAttrList = nullptr;
58 XMLTransformerActions *pActions =
59 GetTransformer().GetUserDefinedActions( m_nActionMap );
60 OSL_ENSURE( pActions, "go no actions" );
61 if( pActions )
63 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
64 for( sal_Int16 i=0; i < nAttrCount; ++i )
66 const OUString& rAttrName = xAttrList->getNameByIndex( i );
67 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
68 OUString aLocalName;
69 sal_uInt16 nPrefix =
70 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
71 &aLocalName );
73 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
74 XMLTransformerActions::const_iterator aIter =
75 pActions->find( aKey );
76 if( !(aIter == pActions->end() ) )
78 if( !pMutableAttrList )
80 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
81 xAttrList = pMutableAttrList;
83 sal_uInt32 nAction = (*aIter).second.m_nActionType;
84 switch( nAction )
86 case XML_ATACTION_MOVE_TO_ELEM:
88 OUString aElemQName(
89 GetTransformer().GetNamespaceMap().GetQNameByKey(
90 (*aIter).second.GetQNamePrefixFromParam1(),
91 ::xmloff::token::GetXMLToken(
92 (*aIter).second.GetQNameTokenFromParam1()) ) );
93 rtl::Reference<XMLTransformerContext> pContext(
94 new XMLPersTextContentTContext( GetTransformer(),
95 aElemQName ));
96 pContext->Characters( rAttrValue );
97 aChildContexts.push_back(pContext);
98 pMutableAttrList->RemoveAttributeByIndex( i );
99 --i;
100 --nAttrCount;
102 break;
103 default:
104 OSL_ENSURE( false, "unknown action" );
105 break;
110 XMLTransformerContext::StartElement( xAttrList );
112 for (auto const & i: aChildContexts)
114 i->Export();
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */