1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "attrlistimpl.hxx" 29 30 #include <vector> 31 32 #include <cppuhelper/weak.hxx> 33 34 using namespace ::std; 35 using namespace ::rtl; 36 using namespace ::cppu; 37 using namespace ::com::sun::star::uno; 38 using namespace ::com::sun::star::util; 39 using namespace ::com::sun::star::xml::sax; 40 41 42 namespace sax_expatwrap { 43 struct TagAttribute 44 { 45 TagAttribute() 46 {} 47 TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue ) 48 { 49 this->sName = aName; 50 this->sType = aType; 51 this->sValue = aValue; 52 } 53 54 OUString sName; 55 OUString sType; 56 OUString sValue; 57 }; 58 59 struct AttributeList_impl 60 { 61 AttributeList_impl() 62 { 63 // performance improvement during adding 64 vecAttribute.reserve(20); 65 } 66 vector<struct TagAttribute> vecAttribute; 67 }; 68 69 70 71 sal_Int16 AttributeList::getLength(void) throw (RuntimeException) 72 { 73 return static_cast<sal_Int16>(m_pImpl->vecAttribute.size()); 74 } 75 76 77 AttributeList::AttributeList( const AttributeList &r ) : 78 cppu::WeakImplHelper2<XAttributeList, XCloneable>() 79 { 80 m_pImpl = new AttributeList_impl; 81 *m_pImpl = *(r.m_pImpl); 82 } 83 84 OUString AttributeList::getNameByIndex(sal_Int16 i) throw (RuntimeException) 85 { 86 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) { 87 return m_pImpl->vecAttribute[i].sName; 88 } 89 return OUString(); 90 } 91 92 93 OUString AttributeList::getTypeByIndex(sal_Int16 i) throw (RuntimeException) 94 { 95 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) { 96 return m_pImpl->vecAttribute[i].sType; 97 } 98 return OUString(); 99 } 100 101 OUString AttributeList::getValueByIndex(sal_Int16 i) throw (RuntimeException) 102 { 103 if( std::vector< TagAttribute >::size_type(i) < m_pImpl->vecAttribute.size() ) { 104 return m_pImpl->vecAttribute[i].sValue; 105 } 106 return OUString(); 107 108 } 109 110 OUString AttributeList::getTypeByName( const OUString& sName ) throw (RuntimeException) 111 { 112 vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin(); 113 114 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) { 115 if( (*ii).sName == sName ) { 116 return (*ii).sType; 117 } 118 } 119 return OUString(); 120 } 121 122 OUString AttributeList::getValueByName(const OUString& sName) throw (RuntimeException) 123 { 124 vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin(); 125 126 for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) { 127 if( (*ii).sName == sName ) { 128 return (*ii).sValue; 129 } 130 } 131 return OUString(); 132 } 133 134 135 Reference< XCloneable > AttributeList::createClone() throw (RuntimeException) 136 { 137 AttributeList *p = new AttributeList( *this ); 138 return Reference< XCloneable > ( (XCloneable * ) p ); 139 } 140 141 142 143 AttributeList::AttributeList() 144 { 145 m_pImpl = new AttributeList_impl; 146 } 147 148 149 150 AttributeList::~AttributeList() 151 { 152 delete m_pImpl; 153 } 154 155 156 void AttributeList::addAttribute( const OUString &sName , 157 const OUString &sType , 158 const OUString &sValue ) 159 { 160 m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) ); 161 } 162 163 void AttributeList::clear() 164 { 165 m_pImpl->vecAttribute.clear(); 166 } 167 168 } 169