bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / forms / attriblistmerge.cxx
blob37a9659670468bb3674e502c361f55076cf39ad1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "attriblistmerge.hxx"
22 //.........................................................................
23 namespace xmloff
25 //.........................................................................
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star;
30 //=====================================================================
31 //= OAttribListMerger
32 //=====================================================================
33 //---------------------------------------------------------------------
34 void OAttribListMerger::addList(const Reference< xml::sax::XAttributeList >& _rxList)
36 OSL_ENSURE(_rxList.is(), "OAttribListMerger::addList: invalid list!");
37 if (_rxList.is())
38 m_aLists.push_back(_rxList);
41 //---------------------------------------------------------------------
42 sal_Bool OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
44 sal_Int16 nLeftOver = _nGlobalIndex;
45 ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
47 for ( ; (aLookupSublist != m_aLists.end()) && (nLeftOver >= (*aLookupSublist)->getLength());
48 ++aLookupSublist
50 nLeftOver = nLeftOver - (*aLookupSublist)->getLength();
52 if (aLookupSublist == m_aLists.end())
54 OSL_FAIL("OAttribListMerger::seekToIndex: invalid index!");
55 return sal_False;
57 _rSubList = *aLookupSublist;
58 _rLocalIndex = nLeftOver;
59 return sal_True;
62 //---------------------------------------------------------------------
63 sal_Bool OAttribListMerger::seekToName(const OUString& _rName, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
65 for ( ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
66 aLookupSublist != m_aLists.end();
67 ++aLookupSublist
69 for (sal_Int16 i=0; i<(*aLookupSublist)->getLength(); ++i)
70 if ((*aLookupSublist)->getNameByIndex(i) == _rName)
72 _rSubList = *aLookupSublist;
73 _rLocalIndex = i;
74 return sal_True;
77 OSL_FAIL("OAttribListMerger::seekToName: did not find the name!");
78 return sal_False;
81 //---------------------------------------------------------------------
82 sal_Int16 SAL_CALL OAttribListMerger::getLength( ) throw(RuntimeException)
84 sal_Int16 nCount = 0;
85 for ( ConstAttributeListArrayIterator aAccumulate = m_aLists.begin();
86 aAccumulate != m_aLists.end();
87 ++aAccumulate
89 nCount = nCount + (*aAccumulate)->getLength();
90 return nCount;
93 //---------------------------------------------------------------------
94 OUString SAL_CALL OAttribListMerger::getNameByIndex( sal_Int16 i ) throw(RuntimeException)
96 Reference< xml::sax::XAttributeList > xSubList;
97 sal_Int16 nLocalIndex;
99 if (!seekToIndex(i, xSubList, nLocalIndex))
100 return OUString();
102 return xSubList->getNameByIndex(nLocalIndex);
105 //---------------------------------------------------------------------
106 OUString SAL_CALL OAttribListMerger::getTypeByIndex( sal_Int16 i ) throw(RuntimeException)
108 Reference< xml::sax::XAttributeList > xSubList;
109 sal_Int16 nLocalIndex;
111 if (!seekToIndex(i, xSubList, nLocalIndex))
112 return OUString();
114 return xSubList->getTypeByIndex(nLocalIndex);
117 //---------------------------------------------------------------------
118 OUString SAL_CALL OAttribListMerger::getTypeByName( const OUString& _rName ) throw(RuntimeException)
120 Reference< xml::sax::XAttributeList > xSubList;
121 sal_Int16 nLocalIndex;
123 if (!seekToName(_rName, xSubList, nLocalIndex))
124 return OUString();
126 // though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
127 // assuming that this is faster
128 return xSubList->getTypeByIndex(nLocalIndex);
131 //---------------------------------------------------------------------
132 OUString SAL_CALL OAttribListMerger::getValueByIndex( sal_Int16 i ) throw(RuntimeException)
134 Reference< xml::sax::XAttributeList > xSubList;
135 sal_Int16 nLocalIndex;
137 if (!seekToIndex(i, xSubList, nLocalIndex))
138 return OUString();
140 return xSubList->getValueByIndex(nLocalIndex);
143 //---------------------------------------------------------------------
144 OUString SAL_CALL OAttribListMerger::getValueByName( const OUString& _rName ) throw(RuntimeException)
146 Reference< xml::sax::XAttributeList > xSubList;
147 sal_Int16 nLocalIndex;
149 if (!seekToName(_rName, xSubList, nLocalIndex))
150 return OUString();
152 // though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
153 // assuming that this is faster
154 return xSubList->getValueByIndex(nLocalIndex);
157 //.........................................................................
158 } // namespace xmloff
159 //.........................................................................
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */