1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlcnitm.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <com/sun/star/xml/AttributeData.hpp>
34 #include <com/sun/star/lang/XUnoTunnel.hpp>
35 #include <xmloff/xmlcnimp.hxx>
36 #ifndef _XMLOFF_XMLCNITM_HXX
37 #include <xmloff/unoatrcn.hxx>
39 #include "xmlcnitm.hxx"
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::container
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::xml
;
46 // ------------------------------------------------------------------------
48 TYPEINIT1(SvXMLAttrContainerItem
, SfxPoolItem
);
50 SvXMLAttrContainerItem::SvXMLAttrContainerItem( USHORT _nWhich
) :
51 SfxPoolItem( _nWhich
)
53 pImpl
= new SvXMLAttrContainerData
;
56 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
57 const SvXMLAttrContainerItem
& rItem
) :
60 pImpl
= new SvXMLAttrContainerData( *rItem
.pImpl
);
63 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
68 int SvXMLAttrContainerItem::operator==( const SfxPoolItem
& rItem
) const
70 DBG_ASSERT( rItem
.ISA(SvXMLAttrContainerItem
),
71 "SvXMLAttrContainerItem::operator ==(): Bad type");
72 return *pImpl
== *((const SvXMLAttrContainerItem
&)rItem
).pImpl
;
75 int SvXMLAttrContainerItem::Compare( const SfxPoolItem
&/*rWith*/ ) const
77 DBG_ASSERT( !this, "not yet implemented" );
82 SfxItemPresentation
SvXMLAttrContainerItem::GetPresentation(
83 SfxItemPresentation
/*ePresentation*/,
84 SfxMapUnit
/*eCoreMetric*/,
85 SfxMapUnit
/*ePresentationMetric*/,
87 const IntlWrapper
* /*pIntlWrapper*/ ) const
89 return SFX_ITEM_PRESENTATION_NONE
;
92 USHORT
SvXMLAttrContainerItem::GetVersion( USHORT
/*nFileFormatVersion*/ ) const
94 // This item should never be stored
98 BOOL
SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any
& rVal
, BYTE
/*nMemberId*/ ) const
100 Reference
<XNameContainer
> xContainer
=
101 new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl
) );
103 rVal
.setValue( &xContainer
, ::getCppuType((Reference
<XNameContainer
>*)0) );
106 BOOL
SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any
& rVal
, BYTE
/*nMemberId*/ )
108 Reference
<XInterface
> xRef
;
109 SvUnoAttributeContainer
* pContainer
= NULL
;
111 if( rVal
.getValue() != NULL
&& rVal
.getValueType().getTypeClass() == TypeClass_INTERFACE
)
113 xRef
= *(Reference
<XInterface
>*)rVal
.getValue();
114 Reference
<XUnoTunnel
> xTunnel(xRef
, UNO_QUERY
);
116 pContainer
= (SvUnoAttributeContainer
*)(ULONG
)xTunnel
->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
122 pImpl
= new SvXMLAttrContainerData( * pContainer
->GetContainerImpl() );
126 SvXMLAttrContainerData
* pNewImpl
= new SvXMLAttrContainerData
;
130 Reference
<XNameContainer
> xContainer( xRef
, UNO_QUERY
);
131 if( !xContainer
.is() )
134 const Sequence
< ::rtl::OUString
> aNameSequence( xContainer
->getElementNames() );
135 const ::rtl::OUString
* pNames
= aNameSequence
.getConstArray();
136 const INT32 nCount
= aNameSequence
.getLength();
138 AttributeData
* pData
;
141 for( nAttr
= 0; nAttr
< nCount
; nAttr
++ )
143 const ::rtl::OUString
aName( *pNames
++ );
145 aAny
= xContainer
->getByName( aName
);
146 if( aAny
.getValue() == NULL
|| aAny
.getValueType() != ::getCppuType((AttributeData
*)0) )
149 pData
= (AttributeData
*)aAny
.getValue();
150 sal_Int32 pos
= aName
.indexOf( sal_Unicode(':') );
153 const ::rtl::OUString
aPrefix( aName
.copy( 0, pos
));
154 const ::rtl::OUString
aLName( aName
.copy( pos
+1 ));
156 if( pData
->Namespace
.getLength() == 0 )
158 if( !pNewImpl
->AddAttr( aPrefix
, aLName
, pData
->Value
) )
163 if( !pNewImpl
->AddAttr( aPrefix
, pData
->Namespace
, aLName
, pData
->Value
) )
169 if( !pNewImpl
->AddAttr( aName
, pData
->Value
) )
174 if( nAttr
== nCount
)
195 BOOL
SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString
& rLName
,
196 const ::rtl::OUString
& rValue
)
198 return pImpl
->AddAttr( rLName
, rValue
);
201 BOOL
SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString
& rPrefix
,
202 const ::rtl::OUString
& rNamespace
, const ::rtl::OUString
& rLName
,
203 const ::rtl::OUString
& rValue
)
205 return pImpl
->AddAttr( rPrefix
, rNamespace
, rLName
, rValue
);
208 USHORT
SvXMLAttrContainerItem::GetAttrCount() const
210 return (USHORT
)pImpl
->GetAttrCount();
213 ::rtl::OUString
SvXMLAttrContainerItem::GetAttrNamespace( USHORT i
) const
215 return pImpl
->GetAttrNamespace( i
);
218 ::rtl::OUString
SvXMLAttrContainerItem::GetAttrPrefix( USHORT i
) const
220 return pImpl
->GetAttrPrefix( i
);
223 const ::rtl::OUString
& SvXMLAttrContainerItem::GetAttrLName( USHORT i
) const
225 return pImpl
->GetAttrLName( i
);
228 const ::rtl::OUString
& SvXMLAttrContainerItem::GetAttrValue( USHORT i
) const
230 return pImpl
->GetAttrValue( i
);
234 USHORT
SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
236 return pImpl
->GetFirstNamespaceIndex();
239 USHORT
SvXMLAttrContainerItem::GetNextNamespaceIndex( USHORT nIdx
) const
241 return pImpl
->GetNextNamespaceIndex( nIdx
);
244 const ::rtl::OUString
& SvXMLAttrContainerItem::GetNamespace( USHORT i
) const
246 return pImpl
->GetNamespace( i
);
249 const ::rtl::OUString
& SvXMLAttrContainerItem::GetPrefix( USHORT i
) const
251 return pImpl
->GetPrefix( i
);