1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include <tools/debug.hxx> 31 #include <com/sun/star/xml/AttributeData.hpp> 32 #include <com/sun/star/lang/XUnoTunnel.hpp> 33 34 #include <xmloff/xmlcnimp.hxx> 35 #include "xmloff/unoatrcn.hxx" 36 37 using namespace rtl; 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star::container; 40 using namespace ::com::sun::star::lang; 41 using namespace ::com::sun::star::xml; 42 43 typedef ::rtl::OUString *OUStringPtr; 44 SV_DECL_PTRARR_DEL( SvXMLAttrContainerData_Impl, OUStringPtr, 5, 5 ) 45 SV_IMPL_PTRARR( SvXMLAttrContainerData_Impl, OUStringPtr ) 46 47 48 SvXMLAttrContainerData::SvXMLAttrContainerData( 49 const SvXMLAttrContainerData& rImpl ) : 50 aNamespaceMap( rImpl.aNamespaceMap ), 51 pLNames( new SvXMLAttrContainerData_Impl ), 52 pValues( new SvXMLAttrContainerData_Impl ) 53 { 54 sal_uInt16 nCount = rImpl.pLNames->Count(); 55 for( sal_uInt16 i=0; i<nCount; i++ ) 56 { 57 aPrefixPoss.Insert( rImpl.aPrefixPoss[i], i ); 58 pLNames->Insert( new OUString( *(*rImpl.pLNames)[i] ), i ); 59 pValues->Insert( new OUString( *(*rImpl.pValues)[i] ), i ); 60 } 61 } 62 63 SvXMLAttrContainerData::SvXMLAttrContainerData() : 64 pLNames( new SvXMLAttrContainerData_Impl ), 65 pValues( new SvXMLAttrContainerData_Impl ) 66 { 67 } 68 69 SvXMLAttrContainerData::~SvXMLAttrContainerData() 70 { 71 delete pLNames; 72 delete pValues; 73 } 74 75 int SvXMLAttrContainerData::operator ==( 76 const SvXMLAttrContainerData& rCmp ) const 77 { 78 sal_Bool bRet = pLNames->Count() == rCmp.pLNames->Count() && 79 aNamespaceMap == rCmp.aNamespaceMap; 80 if( bRet ) 81 { 82 sal_uInt16 nCount = pLNames->Count(); 83 sal_uInt16 i; 84 for( i=0; bRet && i < nCount; i++ ) 85 bRet = aPrefixPoss[i] == rCmp.aPrefixPoss[i]; 86 87 if( bRet ) 88 { 89 for( i=0; bRet && i < nCount; i++ ) 90 bRet = *(*pLNames)[i] == *(*rCmp.pLNames)[i] && 91 *(*pValues)[i] == *(*rCmp.pValues)[i]; 92 } 93 } 94 95 return (int)bRet; 96 } 97 98 sal_Bool SvXMLAttrContainerData::AddAttr( const OUString& rLName, 99 const OUString& rValue ) 100 { 101 aPrefixPoss.Insert( USHRT_MAX, aPrefixPoss.Count() ); 102 pLNames->Insert( new OUString(rLName), pLNames->Count() ); 103 pValues->Insert( new OUString(rValue), pValues->Count() ); 104 105 return sal_True; 106 } 107 108 sal_Bool SvXMLAttrContainerData::AddAttr( const OUString& rPrefix, 109 const OUString& rNamespace, 110 const OUString& rLName, 111 const OUString& rValue ) 112 { 113 sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace ); 114 aPrefixPoss.Insert( nPos, aPrefixPoss.Count() ); 115 pLNames->Insert( new OUString(rLName), pLNames->Count() ); 116 pValues->Insert( new OUString(rValue), pValues->Count() ); 117 118 return sal_True; 119 } 120 121 sal_Bool SvXMLAttrContainerData::AddAttr( const OUString& rPrefix, 122 const OUString& rLName, 123 const OUString& rValue ) 124 { 125 sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix ); 126 if( USHRT_MAX == nPos ) 127 return sal_False; 128 129 aPrefixPoss.Insert( nPos, aPrefixPoss.Count() ); 130 pLNames->Insert( new OUString(rLName), pLNames->Count() ); 131 pValues->Insert( new OUString(rValue), pValues->Count() ); 132 133 return sal_True; 134 } 135 136 sal_Bool SvXMLAttrContainerData::SetAt( sal_uInt16 i, 137 const rtl::OUString& rLName, const rtl::OUString& rValue ) 138 { 139 if( i >= GetAttrCount() ) 140 return sal_False; 141 142 *(*pLNames)[i] = rLName; 143 *(*pValues)[i] = rValue; 144 aPrefixPoss[i] = USHRT_MAX; 145 146 return sal_True; 147 } 148 149 sal_Bool SvXMLAttrContainerData::SetAt( sal_uInt16 i, 150 const rtl::OUString& rPrefix, const rtl::OUString& rNamespace, 151 const rtl::OUString& rLName, const rtl::OUString& rValue ) 152 { 153 if( i >= GetAttrCount() ) 154 return sal_False; 155 156 sal_uInt16 nPos = aNamespaceMap.Add( rPrefix, rNamespace ); 157 if( USHRT_MAX == nPos ) 158 return sal_False; 159 160 *(*pLNames)[i] = rLName; 161 *(*pValues)[i] = rValue; 162 aPrefixPoss[i] = nPos; 163 164 return sal_True; 165 } 166 167 sal_Bool SvXMLAttrContainerData::SetAt( sal_uInt16 i, 168 const rtl::OUString& rPrefix, 169 const rtl::OUString& rLName, 170 const rtl::OUString& rValue ) 171 { 172 if( i >= GetAttrCount() ) 173 return sal_False; 174 175 sal_uInt16 nPos = aNamespaceMap.GetIndexByPrefix( rPrefix ); 176 if( USHRT_MAX == nPos ) 177 return sal_False; 178 179 *(*pLNames)[i] = rLName; 180 *(*pValues)[i] = rValue; 181 aPrefixPoss[i] = nPos; 182 183 return sal_True; 184 } 185 186 void SvXMLAttrContainerData::Remove( sal_uInt16 i ) 187 { 188 if( i < GetAttrCount() ) 189 { 190 delete (*pLNames)[i]; 191 pLNames->Remove( i ); 192 delete (*pValues)[i]; 193 pValues->Remove( i ); 194 aPrefixPoss.Remove( i ); 195 } 196 else 197 { 198 DBG_ERROR( "illegal index" ); 199 } 200 } 201 202 sal_uInt16 SvXMLAttrContainerData::GetAttrCount() const 203 { 204 return pLNames->Count(); 205 } 206 207 const ::rtl::OUString& SvXMLAttrContainerData::GetAttrLName(sal_uInt16 i) const 208 { 209 OSL_ENSURE( i < pLNames->Count(), "SvXMLAttrContainerData::GetLName: illegal index" ); 210 return *(*pLNames)[i]; 211 } 212 213 const ::rtl::OUString& SvXMLAttrContainerData::GetAttrValue(sal_uInt16 i) const 214 { 215 OSL_ENSURE( i < pValues->Count(), "SvXMLAttrContainerData::GetValue: illegal index" ); 216 return *(*pValues)[i]; 217 } 218 219