Update ooo320-m1
[ooovba.git] / svx / source / items / xmlcnitm.cxx
blobb7e626095171c76bd884ae9177411860b9ace24a
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 $
10 * $Revision: 1.10 $
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>
38 #endif
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 ) :
58 SfxPoolItem( rItem )
60 pImpl = new SvXMLAttrContainerData( *rItem.pImpl );
63 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
65 delete pImpl;
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" );
79 return 0;
82 SfxItemPresentation SvXMLAttrContainerItem::GetPresentation(
83 SfxItemPresentation /*ePresentation*/,
84 SfxMapUnit /*eCoreMetric*/,
85 SfxMapUnit /*ePresentationMetric*/,
86 XubString &/*rText*/,
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
95 return USHRT_MAX;
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) );
104 return TRUE;
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);
115 if( xTunnel.is() )
116 pContainer = (SvUnoAttributeContainer*)(ULONG)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
119 if( pContainer )
121 delete pImpl;
122 pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() );
124 else
126 SvXMLAttrContainerData* pNewImpl = new SvXMLAttrContainerData;
130 Reference<XNameContainer> xContainer( xRef, UNO_QUERY );
131 if( !xContainer.is() )
132 return FALSE;
134 const Sequence< ::rtl::OUString > aNameSequence( xContainer->getElementNames() );
135 const ::rtl::OUString* pNames = aNameSequence.getConstArray();
136 const INT32 nCount = aNameSequence.getLength();
137 Any aAny;
138 AttributeData* pData;
139 INT32 nAttr;
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) )
147 return FALSE;
149 pData = (AttributeData*)aAny.getValue();
150 sal_Int32 pos = aName.indexOf( sal_Unicode(':') );
151 if( pos != -1 )
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 ) )
159 break;
161 else
163 if( !pNewImpl->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
164 break;
167 else
169 if( !pNewImpl->AddAttr( aName, pData->Value ) )
170 break;
174 if( nAttr == nCount )
176 delete pImpl;
177 pImpl = pNewImpl;
179 else
181 delete pNewImpl;
182 return FALSE;
185 catch(...)
187 delete pNewImpl;
188 return FALSE;
191 return TRUE;
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 );