Update git submodules
[LibreOffice.git] / xmloff / source / transform / PersAttrListTContext.cxx
blob9631c5ab585dff7db0c73534cfc6369a2a6bca75
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 "IgnoreTContext.hxx"
21 #include "TransformerBase.hxx"
22 #include "MutableAttrList.hxx"
23 #include <xmloff/namespacemap.hxx>
24 #include "PersAttrListTContext.hxx"
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::xml::sax;
30 void XMLPersAttrListTContext::AddAttribute(
31 sal_uInt16 nAPrefix,
32 ::xmloff::token::XMLTokenEnum eAToken,
33 ::xmloff::token::XMLTokenEnum eVToken )
35 const OUString& aAttrValue( ::xmloff::token::GetXMLToken( eVToken ) );
36 AddAttribute( nAPrefix, eAToken, aAttrValue );
39 void XMLPersAttrListTContext::AddAttribute(
40 sal_uInt16 nAPrefix,
41 ::xmloff::token::XMLTokenEnum eAToken,
42 const OUString & rValue )
44 OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
45 nAPrefix, ::xmloff::token::GetXMLToken( eAToken ) ) );
46 const OUString& aAttrValue( rValue );
48 rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
49 if( m_xAttrList.is() )
51 pMutableAttrList =
52 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
54 else
56 pMutableAttrList = new XMLMutableAttributeList ;
57 m_xAttrList = pMutableAttrList;
60 pMutableAttrList->AddAttribute( aAttrQName, aAttrValue );
63 XMLPersAttrListTContext::XMLPersAttrListTContext(
64 XMLTransformerBase& rImp,
65 const OUString& rQName ) :
66 XMLTransformerContext( rImp, rQName ),
67 m_aElemQName( rQName ),
68 m_nActionMap( INVALID_ACTIONS )
72 XMLPersAttrListTContext::XMLPersAttrListTContext(
73 XMLTransformerBase& rImp,
74 const OUString& rQName,
75 sal_uInt16 nActionMap ) :
76 XMLTransformerContext( rImp, rQName ),
77 m_aElemQName( rQName ),
78 m_nActionMap( nActionMap )
82 XMLPersAttrListTContext::XMLPersAttrListTContext(
83 XMLTransformerBase& rImp,
84 const OUString& rQName,
85 sal_uInt16 nPrefix,
86 ::xmloff::token::XMLTokenEnum eToken ) :
87 XMLTransformerContext( rImp, rQName ),
88 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
89 ::xmloff::token::GetXMLToken( eToken ) ) ),
90 m_nActionMap( INVALID_ACTIONS )
94 XMLPersAttrListTContext::XMLPersAttrListTContext(
95 XMLTransformerBase& rImp,
96 const OUString& rQName,
97 sal_uInt16 nPrefix,
98 ::xmloff::token::XMLTokenEnum eToken,
99 sal_uInt16 nActionMap ) :
100 XMLTransformerContext( rImp, rQName ),
101 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
102 ::xmloff::token::GetXMLToken( eToken ) ) ),
103 m_nActionMap( nActionMap )
107 rtl::Reference<XMLTransformerContext> XMLPersAttrListTContext::CreateChildContext(
108 sal_uInt16 /*nPrefix*/,
109 const OUString& /*rLocalName*/,
110 const OUString& rQName,
111 const Reference< XAttributeList >& )
113 // ignore all child elements
114 return new XMLIgnoreTransformerContext( GetTransformer(),
115 rQName, true, true );
118 void XMLPersAttrListTContext::StartElement(
119 const Reference< XAttributeList >& rAttrList )
121 XMLMutableAttributeList *pMutableAttrList = nullptr;
123 Reference< XAttributeList > xAttrList( rAttrList );
124 if( m_nActionMap != INVALID_ACTIONS )
126 pMutableAttrList =
127 GetTransformer().ProcessAttrList( xAttrList, m_nActionMap,
128 true );
131 if( m_xAttrList.is() )
133 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
134 ->AppendAttributeList( xAttrList );
136 else if( pMutableAttrList )
138 m_xAttrList = std::move(xAttrList);
140 else
142 m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
146 void XMLPersAttrListTContext::EndElement()
148 // ignore for now
151 void XMLPersAttrListTContext::Characters( const OUString& )
155 bool XMLPersAttrListTContext::IsPersistent() const
157 return true;
160 void XMLPersAttrListTContext::Export()
162 GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList );
163 ExportContent();
164 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
167 void XMLPersAttrListTContext::ExportContent()
169 // nothing to export
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */