1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "saxattrlist.hxx"
32 
33 namespace pdfi
34 {
35 
36 SaxAttrList::SaxAttrList( const std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash >& rMap )
37 {
38     m_aAttributes.reserve(rMap.size());
39     for( std::hash_map< rtl::OUString,
40                         rtl::OUString,
41                         rtl::OUStringHash >::const_iterator it = rMap.begin();
42          it != rMap.end(); ++it )
43     {
44         m_aIndexMap[ it->first ] = m_aAttributes.size();
45         m_aAttributes.push_back( AttrEntry( it->first, it->second ) );
46     }
47 }
48 
49 SaxAttrList::SaxAttrList( const SaxAttrList& rClone ) :
50     cppu::WeakImplHelper2<com::sun::star::xml::sax::XAttributeList, com::sun::star::util::XCloneable>(rClone),
51     m_aAttributes( rClone.m_aAttributes ),
52     m_aIndexMap( rClone.m_aIndexMap )
53 {
54 }
55 
56 SaxAttrList::~SaxAttrList()
57 {
58 }
59 
60 namespace {
61     static const rtl::OUString& getCDATAString()
62     {
63         static rtl::OUString aStr( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
64         return aStr;
65     }
66 }
67 
68 sal_Int16 SAL_CALL SaxAttrList::getLength() throw()
69 {
70     return sal_Int16(m_aAttributes.size());
71 }
72 rtl::OUString SAL_CALL SaxAttrList::getNameByIndex( sal_Int16 i_nIndex ) throw()
73 {
74     return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aName : rtl::OUString();
75 }
76 
77 rtl::OUString SAL_CALL SaxAttrList::getTypeByIndex( sal_Int16 i_nIndex) throw()
78 {
79     return (i_nIndex < sal_Int16(m_aAttributes.size())) ? getCDATAString() : rtl::OUString();
80 }
81 
82 rtl::OUString SAL_CALL SaxAttrList::getTypeByName( const ::rtl::OUString& i_rName ) throw()
83 {
84     return (m_aIndexMap.find( i_rName ) != m_aIndexMap.end()) ? getCDATAString() : rtl::OUString();
85 }
86 
87 rtl::OUString SAL_CALL SaxAttrList::getValueByIndex( sal_Int16 i_nIndex ) throw()
88 {
89     return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aValue : rtl::OUString();
90 }
91 
92 rtl::OUString SAL_CALL SaxAttrList::getValueByName(const ::rtl::OUString& i_rName) throw()
93 {
94     std::hash_map< rtl::OUString, size_t, rtl::OUStringHash >::const_iterator it = m_aIndexMap.find( i_rName );
95     return (it != m_aIndexMap.end()) ? m_aAttributes[it->second].m_aValue : rtl::OUString();
96 }
97 
98 com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL SaxAttrList::createClone() throw()
99 {
100     return new SaxAttrList( *this );
101 }
102 
103 }
104 
105