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