merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / MutableAttrList.cxx
blobbdf0de6318ccf63a5922706747cd94726a145a60
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MutableAttrList.cxx,v $
10 * $Revision: 1.10.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <osl/mutex.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <rtl/uuid.h>
36 #include <rtl/memory.h>
37 #include <xmloff/attrlist.hxx>
38 #include "MutableAttrList.hxx"
40 using ::rtl::OUString;
42 using namespace ::osl;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::util;
47 SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList()
49 if( !m_pMutableAttrList )
51 m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList );
52 m_xAttrList = m_pMutableAttrList;
55 return m_pMutableAttrList;
58 XMLMutableAttributeList::XMLMutableAttributeList() :
59 m_pMutableAttrList( new SvXMLAttributeList )
61 m_xAttrList = m_pMutableAttrList;
64 XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
65 XAttributeList> & rAttrList, sal_Bool bClone ) :
66 m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ),
67 m_pMutableAttrList( 0 )
69 if( bClone )
70 GetMutableAttrList();
74 XMLMutableAttributeList::~XMLMutableAttributeList()
76 m_xAttrList = 0;
80 // XUnoTunnel & co
81 const Sequence< sal_Int8 > & XMLMutableAttributeList::getUnoTunnelId() throw()
83 static Sequence< sal_Int8 > * pSeq = 0;
84 if( !pSeq )
86 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
87 if( !pSeq )
89 static Sequence< sal_Int8 > aSeq( 16 );
90 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
91 pSeq = &aSeq;
94 return *pSeq;
97 // XUnoTunnel
98 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
99 const Sequence< sal_Int8 >& rId )
100 throw( RuntimeException )
102 if( rId.getLength() == 16 &&
103 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
104 rId.getConstArray(), 16 ) )
106 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
108 return 0;
111 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength(void)
112 throw( RuntimeException )
114 return m_xAttrList->getLength();
118 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
119 throw( RuntimeException )
121 return m_xAttrList->getNameByIndex( i );
125 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
126 throw( RuntimeException )
128 return m_xAttrList->getTypeByIndex( i );
131 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
132 throw( RuntimeException )
134 return m_xAttrList->getValueByIndex( i );
137 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
138 const OUString& rName )
139 throw( RuntimeException )
141 return m_xAttrList->getTypeByName( rName );
144 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
145 const OUString& rName)
146 throw( RuntimeException )
148 return m_xAttrList->getValueByName( rName );
152 Reference< XCloneable > XMLMutableAttributeList::createClone()
153 throw( RuntimeException )
155 // A cloned list will be a read only list!
156 Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
157 return r;
160 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
161 const ::rtl::OUString& rValue )
163 GetMutableAttrList()->SetValueByIndex( i, rValue );
166 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
167 const OUString &rValue )
169 GetMutableAttrList()->AddAttribute( rName, rValue );
172 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
174 GetMutableAttrList()->RemoveAttributeByIndex( i );
177 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
178 const OUString& rNewName )
180 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
183 void XMLMutableAttributeList::AppendAttributeList(
184 const Reference< ::com::sun::star::xml::sax::XAttributeList >& r )
186 GetMutableAttrList()->AppendAttributeList( r );
189 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
191 sal_Int16 nIndex = -1;
192 if( m_pMutableAttrList )
194 nIndex = m_pMutableAttrList->GetIndexByName( rName );
196 else
198 sal_Int16 nCount = m_xAttrList->getLength();
199 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
201 if( m_xAttrList->getNameByIndex(i) == rName )
202 nIndex = i;
205 return nIndex;