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
|
|
|
|
2006-09-17 09:20:30 +00:00
|
|
|
|
2012-08-04 12:00:20 +02:00
|
|
|
#include <string.h>
|
2000-11-22 17:04:58 +00:00
|
|
|
#include <vector>
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
2007-06-27 13:56:01 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2011-05-31 22:55:31 +01:00
|
|
|
#include <comphelper/servicehelper.hxx>
|
2016-06-10 19:34:05 +05:30
|
|
|
#include <cppuhelper/implbase.hxx>
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2007-06-27 13:56:01 +00:00
|
|
|
#include <xmloff/attrlist.hxx>
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2008-03-12 09:28:45 +00:00
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
using namespace ::com::sun::star;
|
2003-03-27 17:21:03 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 23:31:44 +00:00
|
|
|
|
|
|
|
struct SvXMLTagAttribute_Impl
|
|
|
|
{
|
2003-03-27 17:21:03 +00:00
|
|
|
SvXMLTagAttribute_Impl( const OUString &rName,
|
2001-06-26 06:26:50 +00:00
|
|
|
const OUString &rValue )
|
|
|
|
: sName(rName),
|
|
|
|
sValue(rValue)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-07-13 07:05:56 +00:00
|
|
|
SvXMLTagAttribute_Impl( const SvXMLTagAttribute_Impl& r ) :
|
|
|
|
sName(r.sName),
|
|
|
|
sValue(r.sValue)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
OUString sName;
|
|
|
|
OUString sValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SvXMLAttributeList_Impl
|
|
|
|
{
|
|
|
|
SvXMLAttributeList_Impl()
|
|
|
|
{
|
|
|
|
// performance improvement during adding
|
|
|
|
vecAttribute.reserve(20);
|
|
|
|
}
|
2004-07-13 07:05:56 +00:00
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
::std::vector<struct SvXMLTagAttribute_Impl> vecAttribute;
|
2004-07-13 07:05:56 +00:00
|
|
|
typedef ::std::vector<struct SvXMLTagAttribute_Impl>::size_type size_type;
|
2000-09-18 23:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
sal_Int16 SAL_CALL SvXMLAttributeList::getLength()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2006-10-12 13:38:51 +00:00
|
|
|
return sal::static_int_cast< sal_Int16 >(m_pImpl->vecAttribute.size());
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 07:05:56 +00:00
|
|
|
SvXMLAttributeList::SvXMLAttributeList( const SvXMLAttributeList &r ) :
|
2016-06-10 19:34:05 +05:30
|
|
|
cppu::WeakImplHelper<css::xml::sax::XAttributeList, css::util::XCloneable, css::lang::XUnoTunnel>(r),
|
2004-07-13 07:05:56 +00:00
|
|
|
m_pImpl( new SvXMLAttributeList_Impl( *r.m_pImpl ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLAttributeList::SvXMLAttributeList( const uno::Reference<
|
|
|
|
xml::sax::XAttributeList> & rAttrList )
|
2015-11-17 08:03:48 +02:00
|
|
|
: m_pImpl( new SvXMLAttributeList_Impl),
|
|
|
|
sType( GetXMLToken(XML_CDATA) )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2004-07-13 07:05:56 +00:00
|
|
|
|
|
|
|
SvXMLAttributeList* pImpl =
|
|
|
|
SvXMLAttributeList::getImplementation( rAttrList );
|
|
|
|
|
|
|
|
if( pImpl )
|
|
|
|
*m_pImpl = *(pImpl->m_pImpl);
|
|
|
|
else
|
|
|
|
AppendAttributeList( rAttrList );
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL SvXMLAttributeList::getNameByIndex(sal_Int16 i)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sName : OUString();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL SvXMLAttributeList::getTypeByIndex(sal_Int16)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2003-03-27 17:21:03 +00:00
|
|
|
return sType;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL SvXMLAttributeList::getValueByIndex(sal_Int16 i)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2009-04-23 10:42:05 +00:00
|
|
|
return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sValue : OUString();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL SvXMLAttributeList::getTypeByName( const OUString& )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2003-03-27 17:21:03 +00:00
|
|
|
return sType;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL SvXMLAttributeList::getValueByName(const OUString& sName)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2018-09-19 08:25:34 +03:00
|
|
|
auto ii = std::find_if(m_pImpl->vecAttribute.begin(), m_pImpl->vecAttribute.end(),
|
|
|
|
[&sName](struct SvXMLTagAttribute_Impl& rAttr) { return rAttr.sName == sName; });
|
|
|
|
|
|
|
|
if (ii != m_pImpl->vecAttribute.end())
|
|
|
|
return (*ii).sValue;
|
2000-09-18 23:31:44 +00:00
|
|
|
|
|
|
|
return OUString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
uno::Reference< css::util::XCloneable > SvXMLAttributeList::createClone()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2015-11-26 08:43:00 +02:00
|
|
|
uno::Reference< css::util::XCloneable > r = new SvXMLAttributeList( *this );
|
2000-09-18 23:31:44 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SvXMLAttributeList::SvXMLAttributeList()
|
2015-11-17 08:03:48 +02:00
|
|
|
: m_pImpl( new SvXMLAttributeList_Impl ),
|
|
|
|
sType( GetXMLToken(XML_CDATA) )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SvXMLAttributeList::~SvXMLAttributeList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SvXMLAttributeList::AddAttribute( const OUString &sName ,
|
|
|
|
const OUString &sValue )
|
|
|
|
{
|
2017-09-14 08:35:19 +02:00
|
|
|
m_pImpl->vecAttribute.emplace_back( sName , sValue );
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLAttributeList::Clear()
|
|
|
|
{
|
|
|
|
m_pImpl->vecAttribute.clear();
|
|
|
|
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( ! getLength() );
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 15:04:48 +02:00
|
|
|
void SvXMLAttributeList::RemoveAttribute( const OUString& sName )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2018-09-19 08:25:34 +03:00
|
|
|
auto ii = std::find_if(m_pImpl->vecAttribute.begin(), m_pImpl->vecAttribute.end(),
|
|
|
|
[&sName](struct SvXMLTagAttribute_Impl& rAttr) { return rAttr.sName == sName; });
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2018-09-19 08:25:34 +03:00
|
|
|
if (ii != m_pImpl->vecAttribute.end())
|
|
|
|
m_pImpl->vecAttribute.erase( ii );
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 08:43:00 +02:00
|
|
|
void SvXMLAttributeList::AppendAttributeList( const uno::Reference< css::xml::sax::XAttributeList > &r )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2017-05-07 17:03:35 +10:00
|
|
|
OSL_ASSERT( r.is() );
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2004-07-13 07:05:56 +00:00
|
|
|
sal_Int16 nMax = r->getLength();
|
|
|
|
SvXMLAttributeList_Impl::size_type nTotalSize =
|
|
|
|
m_pImpl->vecAttribute.size() + nMax;
|
2000-09-18 23:31:44 +00:00
|
|
|
m_pImpl->vecAttribute.reserve( nTotalSize );
|
|
|
|
|
2004-07-13 07:05:56 +00:00
|
|
|
for( sal_Int16 i = 0 ; i < nMax ; ++i ) {
|
2017-09-14 08:35:19 +02:00
|
|
|
m_pImpl->vecAttribute.emplace_back(
|
2000-09-18 23:31:44 +00:00
|
|
|
r->getNameByIndex( i ) ,
|
2017-09-14 08:35:19 +02:00
|
|
|
r->getValueByIndex( i ));
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 20:09:29 +01:00
|
|
|
OSL_ASSERT( nTotalSize == static_cast<SvXMLAttributeList_Impl::size_type>(getLength()));
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 07:05:56 +00:00
|
|
|
void SvXMLAttributeList::SetValueByIndex( sal_Int16 i,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rValue )
|
2004-07-13 07:05:56 +00:00
|
|
|
{
|
|
|
|
if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
|
|
|
|
< m_pImpl->vecAttribute.size() )
|
|
|
|
{
|
|
|
|
m_pImpl->vecAttribute[i].sValue = rValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLAttributeList::RemoveAttributeByIndex( sal_Int16 i )
|
|
|
|
{
|
2007-07-06 08:43:11 +00:00
|
|
|
if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
|
|
|
|
< m_pImpl->vecAttribute.size() )
|
|
|
|
m_pImpl->vecAttribute.erase( m_pImpl->vecAttribute.begin() + i );
|
2004-07-13 07:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLAttributeList::RenameAttributeByIndex( sal_Int16 i,
|
|
|
|
const OUString& rNewName )
|
|
|
|
{
|
|
|
|
if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
|
|
|
|
< m_pImpl->vecAttribute.size() )
|
|
|
|
{
|
|
|
|
m_pImpl->vecAttribute[i].sName = rNewName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int16 SvXMLAttributeList::GetIndexByName( const OUString& rName ) const
|
|
|
|
{
|
2018-09-19 08:25:34 +03:00
|
|
|
auto ii = std::find_if(m_pImpl->vecAttribute.begin(), m_pImpl->vecAttribute.end(),
|
|
|
|
[&rName](struct SvXMLTagAttribute_Impl& rAttr) { return rAttr.sName == rName; });
|
|
|
|
|
|
|
|
if (ii != m_pImpl->vecAttribute.end())
|
|
|
|
return static_cast<sal_Int16>(std::distance(m_pImpl->vecAttribute.begin(), ii));
|
2004-07-13 07:05:56 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-31 22:55:31 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class theSvXMLAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLAttributeListUnoTunnelId> {};
|
|
|
|
}
|
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
// XUnoTunnel & co
|
|
|
|
const uno::Sequence< sal_Int8 > & SvXMLAttributeList::getUnoTunnelId() throw()
|
|
|
|
{
|
2011-05-31 22:55:31 +01:00
|
|
|
return theSvXMLAttributeListUnoTunnelId::get().getSeq();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 16:05:03 +02:00
|
|
|
SvXMLAttributeList* SvXMLAttributeList::getImplementation( const uno::Reference< uno::XInterface >& xInt ) throw()
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
|
|
|
|
if( xUT.is() )
|
2006-06-19 17:04:59 +00:00
|
|
|
{
|
|
|
|
return
|
|
|
|
reinterpret_cast<SvXMLAttributeList*>(
|
|
|
|
sal::static_int_cast<sal_IntPtr>(
|
|
|
|
xUT->getSomething( SvXMLAttributeList::getUnoTunnelId())));
|
|
|
|
}
|
2000-09-18 23:31:44 +00:00
|
|
|
else
|
2015-11-10 10:29:15 +01:00
|
|
|
return nullptr;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XUnoTunnel
|
|
|
|
sal_Int64 SAL_CALL SvXMLAttributeList::getSomething( const uno::Sequence< sal_Int8 >& rId )
|
|
|
|
{
|
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:04:59 +00:00
|
|
|
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|