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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include <osl/mutex.hxx> 31 #include <xmloff/xmltoken.hxx> 32 #include <rtl/uuid.h> 33 #include <rtl/memory.h> 34 #include <xmloff/attrlist.hxx> 35 #include "MutableAttrList.hxx" 36 37 using ::rtl::OUString; 38 39 using namespace ::osl; 40 using namespace ::com::sun::star::uno; 41 using namespace ::com::sun::star::lang; 42 using namespace ::com::sun::star::util; 43 44 SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList() 45 { 46 if( !m_pMutableAttrList ) 47 { 48 m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList ); 49 m_xAttrList = m_pMutableAttrList; 50 } 51 52 return m_pMutableAttrList; 53 } 54 55 XMLMutableAttributeList::XMLMutableAttributeList() : 56 m_pMutableAttrList( new SvXMLAttributeList ) 57 { 58 m_xAttrList = m_pMutableAttrList; 59 } 60 61 XMLMutableAttributeList::XMLMutableAttributeList( const Reference< 62 XAttributeList> & rAttrList, sal_Bool bClone ) : 63 m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ), 64 m_pMutableAttrList( 0 ) 65 { 66 if( bClone ) 67 GetMutableAttrList(); 68 } 69 70 71 XMLMutableAttributeList::~XMLMutableAttributeList() 72 { 73 m_xAttrList = 0; 74 } 75 76 77 // XUnoTunnel & co 78 const Sequence< sal_Int8 > & XMLMutableAttributeList::getUnoTunnelId() throw() 79 { 80 static Sequence< sal_Int8 > * pSeq = 0; 81 if( !pSeq ) 82 { 83 Guard< Mutex > aGuard( Mutex::getGlobalMutex() ); 84 if( !pSeq ) 85 { 86 static Sequence< sal_Int8 > aSeq( 16 ); 87 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 88 pSeq = &aSeq; 89 } 90 } 91 return *pSeq; 92 } 93 94 // XUnoTunnel 95 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething( 96 const Sequence< sal_Int8 >& rId ) 97 throw( RuntimeException ) 98 { 99 if( rId.getLength() == 16 && 100 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 101 rId.getConstArray(), 16 ) ) 102 { 103 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this)); 104 } 105 return 0; 106 } 107 108 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength(void) 109 throw( RuntimeException ) 110 { 111 return m_xAttrList->getLength(); 112 } 113 114 115 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i) 116 throw( RuntimeException ) 117 { 118 return m_xAttrList->getNameByIndex( i ); 119 } 120 121 122 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i) 123 throw( RuntimeException ) 124 { 125 return m_xAttrList->getTypeByIndex( i ); 126 } 127 128 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i) 129 throw( RuntimeException ) 130 { 131 return m_xAttrList->getValueByIndex( i ); 132 } 133 134 OUString SAL_CALL XMLMutableAttributeList::getTypeByName( 135 const OUString& rName ) 136 throw( RuntimeException ) 137 { 138 return m_xAttrList->getTypeByName( rName ); 139 } 140 141 OUString SAL_CALL XMLMutableAttributeList::getValueByName( 142 const OUString& rName) 143 throw( RuntimeException ) 144 { 145 return m_xAttrList->getValueByName( rName ); 146 } 147 148 149 Reference< XCloneable > XMLMutableAttributeList::createClone() 150 throw( RuntimeException ) 151 { 152 // A cloned list will be a read only list! 153 Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList ); 154 return r; 155 } 156 157 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i, 158 const ::rtl::OUString& rValue ) 159 { 160 GetMutableAttrList()->SetValueByIndex( i, rValue ); 161 } 162 163 void XMLMutableAttributeList::AddAttribute( const OUString &rName , 164 const OUString &rValue ) 165 { 166 GetMutableAttrList()->AddAttribute( rName, rValue ); 167 } 168 169 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i ) 170 { 171 GetMutableAttrList()->RemoveAttributeByIndex( i ); 172 } 173 174 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i, 175 const OUString& rNewName ) 176 { 177 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName ); 178 } 179 180 void XMLMutableAttributeList::AppendAttributeList( 181 const Reference< ::com::sun::star::xml::sax::XAttributeList >& r ) 182 { 183 GetMutableAttrList()->AppendAttributeList( r ); 184 } 185 186 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const 187 { 188 sal_Int16 nIndex = -1; 189 if( m_pMutableAttrList ) 190 { 191 nIndex = m_pMutableAttrList->GetIndexByName( rName ); 192 } 193 else 194 { 195 sal_Int16 nCount = m_xAttrList->getLength(); 196 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i ) 197 { 198 if( m_xAttrList->getNameByIndex(i) == rName ) 199 nIndex = i; 200 } 201 } 202 return nIndex; 203 } 204