1*190118d0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*190118d0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*190118d0SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*190118d0SAndrew Rist * distributed with this work for additional information 6*190118d0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*190118d0SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*190118d0SAndrew Rist * "License"); you may not use this file except in compliance 9*190118d0SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*190118d0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*190118d0SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*190118d0SAndrew Rist * software distributed under the License is distributed on an 15*190118d0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*190118d0SAndrew Rist * KIND, either express or implied. See the License for the 17*190118d0SAndrew Rist * specific language governing permissions and limitations 18*190118d0SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*190118d0SAndrew Rist *************************************************************/ 21*190118d0SAndrew Rist 22*190118d0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_editeng.hxx" 26cdf0e10cSrcweir #include <com/sun/star/xml/AttributeData.hpp> 27cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 28cdf0e10cSrcweir #include <xmloff/xmlcnimp.hxx> 29cdf0e10cSrcweir #include <xmloff/unoatrcn.hxx> 30cdf0e10cSrcweir #include <editeng/xmlcnitm.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir using namespace ::com::sun::star::uno; 33cdf0e10cSrcweir using namespace ::com::sun::star::container; 34cdf0e10cSrcweir using namespace ::com::sun::star::lang; 35cdf0e10cSrcweir using namespace ::com::sun::star::xml; 36cdf0e10cSrcweir 37cdf0e10cSrcweir // ------------------------------------------------------------------------ 38cdf0e10cSrcweir 39cdf0e10cSrcweir TYPEINIT1(SvXMLAttrContainerItem, SfxPoolItem); 40cdf0e10cSrcweir 41cdf0e10cSrcweir SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) : 42cdf0e10cSrcweir SfxPoolItem( _nWhich ) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir pImpl = new SvXMLAttrContainerData; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir SvXMLAttrContainerItem::SvXMLAttrContainerItem( 48cdf0e10cSrcweir const SvXMLAttrContainerItem& rItem ) : 49cdf0e10cSrcweir SfxPoolItem( rItem ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir pImpl = new SvXMLAttrContainerData( *rItem.pImpl ); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir SvXMLAttrContainerItem::~SvXMLAttrContainerItem() 55cdf0e10cSrcweir { 56cdf0e10cSrcweir delete pImpl; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir int SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const 60cdf0e10cSrcweir { 61cdf0e10cSrcweir DBG_ASSERT( rItem.ISA(SvXMLAttrContainerItem), 62cdf0e10cSrcweir "SvXMLAttrContainerItem::operator ==(): Bad type"); 63cdf0e10cSrcweir return *pImpl == *((const SvXMLAttrContainerItem&)rItem).pImpl; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir int SvXMLAttrContainerItem::Compare( const SfxPoolItem &/*rWith*/ ) const 67cdf0e10cSrcweir { 68cdf0e10cSrcweir DBG_ASSERT( !this, "not yet implemented" ); 69cdf0e10cSrcweir 70cdf0e10cSrcweir return 0; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir SfxItemPresentation SvXMLAttrContainerItem::GetPresentation( 74cdf0e10cSrcweir SfxItemPresentation /*ePresentation*/, 75cdf0e10cSrcweir SfxMapUnit /*eCoreMetric*/, 76cdf0e10cSrcweir SfxMapUnit /*ePresentationMetric*/, 77cdf0e10cSrcweir XubString &/*rText*/, 78cdf0e10cSrcweir const IntlWrapper * /*pIntlWrapper*/ ) const 79cdf0e10cSrcweir { 80cdf0e10cSrcweir return SFX_ITEM_PRESENTATION_NONE; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir sal_uInt16 SvXMLAttrContainerItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const 84cdf0e10cSrcweir { 85cdf0e10cSrcweir // This item should never be stored 86cdf0e10cSrcweir return USHRT_MAX; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir sal_Bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const 90cdf0e10cSrcweir { 91cdf0e10cSrcweir Reference<XNameContainer> xContainer = 92cdf0e10cSrcweir new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl ) ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir rVal.setValue( &xContainer, ::getCppuType((Reference<XNameContainer>*)0) ); 95cdf0e10cSrcweir return sal_True; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir sal_Bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir Reference<XInterface> xRef; 100cdf0e10cSrcweir SvUnoAttributeContainer* pContainer = NULL; 101cdf0e10cSrcweir 102cdf0e10cSrcweir if( rVal.getValue() != NULL && rVal.getValueType().getTypeClass() == TypeClass_INTERFACE ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir xRef = *(Reference<XInterface>*)rVal.getValue(); 105cdf0e10cSrcweir Reference<XUnoTunnel> xTunnel(xRef, UNO_QUERY); 106cdf0e10cSrcweir if( xTunnel.is() ) 107cdf0e10cSrcweir pContainer = (SvUnoAttributeContainer*)(sal_uLong)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId()); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir if( pContainer ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir delete pImpl; 113cdf0e10cSrcweir pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir else 116cdf0e10cSrcweir { 117cdf0e10cSrcweir SvXMLAttrContainerData* pNewImpl = new SvXMLAttrContainerData; 118cdf0e10cSrcweir 119cdf0e10cSrcweir try 120cdf0e10cSrcweir { 121cdf0e10cSrcweir Reference<XNameContainer> xContainer( xRef, UNO_QUERY ); 122cdf0e10cSrcweir if( !xContainer.is() ) 123cdf0e10cSrcweir return sal_False; 124cdf0e10cSrcweir 125cdf0e10cSrcweir const Sequence< ::rtl::OUString > aNameSequence( xContainer->getElementNames() ); 126cdf0e10cSrcweir const ::rtl::OUString* pNames = aNameSequence.getConstArray(); 127cdf0e10cSrcweir const sal_Int32 nCount = aNameSequence.getLength(); 128cdf0e10cSrcweir Any aAny; 129cdf0e10cSrcweir AttributeData* pData; 130cdf0e10cSrcweir sal_Int32 nAttr; 131cdf0e10cSrcweir 132cdf0e10cSrcweir for( nAttr = 0; nAttr < nCount; nAttr++ ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir const ::rtl::OUString aName( *pNames++ ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir aAny = xContainer->getByName( aName ); 137cdf0e10cSrcweir if( aAny.getValue() == NULL || aAny.getValueType() != ::getCppuType((AttributeData*)0) ) 138cdf0e10cSrcweir return sal_False; 139cdf0e10cSrcweir 140cdf0e10cSrcweir pData = (AttributeData*)aAny.getValue(); 141cdf0e10cSrcweir sal_Int32 pos = aName.indexOf( sal_Unicode(':') ); 142cdf0e10cSrcweir if( pos != -1 ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir const ::rtl::OUString aPrefix( aName.copy( 0, pos )); 145cdf0e10cSrcweir const ::rtl::OUString aLName( aName.copy( pos+1 )); 146cdf0e10cSrcweir 147cdf0e10cSrcweir if( pData->Namespace.getLength() == 0 ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir if( !pNewImpl->AddAttr( aPrefix, aLName, pData->Value ) ) 150cdf0e10cSrcweir break; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir else 153cdf0e10cSrcweir { 154cdf0e10cSrcweir if( !pNewImpl->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) ) 155cdf0e10cSrcweir break; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir else 159cdf0e10cSrcweir { 160cdf0e10cSrcweir if( !pNewImpl->AddAttr( aName, pData->Value ) ) 161cdf0e10cSrcweir break; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir if( nAttr == nCount ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir delete pImpl; 168cdf0e10cSrcweir pImpl = pNewImpl; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir else 171cdf0e10cSrcweir { 172cdf0e10cSrcweir delete pNewImpl; 173cdf0e10cSrcweir return sal_False; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir catch(...) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir delete pNewImpl; 179cdf0e10cSrcweir return sal_False; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir return sal_True; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rLName, 187cdf0e10cSrcweir const ::rtl::OUString& rValue ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir return pImpl->AddAttr( rLName, rValue ); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rPrefix, 193cdf0e10cSrcweir const ::rtl::OUString& rNamespace, const ::rtl::OUString& rLName, 194cdf0e10cSrcweir const ::rtl::OUString& rValue ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir return pImpl->AddAttr( rPrefix, rNamespace, rLName, rValue ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const 200cdf0e10cSrcweir { 201cdf0e10cSrcweir return (sal_uInt16)pImpl->GetAttrCount(); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir ::rtl::OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const 205cdf0e10cSrcweir { 206cdf0e10cSrcweir return pImpl->GetAttrNamespace( i ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir ::rtl::OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const 210cdf0e10cSrcweir { 211cdf0e10cSrcweir return pImpl->GetAttrPrefix( i ); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const 215cdf0e10cSrcweir { 216cdf0e10cSrcweir return pImpl->GetAttrLName( i ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const 220cdf0e10cSrcweir { 221cdf0e10cSrcweir return pImpl->GetAttrValue( i ); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const 226cdf0e10cSrcweir { 227cdf0e10cSrcweir return pImpl->GetFirstNamespaceIndex(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const 231cdf0e10cSrcweir { 232cdf0e10cSrcweir return pImpl->GetNextNamespaceIndex( nIdx ); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir const ::rtl::OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const 236cdf0e10cSrcweir { 237cdf0e10cSrcweir return pImpl->GetNamespace( i ); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir const ::rtl::OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const 241cdf0e10cSrcweir { 242cdf0e10cSrcweir return pImpl->GetPrefix( i ); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245