2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 23:31:44 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 20:37:46 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
2008-04-10 20:37:46 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
2008-04-10 20:37:46 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
2008-04-10 20:37:46 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
2008-04-10 20:37:46 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
2008-04-10 20:37:46 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 23:31:44 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <com/sun/star/xml/AttributeData.hpp>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#include <rtl/memory.h>
|
2011-05-31 22:55:31 +01:00
|
|
|
#include <comphelper/servicehelper.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
|
|
|
|
2010-04-16 23:04:00 +02:00
|
|
|
#include "xmloff/unoatrcn.hxx"
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2008-03-12 09:28:58 +00:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
// Interface implementation
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define IMPL ((AttrContainerImpl*)mpData)
|
|
|
|
|
|
|
|
uno::Reference< uno::XInterface > SvUnoAttributeContainer_CreateInstance()
|
|
|
|
{
|
|
|
|
return *(new SvUnoAttributeContainer);
|
|
|
|
}
|
|
|
|
|
2001-07-04 12:36:04 +00:00
|
|
|
SvUnoAttributeContainer::SvUnoAttributeContainer( SvXMLAttrContainerData* pContainer)
|
2000-09-18 23:31:44 +00:00
|
|
|
: mpContainer( pContainer )
|
|
|
|
{
|
|
|
|
if( mpContainer == NULL )
|
2001-07-04 12:36:04 +00:00
|
|
|
mpContainer = new SvXMLAttrContainerData;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SvUnoAttributeContainer::~SvUnoAttributeContainer()
|
|
|
|
{
|
|
|
|
delete mpContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
// container::XElementAccess
|
|
|
|
uno::Type SAL_CALL SvUnoAttributeContainer::getElementType(void)
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
return ::getCppuType((const xml::AttributeData*)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SvUnoAttributeContainer::hasElements(void)
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
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();
|
|
|
|
|
|
|
|
sal_Int32 nPos = aName.indexOf( sal_Unicode(':') );
|
|
|
|
if( nPos == -1L )
|
|
|
|
{
|
|
|
|
for( sal_uInt16 nAttr = 0; nAttr < nAttrCount; nAttr++ )
|
|
|
|
{
|
|
|
|
if( mpContainer->GetAttrLName(nAttr) == aName &&
|
|
|
|
mpContainer->GetAttrPrefix(nAttr).getLength() == 0L )
|
|
|
|
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> {};
|
|
|
|
}
|
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
const ::com::sun::star::uno::Sequence< sal_Int8 > & SvUnoAttributeContainer::getUnoTunnelId() throw()
|
|
|
|
{
|
2011-05-31 22:55:31 +01:00
|
|
|
return theSvUnoAttributeContainerUnoTunnelId::get().getSeq();
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SvUnoAttributeContainer* SvUnoAttributeContainer::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
|
|
|
|
{
|
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xInt, ::com::sun::star::uno::UNO_QUERY );
|
|
|
|
if( xUT.is() )
|
2006-06-19 17:05:36 +00:00
|
|
|
{
|
|
|
|
return
|
|
|
|
reinterpret_cast<SvUnoAttributeContainer*>(
|
|
|
|
sal::static_int_cast<sal_IntPtr>(
|
|
|
|
xUT->getSomething( SvUnoAttributeContainer::getUnoTunnelId())));
|
|
|
|
}
|
2000-09-18 23:31:44 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int64 SAL_CALL SvUnoAttributeContainer::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
|
|
|
|
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)
|
|
|
|
throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
sal_uInt16 nAttr = getIndexByName(aName );
|
|
|
|
|
|
|
|
if( nAttr == USHRT_MAX )
|
|
|
|
throw container::NoSuchElementException();
|
|
|
|
|
|
|
|
xml::AttributeData aData;
|
|
|
|
aData.Namespace = mpContainer->GetAttrNamespace(nAttr);
|
2010-11-09 17:15:52 +00:00
|
|
|
aData.Type = OUString(RTL_CONSTASCII_USTRINGPARAM("CDATA"));
|
2000-09-18 23:31:44 +00:00
|
|
|
aData.Value = mpContainer->GetAttrValue(nAttr);
|
|
|
|
|
|
|
|
uno::Any aAny;
|
|
|
|
aAny <<= aData;
|
|
|
|
return aAny;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< OUString > SAL_CALL SvUnoAttributeContainer::getElementNames(void) throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
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) );
|
|
|
|
if( sBuffer.getLength() != 0L )
|
|
|
|
sBuffer.append( (sal_Unicode)':' );
|
|
|
|
sBuffer.append( mpContainer->GetAttrLName(nAttr) );
|
|
|
|
*pNames++ = sBuffer.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aElementNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SvUnoAttributeContainer::hasByName(const OUString& aName) throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
return getIndexByName(aName ) != USHRT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
// container::XNameReplace
|
|
|
|
void SAL_CALL SvUnoAttributeContainer::replaceByName(const OUString& aName, const uno::Any& aElement)
|
|
|
|
throw( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
if( aElement.hasValue() && aElement.getValueType() == ::getCppuType((const xml::AttributeData*)0) )
|
|
|
|
{
|
|
|
|
sal_uInt16 nAttr = getIndexByName(aName );
|
|
|
|
if( nAttr == USHRT_MAX )
|
|
|
|
throw container::NoSuchElementException();
|
|
|
|
|
|
|
|
xml::AttributeData* pData = (xml::AttributeData*)aElement.getValue();
|
|
|
|
|
|
|
|
sal_Int32 nPos = aName.indexOf( sal_Unicode(':') );
|
|
|
|
if( nPos != -1L )
|
|
|
|
{
|
|
|
|
const OUString aPrefix( aName.copy( 0L, nPos ));
|
|
|
|
const OUString aLName( aName.copy( nPos+1L ));
|
|
|
|
|
|
|
|
if( pData->Namespace.getLength() == 0L )
|
|
|
|
{
|
|
|
|
if( mpContainer->SetAt( nAttr, aPrefix, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( mpContainer->SetAt( nAttr, aPrefix, pData->Namespace, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( pData->Namespace.getLength() == 0L )
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
throw( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
if( !aElement.hasValue() || aElement.getValueType() != ::getCppuType((const xml::AttributeData*)0) )
|
|
|
|
throw lang::IllegalArgumentException();
|
|
|
|
|
|
|
|
sal_uInt16 nAttr = getIndexByName(aName );
|
|
|
|
if( nAttr != USHRT_MAX )
|
|
|
|
throw container::ElementExistException();
|
|
|
|
|
|
|
|
xml::AttributeData* pData = (xml::AttributeData*)aElement.getValue();
|
|
|
|
|
|
|
|
sal_Int32 nPos = aName.indexOf( sal_Unicode(':') );
|
|
|
|
if( nPos != -1L )
|
|
|
|
{
|
|
|
|
const OUString aPrefix( aName.copy( 0L, nPos ));
|
|
|
|
const OUString aLName( aName.copy( nPos+1L ));
|
|
|
|
|
|
|
|
if( pData->Namespace.getLength() == 0L )
|
|
|
|
{
|
|
|
|
if( mpContainer->AddAttr( aPrefix, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( mpContainer->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( pData->Namespace.getLength() == 0L )
|
|
|
|
{
|
|
|
|
if( mpContainer->AddAttr( aName, pData->Value ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL SvUnoAttributeContainer::removeByName(const OUString& Name)
|
|
|
|
throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
|
|
|
|
{
|
|
|
|
sal_uInt16 nAttr = getIndexByName(Name);
|
|
|
|
if( nAttr == USHRT_MAX )
|
|
|
|
throw container::NoSuchElementException();
|
|
|
|
|
|
|
|
mpContainer->Remove( nAttr );
|
|
|
|
}
|
|
|
|
|
|
|
|
//XServiceInfo
|
|
|
|
OUString SAL_CALL SvUnoAttributeContainer::getImplementationName(void) throw( uno::RuntimeException )
|
|
|
|
{
|
2010-11-09 17:15:52 +00:00
|
|
|
return OUString(RTL_CONSTASCII_USTRINGPARAM( "SvUnoAttributeContainer" ));
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence< OUString > SvUnoAttributeContainer::getSupportedServiceNames(void)
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
2010-11-09 17:15:52 +00:00
|
|
|
OUString aSN( OUString(RTL_CONSTASCII_USTRINGPARAM( "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)
|
|
|
|
throw( uno::RuntimeException )
|
|
|
|
{
|
|
|
|
const uno::Sequence < OUString > aServiceNames( getSupportedServiceNames() );
|
|
|
|
const OUString* pNames = aServiceNames.getConstArray();
|
|
|
|
sal_Int32 nCount = aServiceNames.getLength();
|
|
|
|
while( nCount-- )
|
|
|
|
{
|
|
|
|
if( *pNames++ == ServiceName )
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|