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