1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlcnitm.cxx,v $
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"
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()
78 int SvXMLAttrContainerData::operator ==(
79 const SvXMLAttrContainerData
& rCmp
) const
81 BOOL bRet
= pLNames
->Count() == rCmp
.pLNames
->Count() &&
82 aNamespaceMap
== rCmp
.aNamespaceMap
;
85 USHORT nCount
= pLNames
->Count();
87 for( i
=0; bRet
&& i
< nCount
; i
++ )
88 bRet
= aPrefixPoss
[i
] == rCmp
.aPrefixPoss
[i
];
92 for( i
=0; bRet
&& i
< nCount
; i
++ )
93 bRet
= *(*pLNames
)[i
] == *(*rCmp
.pLNames
)[i
] &&
94 *(*pValues
)[i
] == *(*rCmp
.pValues
)[i
];
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() );
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() );
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
)
132 aPrefixPoss
.Insert( nPos
, aPrefixPoss
.Count() );
133 pLNames
->Insert( new OUString(rLName
), pLNames
->Count() );
134 pValues
->Insert( new OUString(rValue
), pValues
->Count() );
139 BOOL
SvXMLAttrContainerData::SetAt( USHORT i
,
140 const rtl::OUString
& rLName
, const rtl::OUString
& rValue
)
142 if( i
>= GetAttrCount() )
145 *(*pLNames
)[i
] = rLName
;
146 *(*pValues
)[i
] = rValue
;
147 aPrefixPoss
[i
] = USHRT_MAX
;
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() )
159 USHORT nPos
= aNamespaceMap
.Add( rPrefix
, rNamespace
);
160 if( USHRT_MAX
== nPos
)
163 *(*pLNames
)[i
] = rLName
;
164 *(*pValues
)[i
] = rValue
;
165 aPrefixPoss
[i
] = nPos
;
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() )
178 USHORT nPos
= aNamespaceMap
.GetIndexByPrefix( rPrefix
);
179 if( USHRT_MAX
== nPos
)
182 *(*pLNames
)[i
] = rLName
;
183 *(*pValues
)[i
] = rValue
;
184 aPrefixPoss
[i
] = nPos
;
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
);
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
];