bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / items / xmlcnitm.cxx
blob785c6fe01b68317ef25e3e27bea3b5a8d7a92faa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 ) :
42 SfxPoolItem( rItem )
44 pImpl = new SvXMLAttrContainerData( *rItem.pImpl );
47 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
49 delete pImpl;
52 bool SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
54 DBG_ASSERT( rItem.ISA(SvXMLAttrContainerItem),
55 "SvXMLAttrContainerItem::operator ==(): Bad type");
56 return *pImpl == *static_cast<const SvXMLAttrContainerItem&>(rItem).pImpl;
59 int SvXMLAttrContainerItem::Compare( const SfxPoolItem &/*rWith*/ ) const
61 DBG_ASSERT( false, "not yet implemented" );
63 return 0;
66 bool SvXMLAttrContainerItem::GetPresentation(
67 SfxItemPresentation /*ePresentation*/,
68 SfxMapUnit /*eCoreMetric*/,
69 SfxMapUnit /*ePresentationMetric*/,
70 OUString & /*rText*/,
71 const IntlWrapper * /*pIntlWrapper*/ ) const
73 return false;
76 sal_uInt16 SvXMLAttrContainerItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
78 // This item should never be stored
79 return USHRT_MAX;
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, cppu::UnoType<XNameContainer>::get());
88 return true;
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 = *static_cast<Reference<XInterface> const *>(rVal.getValue());
99 Reference<XUnoTunnel> xTunnel(xRef, UNO_QUERY);
100 if( xTunnel.is() )
101 pContainer = reinterpret_cast<SvUnoAttributeContainer*>((sal_uLong)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId()));
104 if( pContainer )
106 delete pImpl;
107 pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() );
109 else
111 std::unique_ptr<SvXMLAttrContainerData> pNewImpl(new SvXMLAttrContainerData);
115 Reference<XNameContainer> xContainer( xRef, UNO_QUERY );
116 if( !xContainer.is() )
117 return false;
119 const Sequence< OUString > aNameSequence( xContainer->getElementNames() );
120 const OUString* pNames = aNameSequence.getConstArray();
121 const sal_Int32 nCount = aNameSequence.getLength();
122 Any aAny;
123 sal_Int32 nAttr;
125 for( nAttr = 0; nAttr < nCount; nAttr++ )
127 const OUString aName( *pNames++ );
129 aAny = xContainer->getByName( aName );
130 if( aAny.getValue() == NULL || aAny.getValueType() != cppu::UnoType<AttributeData>::get() )
131 return false;
133 AttributeData const * pData = static_cast<AttributeData const *>(aAny.getValue());
134 sal_Int32 pos = aName.indexOf( ':' );
135 if( pos != -1 )
137 const OUString aPrefix( aName.copy( 0, pos ));
138 const OUString aLName( aName.copy( pos+1 ));
140 if( pData->Namespace.isEmpty() )
142 if( !pNewImpl->AddAttr( aPrefix, aLName, pData->Value ) )
143 break;
145 else
147 if( !pNewImpl->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
148 break;
151 else
153 if( !pNewImpl->AddAttr( aName, pData->Value ) )
154 break;
158 if( nAttr == nCount )
159 pImpl = pNewImpl.release();
160 else
161 return false;
163 catch(...)
165 return false;
168 return true;
172 bool SvXMLAttrContainerItem::AddAttr( const OUString& rLName,
173 const OUString& rValue )
175 return pImpl->AddAttr( rLName, rValue );
178 bool SvXMLAttrContainerItem::AddAttr( const OUString& rPrefix,
179 const OUString& rNamespace, const OUString& rLName,
180 const OUString& rValue )
182 return pImpl->AddAttr( rPrefix, rNamespace, rLName, rValue );
185 sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
187 return (sal_uInt16)pImpl->GetAttrCount();
190 OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
192 return pImpl->GetAttrNamespace( i );
195 OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
197 return pImpl->GetAttrPrefix( i );
200 const OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
202 return pImpl->GetAttrLName( i );
205 const OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
207 return pImpl->GetAttrValue( i );
211 sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
213 return pImpl->GetFirstNamespaceIndex();
216 sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
218 return pImpl->GetNextNamespaceIndex( nIdx );
221 const OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
223 return pImpl->GetNamespace( i );
226 const OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
228 return pImpl->GetPrefix( i );
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */