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: saxattrlist.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "saxattrlist.hxx"
40 SaxAttrList::SaxAttrList( const std::hash_map
< rtl::OUString
, rtl::OUString
, rtl::OUStringHash
>& rMap
)
42 m_aAttributes
.reserve(rMap
.size());
43 for( std::hash_map
< rtl::OUString
,
45 rtl::OUStringHash
>::const_iterator it
= rMap
.begin();
46 it
!= rMap
.end(); ++it
)
48 m_aIndexMap
[ it
->first
] = m_aAttributes
.size();
49 m_aAttributes
.push_back( AttrEntry( it
->first
, it
->second
) );
53 SaxAttrList::SaxAttrList( const SaxAttrList
& rClone
) :
54 cppu::WeakImplHelper2
<com::sun::star::xml::sax::XAttributeList
, com::sun::star::util::XCloneable
>(rClone
),
55 m_aAttributes( rClone
.m_aAttributes
),
56 m_aIndexMap( rClone
.m_aIndexMap
)
60 SaxAttrList::~SaxAttrList()
65 static const rtl::OUString
& getCDATAString()
67 static rtl::OUString
aStr( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
72 sal_Int16 SAL_CALL
SaxAttrList::getLength() throw()
74 return sal_Int16(m_aAttributes
.size());
76 rtl::OUString SAL_CALL
SaxAttrList::getNameByIndex( sal_Int16 i_nIndex
) throw()
78 return (i_nIndex
< sal_Int16(m_aAttributes
.size())) ? m_aAttributes
[i_nIndex
].m_aName
: rtl::OUString();
81 rtl::OUString SAL_CALL
SaxAttrList::getTypeByIndex( sal_Int16 i_nIndex
) throw()
83 return (i_nIndex
< sal_Int16(m_aAttributes
.size())) ? getCDATAString() : rtl::OUString();
86 rtl::OUString SAL_CALL
SaxAttrList::getTypeByName( const ::rtl::OUString
& i_rName
) throw()
88 return (m_aIndexMap
.find( i_rName
) != m_aIndexMap
.end()) ? getCDATAString() : rtl::OUString();
91 rtl::OUString SAL_CALL
SaxAttrList::getValueByIndex( sal_Int16 i_nIndex
) throw()
93 return (i_nIndex
< sal_Int16(m_aAttributes
.size())) ? m_aAttributes
[i_nIndex
].m_aValue
: rtl::OUString();
96 rtl::OUString SAL_CALL
SaxAttrList::getValueByName(const ::rtl::OUString
& i_rName
) throw()
98 std::hash_map
< rtl::OUString
, size_t, rtl::OUStringHash
>::const_iterator it
= m_aIndexMap
.find( i_rName
);
99 return (it
!= m_aIndexMap
.end()) ? m_aAttributes
[it
->second
].m_aValue
: rtl::OUString();
102 com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
> SAL_CALL
SaxAttrList::createClone() throw()
104 return new SaxAttrList( *this );