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 <com/sun/star/util/XCloneable.hpp>
21 #include "IgnoreTContext.hxx"
22 #include "TransformerBase.hxx"
23 #include "MutableAttrList.hxx"
24 #include <xmloff/nmspmap.hxx>
25 #include "PersAttrListTContext.hxx"
27 using ::rtl::OUString
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::util
;
31 using namespace ::com::sun::star::xml::sax
;
33 TYPEINIT1( XMLPersAttrListTContext
, XMLTransformerContext
);
35 void XMLPersAttrListTContext::AddAttribute(
37 ::xmloff::token::XMLTokenEnum eAToken
,
38 ::xmloff::token::XMLTokenEnum eVToken
)
40 OUString
aAttrValue( ::xmloff::token::GetXMLToken( eVToken
) );
41 AddAttribute( nAPrefix
, eAToken
, aAttrValue
);
44 void XMLPersAttrListTContext::AddAttribute(
46 ::xmloff::token::XMLTokenEnum eAToken
,
47 const ::rtl::OUString
& rValue
)
49 OUString
aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
50 nAPrefix
, ::xmloff::token::GetXMLToken( eAToken
) ) );
51 OUString
aAttrValue( rValue
);
53 XMLMutableAttributeList
*pMutableAttrList
;
54 if( m_xAttrList
.is() )
57 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() );
61 pMutableAttrList
= new XMLMutableAttributeList
;
62 m_xAttrList
= pMutableAttrList
;
65 pMutableAttrList
->AddAttribute( aAttrQName
, aAttrValue
);
68 XMLPersAttrListTContext::XMLPersAttrListTContext(
69 XMLTransformerBase
& rImp
,
70 const OUString
& rQName
) :
71 XMLTransformerContext( rImp
, rQName
),
72 m_aElemQName( rQName
),
73 m_nActionMap( INVALID_ACTIONS
)
77 XMLPersAttrListTContext::XMLPersAttrListTContext(
78 XMLTransformerBase
& rImp
,
79 const OUString
& rQName
,
80 sal_uInt16 nActionMap
) :
81 XMLTransformerContext( rImp
, rQName
),
82 m_aElemQName( rQName
),
83 m_nActionMap( nActionMap
)
87 XMLPersAttrListTContext::XMLPersAttrListTContext(
88 XMLTransformerBase
& rImp
,
89 const OUString
& rQName
,
91 ::xmloff::token::XMLTokenEnum eToken
) :
92 XMLTransformerContext( rImp
, rQName
),
93 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( nPrefix
,
94 ::xmloff::token::GetXMLToken( eToken
) ) ),
95 m_nActionMap( INVALID_ACTIONS
)
99 XMLPersAttrListTContext::XMLPersAttrListTContext(
100 XMLTransformerBase
& rImp
,
101 const OUString
& rQName
,
103 ::xmloff::token::XMLTokenEnum eToken
,
104 sal_uInt16 nActionMap
) :
105 XMLTransformerContext( rImp
, rQName
),
106 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( nPrefix
,
107 ::xmloff::token::GetXMLToken( eToken
) ) ),
108 m_nActionMap( nActionMap
)
112 XMLPersAttrListTContext::~XMLPersAttrListTContext()
116 XMLTransformerContext
*XMLPersAttrListTContext::CreateChildContext(
117 sal_uInt16
/*nPrefix*/,
118 const OUString
& /*rLocalName*/,
119 const OUString
& rQName
,
120 const Reference
< XAttributeList
>& )
122 // ignore all child elements
123 return new XMLIgnoreTransformerContext( GetTransformer(),
124 rQName
, sal_True
, sal_True
);
127 void XMLPersAttrListTContext::StartElement(
128 const Reference
< XAttributeList
>& rAttrList
)
130 XMLMutableAttributeList
*pMutableAttrList
= 0;
132 Reference
< XAttributeList
> xAttrList( rAttrList
);
133 if( m_nActionMap
!= INVALID_ACTIONS
)
136 GetTransformer().ProcessAttrList( xAttrList
, m_nActionMap
,
140 if( m_xAttrList
.is() )
142 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
143 ->AppendAttributeList( xAttrList
);
145 else if( pMutableAttrList
)
147 m_xAttrList
= xAttrList
;
151 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, sal_True
);
155 void XMLPersAttrListTContext::EndElement()
160 void XMLPersAttrListTContext::Characters( const OUString
& )
164 sal_Bool
XMLPersAttrListTContext::IsPersistent() const
169 void XMLPersAttrListTContext::Export()
171 GetTransformer().GetDocHandler()->startElement( m_aElemQName
, m_xAttrList
);
173 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
176 void XMLPersAttrListTContext::ExportContent()
181 Reference
< XAttributeList
> XMLPersAttrListTContext::GetAttrList() const
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */