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/xml/AttributeData.hpp>
21 #include <com/sun/star/lang/XUnoTunnel.hpp>
22 #include <xmloff/xmlcnimp.hxx>
23 #include <xmloff/unoatrcn.hxx>
24 #include <editeng/xmlcnitm.hxx>
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star::container
;
28 using namespace ::com::sun::star::lang
;
29 using namespace ::com::sun::star::xml
;
32 TYPEINIT1(SvXMLAttrContainerItem
, SfxPoolItem
);
34 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich
) :
35 SfxPoolItem( _nWhich
)
37 pImpl
= new SvXMLAttrContainerData
;
40 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
41 const SvXMLAttrContainerItem
& rItem
) :
44 pImpl
= new SvXMLAttrContainerData( *rItem
.pImpl
);
47 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
52 int SvXMLAttrContainerItem::operator==( const SfxPoolItem
& rItem
) const
54 DBG_ASSERT( rItem
.ISA(SvXMLAttrContainerItem
),
55 "SvXMLAttrContainerItem::operator ==(): Bad type");
56 return *pImpl
== *((const SvXMLAttrContainerItem
&)rItem
).pImpl
;
59 int SvXMLAttrContainerItem::Compare( const SfxPoolItem
&/*rWith*/ ) const
61 DBG_ASSERT( !this, "not yet implemented" );
66 SfxItemPresentation
SvXMLAttrContainerItem::GetPresentation(
67 SfxItemPresentation
/*ePresentation*/,
68 SfxMapUnit
/*eCoreMetric*/,
69 SfxMapUnit
/*ePresentationMetric*/,
71 const IntlWrapper
* /*pIntlWrapper*/ ) const
73 return SFX_ITEM_PRESENTATION_NONE
;
76 sal_uInt16
SvXMLAttrContainerItem::GetVersion( sal_uInt16
/*nFileFormatVersion*/ ) const
78 // This item should never be stored
82 bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
84 Reference
<XNameContainer
> xContainer
=
85 new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl
) );
87 rVal
.setValue( &xContainer
, ::getCppuType((Reference
<XNameContainer
>*)0) );
91 bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
93 Reference
<XInterface
> xRef
;
94 SvUnoAttributeContainer
* pContainer
= NULL
;
96 if( rVal
.getValue() != NULL
&& rVal
.getValueType().getTypeClass() == TypeClass_INTERFACE
)
98 xRef
= *(Reference
<XInterface
>*)rVal
.getValue();
99 Reference
<XUnoTunnel
> xTunnel(xRef
, UNO_QUERY
);
101 pContainer
= (SvUnoAttributeContainer
*)(sal_uLong
)xTunnel
->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
107 pImpl
= new SvXMLAttrContainerData( * pContainer
->GetContainerImpl() );
111 std::auto_ptr
<SvXMLAttrContainerData
> pNewImpl(new SvXMLAttrContainerData
);
115 Reference
<XNameContainer
> xContainer( xRef
, UNO_QUERY
);
116 if( !xContainer
.is() )
119 const Sequence
< OUString
> aNameSequence( xContainer
->getElementNames() );
120 const OUString
* pNames
= aNameSequence
.getConstArray();
121 const sal_Int32 nCount
= aNameSequence
.getLength();
123 AttributeData
* pData
;
126 for( nAttr
= 0; nAttr
< nCount
; nAttr
++ )
128 const OUString
aName( *pNames
++ );
130 aAny
= xContainer
->getByName( aName
);
131 if( aAny
.getValue() == NULL
|| aAny
.getValueType() != ::getCppuType((AttributeData
*)0) )
134 pData
= (AttributeData
*)aAny
.getValue();
135 sal_Int32 pos
= aName
.indexOf( sal_Unicode(':') );
138 const OUString
aPrefix( aName
.copy( 0, pos
));
139 const OUString
aLName( aName
.copy( pos
+1 ));
141 if( pData
->Namespace
.isEmpty() )
143 if( !pNewImpl
->AddAttr( aPrefix
, aLName
, pData
->Value
) )
148 if( !pNewImpl
->AddAttr( aPrefix
, pData
->Namespace
, aLName
, pData
->Value
) )
154 if( !pNewImpl
->AddAttr( aName
, pData
->Value
) )
159 if( nAttr
== nCount
)
160 pImpl
= pNewImpl
.release();
173 sal_Bool
SvXMLAttrContainerItem::AddAttr( const OUString
& rLName
,
174 const OUString
& rValue
)
176 return pImpl
->AddAttr( rLName
, rValue
);
179 sal_Bool
SvXMLAttrContainerItem::AddAttr( const OUString
& rPrefix
,
180 const OUString
& rNamespace
, const OUString
& rLName
,
181 const OUString
& rValue
)
183 return pImpl
->AddAttr( rPrefix
, rNamespace
, rLName
, rValue
);
186 sal_uInt16
SvXMLAttrContainerItem::GetAttrCount() const
188 return (sal_uInt16
)pImpl
->GetAttrCount();
191 OUString
SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i
) const
193 return pImpl
->GetAttrNamespace( i
);
196 OUString
SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i
) const
198 return pImpl
->GetAttrPrefix( i
);
201 const OUString
& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i
) const
203 return pImpl
->GetAttrLName( i
);
206 const OUString
& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i
) const
208 return pImpl
->GetAttrValue( i
);
212 sal_uInt16
SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
214 return pImpl
->GetFirstNamespaceIndex();
217 sal_uInt16
SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx
) const
219 return pImpl
->GetNextNamespaceIndex( nIdx
);
222 const OUString
& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i
) const
224 return pImpl
->GetNamespace( i
);
227 const OUString
& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i
) const
229 return pImpl
->GetPrefix( i
);
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */