Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "attriblistmerge.hxx"
30 : :
31 : : //.........................................................................
32 : : namespace xmloff
33 : : {
34 : : //.........................................................................
35 : :
36 : : using namespace ::com::sun::star::uno;
37 : : using namespace ::com::sun::star::xml;
38 : :
39 : : //=====================================================================
40 : : //= OAttribListMerger
41 : : //=====================================================================
42 : : //---------------------------------------------------------------------
43 : 0 : void OAttribListMerger::addList(const Reference< sax::XAttributeList >& _rxList)
44 : : {
45 : : OSL_ENSURE(_rxList.is(), "OAttribListMerger::addList: invalid list!");
46 [ # # ]: 0 : if (_rxList.is())
47 : 0 : m_aLists.push_back(_rxList);
48 : 0 : }
49 : :
50 : : //---------------------------------------------------------------------
51 : 0 : sal_Bool OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex, Reference< sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
52 : : {
53 : 0 : sal_Int16 nLeftOver = _nGlobalIndex;
54 [ # # ]: 0 : ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
55 : :
56 [ # # ][ # # ]: 0 : for ( ; (aLookupSublist != m_aLists.end()) && (nLeftOver >= (*aLookupSublist)->getLength());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
57 : : ++aLookupSublist
58 : : )
59 [ # # ][ # # ]: 0 : nLeftOver = nLeftOver - (*aLookupSublist)->getLength();
60 : :
61 [ # # ][ # # ]: 0 : if (aLookupSublist == m_aLists.end())
62 : : {
63 : : OSL_FAIL("OAttribListMerger::seekToIndex: invalid index!");
64 : 0 : return sal_False;
65 : : }
66 [ # # ]: 0 : _rSubList = *aLookupSublist;
67 : 0 : _rLocalIndex = nLeftOver;
68 : 0 : return sal_True;
69 : : }
70 : :
71 : : //---------------------------------------------------------------------
72 : 0 : sal_Bool OAttribListMerger::seekToName(const ::rtl::OUString& _rName, Reference< sax::XAttributeList >& _rSubList, sal_Int16& _rLocalIndex)
73 : : {
74 [ # # ][ # # ]: 0 : for ( ConstAttributeListArrayIterator aLookupSublist = m_aLists.begin();
[ # # ]
75 : 0 : aLookupSublist != m_aLists.end();
76 : : ++aLookupSublist
77 : : )
78 [ # # ][ # # ]: 0 : for (sal_Int16 i=0; i<(*aLookupSublist)->getLength(); ++i)
[ # # ]
79 [ # # ][ # # ]: 0 : if ((*aLookupSublist)->getNameByIndex(i) == _rName)
[ # # ]
80 : : {
81 [ # # ]: 0 : _rSubList = *aLookupSublist;
82 : 0 : _rLocalIndex = i;
83 : 0 : return sal_True;
84 : : }
85 : :
86 : : OSL_FAIL("OAttribListMerger::seekToName: did not find the name!");
87 : 0 : return sal_False;
88 : : }
89 : :
90 : : //---------------------------------------------------------------------
91 : 0 : sal_Int16 SAL_CALL OAttribListMerger::getLength( ) throw(RuntimeException)
92 : : {
93 : 0 : sal_Int16 nCount = 0;
94 [ # # ][ # # ]: 0 : for ( ConstAttributeListArrayIterator aAccumulate = m_aLists.begin();
[ # # ]
95 : 0 : aAccumulate != m_aLists.end();
96 : : ++aAccumulate
97 : : )
98 [ # # ][ # # ]: 0 : nCount = nCount + (*aAccumulate)->getLength();
99 : 0 : return nCount;
100 : : }
101 : :
102 : : //---------------------------------------------------------------------
103 : 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getNameByIndex( sal_Int16 i ) throw(RuntimeException)
104 : : {
105 : 0 : Reference< sax::XAttributeList > xSubList;
106 : : sal_Int16 nLocalIndex;
107 : :
108 [ # # ][ # # ]: 0 : if (!seekToIndex(i, xSubList, nLocalIndex))
109 : 0 : return ::rtl::OUString();
110 : :
111 [ # # ][ # # ]: 0 : return xSubList->getNameByIndex(nLocalIndex);
112 : : }
113 : :
114 : : //---------------------------------------------------------------------
115 : 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getTypeByIndex( sal_Int16 i ) throw(RuntimeException)
116 : : {
117 : 0 : Reference< sax::XAttributeList > xSubList;
118 : : sal_Int16 nLocalIndex;
119 : :
120 [ # # ][ # # ]: 0 : if (!seekToIndex(i, xSubList, nLocalIndex))
121 : 0 : return ::rtl::OUString();
122 : :
123 [ # # ][ # # ]: 0 : return xSubList->getTypeByIndex(nLocalIndex);
124 : : }
125 : :
126 : : //---------------------------------------------------------------------
127 : 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getTypeByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
128 : : {
129 : 0 : Reference< sax::XAttributeList > xSubList;
130 : : sal_Int16 nLocalIndex;
131 : :
132 [ # # ][ # # ]: 0 : if (!seekToName(_rName, xSubList, nLocalIndex))
133 : 0 : return ::rtl::OUString();
134 : :
135 : : // though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
136 : : // assuming that this is faster
137 [ # # ][ # # ]: 0 : return xSubList->getTypeByIndex(nLocalIndex);
138 : : }
139 : :
140 : : //---------------------------------------------------------------------
141 : 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getValueByIndex( sal_Int16 i ) throw(RuntimeException)
142 : : {
143 : 0 : Reference< sax::XAttributeList > xSubList;
144 : : sal_Int16 nLocalIndex;
145 : :
146 [ # # ][ # # ]: 0 : if (!seekToIndex(i, xSubList, nLocalIndex))
147 : 0 : return ::rtl::OUString();
148 : :
149 [ # # ][ # # ]: 0 : return xSubList->getValueByIndex(nLocalIndex);
150 : : }
151 : :
152 : : //---------------------------------------------------------------------
153 : 0 : ::rtl::OUString SAL_CALL OAttribListMerger::getValueByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
154 : : {
155 : 0 : Reference< sax::XAttributeList > xSubList;
156 : : sal_Int16 nLocalIndex;
157 : :
158 [ # # ][ # # ]: 0 : if (!seekToName(_rName, xSubList, nLocalIndex))
159 : 0 : return ::rtl::OUString();
160 : :
161 : : // though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
162 : : // assuming that this is faster
163 [ # # ][ # # ]: 0 : return xSubList->getValueByIndex(nLocalIndex);
164 : : }
165 : :
166 : : //.........................................................................
167 : : } // namespace xmloff
168 : : //.........................................................................
169 : :
170 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|