1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <com/sun/star/xml/AttributeData.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <xmloff/xmlcnimp.hxx> 31cdf0e10cSrcweir #include "xmloff/unoatrcn.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace rtl; 34cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35cdf0e10cSrcweir using namespace ::com::sun::star::container; 36cdf0e10cSrcweir using namespace ::com::sun::star::lang; 37cdf0e10cSrcweir using namespace ::com::sun::star::xml; 38cdf0e10cSrcweir 39cdf0e10cSrcweir typedef ::rtl::OUString *OUStringPtr; 40cdf0e10cSrcweir SV_DECL_PTRARR_DEL( SvXMLAttrContainerData_Impl, OUStringPtr, 5, 5 ) 41cdf0e10cSrcweir SV_IMPL_PTRARR( SvXMLAttrContainerData_Impl, OUStringPtr ) 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir SvXMLAttrContainerData::SvXMLAttrContainerData( 45cdf0e10cSrcweir const SvXMLAttrContainerData& rImpl ) : 46cdf0e10cSrcweir aNamespaceMap( rImpl.aNamespaceMap ), 47cdf0e10cSrcweir pLNames( new SvXMLAttrContainerData_Impl ), 48cdf0e10cSrcweir pValues( new SvXMLAttrContainerData_Impl ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir sal_uInt16 nCount = rImpl.pLNames->Count(); 51cdf0e10cSrcweir for( sal_uInt16 i=0; i<nCount; i++ ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir aPrefixPoss.Insert( rImpl.aPrefixPoss[i], i ); 54cdf0e10cSrcweir pLNames->Insert( new OUString( *(*rImpl.pLNames)[i] ), i ); 55cdf0e10cSrcweir pValues->Insert( new OUString( *(*rImpl.pValues)[i] ), i ); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir SvXMLAttrContainerData::SvXMLAttrContainerData() : 60cdf0e10cSrcweir pLNames( new SvXMLAttrContainerData_Impl ), 61cdf0e10cSrcweir pValues( new SvXMLAttrContainerData_Impl ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir SvXMLAttrContainerData::~SvXMLAttrContainerData() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir delete pLNames; 68cdf0e10cSrcweir delete pValues; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir int SvXMLAttrContainerData::operator ==( 72cdf0e10cSrcweir const SvXMLAttrContainerData& rCmp ) const 73cdf0e10cSrcweir { 74cdf0e10cSrcweir sal_Bool bRet = pLNames->Count() == rCmp.pLNames->Count() && 75cdf0e10cSrcweir aNamespaceMap == rCmp.aNamespaceMap; 76cdf0e10cSrcweir if( bRet ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir sal_uInt16 nCount = pLNames->Count(); 79cdf0e10cSrcweir sal_uInt16 i; 80cdf0e10cSrcweir for( i=0; bRet && i < nCount; i++ ) 81cdf0e10cSrcweir bRet = aPrefixPoss[i] == rCmp.aPrefixPoss[i]; 82cdf0e10cSrcweir 83cdf0e10cSrcweir if( bRet ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir for( i=0; bRet && i < nCount; i++ ) 86cdf0e10cSrcweir bRet = *(*pLNames)[i] == *(*rCmp.pLNames)[i] && 87cdf0e10cSrcweir *(*pValues)[i] == *(*rCmp.pValues)[i]; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir return (int)bRet; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir sal_Bool SvXMLAttrContainerData::AddAttr( const OUString& rLName, 95cdf0e10cSrcweir const OUString& rValue ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir aPrefixPoss.Insert( USHRT_MAX, aPrefixPoss.Count() ); 98cdf0e10cSrcweir pLNames->Insert( new OUString(rLName), pLNames->Count() ); 99cdf0e10cSrcweir pValues->Insert( new OUString(rValue), pValues->Count() ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir return sal_True; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir sal_Bool SvXMLAttrContainerData::AddAttr( const OUString& rPrefix, 105cdf0e10cSrcweir const OUString& rNamespace, 106cdf0e10cSrcweir const OUString& rLName, 107cdf0e10cSrcweir const OUString& rValue ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace ); 110cdf0e10cSrcweir aPrefixPoss.Insert( nPos, aPrefixPoss.Count() ); 111cdf0e10cSrcweir pLNames->Insert( new OUString(rLName), pLNames->Count() ); 112cdf0e10cSrcweir pValues->Insert( new OUString(rValue), pValues->Count() ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir return sal_True; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir sal_Bool SvXMLAttrContainerData::AddAttr( const OUString& rPrefix, 118cdf0e10cSrcweir const OUString& rLName, 119cdf0e10cSrcweir const OUString& rValue ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix ); 122cdf0e10cSrcweir if( USHRT_MAX == nPos ) 123cdf0e10cSrcweir return sal_False; 124cdf0e10cSrcweir 125cdf0e10cSrcweir aPrefixPoss.Insert( nPos, aPrefixPoss.Count() ); 126cdf0e10cSrcweir pLNames->Insert( new OUString(rLName), pLNames->Count() ); 127cdf0e10cSrcweir pValues->Insert( new OUString(rValue), pValues->Count() ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir return sal_True; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir sal_Bool SvXMLAttrContainerData::SetAt( sal_uInt16 i, 133cdf0e10cSrcweir const rtl::OUString& rLName, const rtl::OUString& rValue ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir if( i >= GetAttrCount() ) 136cdf0e10cSrcweir return sal_False; 137cdf0e10cSrcweir 138cdf0e10cSrcweir *(*pLNames)[i] = rLName; 139cdf0e10cSrcweir *(*pValues)[i] = rValue; 140cdf0e10cSrcweir aPrefixPoss[i] = USHRT_MAX; 141cdf0e10cSrcweir 142cdf0e10cSrcweir return sal_True; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir sal_Bool SvXMLAttrContainerData::SetAt( sal_uInt16 i, 146cdf0e10cSrcweir const rtl::OUString& rPrefix, const rtl::OUString& rNamespace, 147cdf0e10cSrcweir const rtl::OUString& rLName, const rtl::OUString& rValue ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir if( i >= GetAttrCount() ) 150cdf0e10cSrcweir return sal_False; 151cdf0e10cSrcweir 152cdf0e10cSrcweir sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace ); 153cdf0e10cSrcweir if( USHRT_MAX == nPos ) 154cdf0e10cSrcweir return sal_False; 155cdf0e10cSrcweir 156cdf0e10cSrcweir *(*pLNames)[i] = rLName; 157cdf0e10cSrcweir *(*pValues)[i] = rValue; 158cdf0e10cSrcweir aPrefixPoss[i] = nPos; 159cdf0e10cSrcweir 160cdf0e10cSrcweir return sal_True; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir sal_Bool SvXMLAttrContainerData::SetAt( sal_uInt16 i, 164cdf0e10cSrcweir const rtl::OUString& rPrefix, 165cdf0e10cSrcweir const rtl::OUString& rLName, 166cdf0e10cSrcweir const rtl::OUString& rValue ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if( i >= GetAttrCount() ) 169cdf0e10cSrcweir return sal_False; 170cdf0e10cSrcweir 171cdf0e10cSrcweir sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix ); 172cdf0e10cSrcweir if( USHRT_MAX == nPos ) 173cdf0e10cSrcweir return sal_False; 174cdf0e10cSrcweir 175cdf0e10cSrcweir *(*pLNames)[i] = rLName; 176cdf0e10cSrcweir *(*pValues)[i] = rValue; 177cdf0e10cSrcweir aPrefixPoss[i] = nPos; 178cdf0e10cSrcweir 179cdf0e10cSrcweir return sal_True; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir void SvXMLAttrContainerData::Remove( sal_uInt16 i ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir if( i < GetAttrCount() ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir delete (*pLNames)[i]; 187cdf0e10cSrcweir pLNames->Remove( i ); 188cdf0e10cSrcweir delete (*pValues)[i]; 189cdf0e10cSrcweir pValues->Remove( i ); 190cdf0e10cSrcweir aPrefixPoss.Remove( i ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir else 193cdf0e10cSrcweir { 194cdf0e10cSrcweir DBG_ERROR( "illegal index" ); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir sal_uInt16 SvXMLAttrContainerData::GetAttrCount() const 199cdf0e10cSrcweir { 200cdf0e10cSrcweir return pLNames->Count(); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir const ::rtl::OUString& SvXMLAttrContainerData::GetAttrLName(sal_uInt16 i) const 204cdf0e10cSrcweir { 205cdf0e10cSrcweir OSL_ENSURE( i < pLNames->Count(), "SvXMLAttrContainerData::GetLName: illegal index" ); 206cdf0e10cSrcweir return *(*pLNames)[i]; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir const ::rtl::OUString& SvXMLAttrContainerData::GetAttrValue(sal_uInt16 i) const 210cdf0e10cSrcweir { 211cdf0e10cSrcweir OSL_ENSURE( i < pValues->Count(), "SvXMLAttrContainerData::GetValue: illegal index" ); 212cdf0e10cSrcweir return *(*pValues)[i]; 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215