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 .
22 #include <com/sun/star/xml/AttributeData.hpp>
23 #include <com/sun/star/lang/XUnoTunnel.hpp>
24 #include <o3tl/any.hxx>
25 #include <xmloff/xmlcnimp.hxx>
26 #include <xmloff/unoatrcn.hxx>
27 #include <editeng/xmlcnitm.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/solar.h>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::container
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star::xml
;
37 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich
) :
38 SfxPoolItem( _nWhich
),
39 pImpl( new SvXMLAttrContainerData
)
43 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
44 const SvXMLAttrContainerItem
& rItem
) :
46 pImpl( new SvXMLAttrContainerData( *rItem
.pImpl
) )
50 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
54 bool SvXMLAttrContainerItem::operator==( const SfxPoolItem
& rItem
) const
56 return SfxPoolItem::operator==(rItem
) &&
57 *pImpl
== *static_cast<const SvXMLAttrContainerItem
&>(rItem
).pImpl
;
60 bool SvXMLAttrContainerItem::GetPresentation(
61 SfxItemPresentation
/*ePresentation*/,
62 MapUnit
/*eCoreMetric*/,
63 MapUnit
/*ePresentationMetric*/,
65 const IntlWrapper
& /*rIntlWrapper*/ ) const
70 bool SvXMLAttrContainerItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
72 Reference
<XNameContainer
> xContainer
73 = new SvUnoAttributeContainer(std::make_unique
<SvXMLAttrContainerData
>(*pImpl
));
79 bool SvXMLAttrContainerItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
81 SvUnoAttributeContainer
* pContainer
= nullptr;
83 Reference
<XUnoTunnel
> xTunnel(rVal
, UNO_QUERY
);
85 pContainer
= reinterpret_cast<SvUnoAttributeContainer
*>(static_cast<sal_uLong
>(xTunnel
->getSomething(SvUnoAttributeContainer::getUnoTunnelId())));
89 pImpl
.reset( new SvXMLAttrContainerData( * pContainer
->GetContainerImpl() ) );
93 std::unique_ptr
<SvXMLAttrContainerData
> pNewImpl(new SvXMLAttrContainerData
);
97 Reference
<XNameContainer
> xContainer( rVal
, UNO_QUERY
);
98 if( !xContainer
.is() )
101 const Sequence
< OUString
> aNameSequence( xContainer
->getElementNames() );
102 const OUString
* pNames
= aNameSequence
.getConstArray();
103 const sal_Int32 nCount
= aNameSequence
.getLength();
107 for( nAttr
= 0; nAttr
< nCount
; nAttr
++ )
109 const OUString
aName( *pNames
++ );
111 aAny
= xContainer
->getByName( aName
);
112 auto pData
= o3tl::tryAccess
<AttributeData
>(aAny
);
116 sal_Int32 pos
= aName
.indexOf( ':' );
119 const OUString
aPrefix( aName
.copy( 0, pos
));
120 const OUString
aLName( aName
.copy( pos
+1 ));
122 if( pData
->Namespace
.isEmpty() )
124 if( !pNewImpl
->AddAttr( aPrefix
, aLName
, pData
->Value
) )
129 if( !pNewImpl
->AddAttr( aPrefix
, pData
->Namespace
, aLName
, pData
->Value
) )
135 if( !pNewImpl
->AddAttr( aName
, pData
->Value
) )
140 if( nAttr
== nCount
)
141 pImpl
= std::move(pNewImpl
);
154 bool SvXMLAttrContainerItem::AddAttr( const OUString
& rLName
,
155 const OUString
& rValue
)
157 return pImpl
->AddAttr( rLName
, rValue
);
160 bool SvXMLAttrContainerItem::AddAttr( const OUString
& rPrefix
,
161 const OUString
& rNamespace
, const OUString
& rLName
,
162 const OUString
& rValue
)
164 return pImpl
->AddAttr( rPrefix
, rNamespace
, rLName
, rValue
);
167 sal_uInt16
SvXMLAttrContainerItem::GetAttrCount() const
169 return static_cast<sal_uInt16
>(pImpl
->GetAttrCount());
172 OUString
SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i
) const
174 return pImpl
->GetAttrNamespace( i
);
177 OUString
SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i
) const
179 return pImpl
->GetAttrPrefix( i
);
182 const OUString
& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i
) const
184 return pImpl
->GetAttrLName( i
);
187 const OUString
& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i
) const
189 return pImpl
->GetAttrValue( i
);
193 sal_uInt16
SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
195 return pImpl
->GetFirstNamespaceIndex();
198 sal_uInt16
SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx
) const
200 return pImpl
->GetNextNamespaceIndex( nIdx
);
203 const OUString
& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i
) const
205 return pImpl
->GetNamespace( i
);
208 const OUString
& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i
) const
210 return pImpl
->GetPrefix( i
);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */