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 #include "attrlistimpl.hxx" 25 26 #include <vector> 27 28 #include <cppuhelper/weak.hxx> 29 30 using namespace ::std; 31 using namespace ::rtl; 32 using namespace ::cppu; 33 using namespace ::com::sun::star::uno; 34 using namespace ::com::sun::star::util; 35 using namespace ::com::sun::star::xml::sax; 36 37 38 namespace sax_expatwrap { 39 struct TagAttribute 40 { 41 TagAttribute() 42 {} 43 TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue ) 44 { 45 this->sName = aName; 46 this->sType = aType; 47 this->sValue = aValue; 48 } 49 50 OUString sName; 51 OUString sType; 52 OUString sValue; 53 }; 54 55 struct AttributeList_impl 56 { 57 AttributeList_impl() 58 { 59 // performance improvement during adding 60 vecAttribute.reserve(20); 61 } 62 vector<struct TagAttribute> vecAttribute; 63 }; 64 65 66 67 sal_Int16 AttributeList::getLength(void) throw (RuntimeException) 68 { 69 return static_cast<sal_Int16>(m_pImpl->vecAttribute.size()); 70 } 71 72 73 AttributeList::AttributeList( const AttributeList &r ) : 74 cppu::WeakImplHelper2<XAttributeList, XCloneable>() 75 { 76 m_pImpl = new AttributeList_impl; 77 *m_pImpl = *(r.m_pImpl); 78 } 79 80 OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException) 81 { 82 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) { 83 return m_pImpl->vecAttribute[i].sName; 84 } 85 return OUString(); 86 } 87 88 89 OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException) 90 { 91 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) { 92 return m_pImpl->vecAttribute[i].sType; 93 } 94 return OUString(); 95 } 96 97 OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException) 98 { 99 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) { 100 return m_pImpl->vecAttribute[i].sValue; 101 } 102 return OUString(); 103 104 } 105 106 OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException) 107 { 108 vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin(); 109 110 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) { 111 if( (*ii).sName == sName ) { 112 return (*ii).sType; 113 } 114 } 115 return OUString(); 116 } 117 118 OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException) 119 { 120 vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin(); 121 122 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) { 123 if( (*ii).sName == sName ) { 124 return (*ii).sValue; 125 } 126 } 127 return OUString(); 128 } 129 130 131 Reference< XCloneable > AttributeList::createClone() throw (RuntimeException) 132 { 133 AttributeList *p = new AttributeList( *this ); 134 return Reference< XCloneable > ( (XCloneable * ) p ); 135 } 136 137 138 139 AttributeList::AttributeList() 140 { 141 m_pImpl = new AttributeList_impl; 142 } 143 144 145 146 AttributeList::~AttributeList() 147 { 148 delete m_pImpl; 149 } 150 151 152 void AttributeList::addAttribute( const OUString &sName , 153 const OUString &sType , 154 const OUString &sValue ) 155 { 156 m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) ); 157 } 158 159 void AttributeList::clear() 160 { 161 m_pImpl->vecAttribute.clear(); 162 } 163 164 } 165