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
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
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.
19*63bba73cSAndrew Rist  *
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 "attriblistmerge.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir //.........................................................................
29cdf0e10cSrcweir namespace xmloff
30cdf0e10cSrcweir {
31cdf0e10cSrcweir //.........................................................................
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
34cdf0e10cSrcweir 	using namespace ::com::sun::star::xml;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 	//=====================================================================
37cdf0e10cSrcweir 	//= OAttribListMerger
38cdf0e10cSrcweir 	//=====================================================================
39cdf0e10cSrcweir 	//---------------------------------------------------------------------
addList(const Reference<sax::XAttributeList> & _rxList)40cdf0e10cSrcweir 	void OAttribListMerger::addList(const Reference< sax::XAttributeList >& _rxList)
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		OSL_ENSURE(_rxList.is(), "OAttribListMerger::addList: invalid list!");
43cdf0e10cSrcweir 		if (_rxList.is())
44cdf0e10cSrcweir 			m_aLists.push_back(_rxList);
45cdf0e10cSrcweir 	}
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	//---------------------------------------------------------------------
seekToIndex(sal_Int16 _nGlobalIndex,Reference<sax::XAttributeList> & _rSubList,sal_Int16 & _rLocalIndex)48cdf0e10cSrcweir 	sal_Bool OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex, Reference< sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 		sal_Int16 nLeftOver = _nGlobalIndex;
51cdf0e10cSrcweir 		ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 		for ( ; (aLookupSublist != m_aLists.end()) && (nLeftOver >= (*aLookupSublist)->getLength());
54cdf0e10cSrcweir 				++aLookupSublist
55cdf0e10cSrcweir 			)
56cdf0e10cSrcweir 			nLeftOver = nLeftOver - (*aLookupSublist)->getLength();
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 		if (aLookupSublist == m_aLists.end())
59cdf0e10cSrcweir 		{
60cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OAttribListMerger::seekToIndex: invalid index!");
61cdf0e10cSrcweir 			return sal_False;
62cdf0e10cSrcweir 		}
63cdf0e10cSrcweir 		_rSubList = *aLookupSublist;
64cdf0e10cSrcweir 		_rLocalIndex = nLeftOver;
65cdf0e10cSrcweir 		return sal_True;
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	//---------------------------------------------------------------------
seekToName(const::rtl::OUString & _rName,Reference<sax::XAttributeList> & _rSubList,sal_Int16 & _rLocalIndex)69cdf0e10cSrcweir 	sal_Bool OAttribListMerger::seekToName(const ::rtl::OUString& _rName, Reference< sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		for (	ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
72cdf0e10cSrcweir 				aLookupSublist != m_aLists.end();
73cdf0e10cSrcweir 				++aLookupSublist
74cdf0e10cSrcweir 			)
75cdf0e10cSrcweir 			for	(sal_Int16 i=0; i<(*aLookupSublist)->getLength(); ++i)
76cdf0e10cSrcweir 				if ((*aLookupSublist)->getNameByIndex(i) == _rName)
77cdf0e10cSrcweir 				{
78cdf0e10cSrcweir 					_rSubList = *aLookupSublist;
79cdf0e10cSrcweir 					_rLocalIndex = i;
80cdf0e10cSrcweir 					return sal_True;
81cdf0e10cSrcweir 				}
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "OAttribListMerger::seekToName: did not find the name!");
84cdf0e10cSrcweir 		return sal_False;
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	//---------------------------------------------------------------------
getLength()88cdf0e10cSrcweir 	sal_Int16 SAL_CALL OAttribListMerger::getLength(  ) throw(RuntimeException)
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		sal_Int16 nCount = 0;
91cdf0e10cSrcweir 		for (	ConstAttributeListArrayIterator aAccumulate = m_aLists.begin();
92cdf0e10cSrcweir 				aAccumulate != m_aLists.end();
93cdf0e10cSrcweir 				++aAccumulate
94cdf0e10cSrcweir 			)
95cdf0e10cSrcweir 			nCount = nCount + (*aAccumulate)->getLength();
96cdf0e10cSrcweir 		return nCount;
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	//---------------------------------------------------------------------
getNameByIndex(sal_Int16 i)100cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OAttribListMerger::getNameByIndex( sal_Int16 i ) throw(RuntimeException)
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir 		Reference< sax::XAttributeList > xSubList;
103cdf0e10cSrcweir 		sal_Int16 nLocalIndex;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		if (!seekToIndex(i, xSubList, nLocalIndex))
106cdf0e10cSrcweir 			return ::rtl::OUString();
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		return xSubList->getNameByIndex(nLocalIndex);
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	//---------------------------------------------------------------------
getTypeByIndex(sal_Int16 i)112cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OAttribListMerger::getTypeByIndex( sal_Int16 i ) throw(RuntimeException)
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir 		Reference< sax::XAttributeList > xSubList;
115cdf0e10cSrcweir 		sal_Int16 nLocalIndex;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		if (!seekToIndex(i, xSubList, nLocalIndex))
118cdf0e10cSrcweir 			return ::rtl::OUString();
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		return xSubList->getTypeByIndex(nLocalIndex);
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	//---------------------------------------------------------------------
getTypeByName(const::rtl::OUString & _rName)124cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OAttribListMerger::getTypeByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 		Reference< sax::XAttributeList > xSubList;
127cdf0e10cSrcweir 		sal_Int16 nLocalIndex;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		if (!seekToName(_rName, xSubList, nLocalIndex))
130cdf0e10cSrcweir 			return ::rtl::OUString();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 		// though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
133cdf0e10cSrcweir 		// assuming that this is faster
134cdf0e10cSrcweir 		return xSubList->getTypeByIndex(nLocalIndex);
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	//---------------------------------------------------------------------
getValueByIndex(sal_Int16 i)138cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OAttribListMerger::getValueByIndex( sal_Int16 i ) throw(RuntimeException)
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		Reference< sax::XAttributeList > xSubList;
141cdf0e10cSrcweir 		sal_Int16 nLocalIndex;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		if (!seekToIndex(i, xSubList, nLocalIndex))
144cdf0e10cSrcweir 			return ::rtl::OUString();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		return xSubList->getValueByIndex(nLocalIndex);
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	//---------------------------------------------------------------------
getValueByName(const::rtl::OUString & _rName)150cdf0e10cSrcweir 	::rtl::OUString SAL_CALL OAttribListMerger::getValueByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		Reference< sax::XAttributeList > xSubList;
153cdf0e10cSrcweir 		sal_Int16 nLocalIndex;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		if (!seekToName(_rName, xSubList, nLocalIndex))
156cdf0e10cSrcweir 			return ::rtl::OUString();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		// though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
159cdf0e10cSrcweir 		// assuming that this is faster
160cdf0e10cSrcweir 		return xSubList->getValueByIndex(nLocalIndex);
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //.........................................................................
164cdf0e10cSrcweir }	// namespace xmloff
165cdf0e10cSrcweir //.........................................................................
166cdf0e10cSrcweir 
167