Use o3tl::convert in Math
[LibreOffice.git] / editeng / source / items / xmlcnitm.cxx
blob7bcfe11f9a5580992035dc26b5a2acdd75b552d7
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>
29 #include <tools/solar.h>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::container;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::xml;
37 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) :
38 SfxPoolItem( _nWhich )
42 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
43 const SvXMLAttrContainerItem& rItem ) :
44 SfxPoolItem( rItem ),
45 maContainerData( rItem.maContainerData )
49 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
53 bool SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
55 return SfxPoolItem::operator==(rItem) &&
56 maContainerData == static_cast<const SvXMLAttrContainerItem&>(rItem).maContainerData;
59 bool SvXMLAttrContainerItem::GetPresentation(
60 SfxItemPresentation /*ePresentation*/,
61 MapUnit /*eCoreMetric*/,
62 MapUnit /*ePresentationMetric*/,
63 OUString & /*rText*/,
64 const IntlWrapper& /*rIntlWrapper*/ ) const
66 return false;
69 bool SvXMLAttrContainerItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
71 Reference<XNameContainer> xContainer
72 = new SvUnoAttributeContainer(std::make_unique<SvXMLAttrContainerData>(maContainerData));
74 rVal <<= xContainer;
75 return true;
78 bool SvXMLAttrContainerItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
80 Reference<XUnoTunnel> xTunnel(rVal, UNO_QUERY);
81 if (auto pContainer = comphelper::getFromUnoTunnel<SvUnoAttributeContainer>(xTunnel))
83 maContainerData = *pContainer->GetContainerImpl();
85 else
87 SvXMLAttrContainerData aNewImpl;
89 try
91 Reference<XNameContainer> xContainer( rVal, UNO_QUERY );
92 if( !xContainer.is() )
93 return false;
95 const Sequence< OUString > aNameSequence( xContainer->getElementNames() );
96 const OUString* pNames = aNameSequence.getConstArray();
97 const sal_Int32 nCount = aNameSequence.getLength();
98 Any aAny;
99 sal_Int32 nAttr;
101 for( nAttr = 0; nAttr < nCount; nAttr++ )
103 const OUString aName( *pNames++ );
105 aAny = xContainer->getByName( aName );
106 auto pData = o3tl::tryAccess<AttributeData>(aAny);
107 if( !pData )
108 return false;
110 sal_Int32 pos = aName.indexOf( ':' );
111 if( pos != -1 )
113 const OUString aPrefix( aName.copy( 0, pos ));
114 const OUString aLName( aName.copy( pos+1 ));
116 if( pData->Namespace.isEmpty() )
118 if( !aNewImpl.AddAttr( aPrefix, aLName, pData->Value ) )
119 break;
121 else
123 if( !aNewImpl.AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
124 break;
127 else
129 if( !aNewImpl.AddAttr( aName, pData->Value ) )
130 break;
134 if( nAttr == nCount )
135 maContainerData = std::move(aNewImpl);
136 else
137 return false;
139 catch(...)
141 return false;
144 return true;
148 bool SvXMLAttrContainerItem::AddAttr( const OUString& rLName,
149 const OUString& rValue )
151 return maContainerData.AddAttr( rLName, rValue );
154 bool SvXMLAttrContainerItem::AddAttr( const OUString& rPrefix,
155 const OUString& rNamespace, const OUString& rLName,
156 const OUString& rValue )
158 return maContainerData.AddAttr( rPrefix, rNamespace, rLName, rValue );
161 sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
163 return static_cast<sal_uInt16>(maContainerData.GetAttrCount());
166 OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
168 return maContainerData.GetAttrNamespace( i );
171 OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
173 return maContainerData.GetAttrPrefix( i );
176 const OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
178 return maContainerData.GetAttrLName( i );
181 const OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
183 return maContainerData.GetAttrValue( i );
187 sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
189 return maContainerData.GetFirstNamespaceIndex();
192 sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
194 return maContainerData.GetNextNamespaceIndex( nIdx );
197 const OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
199 return maContainerData.GetNamespace( i );
202 const OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
204 return maContainerData.GetPrefix( i );
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */