2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2012-08-04 12:00:20 +02:00
|
|
|
#include <string.h>
|
2000-09-18 23:31:44 +00:00
|
|
|
#include <com/sun/star/xml/AttributeData.hpp>
|
2016-06-02 15:06:06 +02:00
|
|
|
#include <o3tl/any.hxx>
|
2016-09-09 14:55:12 +02:00
|
|
|
#include <o3tl/make_unique.hxx>
|
2000-09-18 23:31:44 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2011-05-31 22:55:31 +01:00
|
|
|
#include <comphelper/servicehelper.hxx>
|
2013-09-25 15:41:29 -03:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2011-08-10 15:14:10 +01:00
|
|
|
#include <limits.h>
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2007-06-27 13:56:37 +00:00
|
|
|
#include <xmloff/xmlcnimp.hxx>
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2013-11-11 22:30:35 -06:00
|
|
|
#include <xmloff/unoatrcn.hxx>
|
2000-09-18 23:31:44 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
// Interface implementation
|
|
|
|
|
|
|
|
uno::Reference< uno::XInterface > SvUnoAttributeContainer_CreateInstance()
|
|
|
|
{
|
|
|
|
return *(new SvUnoAttributeContainer);
|
|
|
|
}
|
|
|
|
|
2016-09-09 14:55:12 +02:00
|
|
|
SvUnoAttributeContainer::SvUnoAttributeContainer( std::unique_ptr<SvXMLAttrContainerData> pContainer)
|
|
|
|
: mpContainer( std::move( pContainer ) )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2016-09-09 14:55:12 +02:00
|
|
|
if( !mpContainer )
|
|
|
|
mpContainer = o3tl::make_unique<SvXMLAttrContainerData>();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// container::XElementAccess
|
2015-04-14 12:44:47 +02:00
|
|
|
uno::Type SAL_CALL SvUnoAttributeContainer::getElementType()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2014-05-20 23:29:28 +02:00
|
|
|
return cppu::UnoType<xml::AttributeData>::get();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
sal_Bool SAL_CALL SvUnoAttributeContainer::hasElements()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2006-10-12 13:39:04 +00:00
|
|
|
return mpContainer->GetAttrCount() != 0;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt16 SvUnoAttributeContainer::getIndexByName(const OUString& aName ) const
|
|
|
|
{
|
|
|
|
const sal_uInt16 nAttrCount = mpContainer->GetAttrCount();
|
|
|
|
|
2013-11-13 12:10:31 +02:00
|
|
|
sal_Int32 nPos = aName.indexOf( ':' );
|
2000-09-18 23:31:44 +00:00
|
|
|
if( nPos == -1L )
|
|
|
|
{
|
|
|
|
for( sal_uInt16 nAttr = 0; nAttr < nAttrCount; nAttr++ )
|
|
|
|
{
|
|
|
|
if( mpContainer->GetAttrLName(nAttr) == aName &&
|
2012-01-25 17:00:07 -02:00
|
|
|
mpContainer->GetAttrPrefix(nAttr).isEmpty() )
|
2000-09-18 23:31:44 +00:00
|
|
|
return nAttr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const OUString aPrefix( aName.copy( 0L, nPos ) );
|
|
|
|
const OUString aLName( aName.copy( nPos+1L ) );
|
|
|
|
|
|
|
|
for( sal_uInt16 nAttr = 0; nAttr < nAttrCount; nAttr++ )
|
|
|
|
{
|
|
|
|
if( mpContainer->GetAttrLName(nAttr) == aLName &&
|
|
|
|
mpContainer->GetAttrPrefix(nAttr) == aPrefix )
|
|
|
|
return nAttr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return USHRT_MAX;
|
|
|
|
}
|
|
|
|
|
2011-05-31 22:55:31 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class theSvUnoAttributeContainerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvUnoAttributeContainerUnoTunnelId> {};
|
|
|
|
}
|
|
|
|
|
2015-11-26 08:43:00 +02:00
|
|
|
const css::uno::Sequence< sal_Int8 > & SvUnoAttributeContainer::getUnoTunnelId() throw()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2011-05-31 22:55:31 +01:00
|
|
|
return theSvUnoAttributeContainerUnoTunnelId::get().getSeq();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
sal_Int64 SAL_CALL SvUnoAttributeContainer::getSomething( const css::uno::Sequence< sal_Int8 >& rId )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2012-08-04 12:00:20 +02:00
|
|
|
if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
|
2000-09-18 23:31:44 +00:00
|
|
|
rId.getConstArray(), 16 ) )
|
|
|
|
{
|
2006-06-19 17:05:36 +00:00
|
|
|
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// container::XNameAccess
|
|
|
|
uno::Any SAL_CALL SvUnoAttributeContainer::getByName(const OUString& aName)
|
|
|
|
{
|
|
|
|
sal_uInt16 nAttr = getIndexByName(aName );
|
|
|
|
|
|
|
|
if( nAttr == USHRT_MAX )
|
|
|
|
throw container::NoSuchElementException();
|
|
|
|
|
|
|
|
xml::AttributeData aData;
|
|
|
|
aData.Namespace = mpContainer->GetAttrNamespace(nAttr);
|
2013-11-04 14:00:40 +02:00
|
|
|
aData.Type = "CDATA";
|
2000-09-18 23:31:44 +00:00
|
|
|
aData.Value = mpContainer->GetAttrValue(nAttr);
|
|
|
|
|
2016-05-03 08:39:03 +02:00
|
|
|
return uno::Any(aData);
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
uno::Sequence< OUString > SAL_CALL SvUnoAttributeContainer::getElementNames()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
const sal_uInt16 nAttrCount = mpContainer->GetAttrCount();
|
|
|
|
|
|
|
|
uno::Sequence< OUString > aElementNames( (sal_Int32)nAttrCount );
|
|
|
|
OUString *pNames = aElementNames.getArray();
|
|
|
|
|
|
|
|
for( sal_uInt16 nAttr = 0; nAttr < nAttrCount; nAttr++ )
|
|
|
|
{
|
|
|
|
OUStringBuffer sBuffer( mpContainer->GetAttrPrefix(nAttr) );
|
2013-06-18 19:53:19 +02:00
|
|
|
if( !sBuffer.isEmpty() )
|
2013-11-13 12:10:31 +02:00
|
|
|
sBuffer.append( ':' );
|
2000-09-18 23:31:44 +00:00
|
|
|
sBuffer.append( mpContainer->GetAttrLName(nAttr) );
|
|
|
|
*pNames++ = sBuffer.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aElementNames;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
sal_Bool SAL_CALL SvUnoAttributeContainer::hasByName(const OUString& aName)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
return getIndexByName(aName ) != USHRT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
// container::XNameReplace
|
|
|
|
void SAL_CALL SvUnoAttributeContainer::replaceByName(const OUString& aName, const uno::Any& aElement)
|
|
|
|
{
|
2016-06-10 15:52:05 +02:00
|
|
|
if( auto pData = o3tl::tryAccess<xml::AttributeData>(aElement) )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
sal_uInt16 nAttr = getIndexByName(aName );
|
|
|
|
if( nAttr == USHRT_MAX )
|
|
|
|
throw container::NoSuchElementException();
|
|
|
|
|
2013-11-13 12:10:31 +02:00
|
|
|
sal_Int32 nPos = aName.indexOf( ':' );
|
2000-09-18 23:31:44 +00:00
|
|
|
if( nPos != -1L )
|
|
|
|
{
|
|
|
|
const OUString aPrefix( aName.copy( 0L, nPos ));
|
|
|
|
const OUString aLName( aName.copy( nPos+1L ));
|
|
|
|
|
2012-01-25 17:00:07 -02:00
|
|
|
if( pData->Namespace.isEmpty() )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
if( mpContainer->SetAt( nAttr, aPrefix, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( mpContainer->SetAt( nAttr, aPrefix, pData->Namespace, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-25 17:00:07 -02:00
|
|
|
if( pData->Namespace.isEmpty() )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
if( mpContainer->SetAt( nAttr, aName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw lang::IllegalArgumentException();
|
|
|
|
}
|
|
|
|
|
|
|
|
// container::XNameContainer
|
|
|
|
void SAL_CALL SvUnoAttributeContainer::insertByName(const OUString& aName, const uno::Any& aElement)
|
|
|
|
{
|
2016-06-10 15:52:05 +02:00
|
|
|
auto pData = o3tl::tryAccess<xml::AttributeData>(aElement);
|
2016-06-02 15:06:06 +02:00
|
|
|
if( !pData )
|
2000-09-18 23:31:44 +00:00
|
|
|
throw lang::IllegalArgumentException();
|
|
|
|
|
|
|
|
sal_uInt16 nAttr = getIndexByName(aName );
|
|
|
|
if( nAttr != USHRT_MAX )
|
|
|
|
throw container::ElementExistException();
|
|
|
|
|
2013-11-13 12:10:31 +02:00
|
|
|
sal_Int32 nPos = aName.indexOf( ':' );
|
2000-09-18 23:31:44 +00:00
|
|
|
if( nPos != -1L )
|
|
|
|
{
|
|
|
|
const OUString aPrefix( aName.copy( 0L, nPos ));
|
|
|
|
const OUString aLName( aName.copy( nPos+1L ));
|
|
|
|
|
2012-01-25 17:00:07 -02:00
|
|
|
if( pData->Namespace.isEmpty() )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
if( mpContainer->AddAttr( aPrefix, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( mpContainer->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-25 17:00:07 -02:00
|
|
|
if( pData->Namespace.isEmpty() )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
if( mpContainer->AddAttr( aName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL SvUnoAttributeContainer::removeByName(const OUString& Name)
|
|
|
|
{
|
|
|
|
sal_uInt16 nAttr = getIndexByName(Name);
|
|
|
|
if( nAttr == USHRT_MAX )
|
|
|
|
throw container::NoSuchElementException();
|
|
|
|
|
|
|
|
mpContainer->Remove( nAttr );
|
|
|
|
}
|
|
|
|
|
|
|
|
//XServiceInfo
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL SvUnoAttributeContainer::getImplementationName()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2012-06-02 08:58:21 -05:00
|
|
|
return OUString( "SvUnoAttributeContainer" );
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
uno::Sequence< OUString > SvUnoAttributeContainer::getSupportedServiceNames()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2013-12-13 10:54:12 +02:00
|
|
|
OUString aSN( "com.sun.star.xml.AttributeContainer" );
|
2000-09-18 23:31:44 +00:00
|
|
|
uno::Sequence< OUString > aNS( &aSN, 1L );
|
|
|
|
return aNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SvUnoAttributeContainer::supportsService(const OUString& ServiceName)
|
|
|
|
{
|
2013-09-25 15:41:29 -03:00
|
|
|
return cppu::supportsService(this, ServiceName);
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|