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 .
21 #include <com/sun/star/xml/AttributeData.hpp>
22 #include <com/sun/star/lang/XUnoTunnel.hpp>
23 #include <o3tl/any.hxx>
24 #include <xmloff/xmlcnimp.hxx>
25 #include <xmloff/unoatrcn.hxx>
26 #include <editeng/xmlcnitm.hxx>
27 #include <tools/solar.h>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::container
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::xml
;
35 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich
) :
36 SfxPoolItem( _nWhich
),
37 pImpl( new SvXMLAttrContainerData
)
41 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
42 const SvXMLAttrContainerItem
& rItem
) :
44 pImpl( new SvXMLAttrContainerData( *rItem
.pImpl
) )
48 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
52 bool SvXMLAttrContainerItem::operator==( const SfxPoolItem
& rItem
) const
54 return SfxPoolItem::operator==(rItem
) &&
55 *pImpl
== *static_cast<const SvXMLAttrContainerItem
&>(rItem
).pImpl
;
58 bool SvXMLAttrContainerItem::GetPresentation(
59 SfxItemPresentation
/*ePresentation*/,
60 MapUnit
/*eCoreMetric*/,
61 MapUnit
/*ePresentationMetric*/,
63 const IntlWrapper
& /*rIntlWrapper*/ ) const
68 bool SvXMLAttrContainerItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
70 Reference
<XNameContainer
> xContainer
71 = new SvUnoAttributeContainer(std::make_unique
<SvXMLAttrContainerData
>(*pImpl
));
77 bool SvXMLAttrContainerItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
79 SvUnoAttributeContainer
* pContainer
= nullptr;
81 Reference
<XUnoTunnel
> xTunnel(rVal
, UNO_QUERY
);
83 pContainer
= reinterpret_cast<SvUnoAttributeContainer
*>(static_cast<sal_uLong
>(xTunnel
->getSomething(SvUnoAttributeContainer::getUnoTunnelId())));
87 pImpl
.reset( new SvXMLAttrContainerData( * pContainer
->GetContainerImpl() ) );
91 std::unique_ptr
<SvXMLAttrContainerData
> pNewImpl(new SvXMLAttrContainerData
);
95 Reference
<XNameContainer
> xContainer( rVal
, UNO_QUERY
);
96 if( !xContainer
.is() )
99 const Sequence
< OUString
> aNameSequence( xContainer
->getElementNames() );
100 const OUString
* pNames
= aNameSequence
.getConstArray();
101 const sal_Int32 nCount
= aNameSequence
.getLength();
105 for( nAttr
= 0; nAttr
< nCount
; nAttr
++ )
107 const OUString
aName( *pNames
++ );
109 aAny
= xContainer
->getByName( aName
);
110 auto pData
= o3tl::tryAccess
<AttributeData
>(aAny
);
114 sal_Int32 pos
= aName
.indexOf( ':' );
117 const OUString
aPrefix( aName
.copy( 0, pos
));
118 const OUString
aLName( aName
.copy( pos
+1 ));
120 if( pData
->Namespace
.isEmpty() )
122 if( !pNewImpl
->AddAttr( aPrefix
, aLName
, pData
->Value
) )
127 if( !pNewImpl
->AddAttr( aPrefix
, pData
->Namespace
, aLName
, pData
->Value
) )
133 if( !pNewImpl
->AddAttr( aName
, pData
->Value
) )
138 if( nAttr
== nCount
)
139 pImpl
= std::move(pNewImpl
);
152 bool SvXMLAttrContainerItem::AddAttr( const OUString
& rLName
,
153 const OUString
& rValue
)
155 return pImpl
->AddAttr( rLName
, rValue
);
158 bool SvXMLAttrContainerItem::AddAttr( const OUString
& rPrefix
,
159 const OUString
& rNamespace
, const OUString
& rLName
,
160 const OUString
& rValue
)
162 return pImpl
->AddAttr( rPrefix
, rNamespace
, rLName
, rValue
);
165 sal_uInt16
SvXMLAttrContainerItem::GetAttrCount() const
167 return static_cast<sal_uInt16
>(pImpl
->GetAttrCount());
170 OUString
SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i
) const
172 return pImpl
->GetAttrNamespace( i
);
175 OUString
SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i
) const
177 return pImpl
->GetAttrPrefix( i
);
180 const OUString
& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i
) const
182 return pImpl
->GetAttrLName( i
);
185 const OUString
& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i
) const
187 return pImpl
->GetAttrValue( i
);
191 sal_uInt16
SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
193 return pImpl
->GetFirstNamespaceIndex();
196 sal_uInt16
SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx
) const
198 return pImpl
->GetNextNamespaceIndex( nIdx
);
201 const OUString
& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i
) const
203 return pImpl
->GetNamespace( i
);
206 const OUString
& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i
) const
208 return pImpl
->GetPrefix( i
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */