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: attrlistimpl.cxx,v $
10 * $Revision: 1.8.10.1 $
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 #include "attrlistimpl.hxx"
35 #if OSL_DEBUG_LEVEL == 0
42 #include <cppuhelper/weak.hxx>
44 using namespace ::std
;
45 using namespace ::rtl
;
46 using namespace ::cppu
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::util
;
49 using namespace ::com::sun::star::xml::sax
;
52 namespace sax_expatwrap
{
57 TagAttribute( const OUString
&aName
, const OUString
&aType
, const OUString
&aValue
)
61 this->sValue
= aValue
;
69 struct AttributeList_impl
73 // performance improvement during adding
74 vecAttribute
.reserve(20);
76 vector
<struct TagAttribute
> vecAttribute
;
81 sal_Int16
AttributeList::getLength(void) throw (RuntimeException
)
83 return static_cast<sal_Int16
>(m_pImpl
->vecAttribute
.size());
87 AttributeList::AttributeList( const AttributeList
&r
) :
88 cppu::WeakImplHelper2
<XAttributeList
, XCloneable
>()
90 m_pImpl
= new AttributeList_impl
;
91 *m_pImpl
= *(r
.m_pImpl
);
94 OUString
AttributeList::getNameByIndex(sal_Int16 i
) throw (RuntimeException
)
96 if( std::vector
< TagAttribute
>::size_type(i
) < m_pImpl
->vecAttribute
.size() ) {
97 return m_pImpl
->vecAttribute
[i
].sName
;
103 OUString
AttributeList::getTypeByIndex(sal_Int16 i
) throw (RuntimeException
)
105 if( std::vector
< TagAttribute
>::size_type(i
) < m_pImpl
->vecAttribute
.size() ) {
106 return m_pImpl
->vecAttribute
[i
].sType
;
111 OUString
AttributeList::getValueByIndex(sal_Int16 i
) throw (RuntimeException
)
113 if( std::vector
< TagAttribute
>::size_type(i
) < m_pImpl
->vecAttribute
.size() ) {
114 return m_pImpl
->vecAttribute
[i
].sValue
;
120 OUString
AttributeList::getTypeByName( const OUString
& sName
) throw (RuntimeException
)
122 vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
124 for( ; ii
!= m_pImpl
->vecAttribute
.end() ; ii
++ ) {
125 if( (*ii
).sName
== sName
) {
132 OUString
AttributeList::getValueByName(const OUString
& sName
) throw (RuntimeException
)
134 vector
<struct TagAttribute
>::iterator ii
= m_pImpl
->vecAttribute
.begin();
136 for( ; ii
!= m_pImpl
->vecAttribute
.end() ; ii
++ ) {
137 if( (*ii
).sName
== sName
) {
145 Reference
< XCloneable
> AttributeList::createClone() throw (RuntimeException
)
147 AttributeList
*p
= new AttributeList( *this );
148 return Reference
< XCloneable
> ( (XCloneable
* ) p
);
153 AttributeList::AttributeList()
155 m_pImpl
= new AttributeList_impl
;
160 AttributeList::~AttributeList()
166 void AttributeList::addAttribute( const OUString
&sName
,
167 const OUString
&sType
,
168 const OUString
&sValue
)
170 m_pImpl
->vecAttribute
.push_back( TagAttribute( sName
, sType
, sValue
) );
173 void AttributeList::clear()
175 m_pImpl
->vecAttribute
.clear();