merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / core / xmlcnitm.cxx
blobd7d3035bc93b5b70aa658a0a15b06c49c1513c77
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlcnitm.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <com/sun/star/xml/AttributeData.hpp>
35 #include <com/sun/star/lang/XUnoTunnel.hpp>
37 #include <xmloff/xmlcnimp.hxx>
38 #include "unoatrcn.hxx"
40 using namespace rtl;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::xml;
46 typedef ::rtl::OUString *OUStringPtr;
47 SV_DECL_PTRARR_DEL( SvXMLAttrContainerData_Impl, OUStringPtr, 5, 5 )
48 SV_IMPL_PTRARR( SvXMLAttrContainerData_Impl, OUStringPtr )
51 SvXMLAttrContainerData::SvXMLAttrContainerData(
52 const SvXMLAttrContainerData& rImpl ) :
53 aNamespaceMap( rImpl.aNamespaceMap ),
54 pLNames( new SvXMLAttrContainerData_Impl ),
55 pValues( new SvXMLAttrContainerData_Impl )
57 USHORT nCount = rImpl.pLNames->Count();
58 for( USHORT i=0; i<nCount; i++ )
60 aPrefixPoss.Insert( rImpl.aPrefixPoss[i], i );
61 pLNames->Insert( new OUString( *(*rImpl.pLNames)[i] ), i );
62 pValues->Insert( new OUString( *(*rImpl.pValues)[i] ), i );
66 SvXMLAttrContainerData::SvXMLAttrContainerData() :
67 pLNames( new SvXMLAttrContainerData_Impl ),
68 pValues( new SvXMLAttrContainerData_Impl )
72 SvXMLAttrContainerData::~SvXMLAttrContainerData()
74 delete pLNames;
75 delete pValues;
78 int SvXMLAttrContainerData::operator ==(
79 const SvXMLAttrContainerData& rCmp ) const
81 BOOL bRet = pLNames->Count() == rCmp.pLNames->Count() &&
82 aNamespaceMap == rCmp.aNamespaceMap;
83 if( bRet )
85 USHORT nCount = pLNames->Count();
86 USHORT i;
87 for( i=0; bRet && i < nCount; i++ )
88 bRet = aPrefixPoss[i] == rCmp.aPrefixPoss[i];
90 if( bRet )
92 for( i=0; bRet && i < nCount; i++ )
93 bRet = *(*pLNames)[i] == *(*rCmp.pLNames)[i] &&
94 *(*pValues)[i] == *(*rCmp.pValues)[i];
98 return (int)bRet;
101 BOOL SvXMLAttrContainerData::AddAttr( const OUString& rLName,
102 const OUString& rValue )
104 aPrefixPoss.Insert( USHRT_MAX, aPrefixPoss.Count() );
105 pLNames->Insert( new OUString(rLName), pLNames->Count() );
106 pValues->Insert( new OUString(rValue), pValues->Count() );
108 return TRUE;
111 BOOL SvXMLAttrContainerData::AddAttr( const OUString& rPrefix,
112 const OUString& rNamespace,
113 const OUString& rLName,
114 const OUString& rValue )
116 USHORT nPos = aNamespaceMap.Add( rPrefix, rNamespace );
117 aPrefixPoss.Insert( nPos, aPrefixPoss.Count() );
118 pLNames->Insert( new OUString(rLName), pLNames->Count() );
119 pValues->Insert( new OUString(rValue), pValues->Count() );
121 return TRUE;
124 BOOL SvXMLAttrContainerData::AddAttr( const OUString& rPrefix,
125 const OUString& rLName,
126 const OUString& rValue )
128 USHORT nPos = aNamespaceMap.GetIndexByPrefix( rPrefix );
129 if( USHRT_MAX == nPos )
130 return FALSE;
132 aPrefixPoss.Insert( nPos, aPrefixPoss.Count() );
133 pLNames->Insert( new OUString(rLName), pLNames->Count() );
134 pValues->Insert( new OUString(rValue), pValues->Count() );
136 return TRUE;
139 BOOL SvXMLAttrContainerData::SetAt( USHORT i,
140 const rtl::OUString& rLName, const rtl::OUString& rValue )
142 if( i >= GetAttrCount() )
143 return FALSE;
145 *(*pLNames)[i] = rLName;
146 *(*pValues)[i] = rValue;
147 aPrefixPoss[i] = USHRT_MAX;
149 return TRUE;
152 BOOL SvXMLAttrContainerData::SetAt( USHORT i,
153 const rtl::OUString& rPrefix, const rtl::OUString& rNamespace,
154 const rtl::OUString& rLName, const rtl::OUString& rValue )
156 if( i >= GetAttrCount() )
157 return FALSE;
159 USHORT nPos = aNamespaceMap.Add( rPrefix, rNamespace );
160 if( USHRT_MAX == nPos )
161 return FALSE;
163 *(*pLNames)[i] = rLName;
164 *(*pValues)[i] = rValue;
165 aPrefixPoss[i] = nPos;
167 return TRUE;
170 BOOL SvXMLAttrContainerData::SetAt( USHORT i,
171 const rtl::OUString& rPrefix,
172 const rtl::OUString& rLName,
173 const rtl::OUString& rValue )
175 if( i >= GetAttrCount() )
176 return FALSE;
178 USHORT nPos = aNamespaceMap.GetIndexByPrefix( rPrefix );
179 if( USHRT_MAX == nPos )
180 return FALSE;
182 *(*pLNames)[i] = rLName;
183 *(*pValues)[i] = rValue;
184 aPrefixPoss[i] = nPos;
186 return TRUE;
189 void SvXMLAttrContainerData::Remove( USHORT i )
191 if( i < GetAttrCount() )
193 delete (*pLNames)[i];
194 pLNames->Remove( i );
195 delete (*pValues)[i];
196 pValues->Remove( i );
197 aPrefixPoss.Remove( i );
199 else
201 DBG_ERROR( "illegal index" );
205 sal_uInt16 SvXMLAttrContainerData::GetAttrCount() const
207 return pLNames->Count();
210 const ::rtl::OUString& SvXMLAttrContainerData::GetAttrLName(sal_uInt16 i) const
212 OSL_ENSURE( i < pLNames->Count(), "SvXMLAttrContainerData::GetLName: illegal index" );
213 return *(*pLNames)[i];
216 const ::rtl::OUString& SvXMLAttrContainerData::GetAttrValue(sal_uInt16 i) const
218 OSL_ENSURE( i < pValues->Count(), "SvXMLAttrContainerData::GetValue: illegal index" );
219 return *(*pValues)[i];