Bump version to 24.04.3.4
[LibreOffice.git] / editeng / source / items / xmlcnitm.cxx
blob7507ed2afdd00edc756d8c2dc3435edbc3980197
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 <memory>
22 #include <comphelper/servicehelper.hxx>
23 #include <com/sun/star/xml/AttributeData.hpp>
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
25 #include <o3tl/any.hxx>
26 #include <xmloff/xmlcnimp.hxx>
27 #include <xmloff/unoatrcn.hxx>
28 #include <editeng/xmlcnitm.hxx>
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::container;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::xml;
36 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) :
37 SfxPoolItem( _nWhich )
41 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
42 const SvXMLAttrContainerItem& rItem ) :
43 SfxPoolItem( rItem ),
44 maContainerData( rItem.maContainerData )
48 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
52 bool SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
54 return SfxPoolItem::operator==(rItem) &&
55 maContainerData == static_cast<const SvXMLAttrContainerItem&>(rItem).maContainerData;
58 bool SvXMLAttrContainerItem::GetPresentation(
59 SfxItemPresentation /*ePresentation*/,
60 MapUnit /*eCoreMetric*/,
61 MapUnit /*ePresentationMetric*/,
62 OUString & /*rText*/,
63 const IntlWrapper& /*rIntlWrapper*/ ) const
65 return false;
68 bool SvXMLAttrContainerItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
70 Reference<XNameContainer> xContainer
71 = new SvUnoAttributeContainer(std::make_unique<SvXMLAttrContainerData>(maContainerData));
73 rVal <<= xContainer;
74 return true;
77 bool SvXMLAttrContainerItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
79 Reference<XInterface> xTunnel(rVal, UNO_QUERY);
80 if (auto pContainer = dynamic_cast<SvUnoAttributeContainer*>(xTunnel.get()))
82 maContainerData = *pContainer->GetContainerImpl();
84 else
86 SvXMLAttrContainerData aNewImpl;
88 try
90 Reference<XNameContainer> xContainer( rVal, UNO_QUERY );
91 if( !xContainer.is() )
92 return false;
94 const Sequence< OUString > aNameSequence( xContainer->getElementNames() );
95 const OUString* pNames = aNameSequence.getConstArray();
96 const sal_Int32 nCount = aNameSequence.getLength();
97 Any aAny;
98 sal_Int32 nAttr;
100 for( nAttr = 0; nAttr < nCount; nAttr++ )
102 const OUString aName( *pNames++ );
104 aAny = xContainer->getByName( aName );
105 auto pData = o3tl::tryAccess<AttributeData>(aAny);
106 if( !pData )
107 return false;
109 sal_Int32 pos = aName.indexOf( ':' );
110 if( pos != -1 )
112 const OUString aPrefix( aName.copy( 0, pos ));
113 const OUString aLName( aName.copy( pos+1 ));
115 if( pData->Namespace.isEmpty() )
117 if( !aNewImpl.AddAttr( aPrefix, aLName, pData->Value ) )
118 break;
120 else
122 if( !aNewImpl.AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
123 break;
126 else
128 if( !aNewImpl.AddAttr( aName, pData->Value ) )
129 break;
133 if( nAttr == nCount )
134 maContainerData = std::move(aNewImpl);
135 else
136 return false;
138 catch(...)
140 return false;
143 return true;
147 bool SvXMLAttrContainerItem::AddAttr( const OUString& rLName,
148 const OUString& rValue )
150 return maContainerData.AddAttr( rLName, rValue );
153 bool SvXMLAttrContainerItem::AddAttr( const OUString& rPrefix,
154 const OUString& rNamespace, const OUString& rLName,
155 const OUString& rValue )
157 return maContainerData.AddAttr( rPrefix, rNamespace, rLName, rValue );
160 sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
162 return static_cast<sal_uInt16>(maContainerData.GetAttrCount());
165 OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
167 return maContainerData.GetAttrNamespace( i );
170 OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
172 return maContainerData.GetAttrPrefix( i );
175 const OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
177 return maContainerData.GetAttrLName( i );
180 const OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
182 return maContainerData.GetAttrValue( i );
186 sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
188 return maContainerData.GetFirstNamespaceIndex();
191 sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
193 return maContainerData.GetNextNamespaceIndex( nIdx );
196 const OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
198 return maContainerData.GetNamespace( i );
201 const OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
203 return maContainerData.GetPrefix( i );
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */