LibreOffice Module xmloff (master) 1
CreateElemTContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <vector>
23
25#include "MutableAttrList.hxx"
26#include "TransformerBase.hxx"
28#include "FlatTContext.hxx"
31#include <osl/diagnose.h>
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::xml::sax;
35using namespace ::xmloff::token;
36
39 const OUString& rQName,
40 sal_uInt16 nActionMap ) :
41 XMLTransformerContext( rImp, rQName ),
42 m_nActionMap( nActionMap )
43{
44}
45
47 const Reference< XAttributeList >& rAttrList )
48{
49 Reference< XAttributeList > xAttrList( rAttrList );
50
51 std::vector<rtl::Reference<XMLTransformerContext>> aChildContexts;
52
54 XMLTransformerActions *pActions =
56 OSL_ENSURE( pActions, "go no actions" );
57 if( pActions )
58 {
59 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
60 for( sal_Int16 i=0; i < nAttrCount; ++i )
61 {
62 const OUString& rAttrName = xAttrList->getNameByIndex( i );
63 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
64 OUString aLocalName;
65 sal_uInt16 nPrefix =
67 &aLocalName );
68
69 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
70 XMLTransformerActions::const_iterator aIter =
71 pActions->find( aKey );
72 if( aIter != pActions->end() )
73 {
74 if( !pMutableAttrList )
75 {
76 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
77 xAttrList = pMutableAttrList;
78 }
79 sal_uInt32 nAction = (*aIter).second.m_nActionType;
80 switch( nAction )
81 {
83 {
84 OUString aElemQName(
85 GetTransformer().GetNamespaceMap().GetQNameByKey(
86 (*aIter).second.GetQNamePrefixFromParam1(),
88 (*aIter).second.GetQNameTokenFromParam1()) ) );
91 aElemQName ));
92 pContext->Characters( rAttrValue );
93 aChildContexts.push_back(pContext);
94 pMutableAttrList->RemoveAttributeByIndex( i );
95 --i;
96 --nAttrCount;
97 }
98 break;
99 default:
100 OSL_ENSURE( false, "unknown action" );
101 break;
102 }
103 }
104 }
105 }
107
108 for (auto const & i: aChildContexts)
109 {
110 i->Export();
111 }
112}
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ XML_ATACTION_MOVE_TO_ELEM
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
XMLCreateElemTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, sal_uInt16 nActionMap)
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
SvXMLNamespaceMap & GetNamespaceMap()
XMLTransformerBase & GetTransformer()
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
int i
Handling of tokens in XML:
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541