1*f9b72d11SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f9b72d11SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f9b72d11SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f9b72d11SAndrew Rist * distributed with this work for additional information
6*f9b72d11SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f9b72d11SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f9b72d11SAndrew Rist * "License"); you may not use this file except in compliance
9*f9b72d11SAndrew Rist * with the License. You may obtain a copy of the License at
10*f9b72d11SAndrew Rist *
11*f9b72d11SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f9b72d11SAndrew Rist *
13*f9b72d11SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f9b72d11SAndrew Rist * software distributed under the License is distributed on an
15*f9b72d11SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f9b72d11SAndrew Rist * KIND, either express or implied. See the License for the
17*f9b72d11SAndrew Rist * specific language governing permissions and limitations
18*f9b72d11SAndrew Rist * under the License.
19*f9b72d11SAndrew Rist *
20*f9b72d11SAndrew Rist *************************************************************/
21*f9b72d11SAndrew Rist
22*f9b72d11SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "attrlistimpl.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <vector>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir using namespace ::std;
31cdf0e10cSrcweir using namespace ::rtl;
32cdf0e10cSrcweir using namespace ::cppu;
33cdf0e10cSrcweir using namespace ::com::sun::star::uno;
34cdf0e10cSrcweir using namespace ::com::sun::star::util;
35cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir namespace sax_expatwrap {
39cdf0e10cSrcweir struct TagAttribute
40cdf0e10cSrcweir {
TagAttributesax_expatwrap::TagAttribute41cdf0e10cSrcweir TagAttribute()
42cdf0e10cSrcweir {}
TagAttributesax_expatwrap::TagAttribute43cdf0e10cSrcweir TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir this->sName = aName;
46cdf0e10cSrcweir this->sType = aType;
47cdf0e10cSrcweir this->sValue = aValue;
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
50cdf0e10cSrcweir OUString sName;
51cdf0e10cSrcweir OUString sType;
52cdf0e10cSrcweir OUString sValue;
53cdf0e10cSrcweir };
54cdf0e10cSrcweir
55cdf0e10cSrcweir struct AttributeList_impl
56cdf0e10cSrcweir {
AttributeList_implsax_expatwrap::AttributeList_impl57cdf0e10cSrcweir AttributeList_impl()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir // performance improvement during adding
60cdf0e10cSrcweir vecAttribute.reserve(20);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir vector<struct TagAttribute> vecAttribute;
63cdf0e10cSrcweir };
64cdf0e10cSrcweir
65cdf0e10cSrcweir
66cdf0e10cSrcweir
getLength(void)67cdf0e10cSrcweir sal_Int16 AttributeList::getLength(void) throw (RuntimeException)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir
AttributeList(const AttributeList & r)73cdf0e10cSrcweir AttributeList::AttributeList( const AttributeList &r ) :
74cdf0e10cSrcweir cppu::WeakImplHelper2<XAttributeList, XCloneable>()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir m_pImpl = new AttributeList_impl;
77cdf0e10cSrcweir *m_pImpl = *(r.m_pImpl);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
getNameByIndex(sal_Int16 i)80cdf0e10cSrcweir OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
83cdf0e10cSrcweir return m_pImpl->vecAttribute[i].sName;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir return OUString();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir
getTypeByIndex(sal_Int16 i)89cdf0e10cSrcweir OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
92cdf0e10cSrcweir return m_pImpl->vecAttribute[i].sType;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir return OUString();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
getValueByIndex(sal_Int16 i)97cdf0e10cSrcweir OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) {
100cdf0e10cSrcweir return m_pImpl->vecAttribute[i].sValue;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir return OUString();
103cdf0e10cSrcweir
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
getTypeByName(const OUString & sName)106cdf0e10cSrcweir OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
109cdf0e10cSrcweir
110cdf0e10cSrcweir for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
111cdf0e10cSrcweir if( (*ii).sName == sName ) {
112cdf0e10cSrcweir return (*ii).sType;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir }
115cdf0e10cSrcweir return OUString();
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
getValueByName(const OUString & sName)118cdf0e10cSrcweir OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
121cdf0e10cSrcweir
122cdf0e10cSrcweir for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
123cdf0e10cSrcweir if( (*ii).sName == sName ) {
124cdf0e10cSrcweir return (*ii).sValue;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir return OUString();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir
createClone()131cdf0e10cSrcweir Reference< XCloneable > AttributeList::createClone() throw (RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir AttributeList *p = new AttributeList( *this );
134cdf0e10cSrcweir return Reference< XCloneable > ( (XCloneable * ) p );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir
138cdf0e10cSrcweir
AttributeList()139cdf0e10cSrcweir AttributeList::AttributeList()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir m_pImpl = new AttributeList_impl;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
144cdf0e10cSrcweir
145cdf0e10cSrcweir
~AttributeList()146cdf0e10cSrcweir AttributeList::~AttributeList()
147cdf0e10cSrcweir {
148cdf0e10cSrcweir delete m_pImpl;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir
addAttribute(const OUString & sName,const OUString & sType,const OUString & sValue)152cdf0e10cSrcweir void AttributeList::addAttribute( const OUString &sName ,
153cdf0e10cSrcweir const OUString &sType ,
154cdf0e10cSrcweir const OUString &sValue )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
clear()159cdf0e10cSrcweir void AttributeList::clear()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir m_pImpl->vecAttribute.clear();
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir }
165