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