1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <osl/mutex.hxx>
27cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
28cdf0e10cSrcweir #include <rtl/uuid.h>
29cdf0e10cSrcweir #include <rtl/memory.h>
30cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
31cdf0e10cSrcweir #include "MutableAttrList.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::osl;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::lang;
38cdf0e10cSrcweir using namespace ::com::sun::star::util;
39cdf0e10cSrcweir 
GetMutableAttrList()40cdf0e10cSrcweir SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	if( !m_pMutableAttrList )
43cdf0e10cSrcweir 	{
44cdf0e10cSrcweir 		m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList );
45cdf0e10cSrcweir 		m_xAttrList = m_pMutableAttrList;
46cdf0e10cSrcweir 	}
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	return m_pMutableAttrList;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
XMLMutableAttributeList()51cdf0e10cSrcweir XMLMutableAttributeList::XMLMutableAttributeList() :
52cdf0e10cSrcweir 	m_pMutableAttrList( new SvXMLAttributeList )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	m_xAttrList = m_pMutableAttrList;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
XMLMutableAttributeList(const Reference<XAttributeList> & rAttrList,sal_Bool bClone)57cdf0e10cSrcweir XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
58cdf0e10cSrcweir 		XAttributeList> & rAttrList, sal_Bool bClone ) :
59cdf0e10cSrcweir 	m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ),
60cdf0e10cSrcweir 	m_pMutableAttrList( 0 )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	if( bClone )
63cdf0e10cSrcweir 		GetMutableAttrList();
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
~XMLMutableAttributeList()67cdf0e10cSrcweir XMLMutableAttributeList::~XMLMutableAttributeList()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	m_xAttrList = 0;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // XUnoTunnel & co
getUnoTunnelId()74cdf0e10cSrcweir const Sequence< sal_Int8 > & XMLMutableAttributeList::getUnoTunnelId() throw()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	static Sequence< sal_Int8 > * pSeq = 0;
77cdf0e10cSrcweir 	if( !pSeq )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
80cdf0e10cSrcweir 		if( !pSeq )
81cdf0e10cSrcweir 		{
82cdf0e10cSrcweir 			static Sequence< sal_Int8 > aSeq( 16 );
83cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
84cdf0e10cSrcweir 			pSeq = &aSeq;
85cdf0e10cSrcweir 		}
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 	return *pSeq;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // XUnoTunnel
getSomething(const Sequence<sal_Int8> & rId)91cdf0e10cSrcweir sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
92cdf0e10cSrcweir 		const Sequence< sal_Int8 >& rId )
93cdf0e10cSrcweir 	throw( RuntimeException )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	if( rId.getLength() == 16 &&
96cdf0e10cSrcweir 		0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
97cdf0e10cSrcweir 								rId.getConstArray(), 16 ) )
98cdf0e10cSrcweir 	{
99cdf0e10cSrcweir 		return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir 	return 0;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
getLength(void)104cdf0e10cSrcweir sal_Int16 SAL_CALL XMLMutableAttributeList::getLength(void)
105cdf0e10cSrcweir 		throw( RuntimeException )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	return m_xAttrList->getLength();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
getNameByIndex(sal_Int16 i)111cdf0e10cSrcweir OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
112cdf0e10cSrcweir 		throw( RuntimeException )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	return m_xAttrList->getNameByIndex( i );
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 
getTypeByIndex(sal_Int16 i)118cdf0e10cSrcweir OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
119cdf0e10cSrcweir 		throw( RuntimeException )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	return m_xAttrList->getTypeByIndex( i );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
getValueByIndex(sal_Int16 i)124cdf0e10cSrcweir OUString SAL_CALL  XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
125cdf0e10cSrcweir 	throw( RuntimeException )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	return m_xAttrList->getValueByIndex( i );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
getTypeByName(const OUString & rName)130cdf0e10cSrcweir OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
131cdf0e10cSrcweir 		const OUString& rName )
132cdf0e10cSrcweir 		throw( RuntimeException )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	return m_xAttrList->getTypeByName( rName );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
getValueByName(const OUString & rName)137cdf0e10cSrcweir OUString SAL_CALL XMLMutableAttributeList::getValueByName(
138cdf0e10cSrcweir 		const OUString& rName)
139cdf0e10cSrcweir 		throw( RuntimeException )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	return m_xAttrList->getValueByName( rName );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
createClone()145cdf0e10cSrcweir Reference< XCloneable > XMLMutableAttributeList::createClone()
146cdf0e10cSrcweir 		throw( RuntimeException )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	// A cloned list will be a read only list!
149cdf0e10cSrcweir 	Reference< XCloneable >  r = new SvXMLAttributeList( m_xAttrList );
150cdf0e10cSrcweir 	return r;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
SetValueByIndex(sal_Int16 i,const::rtl::OUString & rValue)153cdf0e10cSrcweir void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
154cdf0e10cSrcweir 											   const ::rtl::OUString& rValue )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	GetMutableAttrList()->SetValueByIndex( i, rValue );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
AddAttribute(const OUString & rName,const OUString & rValue)159cdf0e10cSrcweir void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
160cdf0e10cSrcweir 											const OUString &rValue )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	GetMutableAttrList()->AddAttribute( rName, rValue );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
RemoveAttributeByIndex(sal_Int16 i)165cdf0e10cSrcweir void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	GetMutableAttrList()->RemoveAttributeByIndex( i );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
RenameAttributeByIndex(sal_Int16 i,const OUString & rNewName)170cdf0e10cSrcweir void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
171cdf0e10cSrcweir 												  	const OUString& rNewName )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
AppendAttributeList(const Reference<::com::sun::star::xml::sax::XAttributeList> & r)176cdf0e10cSrcweir void XMLMutableAttributeList::AppendAttributeList(
177cdf0e10cSrcweir 		const Reference< ::com::sun::star::xml::sax::XAttributeList >& r )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	GetMutableAttrList()->AppendAttributeList( r );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
GetIndexByName(const OUString & rName) const182cdf0e10cSrcweir sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	sal_Int16 nIndex = -1;
185cdf0e10cSrcweir 	if( m_pMutableAttrList )
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		nIndex = m_pMutableAttrList->GetIndexByName( rName );
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	else
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir 		sal_Int16 nCount = m_xAttrList->getLength();
192cdf0e10cSrcweir 		for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
193cdf0e10cSrcweir 		{
194cdf0e10cSrcweir 			if( m_xAttrList->getNameByIndex(i) == rName )
195cdf0e10cSrcweir 				nIndex = i;
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 	}
198cdf0e10cSrcweir 	return nIndex;
199cdf0e10cSrcweir }
200