25#include <com/sun/star/container/XNameAccess.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
34using namespace ::
cppu;
47 class NamespaceMap :
public WeakImplHelper< XNameAccess, XServiceInfo >
50 sal_uInt16* mpWhichIds;
54 NamespaceMap( sal_uInt16* pWhichIds,
SfxItemPool* pPool );
57 virtual Any SAL_CALL getByName(
const OUString& aName )
override;
58 virtual Sequence< OUString > SAL_CALL getElementNames( )
override;
59 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override;
62 virtual Type SAL_CALL getElementType( )
override;
63 virtual sal_Bool SAL_CALL hasElements( )
override;
75 return getXWeak(
new NamespaceMap( pWhichIds, pPool ));
81 Sequence<OUString> aSupportedServiceNames {
"com.sun.star.xml.NamespaceMap" };
82 return aSupportedServiceNames;
88 return "com.sun.star.comp.Svx.NamespaceMap";
93 class NamespaceIteratorImpl
98 sal_uInt16* mpWhichId;
100 std::vector<const SvXMLAttrContainerItem*> mvItems;
104 sal_uInt16 mnCurrentAttr;
108 NamespaceIteratorImpl( sal_uInt16* pWhichIds,
SfxItemPool* pPool );
110 bool next( OUString& rPrefix, OUString& rURL );
116using namespace ::
svx;
119NamespaceIteratorImpl::NamespaceIteratorImpl( sal_uInt16* pWhichIds,
SfxItemPool* pPool )
122 mpCurrentAttr =
nullptr;
125 mpWhichId = pWhichIds;
128 if (mpWhichId && (0 != *mpWhichId) && mpPool)
130 mvItems.reserve(mpPool->GetItemCount2( *mpWhichId ));
131 for (
const SfxPoolItem* pItem : mpPool->GetItemSurrogates( *mpWhichId ))
136bool NamespaceIteratorImpl::next( OUString& rPrefix, OUString& rURL )
139 if( mpCurrentAttr && (mnCurrentAttr != USHRT_MAX) )
141 rPrefix = mpCurrentAttr->GetPrefix( mnCurrentAttr );
142 rURL = mpCurrentAttr->GetNamespace( mnCurrentAttr );
144 mnCurrentAttr = mpCurrentAttr->GetNextNamespaceIndex( mnCurrentAttr );
149 mpCurrentAttr =
nullptr;
153 if( mnItem ==
static_cast<sal_Int32
>(mvItems.size()) )
158 if( 0 == *mpWhichId )
165 mvItems.reserve(mpPool->GetItemCount2( *mpWhichId ));
166 for (
const SfxPoolItem* pItem2 : mpPool->GetItemSurrogates( *mpWhichId ))
169 return next( rPrefix, rURL );
172 auto pItem = mvItems[mnItem];
174 if( pItem->GetAttrCount() > 0 )
176 mpCurrentAttr = pItem;
177 mnCurrentAttr = pItem->GetFirstNamespaceIndex();
179 return next( rPrefix, rURL );
183NamespaceMap::NamespaceMap( sal_uInt16* pWhichIds,
SfxItemPool* pPool )
184: mpWhichIds( pWhichIds ), mpPool( pPool )
189Any SAL_CALL NamespaceMap::getByName(
const OUString& aName )
191 NamespaceIteratorImpl aIter( mpWhichIds, mpPool );
200 bFound = aIter.next( aPrefix, aURL );
202 while( bFound && (aPrefix != aName ) );
205 throw NoSuchElementException();
210Sequence< OUString > SAL_CALL NamespaceMap::getElementNames()
212 NamespaceIteratorImpl aIter( mpWhichIds, mpPool );
217 std::set< OUString > aPrefixSet;
219 while( aIter.next( aPrefix, aURL ) )
220 aPrefixSet.insert( aPrefix );
225sal_Bool SAL_CALL NamespaceMap::hasByName(
const OUString& aName )
227 NamespaceIteratorImpl aIter( mpWhichIds, mpPool );
236 bFound = aIter.next( aPrefix, aURL );
238 while( bFound && (aPrefix != aName ) );
244Type SAL_CALL NamespaceMap::getElementType()
246 return ::cppu::UnoType<OUString>::get();
249sal_Bool SAL_CALL NamespaceMap::hasElements()
251 NamespaceIteratorImpl aIter( mpWhichIds, mpPool );
256 return aIter.next( aPrefix, aURL );
260OUString SAL_CALL NamespaceMap::getImplementationName( )
265sal_Bool SAL_CALL NamespaceMap::supportsService(
const OUString& serviceName )
270Sequence< OUString > SAL_CALL NamespaceMap::getSupportedServiceNames( )
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static Sequence< OUString > NamespaceMap_getSupportedServiceNames() noexcept
static OUString NamespaceMap_getImplementationName() noexcept
Reference< XInterface > NamespaceMap_createInstance(sal_uInt16 *pWhichIds, SfxItemPool *pPool)