1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attriblistmerge.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "attriblistmerge.hxx"
35 //.........................................................................
38 //.........................................................................
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::xml
;
43 //=====================================================================
45 //=====================================================================
46 //---------------------------------------------------------------------
47 void OAttribListMerger::addList(const Reference
< sax::XAttributeList
>& _rxList
)
49 OSL_ENSURE(_rxList
.is(), "OAttribListMerger::addList: invalid list!");
51 m_aLists
.push_back(_rxList
);
54 //---------------------------------------------------------------------
55 sal_Bool
OAttribListMerger::seekToIndex(sal_Int16 _nGlobalIndex
, Reference
< sax::XAttributeList
>& _rSubList
, sal_Int16
& _rLocalIndex
)
57 sal_Int16 nLeftOver
= _nGlobalIndex
;
58 ConstAttributeListArrayIterator aLookupSublist
= m_aLists
.begin();
60 for ( ; (aLookupSublist
!= m_aLists
.end()) && (nLeftOver
>= (*aLookupSublist
)->getLength());
63 nLeftOver
= nLeftOver
- (*aLookupSublist
)->getLength();
65 if (aLookupSublist
== m_aLists
.end())
67 OSL_ENSURE(sal_False
, "OAttribListMerger::seekToIndex: invalid index!");
70 _rSubList
= *aLookupSublist
;
71 _rLocalIndex
= nLeftOver
;
75 //---------------------------------------------------------------------
76 sal_Bool
OAttribListMerger::seekToName(const ::rtl::OUString
& _rName
, Reference
< sax::XAttributeList
>& _rSubList
, sal_Int16
& _rLocalIndex
)
78 for ( ConstAttributeListArrayIterator aLookupSublist
= m_aLists
.begin();
79 aLookupSublist
!= m_aLists
.end();
82 for (sal_Int16 i
=0; i
<(*aLookupSublist
)->getLength(); ++i
)
83 if ((*aLookupSublist
)->getNameByIndex(i
) == _rName
)
85 _rSubList
= *aLookupSublist
;
90 OSL_ENSURE(sal_False
, "OAttribListMerger::seekToName: did not find the name!");
94 //---------------------------------------------------------------------
95 sal_Int16 SAL_CALL
OAttribListMerger::getLength( ) throw(RuntimeException
)
98 for ( ConstAttributeListArrayIterator aAccumulate
= m_aLists
.begin();
99 aAccumulate
!= m_aLists
.end();
102 nCount
= nCount
+ (*aAccumulate
)->getLength();
106 //---------------------------------------------------------------------
107 ::rtl::OUString SAL_CALL
OAttribListMerger::getNameByIndex( sal_Int16 i
) throw(RuntimeException
)
109 Reference
< sax::XAttributeList
> xSubList
;
110 sal_Int16 nLocalIndex
;
112 if (!seekToIndex(i
, xSubList
, nLocalIndex
))
113 return ::rtl::OUString();
115 return xSubList
->getNameByIndex(nLocalIndex
);
118 //---------------------------------------------------------------------
119 ::rtl::OUString SAL_CALL
OAttribListMerger::getTypeByIndex( sal_Int16 i
) throw(RuntimeException
)
121 Reference
< sax::XAttributeList
> xSubList
;
122 sal_Int16 nLocalIndex
;
124 if (!seekToIndex(i
, xSubList
, nLocalIndex
))
125 return ::rtl::OUString();
127 return xSubList
->getTypeByIndex(nLocalIndex
);
130 //---------------------------------------------------------------------
131 ::rtl::OUString SAL_CALL
OAttribListMerger::getTypeByName( const ::rtl::OUString
& _rName
) throw(RuntimeException
)
133 Reference
< sax::XAttributeList
> xSubList
;
134 sal_Int16 nLocalIndex
;
136 if (!seekToName(_rName
, xSubList
, nLocalIndex
))
137 return ::rtl::OUString();
139 // though we're in getTypeByName here, we reroute this to the getTypeByIndex of the sub list,
140 // assuming that this is faster
141 return xSubList
->getTypeByIndex(nLocalIndex
);
144 //---------------------------------------------------------------------
145 ::rtl::OUString SAL_CALL
OAttribListMerger::getValueByIndex( sal_Int16 i
) throw(RuntimeException
)
147 Reference
< sax::XAttributeList
> xSubList
;
148 sal_Int16 nLocalIndex
;
150 if (!seekToIndex(i
, xSubList
, nLocalIndex
))
151 return ::rtl::OUString();
153 return xSubList
->getValueByIndex(nLocalIndex
);
156 //---------------------------------------------------------------------
157 ::rtl::OUString SAL_CALL
OAttribListMerger::getValueByName( const ::rtl::OUString
& _rName
) throw(RuntimeException
)
159 Reference
< sax::XAttributeList
> xSubList
;
160 sal_Int16 nLocalIndex
;
162 if (!seekToName(_rName
, xSubList
, nLocalIndex
))
163 return ::rtl::OUString();
165 // though we're in getValueByName here, we reroute this to the getValueByIndex of the sub list,
166 // assuming that this is faster
167 return xSubList
->getValueByIndex(nLocalIndex
);
170 //.........................................................................
171 } // namespace xmloff
172 //.........................................................................