Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "attriblistmerge.hxx"
21 :
22 : //.........................................................................
23 : namespace xmloff
24 : {
25 : //.........................................................................
26 :
27 : using namespace ::com::sun::star::uno;
28 : using namespace ::com::sun::star;
29 :
30 : //=====================================================================
31 : //= OAttribListMerger
32 : //=====================================================================
33 : //---------------------------------------------------------------------
34 0 : void OAttribListMerger::addList(const Reference< xml::sax::XAttributeList >& _rxList)
35 : {
36 : OSL_ENSURE(_rxList.is(), "OAttribListMerger::addList: invalid list!");
37 0 : if (_rxList.is())
38 0 : m_aLists.push_back(_rxList);
39 0 : }
40 :
41 : //---------------------------------------------------------------------
42 0 : sal_Bool OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
43 : {
44 0 : sal_Int16 nLeftOver = _nGlobalIndex;
45 0 : ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
46 :
47 0 : for ( ; (aLookupSublist != m_aLists.end()) && (nLeftOver >= (*aLookupSublist)->getLength());
48 : ++aLookupSublist
49 : )
50 0 : nLeftOver = nLeftOver - (*aLookupSublist)->getLength();
51 :
52 0 : if (aLookupSublist == m_aLists.end())
53 : {
54 : OSL_FAIL("OAttribListMerger::seekToIndex: invalid index!");
55 0 : return sal_False;
56 : }
57 0 : _rSubList = *aLookupSublist;
58 0 : _rLocalIndex = nLeftOver;
59 0 : return sal_True;
60 : }
61 :
62 : //---------------------------------------------------------------------
63 0 : sal_Bool OAttribListMerger::seekToName(const ::rtl::OUString& _rName, Reference< xml::sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
64 : {
65 0 : for ( ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
66 0 : aLookupSublist != m_aLists.end();
67 : ++aLookupSublist
68 : )
69 0 : for (sal_Int16 i=0; i<(*aLookupSublist)->getLength(); ++i)
70 0 : if ((*aLookupSublist)->getNameByIndex(i) == _rName)
71 : {
72 0 : _rSubList = *aLookupSublist;
73 0 : _rLocalIndex = i;
74 0 : return sal_True;
75 : }
76 :
77 : OSL_FAIL("OAttribListMerger::seekToName: did not find the name!");
78 0 : return sal_False;
79 : }
80 :
81 : //---------------------------------------------------------------------
82 0 : sal_Int16 SAL_CALL OAttribListMerger::getLength( ) throw(RuntimeException)
83 : {
84 0 : sal_Int16 nCount = 0;
85 0 : for ( ConstAttributeListArrayIterator aAccumulate = m_aLists.begin();
86 0 : aAccumulate != m_aLists.end();
87 : ++aAccumulate
88 : )
89 0 : nCount = nCount + (*aAccumulate)->getLength();
90 0 : return nCount;
91 : }
92 :
93 : //---------------------------------------------------------------------
94 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getNameByIndex( sal_Int16 i ) throw(RuntimeException)
95 : {
96 0 : Reference< xml::sax::XAttributeList > xSubList;
97 : sal_Int16 nLocalIndex;
98 :
99 0 : if (!seekToIndex(i, xSubList, nLocalIndex))
100 0 : return ::rtl::OUString();
101 :
102 0 : return xSubList->getNameByIndex(nLocalIndex);
103 : }
104 :
105 : //---------------------------------------------------------------------
106 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getTypeByIndex( sal_Int16 i ) throw(RuntimeException)
107 : {
108 0 : Reference< xml::sax::XAttributeList > xSubList;
109 : sal_Int16 nLocalIndex;
110 :
111 0 : if (!seekToIndex(i, xSubList, nLocalIndex))
112 0 : return ::rtl::OUString();
113 :
114 0 : return xSubList->getTypeByIndex(nLocalIndex);
115 : }
116 :
117 : //---------------------------------------------------------------------
118 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getTypeByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
119 : {
120 0 : Reference< xml::sax::XAttributeList > xSubList;
121 : sal_Int16 nLocalIndex;
122 :
123 0 : if (!seekToName(_rName, xSubList, nLocalIndex))
124 0 : return ::rtl::OUString();
125 :
126 : // though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
127 : // assuming that this is faster
128 0 : return xSubList->getTypeByIndex(nLocalIndex);
129 : }
130 :
131 : //---------------------------------------------------------------------
132 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getValueByIndex( sal_Int16 i ) throw(RuntimeException)
133 : {
134 0 : Reference< xml::sax::XAttributeList > xSubList;
135 : sal_Int16 nLocalIndex;
136 :
137 0 : if (!seekToIndex(i, xSubList, nLocalIndex))
138 0 : return ::rtl::OUString();
139 :
140 0 : return xSubList->getValueByIndex(nLocalIndex);
141 : }
142 :
143 : //---------------------------------------------------------------------
144 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getValueByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
145 : {
146 0 : Reference< xml::sax::XAttributeList > xSubList;
147 : sal_Int16 nLocalIndex;
148 :
149 0 : if (!seekToName(_rName, xSubList, nLocalIndex))
150 0 : return ::rtl::OUString();
151 :
152 : // though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
153 : // assuming that this is faster
154 0 : return xSubList->getValueByIndex(nLocalIndex);
155 : }
156 :
157 : //.........................................................................
158 : } // namespace xmloff
159 : //.........................................................................
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|