1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/xml/AttributeData.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <xmloff/xmlcnimp.hxx>
32 #include <xmloff/unoatrcn.hxx>
33 #include <editeng/xmlcnitm.hxx>
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::container
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::xml
;
41 TYPEINIT1(SvXMLAttrContainerItem
, SfxPoolItem
);
43 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich
) :
44 SfxPoolItem( _nWhich
)
46 pImpl
= new SvXMLAttrContainerData
;
49 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
50 const SvXMLAttrContainerItem
& rItem
) :
53 pImpl
= new SvXMLAttrContainerData( *rItem
.pImpl
);
56 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
61 int SvXMLAttrContainerItem::operator==( const SfxPoolItem
& rItem
) const
63 DBG_ASSERT( rItem
.ISA(SvXMLAttrContainerItem
),
64 "SvXMLAttrContainerItem::operator ==(): Bad type");
65 return *pImpl
== *((const SvXMLAttrContainerItem
&)rItem
).pImpl
;
68 int SvXMLAttrContainerItem::Compare( const SfxPoolItem
&/*rWith*/ ) const
70 DBG_ASSERT( !this, "not yet implemented" );
75 SfxItemPresentation
SvXMLAttrContainerItem::GetPresentation(
76 SfxItemPresentation
/*ePresentation*/,
77 SfxMapUnit
/*eCoreMetric*/,
78 SfxMapUnit
/*ePresentationMetric*/,
80 const IntlWrapper
* /*pIntlWrapper*/ ) const
82 return SFX_ITEM_PRESENTATION_NONE
;
85 sal_uInt16
SvXMLAttrContainerItem::GetVersion( sal_uInt16
/*nFileFormatVersion*/ ) const
87 // This item should never be stored
91 bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ ) const
93 Reference
<XNameContainer
> xContainer
=
94 new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl
) );
96 rVal
.setValue( &xContainer
, ::getCppuType((Reference
<XNameContainer
>*)0) );
100 bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8
/*nMemberId*/ )
102 Reference
<XInterface
> xRef
;
103 SvUnoAttributeContainer
* pContainer
= NULL
;
105 if( rVal
.getValue() != NULL
&& rVal
.getValueType().getTypeClass() == TypeClass_INTERFACE
)
107 xRef
= *(Reference
<XInterface
>*)rVal
.getValue();
108 Reference
<XUnoTunnel
> xTunnel(xRef
, UNO_QUERY
);
110 pContainer
= (SvUnoAttributeContainer
*)(sal_uLong
)xTunnel
->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
116 pImpl
= new SvXMLAttrContainerData( * pContainer
->GetContainerImpl() );
120 std::auto_ptr
<SvXMLAttrContainerData
> pNewImpl(new SvXMLAttrContainerData
);
124 Reference
<XNameContainer
> xContainer( xRef
, UNO_QUERY
);
125 if( !xContainer
.is() )
128 const Sequence
< ::rtl::OUString
> aNameSequence( xContainer
->getElementNames() );
129 const ::rtl::OUString
* pNames
= aNameSequence
.getConstArray();
130 const sal_Int32 nCount
= aNameSequence
.getLength();
132 AttributeData
* pData
;
135 for( nAttr
= 0; nAttr
< nCount
; nAttr
++ )
137 const ::rtl::OUString
aName( *pNames
++ );
139 aAny
= xContainer
->getByName( aName
);
140 if( aAny
.getValue() == NULL
|| aAny
.getValueType() != ::getCppuType((AttributeData
*)0) )
143 pData
= (AttributeData
*)aAny
.getValue();
144 sal_Int32 pos
= aName
.indexOf( sal_Unicode(':') );
147 const ::rtl::OUString
aPrefix( aName
.copy( 0, pos
));
148 const ::rtl::OUString
aLName( aName
.copy( pos
+1 ));
150 if( pData
->Namespace
.isEmpty() )
152 if( !pNewImpl
->AddAttr( aPrefix
, aLName
, pData
->Value
) )
157 if( !pNewImpl
->AddAttr( aPrefix
, pData
->Namespace
, aLName
, pData
->Value
) )
163 if( !pNewImpl
->AddAttr( aName
, pData
->Value
) )
168 if( nAttr
== nCount
)
169 pImpl
= pNewImpl
.release();
182 sal_Bool
SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString
& rLName
,
183 const ::rtl::OUString
& rValue
)
185 return pImpl
->AddAttr( rLName
, rValue
);
188 sal_Bool
SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString
& rPrefix
,
189 const ::rtl::OUString
& rNamespace
, const ::rtl::OUString
& rLName
,
190 const ::rtl::OUString
& rValue
)
192 return pImpl
->AddAttr( rPrefix
, rNamespace
, rLName
, rValue
);
195 sal_uInt16
SvXMLAttrContainerItem::GetAttrCount() const
197 return (sal_uInt16
)pImpl
->GetAttrCount();
200 ::rtl::OUString
SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i
) const
202 return pImpl
->GetAttrNamespace( i
);
205 ::rtl::OUString
SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i
) const
207 return pImpl
->GetAttrPrefix( i
);
210 const ::rtl::OUString
& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i
) const
212 return pImpl
->GetAttrLName( i
);
215 const ::rtl::OUString
& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i
) const
217 return pImpl
->GetAttrValue( i
);
221 sal_uInt16
SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
223 return pImpl
->GetFirstNamespaceIndex();
226 sal_uInt16
SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx
) const
228 return pImpl
->GetNextNamespaceIndex( nIdx
);
231 const ::rtl::OUString
& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i
) const
233 return pImpl
->GetNamespace( i
);
236 const ::rtl::OUString
& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i
) const
238 return pImpl
->GetPrefix( i
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */