1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26 
27 #include "saxattrlist.hxx"
28 
29 namespace pdfi
30 {
31 
SaxAttrList(const std::hash_map<rtl::OUString,rtl::OUString,rtl::OUStringHash> & rMap)32 SaxAttrList::SaxAttrList( const std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash >& rMap )
33 {
34     m_aAttributes.reserve(rMap.size());
35     for( std::hash_map< rtl::OUString,
36                         rtl::OUString,
37                         rtl::OUStringHash >::const_iterator it = rMap.begin();
38          it != rMap.end(); ++it )
39     {
40         m_aIndexMap[ it->first ] = m_aAttributes.size();
41         m_aAttributes.push_back( AttrEntry( it->first, it->second ) );
42     }
43 }
44 
SaxAttrList(const SaxAttrList & rClone)45 SaxAttrList::SaxAttrList( const SaxAttrList& rClone ) :
46     cppu::WeakImplHelper2<com::sun::star::xml::sax::XAttributeList, com::sun::star::util::XCloneable>(rClone),
47     m_aAttributes( rClone.m_aAttributes ),
48     m_aIndexMap( rClone.m_aIndexMap )
49 {
50 }
51 
~SaxAttrList()52 SaxAttrList::~SaxAttrList()
53 {
54 }
55 
56 namespace {
getCDATAString()57     static const rtl::OUString& getCDATAString()
58     {
59         static rtl::OUString aStr( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
60         return aStr;
61     }
62 }
63 
getLength()64 sal_Int16 SAL_CALL SaxAttrList::getLength() throw()
65 {
66     return sal_Int16(m_aAttributes.size());
67 }
getNameByIndex(sal_Int16 i_nIndex)68 rtl::OUString SAL_CALL SaxAttrList::getNameByIndex( sal_Int16 i_nIndex ) throw()
69 {
70     return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aName : rtl::OUString();
71 }
72 
getTypeByIndex(sal_Int16 i_nIndex)73 rtl::OUString SAL_CALL SaxAttrList::getTypeByIndex( sal_Int16 i_nIndex) throw()
74 {
75     return (i_nIndex < sal_Int16(m_aAttributes.size())) ? getCDATAString() : rtl::OUString();
76 }
77 
getTypeByName(const::rtl::OUString & i_rName)78 rtl::OUString SAL_CALL SaxAttrList::getTypeByName( const ::rtl::OUString& i_rName ) throw()
79 {
80     return (m_aIndexMap.find( i_rName ) != m_aIndexMap.end()) ? getCDATAString() : rtl::OUString();
81 }
82 
getValueByIndex(sal_Int16 i_nIndex)83 rtl::OUString SAL_CALL SaxAttrList::getValueByIndex( sal_Int16 i_nIndex ) throw()
84 {
85     return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aValue : rtl::OUString();
86 }
87 
getValueByName(const::rtl::OUString & i_rName)88 rtl::OUString SAL_CALL SaxAttrList::getValueByName(const ::rtl::OUString& i_rName) throw()
89 {
90     std::hash_map< rtl::OUString, size_t, rtl::OUStringHash >::const_iterator it = m_aIndexMap.find( i_rName );
91     return (it != m_aIndexMap.end()) ? m_aAttributes[it->second].m_aValue : rtl::OUString();
92 }
93 
createClone()94 com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL SaxAttrList::createClone() throw()
95 {
96     return new SaxAttrList( *this );
97 }
98 
99 }
100 
101